-
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-31975][SQL] Show AnalysisException when WindowFunction is used without WindowExpression #28808
Conversation
Test build #123895 has finished for PR 28808 at commit
|
retest this please. |
Test build #123913 has finished for PR 28808 at commit
|
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
Outdated
Show resolved
Hide resolved
@@ -158,6 +158,9 @@ trait CheckAnalysis extends PredicateHelper { | |||
case g: GroupingID => | |||
failAnalysis("grouping_id() can only be used with GroupingSets/Cube/Rollup") | |||
|
|||
case Alias(w: WindowFunction, _) => | |||
failAnalysis(s"Window function '$w' call requires an OVER clause.") |
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.
Sorry, seems we need to remove single quotation marks:
spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
Line 2734 in b2011a2
failAnalysis(s"Window function $wf requires window to be ordered, please add ORDER BY " + |
Test build #123921 has finished for PR 28808 at commit
|
Test build #123932 has finished for PR 28808 at commit
|
Test build #123951 has finished for PR 28808 at commit
|
cc @jiangxb1987 |
also cc @HyukjinKwon @cloud-fan a minor change. |
@@ -158,6 +158,9 @@ trait CheckAnalysis extends PredicateHelper { | |||
case g: GroupingID => | |||
failAnalysis("grouping_id() can only be used with GroupingSets/Cube/Rollup") | |||
|
|||
case Alias(w: WindowFunction, _) => | |||
failAnalysis(s"Window function $w call requires an OVER clause.") |
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.
nit: we can remove call
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.
removed.
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, please resolve the conflicts.
@@ -158,6 +158,9 @@ trait CheckAnalysis extends PredicateHelper { | |||
case g: GroupingID => | |||
failAnalysis("grouping_id() can only be used with GroupingSets/Cube/Rollup") | |||
|
|||
case Alias(w: WindowFunction, _) => |
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 why do we have to match the 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.
The right way is Alias(WindowExpression(w: WindowFunction, _), _)
and without over
it is Alias(w: WindowFunction, _)
.
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.
then the check doesn't work for cases like rank() + 1
?
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.
good catch ! we need to check all expression.
Test build #124911 has finished for PR 28808 at commit
|
retest this please |
@@ -884,4 +884,15 @@ class AnalysisSuite extends AnalysisTest with Matchers { | |||
Seq("Intersect can only be performed on tables with the compatible column types. " + | |||
"timestamp <> double at the second column of the second table")) | |||
} | |||
|
|||
test("throw user facing error when use WindowFunction directly") { |
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.
Shall we add a JIRA prefix here? SPARK-31975: ...
@@ -158,6 +158,11 @@ trait CheckAnalysis extends PredicateHelper { | |||
case g: GroupingID => | |||
failAnalysis("grouping_id() can only be used with GroupingSets/Cube/Rollup") | |||
|
|||
case e: Expression if e.children.exists(_.isInstanceOf[WindowFunction]) && | |||
!e.isInstanceOf[WindowExpression] => |
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.
nit: indent
Test build #124949 has started for PR 28808 at commit |
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.
+1, LGTM. Thank you, @ulysses-you .
BTW, @ulysses-you . I updated the PR title and the description a little.
retest this please |
Thank you @dongjoon-hyun , thanks for help test @HyukjinKwon . |
Test build #125024 has finished for PR 28808 at commit
|
retest this please |
Test build #125064 has finished for PR 28808 at commit
|
retest this please |
Test build #125082 has finished for PR 28808 at commit
|
retest this please |
Test build #125175 has finished for PR 28808 at commit
|
retest this please. |
Test build #125185 has finished for PR 28808 at commit
|
thanks, merging to master! |
thanks for merging! thanks all! |
What changes were proposed in this pull request?
Add WindowFunction check at
CheckAnalysis
.Why are the changes needed?
Provide friendly error msg.
BEFORE
AFTER
Does this PR introduce any user-facing change?
Yes, user wiill be given a better error msg.
How was this patch tested?
Pass the newly added UT.