Exemplo n.º 1
0
        internal static bool AssociateDataSourcesToSelect(this DType self, DataSourceToQueryOptionsMap dataSourceToQueryOptionsMap, string columnName, DType columnType, bool skipIfNotInSchema = false, bool skipExpands = false)
        {
            Contracts.AssertValue(dataSourceToQueryOptionsMap);
            Contracts.AssertNonEmpty(columnName);
            Contracts.AssertValue(columnType);

            bool retval = false;

            if (self.HasExpandInfo && self.ExpandInfo != null && !skipExpands)
            {
                var qOptions = dataSourceToQueryOptionsMap.GetOrCreateQueryOptions(self.ExpandInfo.ParentDataSource as IExternalTabularDataSource);
                retval |= qOptions.AddExpand(self.ExpandInfo, out var expandQueryOptions);
                if (expandQueryOptions != null)
                {
                    retval |= expandQueryOptions.AddSelect(columnName);
                }
            }
            else
            {
                foreach (var tabularDataSource in self.AssociatedDataSources)
                {
                    // Skip if this column doesn't belong to this datasource.
                    if (skipIfNotInSchema && !tabularDataSource.Schema.Contains(new DName(columnName)))
                    {
                        continue;
                    }

                    retval |= dataSourceToQueryOptionsMap.AddSelect((IExternalTabularDataSource)tabularDataSource, new DName(columnName));

                    if (columnType.IsExpandEntity && columnType.ExpandInfo != null && !skipExpands)
                    {
                        var scopedExpandInfo = columnType.ExpandInfo;
                        var qOptions         = dataSourceToQueryOptionsMap.GetOrCreateQueryOptions(scopedExpandInfo.ParentDataSource as IExternalTabularDataSource);
                        retval |= qOptions.AddExpand(scopedExpandInfo, out _);
                    }
                }
            }

            return(retval);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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);
        }