private String toPatternText(EPLTreeWalkerListener walker) { PatternStreamSpecRaw raw = (PatternStreamSpecRaw)walker.GetStatementSpec().StreamSpecs[0]; StringWriter writer = new StringWriter(); raw.EvalFactoryNode.ToEPL(writer, PatternExpressionPrecedenceEnum.MINIMUM); return(writer.ToString()); }
public void TestVisibilityAnalysis() { var patternTests = new String[][] { new [] { "A", "[]" }, new [] { "A B", "[B=[A]]" }, new [] { "A B*", "[B=[A]]" }, new [] { "A B B", "[B=[A]]" }, new [] { "A B A", "[A=[B], B=[A]]" }, new [] { "A B+ C", "[B=[A], C=[A, B]]" }, new [] { "(A B)+ C", "[B=[A], C=[A, B]]" }, new [] { "D (A B)+ (G H)? C", "[A=[D], B=[A, D], C=[A, B, D, G, H], G=[A, B, D], H=[A, B, D, G]]" }, new [] { "A B | A C", "[B=[A], C=[A]]" }, new [] { "(A B*) | (A+ C)", "[B=[A], C=[A]]" }, new [] { "A (B | C) D", "[B=[A], C=[A], D=[A, B, C]]" }, new [] { "(((A))) (((B))) (( C | (D E)))", "[B=[A], C=[A, B], D=[A, B], E=[A, B, D]]" }, new [] { "(A | B) C", "[C=[A, B]]" }, new [] { "(A | B) (C | A)", "[A=[B], C=[A, B]]" }, }; for (int i = 0; i < patternTests.Length; i++) { String pattern = patternTests[i][0]; String expected = patternTests[i][1]; String expression = "select * from MyEvent.win:keepall() match_recognize (" + " partition by string measures A.string as a_string pattern ( " + pattern + ") define A as (A.value = 1) )"; EPLTreeWalkerListener walker = SupportParserHelper.ParseAndWalkEPL(expression); StatementSpecRaw raw = walker.GetStatementSpec(); RowRegexExprNode parent = raw.MatchRecognizeSpec.Pattern; IDictionary <String, ISet <String> > visibility = EventRowRegexHelper.DetermineVisibility(parent); // sort, for comparing var visibilitySorted = new LinkedHashMap <String, IList <String> >(); var tagsSorted = new List <String>(visibility.Keys); tagsSorted.Sort(); foreach (string tag in tagsSorted) { var sorted = new List <String>(visibility.Get(tag)); sorted.Sort(); visibilitySorted.Put(tag, sorted); } Assert.AreEqual(expected, visibilitySorted.Render(), "Failed in :" + pattern); } }
public void TestVariableAnalysis() { var patternTests = new String[][] { new[] { "A", "[A]", "[]" }, new[] { "A B", "[A, B]", "[]" }, new[] { "A B*", "[A]", "[B]" }, new[] { "A B B", "[A]", "[B]" }, new[] { "A B A", "[B]", "[A]" }, new[] { "A B+ C", "[A, C]", "[B]" }, new[] { "A B?", "[A, B]", "[]" }, new[] { "(A B)* C", "[C]", "[A, B]" }, new[] { "D (A B)+ (G H)? C", "[D, G, H, C]", "[A, B]" }, new[] { "A B | A C", "[A, B, C]", "[]" }, new[] { "(A B*) | (A+ C)", "[C]", "[B, A]" }, new[] { "(A | B) | (C | A)", "[A, B, C]", "[]" }, }; for (int i = 0; i < patternTests.Length; i++) { String pattern = patternTests[i][0]; String expression = "select * from MyEvent.win:keepall() match_recognize (" + " partition by TheString measures A.TheString as a_string pattern ( " + pattern + ") define A as (A.value = 1) )"; EPLTreeWalkerListener walker = SupportParserHelper.ParseAndWalkEPL(expression); StatementSpecRaw raw = walker.GetStatementSpec(); RowRegexExprNode parent = raw.MatchRecognizeSpec.Pattern; var singles = new FIFOHashSet <String>(); var multiples = new FIFOHashSet <String>(); EventRowRegexHelper.RecursiveInspectVariables(parent, false, singles, multiples); String @out = "Failed in :" + pattern + " result is : single " + singles.Render() + " multiple " + multiples.Render(); Assert.AreEqual(patternTests[i][1], singles.Render(), @out); Assert.AreEqual(patternTests[i][2], multiples.Render(), @out); } }
private static FilterStreamSpecRaw MakeSpec(String expression) { EPLTreeWalkerListener walker = SupportParserHelper.ParseAndWalkEPL(expression); return((FilterStreamSpecRaw)walker.GetStatementSpec().StreamSpecs[0]); }
public static StatementSpecRaw CompilePattern(String expression, String expressionForErrorMessage, bool addPleaseCheck, EPServicesContext services, SelectClauseStreamSelectorEnum defaultStreamSelector) { // Parse ParseResult parseResult = ParseHelper.Parse(expression, expressionForErrorMessage, addPleaseCheck, PatternParseRule, true); var ast = parseResult.Tree; if (Log.IsDebugEnabled) { ASTUtil.DumpAST(ast); } // Walk EPLTreeWalkerListener 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); } var walkerStatementSpec = walker.GetStatementSpec(); if (walkerStatementSpec.StreamSpecs.Count > 1) { throw new IllegalStateException("Unexpected multiple stream specifications encountered"); } // Get pattern specification var patternStreamSpec = (PatternStreamSpecRaw)walkerStatementSpec.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 = walkerStatementSpec.Annotations; statementSpec.ExpressionNoAnnotations = parseResult.ExpressionWithoutAnnotations; return(statementSpec); }
/// <summary> /// Compile the EPL. /// </summary> /// <param name="eplStatement">expression to compile</param> /// <param name="eplStatementForErrorMsg">use this text for the error message</param> /// <param name="addPleaseCheck">indicator to add a "please check" wording for stack paraphrases</param> /// <param name="statementName">is the name of the statement</param> /// <param name="defaultStreamSelector">the configuration for which insert or remove streams (or both) to produce</param> /// <param name="engineImportService">The engine import service.</param> /// <param name="variableService">The variable service.</param> /// <param name="schedulingService">The scheduling service.</param> /// <param name="engineURI">The engine URI.</param> /// <param name="configSnapshot">The config snapshot.</param> /// <param name="patternNodeFactory">The pattern node factory.</param> /// <param name="contextManagementService">The context management service.</param> /// <param name="exprDeclaredService">The expr declared service.</param> /// <param name="tableService">The table service.</param> /// <returns> /// statement specification /// </returns> /// <exception cref="EPStatementException"> /// </exception> public static StatementSpecRaw CompileEPL( String eplStatement, String eplStatementForErrorMsg, bool addPleaseCheck, String statementName, SelectClauseStreamSelectorEnum defaultStreamSelector, EngineImportService engineImportService, VariableService variableService, SchedulingService schedulingService, String engineURI, ConfigurationInformation configSnapshot, PatternNodeFactory patternNodeFactory, ContextManagementService contextManagementService, ExprDeclaredService exprDeclaredService, TableService tableService) { if (Log.IsDebugEnabled) { Log.Debug(".createEPLStmt StatementName=" + statementName + " eplStatement=" + eplStatement); } var parseResult = ParseHelper.Parse(eplStatement, eplStatementForErrorMsg, addPleaseCheck, EPLParseRule, true); var ast = parseResult.Tree; EPLTreeWalkerListener walker = new EPLTreeWalkerListener( parseResult.TokenStream, engineImportService, variableService, schedulingService, defaultStreamSelector, engineURI, configSnapshot, patternNodeFactory, contextManagementService, parseResult.Scripts, exprDeclaredService, tableService); try { ParseHelper.Walk(ast, walker, eplStatement, eplStatementForErrorMsg); } catch (ASTWalkException ex) { Log.Error(".createEPL Error validating expression", ex); throw new EPStatementException(ex.Message, eplStatementForErrorMsg, ex); } catch (EPStatementSyntaxException) { throw; } catch (Exception ex) { const string message = "Error in expression"; Log.Debug(message, ex); throw new EPStatementException(GetNullableErrortext(message, ex.Message), eplStatementForErrorMsg, ex); } if (Log.IsDebugEnabled) { ASTUtil.DumpAST(ast); } StatementSpecRaw raw = walker.GetStatementSpec(); raw.ExpressionNoAnnotations = parseResult.ExpressionWithoutAnnotations; return(raw); }