@@ -547,13 +547,55 @@ class ObjectExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
547
547
checkObjectExprEvaluation(validateType, input, InternalRow .fromSeq(Seq (Row (input))))
548
548
}
549
549
550
- checkExceptionInExpression[RuntimeException ](
550
+ checkExceptionInExpression[SparkRuntimeException ](
551
551
ValidateExternalType (
552
552
GetExternalRowField (inputObject, index = 0 , fieldName = " c0" ),
553
553
DoubleType ,
554
554
DoubleType ),
555
555
InternalRow .fromSeq(Seq (Row (1 ))),
556
- " java.lang.Integer is not a valid external type for schema of double" )
556
+ " The external type java.lang.Integer is not valid for the type \" DOUBLE\" " )
557
+ }
558
+
559
+ test(" SPARK-49044 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
+ checkErrorInExpression[SparkRuntimeException ](
586
+ expression = ValidateExternalType (
587
+ GetExternalRowField (inputObject, index = 0 , fieldName = " c0" ),
588
+ DoubleType ,
589
+ DoubleType ),
590
+ inputRow = InternalRow .fromSeq(Seq (Row (1 ))),
591
+ errorClass = " INVALID_EXTERNAL_TYPE" ,
592
+ parameters = Map [String , String ](
593
+ " externalType" -> " java.lang.Integer" ,
594
+ " type" -> " \" DOUBLE\" " ,
595
+ " expr" -> (" \" getexternalrowfield(input[0, org.apache.spark.sql.Row, true], " +
596
+ " 0, c0)\" " )
597
+ )
598
+ )
557
599
}
558
600
559
601
private def javaMapSerializerFor (
0 commit comments