Github user maropu commented on a diff in the pull request: https://github.com/apache/spark/pull/20757#discussion_r172855693 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala --- @@ -1408,11 +1409,37 @@ case class ValidateExternalType(child: Expression, expected: DataType) override def dataType: DataType = RowEncoder.externalDataTypeForInput(expected) - override def eval(input: InternalRow): Any = - throw new UnsupportedOperationException("Only code-generated evaluation is supported") - private val errMsg = s" is not a valid external type for schema of ${expected.simpleString}" + private lazy val checkType = expected match { + case _: DecimalType => + (value: Any) => { + Seq(classOf[java.math.BigDecimal], classOf[scala.math.BigDecimal], classOf[Decimal]) + .exists { x => value.getClass.isAssignableFrom(x) } + } + case _: ArrayType => + (value: Any) => { + value.getClass.isAssignableFrom(classOf[Seq[_]]) || value.getClass.isArray + } + case _ if ScalaReflection.isNativeType(expected) => + (value: Any) => { + value.getClass.isAssignableFrom(ScalaReflection.classForNativeTypeOf(expected)) + } + case _ => + (value: Any) => { + value.getClass.isAssignableFrom(dataType.asInstanceOf[ObjectType].cls) --- End diff -- Since I thought the previous version is some difficult to read , I cleaned up the code along with the generated version. How about it?
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org