-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21555][SQL] RuntimeReplaceable should be compared semantically by its canonicalized child #18761
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
Closed
Closed
[SPARK-21555][SQL] RuntimeReplaceable should be compared semantically by its canonicalized child #18761
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,3 +23,9 @@ SELECT float(1), double(1), decimal(1); | |
| SELECT date("2014-04-04"), timestamp(date("2014-04-04")); | ||
| -- error handling: only one argument | ||
| SELECT string(1, 2); | ||
|
|
||
| -- SPARK-21555: RuntimeReplaceable used in group by | ||
| CREATE TABLE test(a INT, foo STRUCT<foo1:STRING,foo2:STRING>) USING parquet; | ||
| INSERT INTO test VALUES(1, ("value1", "value2")); | ||
| SELECT nvl(foo.foo1, "value"), count(*) FROM test GROUP BY nvl(foo.foo1, "value"); | ||
| DROP TABLE test; | ||
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Although this fixes the issue, the root cause is the unneeded aliases (these aliases were added for nested fields) are not properly cleaned up in these
RuntimeReplaceableexpressions by the ruleCleanupAliases.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 know it. However, the aliases actually are replaced by Optimizer because
RuntimeReplaceable. So they are no harm.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.
Btw, those aliases are not children of
RuntimeReplaceablewhich is anUnaryExpression. So we can't trim the aliases out by simple transforming the expressions inCleanupAliases.If we want to replace the non-children aliases in
RuntimeReplaceable, we need to add more codes toRuntimeReplaceableand modify all expressions ofRuntimeReplaceable. It makes the interface ugly IMO.Consider those aliases will be replaced soon and no harm of them, that's why I choose to simply override
canonicalized.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.
First, my only concern is
CleanupAliasesmight be called in the other Analyzer rules. These unneeded aliases could break the assumptions made by the caller ofCleanupAliases.Second, you should post what I said above in the PR description. So far, the description is not clear to the reviewers.
Third, I am ok about the fix, but we should write the comments to explain why we did it here. We need to add two comments. One is in
CleanupAliases; another is above this line to explain why we addcanonicalized.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.
Updated PR description and comments accordingly.
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.
If you meant there is an assumption that
CleanupAliaseswould clean up ALL aliases in a plan, that is not correct. It can only clean up the aliases reachable by expression transformation. I added a comment to clarify this.