cloud-fan commented on a change in pull request #28645: URL: https://github.com/apache/spark/pull/28645#discussion_r442168705
########## File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/ScalaUDF.scala ########## @@ -103,17 +102,19 @@ case class ScalaUDF( } } - private def createToScalaConverter(i: Int, dataType: DataType): Any => Any = { - if (inputEncoders.isEmpty) { - // for untyped Scala UDF - CatalystTypeConverters.createToScalaConverter(dataType) + private def scalaConverter(i: Int, dataType: DataType): Any => Any = { + if (inputEncoders.isEmpty || // for untyped Scala UDF + inputEncoders(i).isEmpty || // for types aren't supported by encoder, e.g. Any + inputPrimitives(i) || // inputPrimitives is not empty when inputEncoders is not empty + dataType.existsRecursively(_.isInstanceOf[UserDefinedType[_]])) { + createToScalaConverter(dataType) } else { - val encoder = inputEncoders(i) - if (encoder.isDefined && encoder.get.isSerializedAsStructForTopLevel) { - val fromRow = encoder.get.resolveAndBind().createDeserializer() + val enc = inputEncoders(i).get + val fromRow = enc.createDeserializer() + if (enc.isSerializedAsStructForTopLevel) { row: Any => fromRow(row.asInstanceOf[InternalRow]) } else { - CatalystTypeConverters.createToScalaConverter(dataType) + value: Any => fromRow(new GenericInternalRow(Array(value))) Review comment: it's too expensive to create a `GenericInternalRow` and `Array` for each input. We should do ``` val inputRow = new GenericInternalRow(1) value: Any => inputRow.set(0, value); fromRow(inputRow) ``` ---------------------------------------------------------------- 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: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org