@@ -556,6 +556,42 @@ class ObjectExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
556
556
" java.lang.Integer is not a valid external type for schema of double" )
557
557
}
558
558
559
+ test(" SPARK-XXXXX ValidateExternalType should return child in error" ) {
560
+ val inputObject = BoundReference (0 , ObjectType (classOf [Row ]), nullable = true )
561
+ Seq (
562
+ (true , BooleanType ),
563
+ (2 .toByte, ByteType ),
564
+ (5 .toShort, ShortType ),
565
+ (23 , IntegerType ),
566
+ (61L , LongType ),
567
+ (1.0f , FloatType ),
568
+ (10.0 , DoubleType ),
569
+ (" abcd" .getBytes, BinaryType ),
570
+ (" abcd" , StringType ),
571
+ (BigDecimal .valueOf(10 ), DecimalType .IntDecimal ),
572
+ (IntervalUtils .stringToInterval(UTF8String .fromString(" interval 3 day" )),
573
+ CalendarIntervalType ),
574
+ (java.math.BigDecimal .valueOf(10 ), DecimalType .BigIntDecimal ),
575
+ (Array (3 , 2 , 1 ), ArrayType (IntegerType ))
576
+ ).foreach { case (input, dt) =>
577
+ val enc = RowEncoder .encoderForDataType(dt, lenient = false )
578
+ val validateType = ValidateExternalType (
579
+ GetExternalRowField (inputObject, index = 0 , fieldName = " c0" ),
580
+ dt,
581
+ EncoderUtils .lenientExternalDataTypeFor(enc))
582
+ checkObjectExprEvaluation(validateType, input, InternalRow .fromSeq(Seq (Row (input))))
583
+ }
584
+
585
+ checkExceptionInExpression[RuntimeException ](
586
+ ValidateExternalType (
587
+ GetExternalRowField (inputObject, index = 0 , fieldName = " c0" ),
588
+ DoubleType ,
589
+ DoubleType ),
590
+ InternalRow .fromSeq(Seq (Row (1 ))),
591
+ " java.lang.Integer is not a valid external type for schema of double" +
592
+ " at getexternalrowfield(input[0, org.apache.spark.sql.Row, true], 0, c0)" )
593
+ }
594
+
559
595
private def javaMapSerializerFor (
560
596
keyClazz : Class [_],
561
597
valueClazz : Class [_])(inputObject : Expression ): Expression = {
0 commit comments