spark icon indicating copy to clipboard operation
spark copied to clipboard

[SPARK-48740][SQL] Catch missing window specification error early

Open asl3 opened this issue 1 year ago • 1 comments

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 <windowName> is not defined in the WINDOW clause.

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

asl3 avatar Jun 27 '24 18:06 asl3

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

gengliangwang avatar Jun 28 '24 21:06 gengliangwang

Thanks, merging to master

gengliangwang avatar Jul 30 '24 00:07 gengliangwang