-
Notifications
You must be signed in to change notification settings - Fork 25k
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: Plug query params into the AstBuilder #51886
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
14893bf
EQL: Add field resolution and verification
costin 55cdd80
EQL: Plug query params into the AstBuilder
costin a484445
Merge branch 'master' into eql/param-event_type
elasticmachine fabd408
Merge branch 'master' into eql/param-event_type
costin 1512fa5
Merge branch 'eql/param-event_type' of github.com:costin/elasticsearc…
costin 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 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 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
18 changes: 18 additions & 0 deletions
18
x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/action/RequestDefaults.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.eql.action; | ||
|
||
public final class RequestDefaults { | ||
|
||
private RequestDefaults() {} | ||
|
||
public static final String FIELD_TIMESTAMP = "@timestamp"; | ||
public static final String FIELD_EVENT_TYPE = "event_type"; | ||
public static final String IMPLICIT_JOIN_KEY = "agent.id"; | ||
|
||
public static int FETCH_SIZE = 50; | ||
} |
97 changes: 97 additions & 0 deletions
97
x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/analysis/AnalysisUtils.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.eql.analysis; | ||
|
||
import org.elasticsearch.xpack.ql.expression.Attribute; | ||
import org.elasticsearch.xpack.ql.expression.FieldAttribute; | ||
import org.elasticsearch.xpack.ql.expression.UnresolvedAttribute; | ||
import org.elasticsearch.xpack.ql.type.DataTypes; | ||
import org.elasticsearch.xpack.ql.type.InvalidMappedField; | ||
import org.elasticsearch.xpack.ql.type.UnsupportedEsField; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
|
||
public final class AnalysisUtils { | ||
|
||
private AnalysisUtils() {} | ||
|
||
// | ||
// Shared methods around the analyzer rules | ||
// | ||
static Attribute resolveAgainstList(UnresolvedAttribute u, Collection<Attribute> attrList) { | ||
return resolveAgainstList(u, attrList, false); | ||
} | ||
|
||
static Attribute resolveAgainstList(UnresolvedAttribute u, Collection<Attribute> attrList, boolean allowCompound) { | ||
List<Attribute> matches = new ArrayList<>(); | ||
|
||
// first take into account the qualified version | ||
boolean qualified = u.qualifier() != null; | ||
|
||
for (Attribute attribute : attrList) { | ||
if (!attribute.synthetic()) { | ||
boolean match = qualified ? Objects.equals(u.qualifiedName(), attribute.qualifiedName()) : | ||
// if the field is unqualified | ||
// first check the names directly | ||
(Objects.equals(u.name(), attribute.name()) | ||
// but also if the qualifier might not be quoted and if there's any ambiguity with nested fields | ||
|| Objects.equals(u.name(), attribute.qualifiedName())); | ||
if (match) { | ||
matches.add(attribute.withLocation(u.source())); | ||
} | ||
} | ||
} | ||
|
||
// none found | ||
if (matches.isEmpty()) { | ||
return null; | ||
} | ||
|
||
if (matches.size() == 1) { | ||
return handleSpecialFields(u, matches.get(0), allowCompound); | ||
} | ||
|
||
return u.withUnresolvedMessage( | ||
"Reference [" + u.qualifiedName() + "] is ambiguous (to disambiguate use quotes or qualifiers); matches any of " | ||
+ matches.stream().map(a -> "\"" + a.qualifier() + "\".\"" + a.name() + "\"").sorted().collect(toList())); | ||
} | ||
|
||
private static Attribute handleSpecialFields(UnresolvedAttribute u, Attribute named, boolean allowCompound) { | ||
// if it's a object/compound type, keep it unresolved with a nice error message | ||
if (named instanceof FieldAttribute) { | ||
FieldAttribute fa = (FieldAttribute) named; | ||
|
||
// incompatible mappings | ||
if (fa.field() instanceof InvalidMappedField) { | ||
named = u.withUnresolvedMessage("Cannot use field [" + fa.name() + "] due to ambiguities being " | ||
+ ((InvalidMappedField) fa.field()).errorMessage()); | ||
} | ||
// unsupported types | ||
else if (DataTypes.isUnsupported(fa.dataType())) { | ||
UnsupportedEsField unsupportedField = (UnsupportedEsField) fa.field(); | ||
if (unsupportedField.hasInherited()) { | ||
named = u.withUnresolvedMessage("Cannot use field [" + fa.name() + "] with unsupported type [" | ||
+ unsupportedField.getOriginalType() + "] " + "in hierarchy (field [" + unsupportedField.getInherited() + "])"); | ||
} else { | ||
named = u.withUnresolvedMessage( | ||
"Cannot use field [" + fa.name() + "] with unsupported type [" + unsupportedField.getOriginalType() + "]"); | ||
} | ||
} | ||
// compound fields | ||
else if (allowCompound == false && DataTypes.isPrimitive(fa.dataType()) == false) { | ||
named = u.withUnresolvedMessage( | ||
"Cannot use field [" + fa.name() + "] type [" + fa.dataType().typeName() + "] only its subfields"); | ||
} | ||
} | ||
return named; | ||
} | ||
} |
This file contains 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
27 changes: 27 additions & 0 deletions
27
x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/analysis/AnalyzerRule.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.eql.analysis; | ||
|
||
import org.elasticsearch.xpack.ql.plan.logical.LogicalPlan; | ||
import org.elasticsearch.xpack.ql.rule.Rule; | ||
|
||
public abstract class AnalyzerRule<SubPlan extends LogicalPlan> extends Rule<SubPlan, LogicalPlan> { | ||
|
||
// transformUp (post-order) - that is first children and then the node | ||
// but with a twist; only if the tree is not resolved or analyzed | ||
@Override | ||
public final LogicalPlan apply(LogicalPlan plan) { | ||
return plan.transformUp(t -> t.analyzed() || skipResolved() && t.resolved() ? t : rule(t), typeToken()); | ||
} | ||
|
||
@Override | ||
protected abstract LogicalPlan rule(SubPlan plan); | ||
|
||
protected boolean skipResolved() { | ||
return true; | ||
} | ||
} |
This file contains 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 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
15 changes: 15 additions & 0 deletions
15
...ql/src/main/java/org/elasticsearch/xpack/eql/expression/function/EqlFunctionRegistry.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.eql.expression.function; | ||
|
||
import org.elasticsearch.xpack.ql.expression.function.FunctionRegistry; | ||
|
||
public class EqlFunctionRegistry extends FunctionRegistry { | ||
|
||
public EqlFunctionRegistry() { | ||
} | ||
} |
This file contains 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 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.
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.
I think
event.category
is the best fit, but we can come back to this in another issue/PR.