Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,19 @@ trait CheckAnalysis extends PredicateHelper with LookupCatalog with QueryErrorsB
}
}

case Window(_, partitionSpec, _, _) =>
// Both `partitionSpec` and `orderSpec` must be orderable. We only need an extra check
// for `partitionSpec` here because `orderSpec` has the type check itself.
partitionSpec.foreach { p =>
if (!RowOrdering.isOrderable(p.dataType)) {
p.failAnalysis(
errorClass = "EXPRESSION_TYPE_IS_NOT_ORDERABLE",
messageParameters = Map(
"expr" -> toSQLExpr(p),
"exprType" -> toSQLType(p.dataType)))
}
}

case GlobalLimit(limitExpr, _) => checkLimitLikeClause("limit", limitExpr)

case LocalLimit(limitExpr, child) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1316,4 +1316,18 @@ class AnalysisErrorSuite extends AnalysisTest with DataTypeErrorsBase {
)
}
}

errorClassTest(
"SPARK-47572: Enforce Window partitionSpec is orderable",
testRelation2.select(
WindowExpression(
new Rank(),
WindowSpecDefinition(
CreateMap(Literal("key") :: UnresolvedAttribute("a") :: Nil) :: Nil,
SortOrder(UnresolvedAttribute("b"), Ascending) :: Nil,
UnspecifiedFrame)).as("window")),
errorClass = "EXPRESSION_TYPE_IS_NOT_ORDERABLE",
messageParameters = Map(
"expr" -> "\"_w0\"",
"exprType" -> "\"MAP<STRING, STRING>\""))
}