public override bool UpdateDataQuerySelects(CallNode callNode, TexlBinding binding, DataSourceToQueryOptionsMap dataSourceToQueryOptionsMap) { Contracts.AssertValue(callNode); Contracts.AssertValue(binding); // Ignore delegation warning if (!CheckArgsCount(callNode, binding, DocumentErrorSeverity.Moderate)) { return(false); } TexlNode[] args = callNode.Args.Children.VerifyValue(); DType dsType = binding.GetType(args[0]); if (dsType.AssociatedDataSources == null) { return(false); } DType columnType = binding.GetType(args[1]); StrLitNode columnNode = args[1].AsStrLit(); if (columnType.Kind != DKind.String || columnNode == null) { return(false); } string columnName = columnNode.Value; Contracts.Assert(dsType.Contains(new DName(columnName))); return(dsType.AssociateDataSourcesToSelect(dataSourceToQueryOptionsMap, columnName, columnType, true)); }
public AllowedValuesMetadata(DType valuesSchema) { Contracts.Assert(valuesSchema.IsTable); Contracts.Assert(valuesSchema.Contains(ValueColumnName)); ValuesSchema = valuesSchema; }
public override bool UpdateDataQuerySelects(CallNode callNode, TexlBinding binding, DataSourceToQueryOptionsMap dataSourceToQueryOptionsMap) { Contracts.AssertValue(callNode); Contracts.AssertValue(binding); if (!CheckArgsCount(callNode, binding)) { return(false); } TexlNode[] args = callNode.Args.Children.VerifyValue(); DType dsType = binding.GetType(args[0]); if (dsType.AssociatedDataSources == null) { return(false); } var resultType = binding.GetType(callNode).VerifyValue(); bool retval = false; foreach (var typedName in resultType.GetNames(DPath.Root)) { DType columnType = typedName.Type; string columnName = typedName.Name.Value; Contracts.Assert(dsType.Contains(new DName(columnName))); retval |= dsType.AssociateDataSourcesToSelect(dataSourceToQueryOptionsMap, columnName, columnType, true); } return(retval); }
public override bool UpdateDataQuerySelects(CallNode callNode, TexlBinding binding, DataSourceToQueryOptionsMap dataSourceToQueryOptionsMap) { Contracts.AssertValue(callNode); Contracts.AssertValue(binding); if (!CheckArgsCount(callNode, binding, DocumentErrorSeverity.Moderate)) { return(false); } TexlNode[] args = callNode.Args.Children.VerifyValue(); DType dsType = binding.GetType(args[0]); if (dsType.AssociatedDataSources == null) { return(false); } bool retval = false; for (int i = 1; i < args.Length; i += 2) { DType columnType = binding.GetType(args[i]); StrLitNode columnNode = args[i].AsStrLit(); if (columnType.Kind != DKind.String || columnNode == null) { continue; } string columnName = columnNode.Value; Contracts.Assert(dsType.Contains(new DName(columnName))); retval |= dsType.AssociateDataSourcesToSelect(dataSourceToQueryOptionsMap, columnName, columnType, true); } return(retval); }
public override OperationCapabilityMetadata Parse(JsonElement dataServiceCapabilitiesJsonObject, DType schema) { Contracts.AssertValid(schema); // Check if any filter metadata is specified or not. var filterRestrictionExists = dataServiceCapabilitiesJsonObject.TryGetProperty(CapabilitiesConstants.Filter_Restriction, out var filterRestrictionJsonObject); var globalFilterFunctionsExists = dataServiceCapabilitiesJsonObject.TryGetProperty(CapabilitiesConstants.Filter_Functions, out var globalFilterFunctionsJsonArray); var globalFilterSupportsExists = dataServiceCapabilitiesJsonObject.TryGetProperty(CapabilitiesConstants.Filter_SupportedFunctions, out var globalFilterSupportedFunctionsJsonArray); var columnCapabilitiesExists = dataServiceCapabilitiesJsonObject.TryGetProperty(CapabilitiesConstants.ColumnsCapabilities, out var columnCapabilitiesJsonObj); if (!filterRestrictionExists && !globalFilterFunctionsExists && !globalFilterSupportsExists && !columnCapabilitiesExists) { return(null); } // Go through all filter restrictions if defined. var columnRestrictions = new Dictionary <DPath, DelegationCapability>(); // If any nonFilterablepropertis exist then mark each column as such. if (filterRestrictionExists && filterRestrictionJsonObject.TryGetProperty(CapabilitiesConstants.Filter_NonFilterableProperties, out var nonFilterablePropertiesJsonArray)) { foreach (var prop in nonFilterablePropertiesJsonArray.EnumerateArray()) { var columnName = DPath.Root.Append(new DName(prop.GetString())); if (!columnRestrictions.ContainsKey(columnName)) { columnRestrictions.Add(columnName, new DelegationCapability(DelegationCapability.Filter)); } } } // Check for any FilterFunctions defined at table level. DelegationCapability filterFunctionsSupportedByAllColumns = DelegationCapability.None; if (globalFilterFunctionsExists) { foreach (var op in globalFilterFunctionsJsonArray.EnumerateArray()) { var operatorStr = op.GetString(); Contracts.AssertNonEmpty(operatorStr); // If we don't support the operator then don't look at this capability. if (!DelegationCapability.OperatorToDelegationCapabilityMap.ContainsKey(operatorStr)) { continue; } // If filter functions are specified at table level then that means filter operation is supported. filterFunctionsSupportedByAllColumns |= DelegationCapability.OperatorToDelegationCapabilityMap[operatorStr] | DelegationCapability.Filter; } } // Check for any FilterSupportedFunctions defined at table level. DelegationCapability?filterFunctionsSupportedByTable = null; if (globalFilterSupportsExists) { filterFunctionsSupportedByTable = DelegationCapability.None; foreach (var op in globalFilterSupportedFunctionsJsonArray.EnumerateArray()) { var operatorStr = op.GetString(); Contracts.AssertNonEmpty(operatorStr); // If we don't support the operator then don't look at this capability. if (!DelegationCapability.OperatorToDelegationCapabilityMap.ContainsKey(operatorStr)) { continue; } // If filter functions are specified at table level then that means filter operation is supported. filterFunctionsSupportedByTable |= DelegationCapability.OperatorToDelegationCapabilityMap[operatorStr] | DelegationCapability.Filter; } } Dictionary <DPath, DelegationCapability> columnCapabilities = new Dictionary <DPath, DelegationCapability>(); if (!columnCapabilitiesExists) { return(new FilterOpMetadata(schema, columnRestrictions, columnCapabilities, filterFunctionsSupportedByAllColumns, filterFunctionsSupportedByTable)); } // Sweep through all column filter capabilities. foreach (var column in columnCapabilitiesJsonObj.EnumerateObject()) { var columnPath = DPath.Root.Append(new DName(column.Name)); // Internal columns don't appear in schema and we don't gather any information about it as they don't appear in expressions. // Task 790576: Runtime should provide visibility information along with delegation metadata information per column if (!schema.Contains(columnPath)) { continue; } // Get capabilities object for column var capabilitiesDefinedByColumn = column.Value; // Get properties object for the column if (capabilitiesDefinedByColumn.TryGetProperty(CapabilitiesConstants.Properties, out var propertyCapabilities)) { foreach (var property in propertyCapabilities.EnumerateObject()) { var propertyPath = columnPath.Append(new DName(property.Name)); var capabilitiesDefinedByColumnProperty = property.Value; if (!capabilitiesDefinedByColumnProperty.TryGetProperty(CapabilitiesConstants.Capabilities, out var propertyCapabilityJsonObject)) { continue; } var propertyCapability = ParseColumnCapability(propertyCapabilityJsonObject, capabilityKey: CapabilitiesConstants.Filter_Functions); if (propertyCapability.Capabilities != DelegationCapability.None) { Contracts.Assert(schema.Contains(propertyPath)); // If column is specified as non-filterable then this metadata shouldn't be present. // But if it is present then we should ignore it. if (!columnRestrictions.ContainsKey(propertyPath)) { columnCapabilities.Add(propertyPath, propertyCapability | DelegationCapability.Filter); } } } } // Get capability object defined for column. // This is optional as for columns with complex types (nested table or record), it will have "properties" key instead. // We are not supporting that case for now. So we ignore it currently. if (!capabilitiesDefinedByColumn.TryGetProperty(CapabilitiesConstants.Capabilities, out var capabilityJsonObject)) { continue; } var isChoice = capabilityJsonObject.TryGetProperty(CapabilitiesConstants.PropertyIsChoice, out var isChoiceElement) && isChoiceElement.GetBoolean(); var capability = ParseColumnCapability(capabilityJsonObject, capabilityKey: CapabilitiesConstants.Filter_Functions); if (capability.Capabilities != DelegationCapability.None) { Contracts.Assert(schema.Contains(columnPath)); // If column is specified as non-filterable then this metadata shouldn't be present. // But if it is present then we should ignore it. if (!columnRestrictions.ContainsKey(columnPath)) { columnCapabilities.Add(columnPath, capability | DelegationCapability.Filter); } if (isChoice == true) { var choicePropertyPath = columnPath.Append(new DName(ODataMetaParser.ValueProperty)); if (!columnRestrictions.ContainsKey(choicePropertyPath)) { columnCapabilities.Add(choicePropertyPath, capability | DelegationCapability.Filter); } } } } return(new FilterOpMetadata(schema, columnRestrictions, columnCapabilities, filterFunctionsSupportedByAllColumns, filterFunctionsSupportedByTable)); }