public static AnnotationPart[] AnnotationsFromSpec(PatternStreamSpecRaw pattern) { Deque <AnnotationPart> parts = null; if (pattern.IsDiscardPartialsOnMatch) { parts = new ArrayDeque <AnnotationPart>(); parts.Add(new AnnotationPart(DISCARDPARTIALSONMATCH)); } if (pattern.IsSuppressSameEventMatches) { if (parts == null) { parts = new ArrayDeque <AnnotationPart>(); } parts.Add(new AnnotationPart(SUPPRESSOVERLAPPINGMATCHES)); } if (parts == null) { return(null); } return(parts.ToArray()); }
public static PatternStreamSpecCompiled CompilePattern( PatternStreamSpecRaw streamSpecRaw, ISet<string> eventTypeReferences, bool isInsertInto, bool isJoin, bool isContextDeclaration, bool isOnTrigger, string optionalStreamName, int streamNum, StatementRawInfo statementRawInfo, StatementCompileTimeServices services) { return CompilePatternWTags( streamSpecRaw, eventTypeReferences, isInsertInto, null, null, isJoin, isContextDeclaration, isOnTrigger, streamNum, statementRawInfo, services); }
public static void WalkStreamSpecs(StatementSpecRaw spec, ExprNodeSubselectDeclaredDotVisitor visitor) { // Determine filter streams foreach (StreamSpecRaw rawSpec in spec.StreamSpecs) { if (rawSpec is FilterStreamSpecRaw) { FilterStreamSpecRaw raw = (FilterStreamSpecRaw)rawSpec; foreach (ExprNode filterExpr in raw.RawFilterSpec.FilterExpressions) { filterExpr.Accept(visitor); } } if (rawSpec is PatternStreamSpecRaw) { PatternStreamSpecRaw patternStreamSpecRaw = (PatternStreamSpecRaw)rawSpec; EvalNodeAnalysisResult analysisResult = EvalNodeUtil.RecursiveAnalyzeChildNodes(patternStreamSpecRaw.EvalFactoryNode); foreach (EvalFactoryNode evalNode in analysisResult.ActiveNodes) { if (evalNode is EvalFilterFactoryNode) { EvalFilterFactoryNode filterNode = (EvalFilterFactoryNode)evalNode; foreach (ExprNode filterExpr in filterNode.RawFilterSpec.FilterExpressions) { filterExpr.Accept(visitor); } } } } } }
private String toPatternText(EPLTreeWalkerListener walker) { PatternStreamSpecRaw raw = (PatternStreamSpecRaw)walker.StatementSpec.StreamSpecs[0]; StringWriter writer = new StringWriter(); raw.EvalFactoryNode.ToEPL(writer, PatternExpressionPrecedenceEnum.MINIMUM); return(writer.ToString()); }
private Pair <MatchEventSpec, ISet <String> > ValidatePatternContextConditionPattern(StatementContext statementContext, ContextDetailConditionPattern pattern, ISet <String> eventTypesReferenced, MatchEventSpec priorMatches, ISet <String> priorAllTags) { var raw = new PatternStreamSpecRaw(pattern.PatternRaw, ViewSpec.EMPTY_VIEWSPEC_ARRAY, null, new StreamSpecOptions(), false, false); var compiled = raw.Compile(statementContext, eventTypesReferenced, false, Collections.GetEmptyList <int>(), priorMatches, priorAllTags, false, true, false); pattern.PatternCompiled = compiled; return(new Pair <MatchEventSpec, ISet <String> >(new MatchEventSpec(compiled.TaggedEventTypes, compiled.ArrayEventTypes), compiled.AllTags)); }
private PatternValidatedDesc ValidatePatternContextConditionPattern( bool isStartCondition, int nestingLevel, ContextSpecConditionPattern pattern, ISet<string> eventTypesReferenced, MatchEventSpec priorMatches, ISet<string> priorAllTags, CreateContextValidationEnv validationEnv) { var raw = new PatternStreamSpecRaw( pattern.PatternRaw, ViewSpec.EMPTY_VIEWSPEC_ARRAY, null, StreamSpecOptions.DEFAULT, false, false); var compiledDesc = StreamSpecCompiler.CompilePatternWTags( raw, eventTypesReferenced, false, priorMatches, priorAllTags, false, true, false, 0, validationEnv.StatementRawInfo, validationEnv.Services); var compiled = (PatternStreamSpecCompiled) compiledDesc.StreamSpecCompiled; pattern.PatternCompiled = compiled; pattern.PatternContext = new PatternContext( 0, compiled.MatchedEventMapMeta, true, nestingLevel, isStartCondition); var forges = compiled.Root.CollectFactories(); foreach (var forge in forges) { forge.CollectSelfFilterAndSchedule( validationEnv.FilterSpecCompileds, validationEnv.ScheduleHandleCallbackProviders); } var spec = new MatchEventSpec(compiled.TaggedEventTypes, compiled.ArrayEventTypes); return new PatternValidatedDesc(spec, compiled.AllTags, compiledDesc.AdditionalForgeables); }
public static void WalkStreamSpecs( StatementSpecRaw spec, ExprNodeSubselectDeclaredDotVisitor visitor) { // determine pattern-filter subqueries foreach (StreamSpecRaw streamSpecRaw in spec.StreamSpecs) { if (streamSpecRaw is PatternStreamSpecRaw) { PatternStreamSpecRaw patternStreamSpecRaw = (PatternStreamSpecRaw) streamSpecRaw; EvalNodeAnalysisResult analysisResult = EvalNodeUtil.RecursiveAnalyzeChildNodes(patternStreamSpecRaw.EvalForgeNode); foreach (EvalForgeNode evalNode in analysisResult.ActiveNodes) { if (evalNode is EvalFilterForgeNode) { EvalFilterForgeNode filterNode = (EvalFilterForgeNode) evalNode; foreach (ExprNode filterExpr in filterNode.RawFilterSpec.FilterExpressions) { filterExpr.Accept(visitor); } } else if (evalNode is EvalObserverForgeNode) { int beforeCount = visitor.Subselects.Count; EvalObserverForgeNode observerNode = (EvalObserverForgeNode) evalNode; foreach (ExprNode param in observerNode.PatternObserverSpec.ObjectParameters) { param.Accept(visitor); } if (visitor.Subselects.Count != beforeCount) { throw new ExprValidationException( "Subselects are not allowed within pattern observer parameters, please consider using a variable instead"); } } } } } // determine filter streams foreach (StreamSpecRaw rawSpec in spec.StreamSpecs) { if (rawSpec is FilterStreamSpecRaw) { FilterStreamSpecRaw raw = (FilterStreamSpecRaw) rawSpec; foreach (ExprNode filterExpr in raw.RawFilterSpec.FilterExpressions) { filterExpr.Accept(visitor); } } } }
public static PatternStreamSpecCompiled CompilePatternWTags( PatternStreamSpecRaw streamSpecRaw, ISet<string> eventTypeReferences, bool isInsertInto, MatchEventSpec tags, ISet<string> priorAllTags, bool isJoin, bool isContextDeclaration, bool isOnTrigger, int streamNum, StatementRawInfo statementRawInfo, StatementCompileTimeServices services) { // validate if ((streamSpecRaw.IsSuppressSameEventMatches || streamSpecRaw.IsDiscardPartialsOnMatch) && (isJoin || isContextDeclaration || isOnTrigger)) { throw new ExprValidationException( "Discard-partials and suppress-matches is not supported in a joins, context declaration and on-action"); } if (tags == null) { tags = new MatchEventSpec(); } var nodeStack = new Stack<EvalForgeNode>(); // detemine ordered tags var allTagNamesOrdered = new LinkedHashSet<string>(); var filterFactoryNodes = EvalNodeUtil.RecursiveGetChildNodes( streamSpecRaw.EvalForgeNode, FilterForFilterFactoryNodes.INSTANCE); if (priorAllTags != null) { allTagNamesOrdered.AddAll(priorAllTags); } foreach (var filterNode in filterFactoryNodes) { var forge = (EvalFilterForgeNode) filterNode; int tagNumber; if (forge.EventAsName != null) { if (!allTagNamesOrdered.Contains(forge.EventAsName)) { allTagNamesOrdered.Add(forge.EventAsName); tagNumber = allTagNamesOrdered.Count - 1; } else { tagNumber = FindTagNumber(forge.EventAsName, allTagNamesOrdered); } forge.EventAsTagNumber = tagNumber; } } // construct root : assigns factory node ids var top = streamSpecRaw.EvalForgeNode; var root = new EvalRootForgeNode(top, statementRawInfo.Annotations); RecursiveCompile( top, eventTypeReferences, isInsertInto, tags, nodeStack, allTagNamesOrdered, streamNum, statementRawInfo, services); var hook = (PatternCompileHook) ImportUtil.GetAnnotationHook( statementRawInfo.Annotations, HookType.INTERNAL_PATTERNCOMPILE, typeof(PatternCompileHook), services.ImportServiceCompileTime); if (hook != null) { hook.Pattern(root); } return new PatternStreamSpecCompiled( root, tags.TaggedEventTypes, tags.ArrayEventTypes, allTagNamesOrdered, streamSpecRaw.ViewSpecs, streamSpecRaw.OptionalStreamName, streamSpecRaw.Options, streamSpecRaw.IsSuppressSameEventMatches, streamSpecRaw.IsDiscardPartialsOnMatch); }
public static StatementSpecRaw CompilePattern( string expression, string expressionForErrorMessage, bool addPleaseCheck, EPServicesContext services, SelectClauseStreamSelectorEnum defaultStreamSelector) { // Parse ParseResult parseResult = ParseHelper.Parse( expression, expressionForErrorMessage, addPleaseCheck, PatternParseRule, true); ITree ast = parseResult.Tree; if (Log.IsDebugEnabled) { ASTUtil.DumpAST(ast); } // Walk var walker = new EPLTreeWalkerListener( parseResult.TokenStream, services.EngineImportService, services.VariableService, services.SchedulingService, defaultStreamSelector, services.EngineURI, services.ConfigSnapshot, services.PatternNodeFactory, services.ContextManagementService, parseResult.Scripts, services.ExprDeclaredService, services.TableService); try { ParseHelper.Walk(ast, walker, expression, expressionForErrorMessage); } catch (ASTWalkException ex) { Log.Debug(".createPattern Error validating expression", ex); throw new EPStatementException(ex.Message, expression); } catch (EPStatementSyntaxException ex) { throw; } catch (Exception ex) { string message = "Error in expression"; Log.Debug(message, ex); throw new EPStatementException(GetNullableErrortext(message, ex.Message), expression); } if (walker.StatementSpec.StreamSpecs.Count > 1) { throw new IllegalStateException("Unexpected multiple stream specifications encountered"); } // Get pattern specification PatternStreamSpecRaw patternStreamSpec = (PatternStreamSpecRaw)walker.StatementSpec.StreamSpecs[0]; // Create statement spec, set pattern stream, set wildcard select var statementSpec = new StatementSpecRaw(SelectClauseStreamSelectorEnum.ISTREAM_ONLY); statementSpec.StreamSpecs.Add(patternStreamSpec); statementSpec.SelectClauseSpec.SelectExprList.Clear(); statementSpec.SelectClauseSpec.SelectExprList.Add(new SelectClauseElementWildcard()); statementSpec.Annotations = walker.StatementSpec.Annotations; statementSpec.ExpressionNoAnnotations = parseResult.ExpressionWithoutAnnotations; return(statementSpec); }
public static void WalkStatement(StatementSpecRaw spec, ExprNodeSubselectDeclaredDotVisitor visitor) { // Look for expressions with sub-selects in select expression list and filter expression // Recursively compile the statement within the statement. foreach (SelectClauseElementRaw raw in spec.SelectClauseSpec.SelectExprList) { if (raw is SelectClauseExprRawSpec) { SelectClauseExprRawSpec rawExpr = (SelectClauseExprRawSpec)raw; rawExpr.SelectExpression.Accept(visitor); } else { continue; } } if (spec.FilterRootNode != null) { spec.FilterRootNode.Accept(visitor); } if (spec.HavingExprRootNode != null) { spec.HavingExprRootNode.Accept(visitor); } if (spec.UpdateDesc != null) { if (spec.UpdateDesc.OptionalWhereClause != null) { spec.UpdateDesc.OptionalWhereClause.Accept(visitor); } foreach (OnTriggerSetAssignment assignment in spec.UpdateDesc.Assignments) { assignment.Expression.Accept(visitor); } } if (spec.OnTriggerDesc != null) { VisitSubselectOnTrigger(spec.OnTriggerDesc, visitor); } // Determine pattern-filter subqueries foreach (StreamSpecRaw streamSpecRaw in spec.StreamSpecs) { if (streamSpecRaw is PatternStreamSpecRaw) { PatternStreamSpecRaw patternStreamSpecRaw = (PatternStreamSpecRaw)streamSpecRaw; EvalNodeAnalysisResult analysisResult = EvalNodeUtil.RecursiveAnalyzeChildNodes(patternStreamSpecRaw.EvalFactoryNode); foreach (EvalFactoryNode evalNode in analysisResult.ActiveNodes) { if (evalNode is EvalFilterFactoryNode) { EvalFilterFactoryNode filterNode = (EvalFilterFactoryNode)evalNode; foreach (ExprNode filterExpr in filterNode.RawFilterSpec.FilterExpressions) { filterExpr.Accept(visitor); } } else if (evalNode is EvalObserverFactoryNode) { int beforeCount = visitor.Subselects.Count; EvalObserverFactoryNode observerNode = (EvalObserverFactoryNode)evalNode; foreach (ExprNode param in observerNode.PatternObserverSpec.ObjectParameters) { param.Accept(visitor); } if (visitor.Subselects.Count != beforeCount) { throw new ExprValidationException("Subselects are not allowed within pattern observer parameters, please consider using a variable instead"); } } } } } // walk streams WalkStreamSpecs(spec, visitor); }
public static StreamSpecCompiledDesc CompilePatternWTags( PatternStreamSpecRaw streamSpecRaw, ISet<string> eventTypeReferences, bool isInsertInto, MatchEventSpec tags, ISet<string> priorAllTags, bool isJoin, bool isContextDeclaration, bool isOnTrigger, int streamNum, StatementRawInfo statementRawInfo, StatementCompileTimeServices services) { // validate if ((streamSpecRaw.IsSuppressSameEventMatches || streamSpecRaw.IsDiscardPartialsOnMatch) && (isJoin || isContextDeclaration || isOnTrigger)) { throw new ExprValidationException( "Discard-partials and suppress-matches is not supported in a joins, context declaration and on-action"); } if (tags == null) { tags = new MatchEventSpec(); } var nodeStack = new Stack<EvalForgeNode>(); // determine ordered tags ISet<string> allTagNamesOrdered = FilterSpecCompilerTagUtil.AssignEventAsTagNumber(priorAllTags, streamSpecRaw.EvalForgeNode); // construct root : assigns factory node ids var top = streamSpecRaw.EvalForgeNode; var root = new EvalRootForgeNode(services.IsAttachPatternText, top, statementRawInfo.Annotations); var additionalForgeables = new List<StmtClassForgeableFactory>(); RecursiveCompile( top, tags, nodeStack, allTagNamesOrdered, streamNum, additionalForgeables, statementRawInfo, services); var hook = (PatternCompileHook) ImportUtil.GetAnnotationHook( statementRawInfo.Annotations, HookType.INTERNAL_PATTERNCOMPILE, typeof(PatternCompileHook), services.ImportServiceCompileTime); hook?.Pattern(root); PatternStreamSpecCompiled compiled = new PatternStreamSpecCompiled( root, tags.TaggedEventTypes, tags.ArrayEventTypes, allTagNamesOrdered, streamSpecRaw.ViewSpecs, streamSpecRaw.OptionalStreamName, streamSpecRaw.Options, streamSpecRaw.IsSuppressSameEventMatches, streamSpecRaw.IsDiscardPartialsOnMatch); return new StreamSpecCompiledDesc(compiled, additionalForgeables); }