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 3 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,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.

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 " +


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 @@ -826,4 +826,9 @@ class AnalysisSuite extends AnalysisTest with Matchers {
}
}
}

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: ...

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