@@ -422,14 +422,15 @@ case class MapObjects private(
422422 lambdaFunction : Expression ,
423423 inputData : Expression ) extends Expression with NonSQLExpression {
424424
425- override def nullable : Boolean = true
425+ override def nullable : Boolean = inputData.nullable
426426
427427 override def children : Seq [Expression ] = lambdaFunction :: inputData :: Nil
428428
429429 override def eval (input : InternalRow ): Any =
430430 throw new UnsupportedOperationException (" Only code-generated evaluation is supported" )
431431
432- override def dataType : DataType = ArrayType (lambdaFunction.dataType)
432+ override def dataType : DataType =
433+ ArrayType (lambdaFunction.dataType, containsNull = lambdaFunction.nullable)
433434
434435 override def doGenCode (ctx : CodegenContext , ev : ExprCode ): ExprCode = {
435436 val elementJavaType = ctx.javaType(loopVarDataType)
@@ -512,6 +513,18 @@ case class MapObjects private(
512513 case _ => s " $loopIsNull = $loopValue == null; "
513514 }
514515
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+
515528 val code = s """
516529 ${genInputData.code}
517530 ${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)};
@@ -528,11 +541,7 @@ case class MapObjects private(
528541 $loopNullCheck
529542
530543 ${genFunction.code}
531- if ( ${genFunction.isNull}) {
532- $convertedArray[ $loopIndex] = null;
533- } else {
534- $convertedArray[ $loopIndex] = $genFunctionValue;
535- }
544+ $setValue
536545
537546 $loopIndex += 1;
538547 }
0 commit comments