Skip to content

Commit

Permalink
Improve error message for nested UnresolvedWindowExpression in CheckA…
Browse files Browse the repository at this point in the history
…nalysis
  • Loading branch information
vladimirg-db committed Aug 16, 2024
1 parent 7b43a6f commit 10c02bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
throw QueryCompilationErrors.invalidStarUsageError(operator.nodeName, Seq(s))
}

// Choud be before `e.checkInputDataTypes()` to produce the correct error for unknown
// window expressions nested inside other expressions
case UnresolvedWindowExpression(_, WindowSpecReference(windowName)) =>
throw QueryCompilationErrors.windowSpecificationNotDefinedError(windowName)

case e: Expression if e.checkInputDataTypes().isFailure =>
e.checkInputDataTypes() match {
case checkRes: TypeCheckResult.DataTypeMismatch =>
Expand Down
22 changes: 22 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4887,6 +4887,28 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
assert(relations.head.options == Map("key1" -> "1", "key2" -> "2"))
}
}

test(
"SPARK-49250: CheckAnalysis for UnresolvedWindowExpression must produce " +
"MISSING_WINDOW_SPECIFICATION error"
) {
for (sqlText <- Seq(
"SELECT SUM(col1) OVER(unspecified_window) FROM VALUES (1)",
"SELECT SUM(col1) OVER(unspecified_window) FROM VALUES (1) GROUP BY col1",
"SELECT (SUM(col1) OVER(unspecified_window) / 1) FROM VALUES (1)"
)) {
checkError(
exception = intercept[AnalysisException](
sql(sqlText)
),
errorClass = "MISSING_WINDOW_SPECIFICATION",
parameters = Map(
"windowName" -> "unspecified_window",
"docroot" -> SPARK_DOC_ROOT
)
)
}
}
}

case class Foo(bar: Option[String])

0 comments on commit 10c02bb

Please sign in to comment.