Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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,18 @@ 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.dataTypeMismatch(p, TypeCheckResult.DataTypeMismatch(
errorSubClass = "INVALID_ORDERING_TYPE",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use the error class EXPRESSION_TYPE_IS_NOT_ORDERABLE?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot really tell the difference between these two error classes, so I just randomly picked one. Now I changed it into EXPRESSION_TYPE_IS_NOT_ORDERABLE instead.

Map("functionName" -> toSQLId(p.prettyName), "dataType" -> 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 @@ -1387,4 +1387,19 @@ 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 = "DATATYPE_MISMATCH.INVALID_ORDERING_TYPE",
messageParameters = Map(
"functionName" -> "`attributereference`",
"dataType" -> "\"MAP<STRING, STRING>\"",
"sqlExpr" -> "\"_w0\""))
}