示例#1
0
        private static ExprNode HandleVariable(
            IList <Chainable> chain,
            VariableMetaData variable,
            StatementSpecMapContext mapContext,
            Func <IList <Chainable>, ExprDotNodeImpl> dotNodeFunction)
        {
            var message = VariableUtil.CheckVariableContextName(mapContext.ContextName, variable);

            if (message != null)
            {
                throw new ValidationException(message);
            }

            ExprNode rootNode = new ExprVariableNodeImpl(variable, null);

            if (chain.Count == 1)
            {
                return(rootNode);
            }

            // Handle simple-subproperty by means of variable node
            if (chain.Count == 2 && chain[1] is ChainableName)
            {
                return(new ExprVariableNodeImpl(variable, chain[1].GetRootNameOrEmptyString()));
            }

            var         subchain = chain.SubList(1, chain.Count);
            ExprDotNode dot      = dotNodeFunction.Invoke(subchain);

            dot.AddChildNode(rootNode);
            return(dot);
        }
示例#2
0
        private static Pair<ExprNode, StatementSpecMapContext> GetExprDeclaredNode(
            Expression expression,
            ICollection<ExpressionDeclItem> stmtLocalExpressions,
            ContextCompileTimeDescriptor contextCompileTimeDescriptor,
            StatementSpecMapEnv mapEnv)
        {
            var mapContext = new StatementSpecMapContext(contextCompileTimeDescriptor, mapEnv);
            foreach (var item in stmtLocalExpressions) {
                mapContext.AddExpressionDeclarations(item);
            }

            var body = StatementSpecMapper.MapExpression(expression, mapContext);
            return new Pair<ExprNode, StatementSpecMapContext>(body, mapContext);
        }
示例#3
0
 private static Pair <Type, ImportSingleRowDesc> TrySingleRow(
     StatementSpecMapContext mapContext,
     string chainFirstName)
 {
     try {
         return(mapContext.ImportService.ResolveSingleRow(chainFirstName, mapContext.ClassProvidedExtension));
     }
     catch (ImportException) {
         return(null);
     }
     catch (ImportUndefinedException) {
         return(null);
     }
 }
示例#4
0
        private static Pair<ExprNode, StatementSpecMapContext> GetExprDeclaredNode(
            Expression expression,
            ICollection<ExpressionDeclItem> stmtLocalExpressions,
            ContextCompileTimeDescriptor contextCompileTimeDescriptor,
            StatementSpecMapEnv mapEnv,
            LazyAllocatedMap<HashableMultiKey, AggregationMultiFunctionForge> plugInAggregations,
            IList<ExpressionScriptProvided> scripts)
        {
            var mapContext = new StatementSpecMapContext(contextCompileTimeDescriptor, mapEnv, plugInAggregations, scripts);
            foreach (var item in stmtLocalExpressions) {
                mapContext.AddExpressionDeclaration(item);
            }

            var body = StatementSpecMapper.MapExpression(expression, mapContext);
            return new Pair<ExprNode, StatementSpecMapContext>(body, mapContext);
        }
示例#5
0
        public static ExprNode ProcessDot(
            bool useChainAsIs,
            bool resolveObjects,
            IList <Chainable> chain,
            StatementSpecMapContext mapContext)
        {
            if (chain.IsEmpty())
            {
                throw new ArgumentException("Empty chain");
            }

            Func <IList <Chainable>, ExprDotNodeImpl> dotNodeFunction = chainSpec => {
                var dotNode = new ExprDotNodeImpl(
                    chainSpec,
                    mapContext.Configuration.Compiler.Expression.IsDuckTyping,
                    mapContext.Configuration.Compiler.Expression.IsUdfCache);
                // add any variables that are referenced
                var variable = dotNode.IsVariableOpGetName(mapContext.VariableCompileTimeResolver);
                if (variable != null)
                {
                    mapContext.VariableNames.Add(variable.VariableName);
                }

                return(dotNode);
            };

            // Resolve objects if required
            if (resolveObjects)
            {
                var resolved = ResolveObject(chain, mapContext, dotNodeFunction);
                if (resolved != null)
                {
                    return(resolved);
                }
            }

            // Check if we are dealing with a plain event property expression, i.e. one without any eventstream-dependent expression
            var plain = DeterminePlainProperty(chain);

            if (plain)
            {
                return(HandlePlain(chain, dotNodeFunction, useChainAsIs));
            }

            return(HandleNonPlain(chain, dotNodeFunction));
        }
示例#6
0
        private static IList <Chainable> HandleClassPrefixedNonProp(
            StatementSpecMapContext mapContext,
            IList <Chainable> chain)
        {
            var indexOfLastProp = GetClassIndexOfLastProp(chain);

            if (indexOfLastProp == -1 || indexOfLastProp == chain.Count - 1)
            {
                return(null);
            }

            var depth      = indexOfLastProp;
            var depthFound = -1;

            while (depth > 0)
            {
                var classNameCandidateX = BuildClassName(chain, depth);
                try {
                    mapContext.ImportService.ResolveClass(classNameCandidateX, false, mapContext.ClassProvidedExtension);
                    depthFound = depth;
                    break;
                }
                catch (Exception) {
                    // expected, handled later when expression validation takes place
                }

                depth--;
            }

            if (depthFound == -1)
            {
                return(null);
            }

            if (depth == indexOfLastProp)
            {
                var classNameCandidateX = BuildClassName(chain, depth);
                return(BuildSubchainWClassname(classNameCandidateX, depth + 1, chain));
            }

            // include the next identifier, i.e. ENUM or CONSTANT etc.
            var classNameCandidate = BuildClassName(chain, depth + 1);

            return(BuildSubchainWClassname(classNameCandidate, depth + 2, chain));
        }
示例#7
0
        public static void ProcessChainable(
            EsperEPL2GrammarParser.ChainableContext ctx,
            IDictionary <ITree, ExprNode> astExprNodeMap,
            ContextCompileTimeDescriptor contextCompileTimeDescriptor,
            StatementSpecMapEnv mapEnv,
            StatementSpecRaw statementSpec,
            ExpressionDeclDesc expressionDeclarations,
            LazyAllocatedMap <HashableMultiKey, AggregationMultiFunctionForge> plugInAggregations,
            IList <ExpressionScriptProvided> scriptExpressions)
        {
            // we first convert the event property into chain spec
            IList <Chainable> chain = ASTChainSpecHelper.GetChainables(ctx, astExprNodeMap);

            // process chain
            StatementSpecMapContext mapContext = new StatementSpecMapContext(contextCompileTimeDescriptor, mapEnv, plugInAggregations, scriptExpressions);

            mapContext.AddExpressionDeclarations(expressionDeclarations);
            ExprNode node = ChainableWalkHelper.ProcessDot(false, true, chain, mapContext);

            astExprNodeMap.Put(ctx, node);
            mapContext.AddTo(statementSpec);
        }
示例#8
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);
        }