Skip to content
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

Merged
merged 18 commits into from
Oct 18, 2024
Merged

Conversation

afoucret
Copy link
Contributor

Work done in the PR

  • Created the new kql plugin into x-pack
  • ANTLR parser:
    • configure gradle to regenerate the parser from the grammar file by using the :x-pack:plugin:kql:regen task
    • initial version of the Kql grammar
    • generated parser code

@afoucret afoucret added >non-issue :Search/Search Search-related issues that do not fall into other categories v9.0.0 v8.17.0 labels Oct 16, 2024
@afoucret afoucret requested review from carlosdelest, ioanatia and a team October 16, 2024 16:20
@afoucret afoucret requested a review from a team as a code owner October 16, 2024 16:20
@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Oct 16, 2024
@elasticsearchmachine
Copy link
Collaborator

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) {
Copy link
Contributor Author

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> {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Generated code

Copy link
Member

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Generated code

@@ -0,0 +1,245 @@
// ANTLR GENERATED CODE: DO NOT EDIT
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Generated code

@@ -0,0 +1,71 @@
token literal names:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Generated code

@@ -0,0 +1,149 @@
// ANTLR GENERATED CODE: DO NOT EDIT
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Generated code

@@ -0,0 +1,264 @@
// ANTLR GENERATED CODE: DO NOT EDIT
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Generated code

Copy link
Member

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:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Generated code

@@ -0,0 +1,21 @@
DEFAULT_SKIP=1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Generated code

@@ -0,0 +1,21 @@
DEFAULT_SKIP=1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Generated code

@afoucret afoucret requested a review from ChrisHegarty October 16, 2024 16:31
@javanna javanna added :Search Relevance/Search Catch all for Search Relevance and removed :Search/Search Search-related issues that do not fall into other categories labels Oct 17, 2024
@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Oct 17, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

@elasticsearchmachine elasticsearchmachine removed the Team:Search Meta label for search team label Oct 17, 2024
Copy link
Member

@carlosdelest carlosdelest left a 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!

@afoucret afoucret added the auto-backport Automatically create backport pull requests when merged label Oct 17, 2024
@afoucret afoucret merged commit 6f60880 into elastic:main Oct 18, 2024
16 checks passed
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.x

afoucret added a commit to afoucret/elasticsearch that referenced this pull request Oct 18, 2024
lkts pushed a commit to lkts/elasticsearch that referenced this pull request Oct 18, 2024
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
Copy link
Member

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;
Copy link
Member

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]

@javanna
Copy link
Member

javanna commented Oct 21, 2024

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.

georgewallace pushed a commit to georgewallace/elasticsearch that referenced this pull request Oct 25, 2024
jfreden pushed a commit to jfreden/elasticsearch that referenced this pull request Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged >non-issue :Search Relevance/Search Catch all for Search Relevance Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v8.17.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants