You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/10/21 09:05:50 UTC

[GitHub] [spark] cloud-fan commented on a change in pull request #34352: [SPARK-37018][SQL] Spark SQL should support create function with Aggregator

cloud-fan commented on a change in pull request #34352:
URL: https://github.com/apache/spark/pull/34352#discussion_r733473172



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/internal/BaseSessionStateBuilder.scala
##########
@@ -410,6 +415,35 @@ class SparkUDFExpressionBuilder extends FunctionExpressionBuilder {
           name, expr.inputTypes.size.toString, input.size)
       }
       expr
+    } else if (classOf[Aggregator[_, _, _]].isAssignableFrom(clazz)) {
+      val aggregator = clazz.getConstructor().newInstance().asInstanceOf[Aggregator[Any, Any, Any]]
+
+      // Construct the input encoder
+      val mirror = universe.runtimeMirror(clazz.getClassLoader)
+      val classType = mirror.classSymbol(clazz)
+      val baseClassType = universe.typeOf[Aggregator[_, _, _]].typeSymbol.asClass
+      val baseType = universe.internal.thisType(classType).baseType(baseClassType)
+      val tpe = baseType.typeArgs.head
+      val cls = mirror.runtimeClass(tpe)

Review comment:
       Is there any reference for the code above? The code looks obscure




-- 
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-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org