public static CreateContextDesc WalkCreateContext(EsperEPL2GrammarParser.CreateContextExprContext ctx, IDictionary <ITree, ExprNode> astExprNodeMap, IDictionary <ITree, EvalFactoryNode> astPatternNodeMap, PropertyEvalSpec propertyEvalSpec, FilterSpecRaw filterSpec) { String contextName = ctx.name.Text; ContextDetail contextDetail; EsperEPL2GrammarParser.CreateContextChoiceContext choice = ctx.createContextDetail().createContextChoice(); if (choice != null) { contextDetail = WalkChoice(choice, astExprNodeMap, astPatternNodeMap, propertyEvalSpec, filterSpec); } else { contextDetail = WalkNested(ctx.createContextDetail().contextContextNested(), astExprNodeMap, astPatternNodeMap, propertyEvalSpec, filterSpec); } return(new CreateContextDesc(contextName, contextDetail)); }
private static ContextSpec WalkChoice( EsperEPL2GrammarParser.CreateContextChoiceContext ctx, IDictionary<ITree, ExprNode> astExprNodeMap, IDictionary<ITree, EvalForgeNode> astPatternNodeMap, PropertyEvalSpec propertyEvalSpec) { // 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 = ExprNodeUtilityQuery.EMPTY_EXPR_ARRAY; } else { distinctExpressions = ASTExprHelper.ExprCollectSubNodesPerNode( ctx.createContextDistinct().expressionList().expression(), astExprNodeMap); } } ContextSpecCondition startEndpoint; if (ctx.START() != null) { var immediate = CheckNow(ctx.i); if (immediate) { startEndpoint = ContextSpecConditionImmediate.INSTANCE; } else { startEndpoint = GetContextCondition(ctx.r1, astExprNodeMap, astPatternNodeMap, propertyEvalSpec, false); } } else { var immediate = CheckNow(ctx.i); startEndpoint = GetContextCondition(ctx.r1, astExprNodeMap, astPatternNodeMap, propertyEvalSpec, immediate); } var overlapping = ctx.INITIATED() != null; var endEndpoint = GetContextCondition(ctx.r2, astExprNodeMap, astPatternNodeMap, propertyEvalSpec, false); return new ContextSpecInitiatedTerminated(startEndpoint, endEndpoint, overlapping, distinctExpressions); } // partitioned if (ctx.PARTITION() != null) { IList<EsperEPL2GrammarParser.CreateContextPartitionItemContext> partitions = ctx.createContextPartitionItem(); IList<ContextSpecKeyedItem> rawSpecs = new List<ContextSpecKeyedItem>(); foreach (var partition in partitions) { var filterSpec = ASTFilterSpecHelper.WalkFilterSpec(partition.eventFilterExpression(), propertyEvalSpec, astExprNodeMap); propertyEvalSpec = null; IList<string> propertyNames = new List<string>(); IList<EsperEPL2GrammarParser.ChainableContext> properties = partition.chainable(); foreach (var property in properties) { var propertyName = ASTUtil.GetPropertyName(property, 0); propertyNames.Add(propertyName); } ASTExprHelper.ExprCollectSubNodes(partition, 0, astExprNodeMap); // remove expressions rawSpecs.Add( new ContextSpecKeyedItem( filterSpec, propertyNames, partition.keywordAllowedIdent() == null ? null : partition.keywordAllowedIdent().GetText())); } IList<ContextSpecConditionFilter> optionalInit = null; if (ctx.createContextPartitionInit() != null) { optionalInit = GetContextPartitionInit(ctx.createContextPartitionInit().createContextFilter(), astExprNodeMap); } ContextSpecCondition optionalTermination = null; if (ctx.createContextPartitionTerm() != null) { optionalTermination = GetContextCondition( ctx.createContextPartitionTerm().createContextRangePoint(), astExprNodeMap, astPatternNodeMap, propertyEvalSpec, false); } return new ContextSpecKeyed(rawSpecs, optionalInit, optionalTermination); } if (ctx.COALESCE() != null) { // hash IList<EsperEPL2GrammarParser.CreateContextCoalesceItemContext> coalesces = ctx.createContextCoalesceItem(); IList<ContextSpecHashItem> rawSpecs = new List<ContextSpecHashItem>(coalesces.Count); foreach (var coalesce in coalesces) { var chain = ASTChainSpecHelper.GetChainables(coalesce.chainable(), astExprNodeMap); var func = chain[0]; var filterSpec = ASTFilterSpecHelper.WalkFilterSpec(coalesce.eventFilterExpression(), propertyEvalSpec, astExprNodeMap); propertyEvalSpec = null; rawSpecs.Add(new ContextSpecHashItem(func, filterSpec)); } var granularity = ctx.g.Text; if (!granularity.ToLowerInvariant().Equals("granularity")) { throw ASTWalkException.From("Expected 'granularity' keyword after list of coalesce items, found '" + granularity + "' instead"); } var num = ASTConstantHelper.Parse(ctx.number()); var preallocateStr = ctx.p?.Text; if (preallocateStr != null && !preallocateStr.ToLowerInvariant().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 ContextSpecHash(rawSpecs, num.AsInt32(), preallocateStr != null); } // categorized if (ctx.createContextGroupItem() != null) { IList<EsperEPL2GrammarParser.CreateContextGroupItemContext> grps = ctx.createContextGroupItem(); IList<ContextSpecCategoryItem> items = new List<ContextSpecCategoryItem>(); foreach (var grp in grps) { var exprNode = ASTExprHelper.ExprCollectSubNodes(grp, 0, astExprNodeMap)[0]; var name = grp.i.Text; items.Add(new ContextSpecCategoryItem(exprNode, name)); } var filterSpec = ASTFilterSpecHelper.WalkFilterSpec(ctx.eventFilterExpression(), propertyEvalSpec, astExprNodeMap); return new ContextSpecCategory(items, filterSpec); } throw new IllegalStateException("Unrecognized context detail type"); }
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"); }