Skip to content
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

Closed
wants to merge 8 commits into from

Conversation

ulysses-you
Copy link
Contributor

@ulysses-you ulysses-you commented Jun 12, 2020

What changes were proposed in this pull request?

Add WindowFunction check at CheckAnalysis.

Why are the changes needed?

Provide friendly error msg.

BEFORE

scala> sql("select rank() from values(1)").show
java.lang.UnsupportedOperationException: Cannot generate code for expression: rank()

AFTER

scala> sql("select rank() from values(1)").show
org.apache.spark.sql.AnalysisException: Window function rank() requires an OVER clause.;;
Project [rank() AS RANK()#3]
+- LocalRelation [col1#2]

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.

@SparkQA
Copy link

SparkQA commented Jun 12, 2020

Test build #123895 has finished for PR 28808 at commit f283385.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@wangyum
Copy link
Member

wangyum commented Jun 12, 2020

retest this please.

@SparkQA
Copy link

SparkQA commented Jun 12, 2020

Test build #123913 has finished for PR 28808 at commit f283385.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@@ -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.")
Copy link
Member

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:

failAnalysis(s"Window function $wf requires window to be ordered, please add ORDER BY " +

@SparkQA
Copy link

SparkQA commented Jun 12, 2020

Test build #123921 has finished for PR 28808 at commit 38df40a.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 12, 2020

Test build #123932 has finished for PR 28808 at commit cd8bbb2.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 13, 2020

Test build #123951 has finished for PR 28808 at commit 335935f.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@wangyum
Copy link
Member

wangyum commented Jun 19, 2020

cc @jiangxb1987

@ulysses-you
Copy link
Contributor Author

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.")
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

Copy link
Contributor

@cloud-fan cloud-fan left a 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, _) =>
Copy link
Contributor

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?

Copy link
Contributor Author

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, _).

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@SparkQA
Copy link

SparkQA commented Jul 2, 2020

Test build #124911 has finished for PR 28808 at commit 972ae13.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

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") {
Copy link
Member

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] =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: indent

@SparkQA
Copy link

SparkQA commented Jul 5, 2020

Test build #124949 has started for PR 28808 at commit 3e116f5.

@dongjoon-hyun dongjoon-hyun changed the title [SPARK-31975][SQL] Throw user facing error when use WindowFunction directly [SPARK-31975][SQL] Show AnalysisException when WindowFunction is used without WindowExpression Jul 6, 2020
Copy link
Member

@dongjoon-hyun dongjoon-hyun left a 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.

@HyukjinKwon
Copy link
Member

retest this please

@ulysses-you
Copy link
Contributor Author

Thank you @dongjoon-hyun , thanks for help test @HyukjinKwon .

@SparkQA
Copy link

SparkQA commented Jul 6, 2020

Test build #125024 has finished for PR 28808 at commit 3e116f5.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

retest this please

@SparkQA
Copy link

SparkQA commented Jul 6, 2020

Test build #125064 has finished for PR 28808 at commit 3e116f5.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

retest this please

@SparkQA
Copy link

SparkQA commented Jul 6, 2020

Test build #125082 has finished for PR 28808 at commit 3e116f5.

  • This patch fails to generate documentation.
  • This patch merges cleanly.
  • This patch adds no public classes.

@HyukjinKwon
Copy link
Member

retest this please

@SparkQA
Copy link

SparkQA commented Jul 7, 2020

Test build #125175 has finished for PR 28808 at commit 3e116f5.

  • This patch fails due to an unknown error code, -9.
  • This patch merges cleanly.
  • This patch adds no public classes.

@wangyum
Copy link
Member

wangyum commented Jul 7, 2020

retest this please.

@SparkQA
Copy link

SparkQA commented Jul 7, 2020

Test build #125185 has finished for PR 28808 at commit 3e116f5.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in 2e23da2 Jul 7, 2020
@ulysses-you
Copy link
Contributor Author

thanks for merging! thanks all!

@ulysses-you ulysses-you deleted the SPARK-31975 branch March 11, 2021 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
7 participants