@@ -422,14 +422,15 @@ case class MapObjects private(
422
422
lambdaFunction : Expression ,
423
423
inputData : Expression ) extends Expression with NonSQLExpression {
424
424
425
- override def nullable : Boolean = true
425
+ override def nullable : Boolean = inputData.nullable
426
426
427
427
override def children : Seq [Expression ] = lambdaFunction :: inputData :: Nil
428
428
429
429
override def eval (input : InternalRow ): Any =
430
430
throw new UnsupportedOperationException (" Only code-generated evaluation is supported" )
431
431
432
- override def dataType : DataType = ArrayType (lambdaFunction.dataType)
432
+ override def dataType : DataType =
433
+ ArrayType (lambdaFunction.dataType, containsNull = lambdaFunction.nullable)
433
434
434
435
override def doGenCode (ctx : CodegenContext , ev : ExprCode ): ExprCode = {
435
436
val elementJavaType = ctx.javaType(loopVarDataType)
@@ -512,6 +513,18 @@ case class MapObjects private(
512
513
case _ => s " $loopIsNull = $loopValue == null; "
513
514
}
514
515
516
+ val setValue = if (lambdaFunction.nullable) {
517
+ s """
518
+ if ( ${genFunction.isNull}) {
519
+ $convertedArray[ $loopIndex] = null;
520
+ } else {
521
+ $convertedArray[ $loopIndex] = $genFunctionValue;
522
+ }
523
+ """
524
+ } else {
525
+ s " $convertedArray[ $loopIndex] = $genFunctionValue; "
526
+ }
527
+
515
528
val code = s """
516
529
${genInputData.code}
517
530
${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)};
@@ -528,11 +541,7 @@ case class MapObjects private(
528
541
$loopNullCheck
529
542
530
543
${genFunction.code}
531
- if ( ${genFunction.isNull}) {
532
- $convertedArray[ $loopIndex] = null;
533
- } else {
534
- $convertedArray[ $loopIndex] = $genFunctionValue;
535
- }
544
+ $setValue
536
545
537
546
$loopIndex += 1;
538
547
}
0 commit comments