Skip to content

Commit 42303d2

Browse files
committed
Complete the update to Cast for UDT.
1 parent d01c661 commit 42303d2

File tree

1 file changed

+8
-0
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions

1 file changed

+8
-0
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.apache.spark.sql.catalyst.expressions
1919

2020
import java.math.{BigDecimal => JavaBigDecimal}
2121

22+
import org.apache.spark.SparkException
2223
import org.apache.spark.sql.catalyst.InternalRow
2324
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
2425
import org.apache.spark.sql.catalyst.expressions.codegen._
@@ -434,6 +435,11 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression {
434435
case array: ArrayType => castArray(from.asInstanceOf[ArrayType].elementType, array.elementType)
435436
case map: MapType => castMap(from.asInstanceOf[MapType], map)
436437
case struct: StructType => castStruct(from.asInstanceOf[StructType], struct)
438+
case udt: UserDefinedType[_]
439+
if udt.userClass == from.asInstanceOf[UserDefinedType[_]].userClass =>
440+
identity[Any]
441+
case _: UserDefinedType[_] =>
442+
throw new SparkException(s"Cannot cast $from to $to.")
437443
}
438444

439445
private[this] lazy val cast: Any => Any = cast(child.dataType, dataType)
@@ -479,6 +485,8 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression {
479485
case udt: UserDefinedType[_]
480486
if udt.userClass == from.asInstanceOf[UserDefinedType[_]].userClass =>
481487
(c, evPrim, evNull) => s"$evPrim = $c;"
488+
case _: UserDefinedType[_] =>
489+
throw new SparkException(s"Cannot cast $from to $to.")
482490
}
483491

484492
// Since we need to cast child expressions recursively inside ComplexTypes, such as Map's

0 commit comments

Comments
 (0)