コード例 #1
0
        private static ExprChainedSpec GetLibFunctionChainSpec(ASTLibModelChainElement element, IDictionary <ITree, ExprNode> astExprNodeMap)
        {
            var methodName = ASTConstantHelper.RemoveTicks(element.FuncName);
            var parameters = ASTLibFunctionHelper.GetExprNodesLibFunc(element.Args, astExprNodeMap);

            return(new ExprChainedSpec(methodName, parameters, !element.HasLeftParen));
        }
コード例 #2
0
ファイル: ASTAnnotationHelper.cs プロジェクト: valmac/nesper
 private static Object WalkValue(
     EsperEPL2GrammarParser.ElementValueEnumContext ctx,
     EngineImportService engineImportService)
 {
     if (ctx.elementValueArrayEnum() != null)
     {
         return(WalkArray(ctx.elementValueArrayEnum(), engineImportService));
     }
     if (ctx.annotationEnum() != null)
     {
         return(Walk(ctx.annotationEnum(), engineImportService));
     }
     else if (ctx.v != null)
     {
         return(ctx.v.Text);
     }
     else if (ctx.classIdentifier() != null)
     {
         return(WalkClassIdent(ctx.classIdentifier(), engineImportService));
     }
     else
     {
         return(ASTConstantHelper.Parse(ctx.constant()));
     }
 }
コード例 #3
0
        public static ExprChainedSpec GetLibFunctionChainSpec(EsperEPL2GrammarParser.LibFunctionNoClassContext ctx, IDictionary <ITree, ExprNode> astExprNodeMap)
        {
            var methodName = ASTConstantHelper.RemoveTicks(ctx.funcIdentChained().GetText());

            var parameters = GetExprNodesLibFunc(ctx.libFunctionArgs(), astExprNodeMap);
            var property   = ctx.l == null;

            return(new ExprChainedSpec(methodName, parameters, property));
        }
コード例 #4
0
ファイル: ASTExprHelper.cs プロジェクト: ikvm/nesper
        public static void AddOptionalNumber(ExprNode exprNode, EsperEPL2GrammarParser.NumberContext number)
        {
            if (number == null)
            {
                return;
            }
            ExprConstantNode constantNode = new ExprConstantNodeImpl(ASTConstantHelper.Parse(number));

            exprNode.AddChildNode(constantNode);
        }
コード例 #5
0
 private static Object ParseNumOrVariableIdent(EsperEPL2GrammarParser.NumberconstantContext num, IToken ident)
 {
     if (ident != null)
     {
         return(ident.Text);
     }
     else
     {
         return(ASTConstantHelper.Parse(num));
     }
 }
コード例 #6
0
 /// <summary>
 /// Walk an annotation root name or child node (nested annotations).
 /// </summary>
 /// <param name="node">annotation walk node</param>
 /// <returns>annotation descriptor</returns>
 /// <throws>com.espertech.esper.epl.parse.ASTWalkException if the walk failed</throws>
 public static Object Walk(CommonTokenStream tokenStream, EsperEPL2GrammarParser.JsonvalueContext node)
 {
     if (node.constant() != null)
     {
         EsperEPL2GrammarParser.ConstantContext constCtx = node.constant();
         if (constCtx.stringconstant() != null)
         {
             return(ExtractString(constCtx.stringconstant().GetText()));
         }
         else
         {
             return(ASTConstantHelper.Parse(constCtx.GetChild(0)));
         }
     }
     else if (node.jsonobject() != null)
     {
         return(WalkObject(tokenStream, node.jsonobject()));
     }
     else if (node.jsonarray() != null)
     {
         return(WalkArray(tokenStream, node.jsonarray()));
     }
     throw ASTWalkException.From("Encountered unexpected node type in json tree", tokenStream, node);
 }
