[SPARK-48740][SQL] Catch missing window specification error early
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 please fix the test failures in SQLQueryTestSuite and I will merge this one.
Thanks, merging to master