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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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] =>
val w = e.children.find(_.isInstanceOf[WindowFunction]).get
failAnalysis(s"Window function $w requires an OVER clause.")

case w @ WindowExpression(AggregateExpression(_, _, true, _, _), _) =>
failAnalysis(s"Distinct window functions are not supported: $w")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("SPARK-31975: Throw user facing error when use WindowFunction directly") {
assertAnalysisError(testRelation2.select(RowNumber()),
Seq("Window function row_number() requires an OVER clause."))

assertAnalysisError(testRelation2.select(Sum(RowNumber())),
Seq("Window function row_number() requires an OVER clause."))

assertAnalysisError(testRelation2.select(RowNumber() + 1),
Seq("Window function row_number() requires an OVER clause."))
}
}