-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
SQL: Resolve attributes recursively for improved subquery support #69765
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aba2f63
Resolve references recursively
39e4cf1
Merge remote-tracking branch 'origin/master' into subquery-npe-fix
015acb3
Verifier error message fix
3b755be
PR suggestions
f739e39
Merge remote-tracking branch 'origin/master' into subquery-npe-fix
932c01c
Bugfix and PR suggestions
fa49615
Merge remote-tracking branch 'origin/master' into subquery-npe-fix
1cb642d
PR suggestions
50ab4d1
Merge remote-tracking branch 'origin/master' into subquery-npe-fix
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,8 +222,8 @@ public LogicalPlan apply(LogicalPlan plan) { | |
AttributeMap.Builder<Expression> builder = AttributeMap.builder(); | ||
// collect aliases | ||
plan.forEachExpressionUp(Alias.class, a -> builder.put(a.toAttribute(), a.child())); | ||
final Map<Attribute, Expression> collectRefs = builder.build(); | ||
java.util.function.Function<ReferenceAttribute, Expression> replaceReference = r -> collectRefs.getOrDefault(r, r); | ||
final AttributeMap<Expression> collectRefs = builder.build(); | ||
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. Noise. 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. Done |
||
java.util.function.Function<ReferenceAttribute, Expression> replaceReference = r -> collectRefs.resolve(r, r); | ||
|
||
plan = plan.transformUp(p -> { | ||
// non attribute defining plans get their references removed | ||
|
@@ -300,7 +300,7 @@ static class PruneOrderByNestedFields extends OptimizerRule<Project> { | |
private void findNested(Expression exp, AttributeMap<Function> functions, Consumer<FieldAttribute> onFind) { | ||
exp.forEachUp(e -> { | ||
if (e instanceof ReferenceAttribute) { | ||
Function f = functions.get(e); | ||
Function f = functions.resolve(e); | ||
if (f != null) { | ||
findNested(f, functions, onFind); | ||
} | ||
|
@@ -578,7 +578,7 @@ private List<NamedExpression> combineProjections(List<? extends NamedExpression> | |
// replace any matching attribute with a lower alias (if there's a match) | ||
// but clean-up non-top aliases at the end | ||
for (NamedExpression ne : upper) { | ||
NamedExpression replacedExp = (NamedExpression) ne.transformUp(Attribute.class, a -> aliases.getOrDefault(a, a)); | ||
NamedExpression replacedExp = (NamedExpression) ne.transformUp(Attribute.class, a -> aliases.resolve(a, a)); | ||
replaced.add((NamedExpression) CleanAliases.trimNonTopLevelAliases(replacedExp)); | ||
} | ||
return replaced; | ||
|
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'd like to see more tests for dealing with:
a. same key, value association - (e,e)
b. handling of default value across association: resolveOrDefault(k, default) for a map with (k, default), (default, value) and also
resolveOrDefault(k, k)
c. handling of cycles: (a, b), (b, c), (c,a ) with a mixture of default value in place.
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.