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-48740][SQL] Catch missing window specification error early #47129

Closed
wants to merge 16 commits into from

Conversation

asl3
Copy link
Contributor

@asl3 asl3 commented Jun 27, 2024

What changes were proposed in this pull request?

Before, aggregate queries containing a window function without a window specification (e.g. PARTITION BY) would return a non-descriptive internal error message:

org.apache.spark.sql.catalyst.analysis.UnresolvedException: [INTERNAL_ERROR] Invalid call to exprId on unresolved object SQLSTATE: XX000

This PR catches the user error early and returns a more accurate description of the issue:

Window specification is not defined in the WINDOW clause for <windowName>. For more information about WINDOW clauses, please refer to '<docroot>/sql-ref-syntax-qry-select-window.html'.

Why are the changes needed?

This change produces a more descriptive error message for window functions, improving the Spark user experience.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Added unit test in sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala

Was this patch authored or co-authored using generative AI tooling?

No

@github-actions github-actions bot added the SQL label Jun 27, 2024
@HyukjinKwon HyukjinKwon changed the title [SPARK-48740] Catch missing window specification error early [SPARK-48740][SQL] Catch missing window specification error early Jun 27, 2024
@asl3 asl3 requested a review from gengliangwang June 28, 2024 00:14
@asl3 asl3 requested a review from gengliangwang June 28, 2024 15:16
@gengliangwang
Copy link
Member

@asl3 please fix the test failures in SQLQueryTestSuite and I will merge this one.

@gengliangwang
Copy link
Member

Thanks, merging to master

fusheng-rd pushed a commit to fusheng-rd/spark that referenced this pull request Aug 6, 2024
### What changes were proposed in this pull request?
Before, aggregate queries containing a window function without a window specification (e.g. `PARTITION BY`) would return a non-descriptive internal error message:

`org.apache.spark.sql.catalyst.analysis.UnresolvedException: [INTERNAL_ERROR] Invalid call to exprId on unresolved object SQLSTATE: XX000`

This PR catches the user error early and returns a more accurate description of the issue:

`Window specification is not defined in the WINDOW clause for <windowName>. For more information about WINDOW clauses, please refer to '<docroot>/sql-ref-syntax-qry-select-window.html'.`

### Why are the changes needed?
This change produces a more descriptive error message for window functions, improving the Spark user experience.

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Added unit test in `sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisErrorSuite.scala`

### Was this patch authored or co-authored using generative AI tooling?
No

Closes apache#47129 from asl3/improve-window-partition-error.

Lead-authored-by: Amanda Liu <[email protected]>
Co-authored-by: Gengliang Wang <[email protected]>
Signed-off-by: Gengliang Wang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants