public void TestDisplayAST() { String expression = "A -> [10] B until C -> D"; Log.Debug(".testDisplayAST parsing: " + expression); Pair <ITree, CommonTokenStream> ast = Parse(expression); SupportParserHelper.DisplayAST(ast.First); }
private void AssertIsValid(string text) { Log.Debug(".assertIsValid Trying text=" + text); Pair<ITree, CommonTokenStream> ast = Parse(text); Log.Debug(".assertIsValid success, tree walking..."); SupportParserHelper.DisplayAST(ast.First); Log.Debug(".assertIsValid done"); }
private void AssertEquivalent(String expressionOne, String expressionTwo) { EPLTreeWalkerListener l1 = SupportParserHelper.ParseAndWalkPattern(expressionOne); EPLTreeWalkerListener l2 = SupportParserHelper.ParseAndWalkPattern(expressionTwo); String t1 = toPatternText(l1); String t2 = toPatternText(l2); Assert.AreEqual(t1, t2); }
public void TestParserNodeGeneration() { String expression = "a(m=1) -> not b() or every c() and d() where a:b (5) and timer:interval(10)"; Log.Debug(".testParserNodeGeneration parsing: " + expression); Pair <ITree, CommonTokenStream> parsed = Parse(expression); ITree ast = parsed.First; SupportParserHelper.DisplayAST(ast); }
public void TestGetPropertyNameEscaped() { String PROPERTY = "a\\.b\\.c"; Pair <ITree, CommonTokenStream> parsed = SupportParserHelper.ParseEventProperty(PROPERTY); ITree propertyNameExprNode = parsed.First.GetChild(0); ASTUtil.DumpAST(propertyNameExprNode); String propertyName = ((IRuleNode)propertyNameExprNode).GetText(); Assert.AreEqual(PROPERTY, propertyName); }
public void TestDisplayAST() { string expression = "select * from A where exp > ANY (select a from B)"; Log.Debug(".testDisplayAST parsing: " + expression); Pair<ITree, CommonTokenStream> ast = Parse(expression); SupportParserHelper.DisplayAST(ast.First); Log.Debug(".testDisplayAST walking..."); EPLTreeWalkerListener listener = SupportEPLTreeWalkerFactory.MakeWalker(ast.Second); var walker = new ParseTreeWalker(); // create standard walker walker.Walk(listener, (IParseTree) ast.First); // initiate walk of tree with listener }
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 TestGetPropertyName() { String PROPERTY = "a('aa').b[1].c"; // Should parse and result in the exact same property name Pair <ITree, CommonTokenStream> parsed = SupportParserHelper.ParseEventProperty(PROPERTY); ITree propertyNameExprNode = parsed.First.GetChild(0); ASTUtil.DumpAST(propertyNameExprNode); String propertyName = ((IRuleNode)propertyNameExprNode).GetText(); Assert.AreEqual(PROPERTY, propertyName); // Try AST with tokens separated, same property name parsed = SupportParserHelper.ParseEventProperty("a( 'aa' ). b [ 1 ] . c"); propertyNameExprNode = parsed.First.GetChild(0); propertyName = ((IRuleNode)propertyNameExprNode).GetText(); Assert.AreEqual(PROPERTY, propertyName); }
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 Pair <ITree, CommonTokenStream> ParseJson(String expression) { return(SupportParserHelper.ParseJson(expression)); }
private static FilterStreamSpecRaw MakeSpec(String expression) { EPLTreeWalkerListener walker = SupportParserHelper.ParseAndWalkEPL(expression); return((FilterStreamSpecRaw)walker.GetStatementSpec().StreamSpecs[0]); }
private static Pair <ITree, CommonTokenStream> Parse(String expression) { return(SupportParserHelper.ParseEPL(expression)); }
private Pair<ITree, CommonTokenStream> Parse(string expression) { return SupportParserHelper.ParseEPL(expression); }