-
Notifications
You must be signed in to change notification settings - Fork 25.6k
EQL: Add AstBuilder to convert to QL tree #51558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ee75ddf
EQL: Add AstBuilder visitors
rw-access b237eea
EQL: Add tests for wildcards and sets
rw-access b594566
EQL: Fix licensing
rw-access 89c9126
EQL: Fix ExpressionTests.java license
rw-access 0658e2b
EQL: Cleanup imports
rw-access eba19f7
EQL: PR feedback and remove LiteralBuilder
rw-access d976f1e
EQL: Split off logical plan from expressions
rw-access 324f54c
EQL: Remove stray import
rw-access 7acdf28
EQL: Add predicate handling for set checks
rw-access 160ba32
EQL: Remove commented out dead code
rw-access 2edd948
EQL: Remove wildcard test, wait until analyzer
rw-access File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| import org.antlr.v4.runtime.misc.Interval; | ||
| import org.antlr.v4.runtime.tree.ParseTree; | ||
| import org.antlr.v4.runtime.tree.TerminalNode; | ||
| import org.elasticsearch.xpack.ql.expression.Expression; | ||
| import org.elasticsearch.xpack.ql.plan.logical.LogicalPlan; | ||
| import org.elasticsearch.xpack.ql.tree.Location; | ||
| import org.elasticsearch.xpack.ql.tree.Source; | ||
| import org.elasticsearch.xpack.ql.util.Check; | ||
|
|
@@ -25,6 +25,8 @@ | |
| */ | ||
| abstract class AbstractBuilder extends EqlBaseBaseVisitor<Object> { | ||
|
|
||
| private static final Pattern slashPattern = Pattern.compile("\\\\."); | ||
|
|
||
| @Override | ||
| public Object visit(ParseTree tree) { | ||
| Object result = super.visit(tree); | ||
|
|
@@ -44,12 +46,12 @@ protected <T> T typedParsing(ParseTree ctx, Class<T> type) { | |
| type.getSimpleName(), (result != null ? result.getClass().getSimpleName() : "null")); | ||
| } | ||
|
|
||
| protected Expression expression(ParseTree ctx) { | ||
| return typedParsing(ctx, Expression.class); | ||
| protected LogicalPlan plan(ParseTree ctx) { | ||
| return typedParsing(ctx, LogicalPlan.class); | ||
| } | ||
|
|
||
| protected List<Expression> expressions(List<? extends ParserRuleContext> ctxs) { | ||
| return visitList(ctxs, Expression.class); | ||
| protected List<LogicalPlan> plans(List<? extends ParserRuleContext> ctxs) { | ||
| return visitList(ctxs, LogicalPlan.class); | ||
| } | ||
|
|
||
| protected <T> List<T> visitList(List<? extends ParserRuleContext> contexts, Class<T> clazz) { | ||
|
|
@@ -113,14 +115,7 @@ static String text(ParseTree node) { | |
| return node == null ? null : node.getText(); | ||
| } | ||
|
|
||
| /** | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you can keep the comment. |
||
| * Extracts the actual unescaped string (literal) value of a terminal node. | ||
| */ | ||
| static String string(TerminalNode node) { | ||
| return node == null ? null : unquoteString(node.getText()); | ||
| } | ||
|
|
||
| static String unquoteString(String text) { | ||
| public static String unquoteString(String text) { | ||
| // remove leading and trailing ' for strings and also eliminate escaped single quotes | ||
| if (text == null) { | ||
| return null; | ||
|
|
@@ -132,9 +127,8 @@ static String unquoteString(String text) { | |
| } | ||
|
|
||
| text = text.substring(1, text.length() - 1); | ||
| Pattern regex = Pattern.compile("\\\\."); | ||
| StringBuffer resultString = new StringBuffer(); | ||
| Matcher regexMatcher = regex.matcher(text); | ||
| Matcher regexMatcher = slashPattern.matcher(text); | ||
|
|
||
| while (regexMatcher.find()) { | ||
| String source = regexMatcher.group(); | ||
|
|
@@ -167,6 +161,7 @@ static String unquoteString(String text) { | |
| replacement = "\\\\"; | ||
| break; | ||
| default: | ||
| // unknown escape sequence, pass through as-is | ||
| replacement = source; | ||
| } | ||
|
|
||
|
|
@@ -183,4 +178,5 @@ public Object visitTerminal(TerminalNode node) { | |
| Source source = source(node); | ||
| throw new ParsingException(source, "Does not know how to handle {}", source.text()); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.