-
Notifications
You must be signed in to change notification settings - Fork 25.2k
ES|QL: Make Fork n-ary #126074
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
ES|QL: Make Fork n-ary #126074
Conversation
var mappedChild = new FragmentExec(child); | ||
physicalChildren.add(mappedChild); | ||
} | ||
return new MergeExec(merge.source(), physicalChildren, merge.output()); | ||
return new MergeExec(fork.source(), physicalChildren, fork.output()); |
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 have kept the name MergeExec
because from an execution standpoint we are merging results from multiple sub plans.
When we add support for multiple forks (fork after fork) - we would likely need a ForkExec
too.
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.
that make sense to me. ++
List<Enrich> unresolvedEnriches = new ArrayList<>(); | ||
List<TableInfo> lookupIndices = new ArrayList<>(); | ||
|
||
plan.forEachUp(UnresolvedRelation.class, p -> { | ||
List<TableInfo> list = p.indexMode() == IndexMode.LOOKUP ? lookupIndices : indices; | ||
list.add(new TableInfo(p.indexPattern())); | ||
Collection<TableInfo> collection = p.indexMode() == IndexMode.LOOKUP ? lookupIndices : indices; |
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 needed to make this change and the ones in TableInfo
because otherwise queries using FORK would fail with the following errror:
elasticsearch/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java
Lines 434 to 438 in d302962
// TODO we plan to support joins in the future when possible, but for now we'll just fail early if we see one | |
if (indices.size() > 1) { | |
// Note: JOINs are not supported but we detect them when | |
listener.onFailure(new MappingException("Queries with multiple indices are not supported")); | |
} else if (indices.size() == 1) { |
Note that this only ensures that we collect distinct values for indices
, not lookupIndices
, meaning there should be no effect on the lookup join functionality.
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 makes sense to. I don't remember exactly, but I did run into this in the past but then didn't need it for a separate reason.
Pinging @elastic/es-analytical-engine (Team:Analytics) |
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 a good change and addresses a number of follow-up tasks that arose during the initial FORK implementation. LGTM
@@ -1458,23 +1418,6 @@ private static Expression castStringLiteral(Expression from, DataType target) { | |||
} | |||
} | |||
|
|||
private static class ImplicitForkCasting extends ParameterizedRule<LogicalPlan, LogicalPlan, AnalyzerContext> { |
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.
Thanks for removing these XXForkXX rules, I was hoping that we could be get to this point when I added them originally.
List<Enrich> unresolvedEnriches = new ArrayList<>(); | ||
List<TableInfo> lookupIndices = new ArrayList<>(); | ||
|
||
plan.forEachUp(UnresolvedRelation.class, p -> { | ||
List<TableInfo> list = p.indexMode() == IndexMode.LOOKUP ? lookupIndices : indices; | ||
list.add(new TableInfo(p.indexPattern())); | ||
Collection<TableInfo> collection = p.indexMode() == IndexMode.LOOKUP ? lookupIndices : indices; |
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 makes sense to. I don't remember exactly, but I did run into this in the past but then didn't need it for a separate reason.
var mappedChild = new FragmentExec(child); | ||
physicalChildren.add(mappedChild); | ||
} | ||
return new MergeExec(merge.source(), physicalChildren, merge.output()); | ||
return new MergeExec(fork.source(), physicalChildren, fork.output()); |
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.
that make sense to me. ++
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.
LGTM
Apologize for the late comment, as fork is still under snapshot, it is fine to address some potential issues as follow ups. We will need to be aware of the limitations of full text functions when generating the children of forks, here is an example
Not all of the commands are allowed to be before full text function, that's how we come across this issue, do we want to push fork before the limit or just error out? |
We should just error out in this case. I think the current behaviour is the one we should expect. |
One piece of feedback we got from #121948 was that
Fork
is not a Nary plan which further complicates the implementation with special treatment ofFork
in the analyzer/optimizer/verifier.We change the planning of
Fork
by making it N-ary, while also solving some of the outstanding issues:elasticsearch/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java
Lines 602 to 604 in 0d64aab
for semantic search, we require rewriting the query builder for the match function on the coordinator. Initially we added special handling of
Fork
inQueryBuilderResolver
. This is now removed since it is no longer necessary. The functionality is tested through csv tests and continues to work.we remove most of the special handling in the analyzer for
Fork
- what remains is stillAddImplicitForkLimit
which is needed to add the default limit for each sub plan.we remove the special handling of
Fork
in the verifier - this will help when we want to add support for allowing more than just where/limit/sort in the Fork branches. Without this change we would need to add more special handling ofFork
to do proper validation.