コード例 #7
0
        /// <summary>
        /// Build an output limit spec from the AST node supplied.
        /// </summary>
        /// <param name="astExprNodeMap">is the map of current AST tree nodes to their respective expression root node</param>
        /// <param name="engineURI">the engine uri</param>
        /// <param name="timeProvider">provides time</param>
        /// <param name="variableService">provides variable resolution</param>
        /// <param name="exprEvaluatorContext">context for expression evaluatiom</param>
        /// <returns>output limit spec</returns>
        public static OutputLimitSpec BuildOutputLimitSpec(
            CommonTokenStream tokenStream,
            EsperEPL2GrammarParser.OutputLimitContext ctx,
            IDictionary <ITree, ExprNode> astExprNodeMap,
            VariableService variableService,
            String engineURI,
            TimeProvider timeProvider,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            OutputLimitLimitType displayLimit = OutputLimitLimitType.DEFAULT;

            if (ctx.k != null)
            {
                switch (ctx.k.Type)
                {
                case EsperEPL2GrammarParser.FIRST: displayLimit = OutputLimitLimitType.FIRST; break;

                case EsperEPL2GrammarParser.LAST: displayLimit = OutputLimitLimitType.LAST; break;

                case EsperEPL2GrammarParser.SNAPSHOT: displayLimit = OutputLimitLimitType.SNAPSHOT; break;

                case EsperEPL2GrammarParser.ALL: displayLimit = OutputLimitLimitType.ALL; break;

                default: throw ASTWalkException.From("Encountered unrecognized token " + ctx.k.Text, tokenStream, ctx);
                }
            }

            // next is a variable, or time period, or number
            String           variableName                  = null;
            double?          rate                          = null;
            ExprNode         whenExpression                = null;
            IList <ExprNode> crontabScheduleSpec           = null;
            IList <OnTriggerSetAssignment> thenExpressions = null;
            ExprTimePeriod                 timePeriodExpr  = null;
            OutputLimitRateType            rateType;
            ExprNode                       andAfterTerminateExpr           = null;
            IList <OnTriggerSetAssignment> andAfterTerminateSetExpressions = null;

            if (ctx.t != null)
            {
                rateType = OutputLimitRateType.TERM;
                if (ctx.expression() != null)
                {
                    andAfterTerminateExpr = ASTExprHelper.ExprCollectSubNodes(ctx.expression(), 0, astExprNodeMap)[0];
                }
                if (ctx.onSetExpr() != null)
                {
                    andAfterTerminateSetExpressions = ASTExprHelper.GetOnTriggerSetAssignments(ctx.onSetExpr().onSetAssignmentList(), astExprNodeMap);
                }
            }
            else if (ctx.wh != null)
            {
                rateType       = OutputLimitRateType.WHEN_EXPRESSION;
                whenExpression = ASTExprHelper.ExprCollectSubNodes(ctx.expression(), 0, astExprNodeMap)[0];
                if (ctx.onSetExpr() != null)
                {
                    thenExpressions = ASTExprHelper.GetOnTriggerSetAssignments(ctx.onSetExpr().onSetAssignmentList(), astExprNodeMap);
                }
            }
            else if (ctx.at != null)
            {
                rateType            = OutputLimitRateType.CRONTAB;
                crontabScheduleSpec = ASTExprHelper.ExprCollectSubNodes(ctx.crontabLimitParameterSet(), 0, astExprNodeMap);
            }
            else
            {
                if (ctx.ev != null)
                {
                    rateType = ctx.e != null ? OutputLimitRateType.EVENTS : OutputLimitRateType.TIME_PERIOD;
                    if (ctx.i != null)
                    {
                        variableName = ctx.i.Text;
                    }
                    else if (ctx.timePeriod() != null)
                    {
                        timePeriodExpr = (ExprTimePeriod)ASTExprHelper.ExprCollectSubNodes(ctx.timePeriod(), 0, astExprNodeMap)[0];
                    }
                    else
                    {
                        ASTExprHelper.ExprCollectSubNodes(ctx.number(), 0, astExprNodeMap);  // remove
                        rate = Double.Parse(ctx.number().GetText());
                    }
                }
                else
                {
                    rateType = OutputLimitRateType.AFTER;
                }
            }

            // get the AFTER time period
            ExprTimePeriod afterTimePeriodExpr = null;
            int?           afterNumberOfEvents = null;

            if (ctx.outputLimitAfter() != null)
            {
                if (ctx.outputLimitAfter().timePeriod() != null)
                {
                    ExprNode expression = ASTExprHelper.ExprCollectSubNodes(ctx.outputLimitAfter(), 0, astExprNodeMap)[0];
                    afterTimePeriodExpr = (ExprTimePeriod)expression;
                }
                else
                {
                    Object constant = ASTConstantHelper.Parse(ctx.outputLimitAfter().number());
                    afterNumberOfEvents = constant.AsInt();
                }
            }

            bool andAfterTerminate = false;

            if (ctx.outputLimitAndTerm() != null)
            {
                andAfterTerminate = true;
                if (ctx.outputLimitAndTerm().expression() != null)
                {
                    andAfterTerminateExpr = ASTExprHelper.ExprCollectSubNodes(ctx.outputLimitAndTerm().expression(), 0, astExprNodeMap)[0];
                }
                if (ctx.outputLimitAndTerm().onSetExpr() != null)
                {
                    andAfterTerminateSetExpressions = ASTExprHelper.GetOnTriggerSetAssignments(ctx.outputLimitAndTerm().onSetExpr().onSetAssignmentList(), astExprNodeMap);
                }
            }

            return(new OutputLimitSpec(rate, variableName, rateType, displayLimit, whenExpression, thenExpressions, crontabScheduleSpec, timePeriodExpr, afterTimePeriodExpr, afterNumberOfEvents, andAfterTerminate, andAfterTerminateExpr, andAfterTerminateSetExpressions));
        }
