Exemple #1
0
        public Pair <ExprNode, IList <ExprChainedSpec> > GetTableNodeChainable(
            StreamTypeService streamTypeService,
            IList <ExprChainedSpec> chainSpec,
            EngineImportService engineImportService)
        {
            chainSpec = new List <ExprChainedSpec>(chainSpec);

            var unresolvedPropertyName = chainSpec[0].Name;
            var col = FindTableColumnMayByPrefixed(streamTypeService, unresolvedPropertyName);

            if (col == null)
            {
                return(null);
            }
            var pair = col.Pair;

            if (pair.Column is TableMetadataColumnAggregation)
            {
                var agg = (TableMetadataColumnAggregation)pair.Column;

                if (chainSpec.Count > 1)
                {
                    var candidateAccessor = chainSpec[1].Name;
                    var exprNode          = (ExprAggregateNodeBase)ASTAggregationHelper.TryResolveAsAggregation(engineImportService, false, candidateAccessor, new LazyAllocatedMap <ConfigurationPlugInAggregationMultiFunction, PlugInAggregationMultiFunctionFactory>(), streamTypeService.EngineURIQualifier);
                    if (exprNode != null)
                    {
                        var identNode = new ExprTableIdentNodeSubpropAccessor(pair.StreamNum, col.OptionalStreamName, agg, exprNode);
                        exprNode.AddChildNodes(chainSpec[1].Parameters);
                        chainSpec.RemoveAt(0);
                        chainSpec.RemoveAt(0);
                        return(new Pair <ExprNode, IList <ExprChainedSpec> >(identNode, chainSpec));
                    }
                }

                var node = new ExprTableIdentNode(null, unresolvedPropertyName);
                var eval = ExprTableEvalStrategyFactory.GetTableAccessEvalStrategy(node, pair.TableMetadata.TableName, pair.StreamNum, agg);
                node.Eval = eval;
                chainSpec.RemoveAt(0);
                return(new Pair <ExprNode, IList <ExprChainedSpec> >(node, chainSpec));
            }
            return(null);
        }
Exemple #2
0
        private static ExprNode ResolveObject(
            IList <Chainable> chain,
            StatementSpecMapContext mapContext,
            Func <IList <Chainable>, ExprDotNodeImpl> dotNodeFunction)
        {
            var chainFirst       = chain[0];
            var chainFirstName   = chainFirst.GetRootNameOrEmptyString();
            var chainFirstParams = chainFirst.GetParametersOrEmpty();

            // Handle script
            var scriptNode = ExprDeclaredHelper.GetExistsScript(
                mapContext.Configuration.Compiler.Scripts.DefaultDialect,
                chainFirstName,
                chainFirstParams,
                mapContext.Scripts,
                mapContext.MapEnv);

            if (scriptNode != null)
            {
                return(HandleScript(scriptNode, chain, dotNodeFunction));
            }

            // Handle Table-related exceptions
            // A table will be "table.more" or "table[x, ...].more"
            var table = mapContext.TableCompileTimeResolver.Resolve(chainFirstName);

            if (table != null)
            {
                var nodes = HandleTable(chain, table, dotNodeFunction);
                if (nodes != null)
                {
                    mapContext.TableExpressions.Add(nodes.Second);
                    return(nodes.First);
                }
            }

            // Handle Variable-related exceptions
            // A variable will be "variable.more" or "variable[x, ...].more"
            var variable = mapContext.VariableCompileTimeResolver.Resolve(chainFirstName);

            if (variable != null)
            {
                mapContext.VariableNames.Add(variable.VariableName);
                return(HandleVariable(chain, variable, mapContext, dotNodeFunction));
            }

            // Handle plug-in single-row functions
            var singleRow = TrySingleRow(mapContext, chainFirstName);

            if (singleRow != null)
            {
                return(HandleSingleRow(singleRow, chain));
            }

            // try additional built-in single-row function
            var singleRowExtNode = mapContext.ImportService.ResolveSingleRowExtendedBuiltin(chainFirstName);

            if (singleRowExtNode != null)
            {
                return(HandleSingleRowExt(singleRowExtNode, chain, dotNodeFunction));
            }

            // Handle declared-expression
            var declaredExpr = ExprDeclaredHelper.GetExistsDeclaredExpr(
                chainFirstName,
                chainFirstParams,
                mapContext.ExpressionDeclarations.Values,
                mapContext.ContextCompileTimeDescriptor,
                mapContext.MapEnv,
                mapContext.PlugInAggregations,
                mapContext.Scripts);

            if (declaredExpr != null)
            {
                mapContext.Add(declaredExpr.Second);
                return(HandleDeclaredExpr(declaredExpr.First, chain, dotNodeFunction));
            }

            // Handle aggregation function
            var aggregationNode = (chainFirst is ChainableName)
                                ? null
                                : ASTAggregationHelper.TryResolveAsAggregation(
                mapContext.ImportService,
                chainFirst.IsDistinct,
                chainFirstName,
                mapContext.PlugInAggregations,
                mapContext.ClassProvidedExtension);

            if (aggregationNode != null)
            {
                return(HandleAggregation(aggregationNode, chain, dotNodeFunction));
            }

            // Handle context property
            if (mapContext.ContextCompileTimeDescriptor != null &&
                mapContext.ContextCompileTimeDescriptor.ContextPropertyRegistry.IsContextPropertyPrefix(chainFirstName))
            {
                var subproperty = ToPlainPropertyString(chain, 1);
                return(new ExprContextPropertyNodeImpl(subproperty));
            }

            // Handle min-max case
            var chainFirstLowerCase = chainFirstName.ToLowerInvariant();

            if (!(chainFirst is ChainableName) &&
                (chainFirstLowerCase.Equals("max", StringComparison.InvariantCultureIgnoreCase) ||
                 chainFirstLowerCase.Equals("min", StringComparison.InvariantCultureIgnoreCase) ||
                 chainFirstLowerCase.Equals("fmax", StringComparison.InvariantCultureIgnoreCase) ||
                 chainFirstLowerCase.Equals("fmin", StringComparison.InvariantCultureIgnoreCase)))
            {
                return(HandleMinMax(chainFirstLowerCase, chain, dotNodeFunction));
            }

            // Handle class name
            var classChain = HandleClassPrefixedNonProp(mapContext, chain);

            if (classChain != null)
            {
                return(dotNodeFunction.Invoke(classChain));
            }

            return(null);
        }