diff --git a/src/libraries/Microsoft.PowerFx.Connectors/Tabular/Capabilities/ServiceCapabilities.cs b/src/libraries/Microsoft.PowerFx.Connectors/Tabular/Capabilities/ServiceCapabilities.cs index 7c8ada31e..545b88bfd 100644 --- a/src/libraries/Microsoft.PowerFx.Connectors/Tabular/Capabilities/ServiceCapabilities.cs +++ b/src/libraries/Microsoft.PowerFx.Connectors/Tabular/Capabilities/ServiceCapabilities.cs @@ -132,11 +132,14 @@ namespace Microsoft.PowerFx.Connectors public static TableDelegationInfo ToDelegationInfo(ServiceCapabilities serviceCapabilities, string tableName, bool isReadOnly, ConnectorType connectorType, string datasetName) { - SortRestrictions sortRestriction = new SortRestrictions() - { - AscendingOnlyProperties = serviceCapabilities?.SortRestriction?.AscendingOnlyProperties, - UnsortableProperties = serviceCapabilities?.SortRestriction?.UnsortableProperties - }; + // sortRestriction == null means sortable = false + SortRestrictions sortRestriction = serviceCapabilities?.SortRestriction != null + ? new SortRestrictions() + { + AscendingOnlyProperties = serviceCapabilities.SortRestriction.AscendingOnlyProperties, + UnsortableProperties = serviceCapabilities.SortRestriction.UnsortableProperties + } + : null; FilterRestrictions filterRestriction = new FilterRestrictions() { @@ -144,10 +147,13 @@ namespace Microsoft.PowerFx.Connectors NonFilterableProperties = serviceCapabilities?.FilterRestriction?.NonFilterableProperties }; - SelectionRestrictions selectionRestriction = new SelectionRestrictions() - { - IsSelectable = serviceCapabilities?.SelectionRestriction?.IsSelectable ?? false - }; + // selectionRestriction == null means selectable = false + SelectionRestrictions selectionRestriction = serviceCapabilities?.SelectionRestriction != null + ? new SelectionRestrictions() + { + IsSelectable = serviceCapabilities.SelectionRestriction.IsSelectable + } + : null; GroupRestrictions groupRestriction = new GroupRestrictions() { @@ -255,6 +261,8 @@ namespace Microsoft.PowerFx.Connectors private static SortRestriction ParseSortRestriction(IDictionary capabilitiesMetaData) { IDictionary sortRestrictionMetaData = capabilitiesMetaData.GetObject(CapabilityConstants.SortRestrictions); + + // When "sortable" = false (or not defined), SortRestriction is null return sortRestrictionMetaData?.GetBool(CapabilityConstants.Sortable) == true ? new SortRestriction(sortRestrictionMetaData.GetList(CapabilityConstants.UnsortableProperties), sortRestrictionMetaData.GetList(CapabilityConstants.AscendingOnlyProperties)) : null; diff --git a/src/libraries/Microsoft.PowerFx.Core/Entities/External/DataSourceInfo.cs b/src/libraries/Microsoft.PowerFx.Core/Entities/External/DataSourceInfo.cs index 7f5d785b5..ef1e6a40d 100644 --- a/src/libraries/Microsoft.PowerFx.Core/Entities/External/DataSourceInfo.cs +++ b/src/libraries/Microsoft.PowerFx.Core/Entities/External/DataSourceInfo.cs @@ -64,7 +64,7 @@ namespace Microsoft.PowerFx.Core.Entities public DName EntityName { get; } - public bool IsSelectable => _delegationInfo.SelectionRestriction == null ? false : _delegationInfo.SelectionRestriction.IsSelectable; + public bool IsSelectable => _delegationInfo.IsSelectable; public bool IsDelegatable => _delegationInfo.IsDelegable; @@ -109,17 +109,17 @@ namespace Microsoft.PowerFx.Core.Entities bool IExternalTabularDataSource.CanIncludeSelect(IExpandInfo expandInfo, string selectColumnName) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } bool IExternalTabularDataSource.CanIncludeExpand(IExpandInfo expandToAdd) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } bool IExternalTabularDataSource.CanIncludeExpand(IExpandInfo parentExpandInfo, IExpandInfo expandToAdd) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } private static List GetCapabilityMetadata(AggregateType recordType, TableDelegationInfo delegationInfo) @@ -152,38 +152,45 @@ namespace Microsoft.PowerFx.Core.Entities } } - Dictionary sortRestrictions = new Dictionary(); - - if (delegationInfo?.SortRestriction?.UnsortableProperties != null) - { - foreach (string unsortableProperty in delegationInfo.SortRestriction.UnsortableProperties) - { - AddOrUpdate(sortRestrictions, unsortableProperty, DelegationCapability.Sort); - } - } - - if (delegationInfo?.SortRestriction?.AscendingOnlyProperties != null) - { - foreach (string ascendingOnlyProperty in delegationInfo.SortRestriction.AscendingOnlyProperties) - { - AddOrUpdate(sortRestrictions, ascendingOnlyProperty, DelegationCapability.SortAscendingOnly); - } - } - Dictionary oDataReplacements = new Dictionary(); FilterOpMetadata filterOpMetadata = new CdpFilterOpMetadata(recordType, delegationInfo); GroupOpMetadata groupOpMetadata = new GroupOpMetadata(type, groupByRestrictions); ODataOpMetadata oDataOpMetadata = new ODataOpMetadata(type, oDataReplacements); - SortOpMetadata sortOpMetadata = new SortOpMetadata(type, sortRestrictions); - return new List() + List metadataList = new List() { filterOpMetadata, groupOpMetadata, - oDataOpMetadata, - sortOpMetadata + oDataOpMetadata }; + + if (delegationInfo?.SortRestriction != null) + { + Dictionary sortRestrictions = new Dictionary(); + + if (delegationInfo?.SortRestriction?.UnsortableProperties != null) + { + foreach (string unsortableProperty in delegationInfo.SortRestriction.UnsortableProperties) + { + AddOrUpdate(sortRestrictions, unsortableProperty, DelegationCapability.Sort); + } + } + + if (delegationInfo?.SortRestriction?.AscendingOnlyProperties != null) + { + foreach (string ascendingOnlyProperty in delegationInfo.SortRestriction.AscendingOnlyProperties) + { + AddOrUpdate(sortRestrictions, ascendingOnlyProperty, DelegationCapability.SortAscendingOnly); + } + } + + SortOpMetadata sortOpMetadata = new SortOpMetadata(type, sortRestrictions); + + metadataList.Add(sortOpMetadata); + } + + return metadataList; } internal static DPath GetReplacementPath(string alias, DPath currentColumnPath) diff --git a/src/libraries/Microsoft.PowerFx.Core/Entities/External/TableDelegationInfo.cs b/src/libraries/Microsoft.PowerFx.Core/Entities/External/TableDelegationInfo.cs index ada22bc5b..4811feed9 100644 --- a/src/libraries/Microsoft.PowerFx.Core/Entities/External/TableDelegationInfo.cs +++ b/src/libraries/Microsoft.PowerFx.Core/Entities/External/TableDelegationInfo.cs @@ -13,6 +13,7 @@ namespace Microsoft.PowerFx.Core.Entities public abstract class TableDelegationInfo { // Defines unsortable columns or columns only supporting ascending ordering + // If set to null, the table is not sortable public SortRestrictions SortRestriction { get; init; } // Defines columns that cannot be sorted and required properties @@ -45,6 +46,12 @@ namespace Microsoft.PowerFx.Core.Entities // Read-Only table public bool IsReadOnly { get; init; } + // Defines when the table is sortable + public bool IsSortable => SortRestriction != null; + + // Defines when columns can be selected + public bool IsSelectable => SelectionRestriction != null && SelectionRestriction.IsSelectable; + // Dataset name public string DatasetName { get; init; } @@ -52,7 +59,7 @@ namespace Microsoft.PowerFx.Core.Entities // Key = field logical name, Value = foreign table logical name internal Dictionary ColumnsWithRelationships { get; init; } - public virtual bool IsDelegable => (SortRestriction != null) || (FilterRestriction != null) || (FilterFunctions != null); + public virtual bool IsDelegable => IsSortable || (FilterRestriction != null) || (FilterFunctions != null); public TableDelegationInfo() {