cloud-fan commented on code in PR #40394: URL: https://github.com/apache/spark/pull/40394#discussion_r1136440410
########## sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUDFs.scala: ########## @@ -130,57 +130,33 @@ private[hive] case class HiveGenericUDF( name: String, funcWrapper: HiveFunctionWrapper, children: Seq[Expression]) extends Expression with HiveInspectors - with Logging with UserDefinedExpression { override def nullable: Boolean = true - override lazy val deterministic: Boolean = isUDFDeterministic && children.forall(_.deterministic) + override lazy val deterministic: Boolean = + isUDFDeterministic && children.forall(_.deterministic) - override def foldable: Boolean = - isUDFDeterministic && returnInspector.isInstanceOf[ConstantObjectInspector] + override def foldable: Boolean = isUDFDeterministic && + evaluator.returnInspector.isInstanceOf[ConstantObjectInspector] - @transient - lazy val function = funcWrapper.createFunction[GenericUDF]() - - @transient - private lazy val argumentInspectors = children.map(toInspector) - - @transient - private lazy val returnInspector = { - function.initializeAndFoldConstants(argumentInspectors.toArray) - } + override lazy val dataType: DataType = inspectorToDataType(evaluator.returnInspector) - // Visible for codegen @transient - lazy val unwrapper: Any => Any = unwrapperFor(returnInspector) + private lazy val evaluator = new HiveGenericUDFEvaluator(funcWrapper, children) @transient - private lazy val isUDFDeterministic = { - val udfType = function.getClass.getAnnotation(classOf[HiveUDFType]) + private val isUDFDeterministic = { + val udfType = evaluator.function.getClass.getAnnotation(classOf[HiveUDFType]) udfType != null && udfType.deterministic() && !udfType.stateful() } - // Visible for codegen - @transient - lazy val deferredObjects: Array[DeferredObject] = argumentInspectors.zip(children).map { - case (inspect, child) => new DeferredObjectAdapter(inspect, child.dataType) - }.toArray[DeferredObject] - - override lazy val dataType: DataType = inspectorToDataType(returnInspector) - override def eval(input: InternalRow): Any = { - returnInspector // Make sure initialized. - - var i = 0 - val length = children.length - while (i < length) { - val idx = i - deferredObjects(i).asInstanceOf[DeferredObjectAdapter] - .set(children(idx).eval(input)) - i += 1 + children.zipWithIndex.map { + case (child, idx) => + evaluator.setArg(idx, child.eval(input)) Review Comment: ```suggestion case (child, idx) => evaluator.setArg(idx, child.eval(input)) ``` -- 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. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org 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