-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Introduce ViewUnionAll to differentiate view-produced unions from subquery unions #143564
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3b61633
Introduce ViewUnionAll to differentiate view-produced unions from sub…
quackaplop 9a597e6
Add changelog for #143564
quackaplop 6091623
Add dedicated ViewUnionAllTests for plan node unit tests
quackaplop 8d38fa0
Add ViewUnionAll to ApproximationSupportTests unsupported commands list
quackaplop a2c3ce4
Change changelog type to bug
quackaplop e2d0505
Delete unneeded changelog file
craigtaverner d6ed962
Add names to subqueries in ViewUnionAll
craigtaverner aa5dbfc
Add more tests for named subqueries and fix bug with Map.hashCode
craigtaverner a27ccbc
Support view names inside ViewUnionAll
craigtaverner 9e9fb6d
Fix EsqlNodeSubclassTests
craigtaverner 8cc54f2
Merge remote-tracking branch 'origin/main' into view_union_all_fork
craigtaverner 5b6ae0a
Ensure that ViewUnionAll survives through semantic analysis
craigtaverner 46b23c3
Mark NamedSubquery unsupported in ApproximationSupportTests
craigtaverner ee52e42
Merge branch 'main' into view_union_all_fork
craigtaverner 145134d
Merge branch 'main' into view_union_all_fork
craigtaverner 369eb46
Merge branch 'main' into view_union_all_fork
craigtaverner efa88cb
Merge remote-tracking branch 'origin/main' into view_union_all_fork
craigtaverner d04f4d2
Fixed AnalyzerTests after merging main
craigtaverner c67a4c9
Merge branch 'main' into view_union_all_fork
craigtaverner 3877822
Merge branch 'main' into view_union_all_fork
craigtaverner 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 hidden or 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 hidden or 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 hidden or 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
68 changes: 68 additions & 0 deletions
68
...ck/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/NamedSubquery.java
This file contains hidden or 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,68 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| package org.elasticsearch.xpack.esql.plan.logical; | ||
|
|
||
| import org.elasticsearch.xpack.esql.core.tree.NodeInfo; | ||
| import org.elasticsearch.xpack.esql.core.tree.Source; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * A {@link Subquery} that carries the view name it was resolved from. | ||
| * <p> | ||
| * Unlike plain {@link Subquery}, the name participates in {@link #equals} and {@link #hashCode}, | ||
| * which allows {@code Node.transformDown} to distinguish a newly-tagged subquery from its | ||
| * untagged predecessor. After view resolution, a post-processing pass converts | ||
| * {@link UnionAll} nodes containing {@code NamedSubquery} children into {@link ViewUnionAll}. | ||
| * <p> | ||
| * This class should only be used during query re-writing and not survive in the final query plan. | ||
| * If we decide to keep named subqueries as a feature later, we should add serialization support. | ||
| */ | ||
| public class NamedSubquery extends Subquery { | ||
| private final String name; | ||
|
|
||
| public NamedSubquery(Source source, LogicalPlan subqueryPlan, String name) { | ||
| super(source, subqueryPlan); | ||
| this.name = Objects.requireNonNull(name); | ||
| } | ||
|
|
||
| public String name() { | ||
| return name; | ||
| } | ||
|
|
||
| @Override | ||
| protected NodeInfo<NamedSubquery> info() { | ||
| return NodeInfo.create(this, NamedSubquery::new, child(), name); | ||
| } | ||
|
|
||
| @Override | ||
| public UnaryPlan replaceChild(LogicalPlan newChild) { | ||
| return new NamedSubquery(source(), newChild, name); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(name, child()); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
| if (obj == null || getClass() != obj.getClass()) { | ||
| return false; | ||
| } | ||
| NamedSubquery other = (NamedSubquery) obj; | ||
| return Objects.equals(name, other.name) && Objects.equals(child(), other.child()); | ||
| } | ||
|
|
||
| @Override | ||
| public String nodeString(NodeStringFormat format) { | ||
| return nodeName() + "[" + name + "]"; | ||
| } | ||
| } |
This file contains hidden or 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.
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.
Could also test subqueries inside views
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.
Done inside the InMemoryViewServiceTests