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

EQL: Add AstBuilder to convert to QL tree #51558

Merged
merged 11 commits into from
Feb 3, 2020
Merged

EQL: Add AstBuilder to convert to QL tree #51558

merged 11 commits into from
Feb 3, 2020

Conversation

rw-access
Copy link
Contributor

@rw-access rw-access commented Jan 28, 2020

This adds visit* methods for the AstBuilder to convert an ANTLR tree into a QL tree. I've only scoped this to stateless expressions (no sequence, join, pipes, ancestry).

There are a few cases of EQL are just shorthand for now, unless we add more optimal/direct support within QL:

  • x in (a, b, c, ...) -> x == a or x == b or x == c or ...
  • x == "some*wildcard*expr*" -> wildcard(x, "some*wildcard*expr*")

Functions get turned into UnresolvedFunction. I think at some point, we'll need to add QL support for these or have these functions be EQL only with a custom registry. I haven't dived much into that yet to see how this works. I'm assuming that this will be done in a separate follow up PR (created issue #51556 for new functions)

Related Issues

@rw-access rw-access added the :Analytics/EQL EQL querying label Jan 28, 2020
@rw-access rw-access requested a review from costin January 28, 2020 18:16
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/EQL)

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

Left a number of comments. Also requested @matriv to take a look at it.
Thanks.

x-pack/plugin/eql/src/main/antlr/EqlBase.g4 Show resolved Hide resolved

switch (op.getSymbol().getType()) {
case EqlBaseParser.EQ:
// TODO: check for left == null after moving IsNotNull from SQL -> QL
Copy link
Member

Choose a reason for hiding this comment

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

IsNotNull and IsNull haven't been moved since in SQL null means missing as oppose to null value. This leads to subtle semantics such as 3-value bool logic (TRUE AND null -> null, FALSE AND null -> FALSE, TRUE AND TRUE -> TRUE).
Are the semantics the same ?

Copy link
Contributor Author

@rw-access rw-access Jan 29, 2020

Choose a reason for hiding this comment

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

Great point. We've used == null and != null for existence checks in EQL, but with ES can fields be set directly to null? That seems like it would rarely provide value. So I think we should be okay with using null as missing here too.

Copy link
Member

Choose a reason for hiding this comment

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

In ES null also means missing however one can set a default value to check on it (see https://www.elastic.co/guide/en/elasticsearch/reference/current/null-value.html).
The not null checks map nicely to dedicated queries (missing / not-missing). Not sure about the bool logic though but we can have dedicated AND / OR for EQL if the behavior differs from that of SQL.

}

// unescaped strings can be interpreted directly
if (text.startsWith("?")) {
Copy link
Member

Choose a reason for hiding this comment

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

Should it be ?" or is ?' allowed as well ? In both cases I would do the check a bit stricter to not trip if somehow a different char follows ?

Copy link
Contributor Author

@rw-access rw-access Jan 29, 2020

Choose a reason for hiding this comment

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

Both ?"..." and ?'...' are valid syntax, and enforced by the grammar, so we're okay. I can add a unit test for leaving a space between ? and "/' or something like that.

@costin costin requested a review from matriv January 29, 2020 15:10
Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

Left also a few comments.

x-pack/plugin/eql/src/main/antlr/EqlBase.g4 Show resolved Hide resolved
@@ -113,14 +115,7 @@ static String text(ParseTree node) {
return node == null ? null : node.getText();
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you can keep the comment.


/*
Copy link
Contributor

Choose a reason for hiding this comment

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

leftover?

assertEquals(new Or(null, lhs, rhs), booleanOr);
}

/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a TODO?

Copy link
Contributor

Choose a reason for hiding this comment

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

@rw-access Is this still needed as is?

@@ -33,4 +34,23 @@ public String name() {
public String toString() {
return name;
}

@Override
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

LGTM - @matriv?

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

LGTM, Please add the relevant version labels.

@costin
Copy link
Member

costin commented Jan 30, 2020

@matriv for EQL we agreed to not add any labels during development, only before the actual release.

@rw-access rw-access merged commit a462700 into elastic:master Feb 3, 2020
@rw-access rw-access deleted the eql-ast-builder branch February 3, 2020 19:00
costin added a commit that referenced this pull request Feb 5, 2020
* EQL: Plug query params into the AstBuilder (#51886)

As the eventType is customizable, plug that into the parser based on the
given request.

(cherry picked from commit 5b4a3a3)

* EQL: Add field resolution and verification (#51872)

Add basic field resolution inside the Analyzer and a basic Verifier to
check for any unresolved fields.

(cherry picked from commit 7087358)

* EQL: Introduce basic execution pipeline (#51809)

Add main classes that form the 'execution' pipeline are added - most of
them have no functionality; the purpose of this PR is to add flesh out
the contract between the various moving parts so that work can start on
them independently.

(cherry picked from commit 9a1bae5)

* EQL: Add AstBuilder to convert to QL tree (#51558)

* EQL: Add AstBuilder visitors
* EQL: Add tests for wildcards and sets
* EQL: Fix licensing
* EQL: Fix ExpressionTests.java license
* EQL: Cleanup imports
* EQL: PR feedback and remove LiteralBuilder
* EQL: Split off logical plan from expressions
* EQL: Remove stray import
* EQL: Add predicate handling for set checks
* EQL: Remove commented out dead code
* EQL: Remove wildcard test, wait until analyzer

(cherry picked from commit a462700)

* EQL grammar updates and tests (#49658)

* EQL: Additional tests and grammar updates
* EQL: Add backtick escaped identifiers
* EQL: Adding keywords to language
* EQL: Add checks for unsupported syntax
* EQL: Testing updates and PR feedback
* EQL: Add string escapes
* EQL: Cleanup grammar for identifier
* EQL: Remove tabs from .eql tests

(cherry picked from commit 6f1890b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/EQL EQL querying
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants