Commit 291647d
[SPARK-49250][SQL] Improve error message for nested UnresolvedWindowExpression in CheckAnalysis
### What changes were proposed in this pull request?
When `CheckAnalysis` encounters `UnresolvedWindowExpression` in `Project` or `Aggregate`, it throws `QueryCompilationErrors.windowSpecificationNotDefinedError`:
- 4718d59c6c4
- 0b48d3f61b7
However, consider the following query:
`SELECT (SUM(col1) OVER(unspecified_window) / 1) FROM VALUES (1)`
Here `UnreolvedWindowExpression` is wrapped into the division expression. And `CheckAnalysis` throws a different unrelated `org.apache.spark.sql.catalyst.analysis.UnresolvedException: [INTERNAL_ERROR] Invalid call to dataType on unresolved object SQLSTATE: XX000` exception earlier from this [case](https://github.com/apache/spark/blob/0b48d3f61b726209e96b0b967530534b5ad9101d/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala#L308).
The solution to improve this would be to match `UnreolvedWindowExpression` early.
### Why are the changes needed?
To improve error message for incorrect window usage.
### Does this PR introduce _any_ user-facing change?
Yes, the error message is better now
### How was this patch tested?
Added a unit test
### Was this patch authored or co-authored using generative AI tooling?
No
Closes #47775 from vladimirg-db/vladimirg-db/better-error-message-for-unresolved-window-expression-in-check-analysis.
Authored-by: Vladimir Golubev <vladimir.golubev@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>1 parent e63c398 commit 291647d
File tree
2 files changed
+27
-0
lines changed- sql
- catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis
- core/src/test/scala/org/apache/spark/sql
2 files changed
+27
-0
lines changedLines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
308 | 313 | | |
309 | 314 | | |
310 | 315 | | |
| |||
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4887 | 4887 | | |
4888 | 4888 | | |
4889 | 4889 | | |
| 4890 | + | |
| 4891 | + | |
| 4892 | + | |
| 4893 | + | |
| 4894 | + | |
| 4895 | + | |
| 4896 | + | |
| 4897 | + | |
| 4898 | + | |
| 4899 | + | |
| 4900 | + | |
| 4901 | + | |
| 4902 | + | |
| 4903 | + | |
| 4904 | + | |
| 4905 | + | |
| 4906 | + | |
| 4907 | + | |
| 4908 | + | |
| 4909 | + | |
| 4910 | + | |
| 4911 | + | |
4890 | 4912 | | |
4891 | 4913 | | |
4892 | 4914 | | |
0 commit comments