-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
[KQL Query] Create the ANTLR parser #114927
Conversation
Pinging @elastic/es-search (Team:Search) |
public class KqlParser { | ||
private static final Logger log = LogManager.getLogger(KqlParser.class); | ||
|
||
public QueryBuilder parseKqlQuery(String kqlQuery, SearchExecutionContext searchExecutionContext) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ This is the main entry point of the parser that we will use to implement the KqlQueryBuilder.
import org.elasticsearch.index.query.QueryBuilder; | ||
import org.elasticsearch.index.query.SearchExecutionContext; | ||
|
||
class KqlAstBuilder extends KqlBaseBaseVisitor<QueryBuilder> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ The KqlAstBuilder will transform the AST into a query builder.
The actual implementation will come in a later PR (the current behavior is to always return a match_all query).
|
||
import static org.elasticsearch.common.logging.LoggerMessageFormat.format; | ||
|
||
public class ParsingException extends ElasticsearchException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Using our own exception type for KQL parsing errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be named something explicit like KqlParsingException
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -0,0 +1,206 @@ | |||
// ANTLR GENERATED CODE: DO NOT EDIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ant:checkstyle] [ERROR] C:\bk\x-pack\plugin\kql\src\main\java\org\elasticsearch\xpack\kql\parser\KqlBaseListener.java:1: Duplicate header javadocs are forbidden [MultipleHeaderJavadoc]
@@ -0,0 +1,133 @@ | |||
// ANTLR GENERATED CODE: DO NOT EDIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,245 @@ | |||
// ANTLR GENERATED CODE: DO NOT EDIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,71 @@ | |||
token literal names: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,149 @@ | |||
// ANTLR GENERATED CODE: DO NOT EDIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,264 @@ | |||
// ANTLR GENERATED CODE: DO NOT EDIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this causes issues it seems in the windows builds.... not sure why.
[ant:checkstyle] [ERROR] C:\bk\x-pack\plugin\kql\src\main\java\org\elasticsearch\xpack\kql\parser\KqlBaseBaseListener.java:1: Duplicate header javadocs are forbidden [MultipleHeaderJavadoc]
@@ -0,0 +1,52 @@ | |||
token literal names: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,21 @@ | |||
DEFAULT_SKIP=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,21 @@ | |||
DEFAULT_SKIP=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x-pack/plugin/kql/src/test/java/org/elasticsearch/xpack/kql/parser/KqlParserTests.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/KqlPlugin.java
Show resolved
Hide resolved
x-pack/plugin/kql/src/test/java/org/elasticsearch/xpack/kql/parser/KqlParserTests.java
Outdated
Show resolved
Hide resolved
Pinging @elastic/es-search-relevance (Team:Search Relevance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good first step for KQL!
💚 Backport successful
|
import org.antlr.v4.runtime.*; | ||
import org.antlr.v4.runtime.atn.*; | ||
import org.antlr.v4.runtime.dfa.DFA; | ||
import org.antlr.v4.runtime.misc.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this imports don't follow the checkstyle rules of the repo
[ant:checkstyle] [ERROR] C:\bk\x-pack\plugin\kql\src\main\java\org\elasticsearch\xpack\kql\parser\KqlBaseLexer.java:13:8: Unused import - org.antlr.v4.runtime.Token. [UnusedImports]
[ant:checkstyle] [ERROR] C:\bk\x-pack\plugin\kql\src\main\java\org\elasticsearch\xpack\kql\parser\KqlBaseLexer.java:14:8: Unused import - org.antlr.v4.runtime.TokenStream. [UnusedImports]
[ant:checkstyle] [ERROR] C:\bk\x-pack\plugin\kql\src\main\java\org\elasticsearch\xpack\kql\parser\KqlBaseLexer.java:15:28: Using the '.*' form of import should be avoided - org.antlr.v4.runtime.*. [AvoidStarImport]
[ant:checkstyle] [ERROR] C:\bk\x-pack\plugin\kql\src\main\java\org\elasticsearch\xpack\kql\parser\KqlBaseLexer.java:16:32: Using the '.*' form of import should be avoided - org.antlr.v4.runtime.atn.*. [AvoidStarImport]
[ant:checkstyle] [ERROR] C:\bk\x-pack\plugin\kql\src\main\java\org\elasticsearch\xpack\kql\parser\KqlBaseLexer.java:18:33: Using the '.*' form of import should be avoided - org.antlr.v4.runtime.misc.*. [AvoidStarImport]
import org.antlr.v4.runtime.tree.*; | ||
import java.util.List; | ||
import java.util.Iterator; | ||
import java.util.ArrayList; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ant:checkstyle] [ERROR] C:\bk\x-pack\plugin\kql\src\main\java\org\elasticsearch\xpack\kql\parser\KqlBaseParser.java:1: Duplicate header javadocs are forbidden [MultipleHeaderJavadoc]
[ant:checkstyle] [ERROR] C:\bk\x-pack\plugin\kql\src\main\java\org\elasticsearch\xpack\kql\parser\KqlBaseParser.java:11:32: Using the '.*' form of import should be avoided - org.antlr.v4.runtime.atn.*. [AvoidStarImport]
[ant:checkstyle] [ERROR] C:\bk\x-pack\plugin\kql\src\main\java\org\elasticsearch\xpack\kql\parser\KqlBaseParser.java:13:28: Using the '.*' form of import should be avoided - org.antlr.v4.runtime.*. [AvoidStarImport]
[ant:checkstyle] [ERROR] C:\bk\x-pack\plugin\kql\src\main\java\org\elasticsearch\xpack\kql\parser\KqlBaseParser.java:14:33: Using the '.*' form of import should be avoided - org.antlr.v4.runtime.misc.*. [AvoidStarImport]
[ant:checkstyle] [ERROR] C:\bk\x-pack\plugin\kql\src\main\java\org\elasticsearch\xpack\kql\parser\KqlBaseParser.java:15:33: Using the '.*' form of import should be avoided - org.antlr.v4.runtime.tree.*. [AvoidStarImport]
[ant:checkstyle] [ERROR] C:\bk\x-pack\plugin\kql\src\main\java\org\elasticsearch\xpack\kql\parser\KqlBaseParser.java:17:8: Unused import - java.util.Iterator. [UnusedImports]
[ant:checkstyle] [ERROR] C:\bk\x-pack\plugin\kql\src\main\java\org\elasticsearch\xpack\kql\parser\KqlBaseParser.java:18:8: Unused import - java.util.ArrayList. [UnusedImports]
I was looking into the windows build failures (https://buildkite.com/elastic/elasticsearch-periodic-platform-support/builds/4478), and I think that perhaps the exclusions rules in the build.gradle file don't work properly on windows. I also noticed that in other places we have separate src folders for generated files, as opposed to having them together with other source files like we did here. That may simplify how we express the exclusions. |
Work done in the PR
kql
plugin intox-pack
:x-pack:plugin:kql:regen
task