dongjoon-hyun commented on code in PR #48251:
URL: https://github.com/apache/spark/pull/48251#discussion_r1778843183
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala:
##########
@@ -1123,33 +1131,42 @@ case class Cast(
variant.VariantGet.cast(v, to, evalMode != EvalMode.TRY, timeZoneId,
zoneId)
})
} else {
- to match {
- case dt if dt == from => identity[Any]
- case VariantType => input =>
variant.VariantExpressionEvalUtils.castToVariant(input, from)
- case _: StringType => castToString(from)
- case BinaryType => castToBinary(from)
- case DateType => castToDate(from)
- case decimal: DecimalType => castToDecimal(from, decimal)
- case TimestampType => castToTimestamp(from)
- case TimestampNTZType => castToTimestampNTZ(from)
- case CalendarIntervalType => castToInterval(from)
- case it: DayTimeIntervalType => castToDayTimeInterval(from, it)
- case it: YearMonthIntervalType => castToYearMonthInterval(from, it)
- case BooleanType => castToBoolean(from)
- case ByteType => castToByte(from)
- case ShortType => castToShort(from)
- case IntegerType => castToInt(from)
- case FloatType => castToFloat(from)
- case LongType => castToLong(from)
- case DoubleType => castToDouble(from)
- case array: ArrayType =>
- castArray(from.asInstanceOf[ArrayType].elementType,
array.elementType)
- case map: MapType => castMap(from.asInstanceOf[MapType], map)
- case struct: StructType => castStruct(from.asInstanceOf[StructType],
struct)
- case udt: UserDefinedType[_] if udt.acceptsType(from) =>
- identity[Any]
- case _: UserDefinedType[_] =>
- throw QueryExecutionErrors.cannotCastError(from, to)
+ from match {
+ // `castToString` has special handling for `UserDefinedType`
+ case udt: UserDefinedType[_] if !to.isInstanceOf[StringType] =>
+ castInternal(udt.sqlType, to)
+ case _ =>
+ to match {
+ case dt if dt == from => identity[Any]
+ case VariantType => input =>
+ variant.VariantExpressionEvalUtils.castToVariant(input, from)
+ case _: StringType => castToString(from)
+ case BinaryType => castToBinary(from)
+ case DateType => castToDate(from)
+ case decimal: DecimalType => castToDecimal(from, decimal)
+ case TimestampType => castToTimestamp(from)
+ case TimestampNTZType => castToTimestampNTZ(from)
+ case CalendarIntervalType => castToInterval(from)
+ case it: DayTimeIntervalType => castToDayTimeInterval(from, it)
+ case it: YearMonthIntervalType => castToYearMonthInterval(from, it)
+ case BooleanType => castToBoolean(from)
+ case ByteType => castToByte(from)
+ case ShortType => castToShort(from)
+ case IntegerType => castToInt(from)
+ case FloatType => castToFloat(from)
+ case LongType => castToLong(from)
+ case DoubleType => castToDouble(from)
+ case array: ArrayType =>
+ castArray(from.asInstanceOf[ArrayType].elementType,
array.elementType)
+ case map: MapType => castMap(from.asInstanceOf[MapType], map)
+ case struct: StructType =>
castStruct(from.asInstanceOf[StructType], struct)
+ case udt: UserDefinedType[_] if udt.acceptsType(from) =>
+ identity[Any]
+ case udt: UserDefinedType[_] =>
+ castInternal(from, udt.sqlType)
Review Comment:
So, this is a new addition with the exception of `castToString`?
--
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]