Skip to content

Commit ae55e01

Browse files
committed
Add check if genFunction returns an Option.
1 parent 7389e15 commit ae55e01

File tree

1 file changed

+12
-3
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions

1 file changed

+12
-3
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@ case class MapObjects(
439439
s"boolean ${loopVar.isNull} = ${genInputData.isNull} || ${loopVar.value} == null;"
440440
}
441441

442+
val isGenFunctionReturnOption = lambdaFunction.dataType match {
443+
case ObjectType(cls) if cls == classOf[Option[_]] => "true"
444+
case _ => "false"
445+
}
446+
442447
s"""
443448
${genInputData.code}
444449

@@ -456,11 +461,15 @@ case class MapObjects(
456461
($elementJavaType)${genInputData.value}${itemAccessor(loopIndex)};
457462
$loopNullCheck
458463

459-
${genFunction.code}
460-
if (${genFunction.isNull}) {
464+
if (${loopVar.isNull} && !${isGenFunctionReturnOption}) {
461465
$convertedArray[$loopIndex] = null;
462466
} else {
463-
$convertedArray[$loopIndex] = ${genFunction.value};
467+
${genFunction.code}
468+
if (${genFunction.isNull}) {
469+
$convertedArray[$loopIndex] = null;
470+
} else {
471+
$convertedArray[$loopIndex] = ${genFunction.value};
472+
}
464473
}
465474

466475
$loopIndex += 1;

0 commit comments

Comments
 (0)