コード例 #8
0
        private static ContextDetail WalkChoice(EsperEPL2GrammarParser.CreateContextChoiceContext ctx, IDictionary <ITree, ExprNode> astExprNodeMap, IDictionary <ITree, EvalFactoryNode> astPatternNodeMap, PropertyEvalSpec propertyEvalSpec, FilterSpecRaw filterSpec)
        {
            // temporal fixed (start+end) and overlapping (initiated/terminated)
            if (ctx.START() != null || ctx.INITIATED() != null)
            {
                ExprNode[] distinctExpressions = null;
                if (ctx.createContextDistinct() != null)
                {
                    if (ctx.createContextDistinct().expressionList() == null)
                    {
                        distinctExpressions = new ExprNode[0];
                    }
                    else
                    {
                        distinctExpressions = ASTExprHelper.ExprCollectSubNodesPerNode(ctx.createContextDistinct().expressionList().expression(), astExprNodeMap);
                    }
                }

                ContextDetailCondition startEndpoint;
                if (ctx.START() != null)
                {
                    bool immediate = CheckNow(ctx.i);
                    if (immediate)
                    {
                        startEndpoint = new ContextDetailConditionImmediate();
                    }
                    else
                    {
                        startEndpoint = GetContextCondition(ctx.r1, astExprNodeMap, astPatternNodeMap, propertyEvalSpec, false);
                    }
                }
                else
                {
                    bool immediate = CheckNow(ctx.i);
                    startEndpoint = GetContextCondition(ctx.r1, astExprNodeMap, astPatternNodeMap, propertyEvalSpec, immediate);
                }

                bool overlapping = ctx.INITIATED() != null;
                ContextDetailCondition endEndpoint = GetContextCondition(ctx.r2, astExprNodeMap, astPatternNodeMap, propertyEvalSpec, false);
                return(new ContextDetailInitiatedTerminated(startEndpoint, endEndpoint, overlapping, distinctExpressions));
            }

            // partitioned
            if (ctx.PARTITION() != null)
            {
                IList <EsperEPL2GrammarParser.CreateContextPartitionItemContext> partitions = ctx.createContextPartitionItem();
                IList <ContextDetailPartitionItem> rawSpecs = new List <ContextDetailPartitionItem>();
                foreach (EsperEPL2GrammarParser.CreateContextPartitionItemContext partition in partitions)
                {
                    filterSpec       = ASTFilterSpecHelper.WalkFilterSpec(partition.eventFilterExpression(), propertyEvalSpec, astExprNodeMap);
                    propertyEvalSpec = null;

                    IList <String> propertyNames = new List <String>();
                    IList <EsperEPL2GrammarParser.EventPropertyContext> properties = partition.eventProperty();
                    foreach (EsperEPL2GrammarParser.EventPropertyContext property in properties)
                    {
                        String propertyName = ASTUtil.GetPropertyName(property, 0);
                        propertyNames.Add(propertyName);
                    }
                    ASTExprHelper.ExprCollectSubNodes(partition, 0, astExprNodeMap); // remove expressions

                    rawSpecs.Add(new ContextDetailPartitionItem(filterSpec, propertyNames));
                }
                return(new ContextDetailPartitioned(rawSpecs));
            }

            // hash
            else if (ctx.COALESCE() != null)
            {
                IList <EsperEPL2GrammarParser.CreateContextCoalesceItemContext> coalesces = ctx.createContextCoalesceItem();
                IList <ContextDetailHashItem> rawSpecs = new List <ContextDetailHashItem>(coalesces.Count);
                foreach (EsperEPL2GrammarParser.CreateContextCoalesceItemContext coalesce in coalesces)
                {
                    ExprChainedSpec func = ASTLibFunctionHelper.GetLibFunctionChainSpec(coalesce.libFunctionNoClass(), astExprNodeMap);
                    filterSpec       = ASTFilterSpecHelper.WalkFilterSpec(coalesce.eventFilterExpression(), propertyEvalSpec, astExprNodeMap);
                    propertyEvalSpec = null;
                    rawSpecs.Add(new ContextDetailHashItem(func, filterSpec));
                }

                String granularity = ctx.g.Text;
                if (!granularity.ToLower().Equals("granularity"))
                {
                    throw ASTWalkException.From("Expected 'granularity' keyword after list of coalesce items, found '" + granularity + "' instead");
                }
                var    num            = ASTConstantHelper.Parse(ctx.number());
                String preallocateStr = ctx.p != null ? ctx.p.Text : null;
                if (preallocateStr != null && !preallocateStr.ToLower().Equals("preallocate"))
                {
                    throw ASTWalkException.From("Expected 'preallocate' keyword after list of coalesce items, found '" + preallocateStr + "' instead");
                }
                if (!num.GetType().IsNumericNonFP() || num.GetType().GetBoxedType() == typeof(long?))
                {
                    throw ASTWalkException.From("Granularity provided must be an int-type number, received " + num.GetType() + " instead");
                }

                return(new ContextDetailHash(rawSpecs, num.AsInt(), preallocateStr != null));
            }

            // categorized
            if (ctx.createContextGroupItem() != null)
            {
                IList <EsperEPL2GrammarParser.CreateContextGroupItemContext> grps = ctx.createContextGroupItem();
                IList <ContextDetailCategoryItem> items = new List <ContextDetailCategoryItem>();
                foreach (EsperEPL2GrammarParser.CreateContextGroupItemContext grp in grps)
                {
                    ExprNode exprNode = ASTExprHelper.ExprCollectSubNodes(grp, 0, astExprNodeMap)[0];
                    String   name     = grp.i.Text;
                    items.Add(new ContextDetailCategoryItem(exprNode, name));
                }
                filterSpec = ASTFilterSpecHelper.WalkFilterSpec(ctx.eventFilterExpression(), propertyEvalSpec, astExprNodeMap);
                return(new ContextDetailCategory(items, filterSpec));
            }

            throw new IllegalStateException("Unrecognized context detail type");
        }