LuciferYang commented on code in PR #38463:
URL: https://github.com/apache/spark/pull/38463#discussion_r1010207329
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeCreator.scala:
##########
@@ -444,17 +460,32 @@ case class CreateNamedStruct(children: Seq[Expression])
extends Expression with
override def checkInputDataTypes(): TypeCheckResult = {
if (children.size % 2 != 0) {
- TypeCheckResult.TypeCheckFailure(s"$prettyName expects an even number of
arguments.")
+ DataTypeMismatch(
+ errorSubClass = "WRONG_NUM_ARGS",
+ messageParameters = Map(
+ "functionName" -> toSQLId(prettyName),
+ "expectedNum" -> "2n (n > 0)",
+ "actualNum" -> children.length.toString
+ )
+ )
} else {
val invalidNames = nameExprs.filterNot(e => e.foldable && e.dataType ==
StringType)
if (invalidNames.nonEmpty) {
- TypeCheckResult.TypeCheckFailure(
- s"Only foldable ${StringType.catalogString} expressions are allowed
to appear at odd" +
- s" position, got: ${invalidNames.mkString(",")}")
+ DataTypeMismatch(
+ errorSubClass = "CREATE_NAMED_STRUCT_WITHOUT_FOLDABLE_STRING",
Review Comment:
Can `NON_FOLDABLE_INPUT` be reused?
##########
core/src/main/resources/error/error-classes.json:
##########
@@ -155,6 +160,21 @@
"To convert values from <srcType> to <targetType>, you can use the
functions <functionNames> instead."
]
},
+ "CREATE_MAP_KEY_DIFF_TYPES" : {
Review Comment:
Cloud we make `DATA_DIFF_TYPES ` more general and reuse it?
##########
core/src/main/resources/error/error-classes.json:
##########
@@ -155,6 +160,21 @@
"To convert values from <srcType> to <targetType>, you can use the
functions <functionNames> instead."
]
},
+ "CREATE_MAP_KEY_DIFF_TYPES" : {
+ "message" : [
+ "The given keys of function <functionName> should all be the same
type, but they are <dataType>."
+ ]
+ },
+ "CREATE_MAP_VALUE_DIFF_TYPES" : {
Review Comment:
ditto
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeCreator.scala:
##########
@@ -668,10 +699,19 @@ case class UpdateFields(structExpr: Expression, fieldOps:
Seq[StructFieldsOperat
override def checkInputDataTypes(): TypeCheckResult = {
val dataType = structExpr.dataType
if (!dataType.isInstanceOf[StructType]) {
- TypeCheckResult.TypeCheckFailure("struct argument should be struct type,
got: " +
- dataType.catalogString)
+ DataTypeMismatch(
+ errorSubClass = "UNEXPECTED_INPUT_TYPE",
+ messageParameters = Map(
+ "paramIndex" -> "1",
+ "requiredType" -> toSQLType(StructType),
+ "inputSql" -> toSQLExpr(structExpr),
+ "inputType" -> toSQLType(structExpr.dataType))
+ )
} else if (newExprs.isEmpty) {
- TypeCheckResult.TypeCheckFailure("cannot drop all fields in struct")
+ DataTypeMismatch(
Review Comment:
It seems that the original message did not clearly describe this error, the
message doesn't look like `DataTypeMismatch`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]