viirya commented on a change in pull request #24636: [SPARK-27684][SQL] Avoid
conversion overhead for primitive types
URL: https://github.com/apache/spark/pull/24636#discussion_r285361122
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ScalaUDF.scala
##########
@@ -1003,22 +1003,38 @@ case class ScalaUDF(
// such as IntegerType, its javaType is `int` and the returned type of
user-defined
// function is Object. Trying to convert an Object to `int` will cause
casting exception.
val evalCode = evals.map(_.code).mkString("\n")
- val (funcArgs, initArgs) = evals.zipWithIndex.map { case (eval, i) =>
- val argTerm = ctx.freshName("arg")
- val convert = s"$convertersTerm[$i].apply(${eval.value})"
- val initArg = s"Object $argTerm = ${eval.isNull} ? null : $convert;"
- (argTerm, initArg)
+ 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)) {
Review comment:
Use `CodeGenerator.isPrimitiveType`?
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]