Skip to content

Commit

Permalink
Added COMPLEX_EXPRESSION_UNSUPPORTED_INPUT.BAD_INPUTS. Tests pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
GideonPotok committed Sep 29, 2024
1 parent 37efd0c commit afd123b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,11 @@
"message" : [
"The collection of input data types must not be empty."
]
},
"BAD_INPUTS" : {
"message" : [
"The input data types to <functionName> must be valid, but found the input types <dataType>."
]
}
},
"sqlState" : "42K09"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.apache.spark.SparkIllegalArgumentException
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.{ExpressionBuilder, TypeCheckResult, UnresolvedWithinGroup}
import org.apache.spark.sql.catalyst.expressions.{Ascending, Descending, Expression, ExpressionDescription, ImplicitCastInputTypes, SortOrder}
import org.apache.spark.sql.catalyst.expressions.Cast.toSQLExpr
import org.apache.spark.sql.catalyst.trees.UnaryLike
import org.apache.spark.sql.catalyst.types.PhysicalDataType
import org.apache.spark.sql.catalyst.util.{ArrayData, CollationFactory, GenericArrayData, UnsafeRowUtils}
Expand Down Expand Up @@ -118,8 +119,9 @@ case class Mode(
CollationFactory.getCollationKey(data.asInstanceOf[UTF8String], st.collationId)
case _ =>
throw new SparkIllegalArgumentException(
errorClass = "COMPLEX_EXPRESSION_UNSUPPORTED_INPUT.NO_INPUT",
errorClass = "COMPLEX_EXPRESSION_UNSUPPORTED_INPUT.BAD_INPUTS",
messageParameters = Map(
"expression" -> toSQLExpr(this),
"functionName" -> toSQLType(prettyName),
"dataType" -> toSQLType(child.dataType))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@ class CollationSQLExpressionsSuite
ModeTestCase("unicode_ci", Map("a" -> 3L, "b" -> 2L, "B" -> 2L), "b")
).foreach { t1 =>
checkError(
exception = intercept[SparkException] {
exception = intercept[SparkIllegalArgumentException] {
Mode(
child = Literal.create(null,
MapType(StringType(t1.collationId), IntegerType))
Expand All @@ -1966,10 +1966,11 @@ class CollationSQLExpressionsSuite
dataType = MapType(StringType(t1.collationId), IntegerType)
)
},
condition = "INTERNAL_ERROR",
parameters = Map("message" ->
"Cannot find sub error class 'COMPLEX_EXPRESSION_UNSUPPORTED_INPUT.NO_INPUT'")
// Map("function" -> "mode(i)", "dataType" -> "MAP<STRING, INT>")
condition = "COMPLEX_EXPRESSION_UNSUPPORTED_INPUT.BAD_INPUTS",
parameters = Map(
"expression" -> "\"mode(NULL)\"",
"functionName" -> "\"MODE\"",
"dataType" -> s"\"MAP<STRING COLLATE ${t1.collationId.toUpperCase()}, INT>\"")
)
}
}
Expand Down

0 comments on commit afd123b

Please sign in to comment.