-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-24488] [SQL] Fix issue when generator is aliased multiple times #21508
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
Conversation
|
ok to test |
| case MultiAlias(_: Generator, _) => false | ||
| case other => hasGenerator(other) | ||
| private def hasNestedGenerator(expr: NamedExpression): Boolean = { | ||
| CleanupAliases.trimNonTopLevelAliases(expr) match { |
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.
CleanupAliases.trimNonTopLevelAliases only strips Alias expressions. Should we also handle the other two cases?
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 to handle the MultiAlias and UnresolvedAlias, and updated the unit test to test all 3.
|
Test build #91564 has finished for PR 21508 at commit
|
|
Test build #91568 has finished for PR 21508 at commit
|
|
Test build #91569 has finished for PR 21508 at commit
|
| } | ||
| } | ||
|
|
||
| def trimNonTopLevelAliases(e: Expression): Expression = e match { |
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.
Instead of duplicating the function here, could we just fixing CleanupAliases.trimNonTopLevelAliases
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.
Sure- I didn't want to break any existing functionality, but I can do that instead.
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
| } | ||
|
|
||
| def trimNonTopLevelAliases(e: Expression): Expression = e match { | ||
| case a: UnresolvedAlias => |
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.
Do we need to handle UnresolvedAlias?
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.
In my use case, no. But I wasn't sure if another use case would care.
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 don't think it'll hurt to handle it.
|
Test build #91665 has finished for PR 21508 at commit
|
| case other => hasGenerator(other) | ||
| private def hasNestedGenerator(expr: NamedExpression): Boolean = { | ||
| CleanupAliases.trimNonTopLevelAliases(expr) match { | ||
| case UnresolvedAlias(_: Generator, _) => false |
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 we do not have a valid case here, we should not add it. Here, I think we just need to handle the resolved alias.
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.
hasNestedGenerator already handled UnresolvedAlias. I'll change CleanupAliases back to only handling resolved aliases.
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
|
Test build #91674 has finished for PR 21508 at commit
|
|
The test failure looks like a flake to me? |
|
Test build #91725 has finished for PR 21508 at commit
|
|
@gatorsmile @hvanhovell is this good to merge? |
|
@gatorsmile @hvanhovell can you take a last look at this? I think it's good to merge. |
|
@gatorsmile @hvanhovell Gentle ping. Let me know if there's someone else who would be better to review. |
|
@gatorsmile @hvanhovell can you take another look at this? |
|
@gatorsmile @hvanhovell, I'm working with @bkrieger and we need this patch soon. May we please get a sign off or else any suggested changes here? |
|
Test build #93177 has finished for PR 21508 at commit
|
|
@gatorsmile @hvanhovell any chance you can take a look at this? |
|
cc @maropu Help review this? |
hvanhovell
left a comment
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, merging to master. Sorry for the hold-up.
Currently, the Analyzer throws an exception if your try to nest a generator. However, it special cases generators "nested" in an alias, and allows that. If you try to alias a generator twice, it is not caught by the special case, so an exception is thrown. This PR trims the unnecessary, non-top-level aliases, so that the generator is allowed. new tests in AnalysisSuite. Author: Brandon Krieger <[email protected]> Closes apache#21508 from bkrieger/bk/SPARK-24488.
What changes were proposed in this pull request?
Currently, the Analyzer throws an exception if you try to nest a generator. However, it special cases generators "nested" in an alias, and allows that. If you try to alias a generator twice, it is not caught by the special case, so an exception is thrown.
This PR trims the unnecessary, non-top-level aliases, so that the generator is allowed.
How was this patch tested?
new tests in AnalysisSuite.