-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
[SPARK-41631][SQL] Support implicit lateral column alias resolution on Aggregate #39040
Conversation
(cherry picked from commit 313b2c9)
@gengliangwang sure, will do today, fyi i was sick yesterday. |
I will shortly address the left todos in this PR. |
…s into one file ### What changes were proposed in this pull request? Move the two rules `WrapLateralColumnAliasReference` and `ResolveLateralColumnAliasReference` into one file `ResolveLateralColumnAlias.scala`, instead of one rule in `Analyzer.scala` and the other one in another file. Also update the code comments. ### Why are the changes needed? Found this issue during reviewing apache#39040 This refactor should make the code easier to read and review. ### Does this PR introduce _any_ user-facing change? No ### How was this patch tested? Existing UT Closes apache#39054 from gengliangwang/refactorLCA. Authored-by: Gengliang Wang <gengliang@apache.org> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
// perform an early check on current Aggregate before any lift-up / push-down to throw | ||
// the same exception such as non-aggregate expressions not in group by, which becomes | ||
// missing input after transformation | ||
earlyCheckAggregate(agg) |
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 seems from checkAnalysis. Could you refactor and reduce duplicated code?
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.
Yes, actually simplified from checkAnalysis
. If this solution works and all tests pass, I can move this method to Aggregate or AnalysisHelper object.
|
||
test("Non-aggregating expressions not in group by still throws the same error") { | ||
// query without lateral alias | ||
assert( |
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.
use checkError
?
@@ -182,6 +183,157 @@ object AnalysisContext { | |||
} | |||
} | |||
|
|||
object Analyzer extends Logging { |
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 even more change than reverting #39054 ...
...talyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveLateralColumnAlias.scala
Outdated
Show resolved
Hide resolved
Is that a Github issue that I can re-request review from only one person? Every time I requested a second reviewer it automatically remove the request from the first reviewer.. But anyway cc @gengliangwang and @cloud-fan to review this PR. |
thanks, merging to master! |
What changes were proposed in this pull request?
This PR implements the implicit lateral column alias on
Aggregate
case. For example,The high level implementation idea is to insert the
Project
node above, and falling back to the resolution of lateral alias of Project code path in the last PR.LateralColumnAliasReference
Aggregate
operator is resolved, it goes through the whole aggregation list, extracts the aggregation expressions and grouping expressions to keep them in thisAggregate
node, and add aProject
above with the original output. It doesn't do anything onLateralColumnAliasReference
, but completely leave it to the Project in the future turns of this rule.Example:
Similar as the last PR (#38776), because lateral column alias has higher resolution priority than outer reference, it will try to resolve an
OuterReference
using lateral column alias, similar as anUnresolvedAttribute
. If success, it stripsOuterReference
and also wraps it withLateralColumnAliasReference
.Why are the changes needed?
Similar as stated in #38776.
Does this PR introduce any user-facing change?
Yes, as shown in the above example, it will be able to resolve lateral column alias in Aggregate.
How was this patch tested?
Existing tests and newly added tests.