-
Notifications
You must be signed in to change notification settings - Fork 25.3k
EQL: Add optional fields #78769
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 optional fields #78769
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,13 @@ | |
"path": "sequence" | ||
} | ||
} | ||
}, | ||
"no_docs_field": { | ||
"type": "keyword" | ||
}, | ||
"default_null_value_field": { | ||
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. "optional_field_default_null" |
||
"type": "keyword", | ||
"null_value": "NULL" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ | |
|
||
import org.elasticsearch.xpack.ql.common.Failure; | ||
import org.elasticsearch.xpack.ql.expression.Attribute; | ||
import org.elasticsearch.xpack.ql.expression.NamedExpression; | ||
import org.elasticsearch.xpack.ql.expression.Expression; | ||
import org.elasticsearch.xpack.ql.expression.Literal; | ||
import org.elasticsearch.xpack.ql.expression.UnresolvedAttribute; | ||
import org.elasticsearch.xpack.ql.expression.function.Function; | ||
import org.elasticsearch.xpack.ql.expression.function.FunctionDefinition; | ||
|
@@ -21,21 +22,24 @@ | |
|
||
import java.util.Collection; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.elasticsearch.xpack.eql.analysis.AnalysisUtils.resolveAgainstList; | ||
import static org.elasticsearch.xpack.ql.analyzer.AnalyzerRules.AddMissingEqualsToBoolField; | ||
import org.elasticsearch.xpack.ql.analyzer.AnalyzerRules.AddMissingEqualsToBoolField; | ||
|
||
public class Analyzer extends RuleExecutor<LogicalPlan> { | ||
|
||
private final Configuration configuration; | ||
private final FunctionRegistry functionRegistry; | ||
private final Verifier verifier; | ||
private final Set<UnresolvedAttribute> optionals; | ||
|
||
public Analyzer(Configuration configuration, FunctionRegistry functionRegistry, Verifier verifier) { | ||
public Analyzer(Configuration configuration, FunctionRegistry functionRegistry, Verifier verifier, Set<UnresolvedAttribute> optionals) { | ||
this.configuration = configuration; | ||
this.functionRegistry = functionRegistry; | ||
this.verifier = verifier; | ||
this.optionals = optionals; | ||
} | ||
|
||
@Override | ||
|
@@ -62,7 +66,7 @@ private LogicalPlan verify(LogicalPlan plan) { | |
return plan; | ||
} | ||
|
||
private static class ResolveRefs extends AnalyzerRule<LogicalPlan> { | ||
private class ResolveRefs extends AnalyzerRule<LogicalPlan> { | ||
|
||
@Override | ||
protected LogicalPlan rule(LogicalPlan plan) { | ||
|
@@ -81,7 +85,11 @@ protected LogicalPlan rule(LogicalPlan plan) { | |
for (LogicalPlan child : plan.children()) { | ||
childrenOutput.addAll(child.output()); | ||
} | ||
NamedExpression named = resolveAgainstList(u, childrenOutput); | ||
Expression named = resolveAgainstList(u, childrenOutput); | ||
// if it's not resolved (it doesn't exist in mappings) and it's an optional field, replace it with "null" | ||
if (named == null && optionals.contains(u)) { | ||
named = Literal.NULL; | ||
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. you could preserve the source (for better error messaging):
|
||
} | ||
// if resolved, return it; otherwise keep it in place to be resolved later | ||
if (named != null) { | ||
if (log.isTraceEnabled()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,15 @@ | |
package org.elasticsearch.xpack.eql.parser; | ||
|
||
import org.elasticsearch.xpack.eql.parser.EqlBaseParser.SingleStatementContext; | ||
import org.elasticsearch.xpack.ql.expression.UnresolvedAttribute; | ||
import org.elasticsearch.xpack.ql.plan.logical.LogicalPlan; | ||
|
||
import java.util.Set; | ||
|
||
public class AstBuilder extends LogicalPlanBuilder { | ||
|
||
AstBuilder(ParserParams params) { | ||
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. You could keep the old constructor around and make it a shortcut to |
||
super(params); | ||
AstBuilder(ParserParams params, Set<UnresolvedAttribute> optionals) { | ||
super(params, optionals); | ||
} | ||
|
||
@Override | ||
|
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.
Improved name would be - "optional_field_mapping_only". Potentially drop optional.