cloud-fan commented on a change in pull request #28645:
URL: https://github.com/apache/spark/pull/28645#discussion_r442172493
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ScalaUDF.scala
##########
@@ -1064,14 +1065,32 @@ case class ScalaUDF(
val (funcArgs, initArgs) =
evals.zipWithIndex.zip(children.map(_.dataType)).map {
case ((eval, i), dt) =>
val argTerm = ctx.freshName("arg")
- val initArg = if (CatalystTypeConverters.isPrimitive(dt)) {
+ // Check `inputPrimitives` when it's not empty in order to figure out
the Option
+ // type as non primitive type, e.g., Option[Int]. Fall back to
`isPrimitive` when
+ // `inputPrimitives` is empty for other cases, e.g., Java UDF, untyped
Scala UDF
+ val primitive = (inputPrimitives.isEmpty && isPrimitive(dt)) ||
+ (inputPrimitives.nonEmpty && inputPrimitives(i))
+ val initArg = if (primitive) {
val convertedTerm = ctx.freshName("conv")
s"""
|${CodeGenerator.boxedType(dt)} $convertedTerm = ${eval.value};
|Object $argTerm = ${eval.isNull} ? null : $convertedTerm;
""".stripMargin
} else {
- s"Object $argTerm = ${eval.isNull} ? null :
$convertersTerm[$i].apply(${eval.value});"
+ s"""
+ |Object $argTerm = null;
+ |// handle the top level Option type specifically
Review comment:
What's special for top-level Option?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]