Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-47572][SQL] Enforce Window partitionSpec is orderable. #45730

Closed
wants to merge 3 commits into from
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>\""))
}