cloud-fan commented on a change in pull request #34303:
URL: https://github.com/apache/spark/pull/34303#discussion_r730971965
##########
File path:
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveSessionCatalog.scala
##########
@@ -119,10 +125,52 @@ private[sql] class HiveSessionCatalog(
try {
super.makeFunctionExpression(name, clazz, input)
} catch {
- // If `super.makeFunctionExpression` throw `InvalidUDFClassException`,
we construct
- // Hive UDF/UDAF/UDTF with function definition. Otherwise, we just
throw it earlier.
+ // If `super.makeFunctionExpression` throw `InvalidUDFClassException`,
we try to construct
+ // ScalaAggregator or Hive UDF/UDAF/UDTF with function definition.
Otherwise,
+ // we just throw it earlier.
case _: InvalidUDFClassException =>
- makeHiveFunctionExpression(name, clazz, input)
+ val clsForAggregator = classOf[Aggregator[_, _, _]]
+ if (clsForAggregator.isAssignableFrom(clazz)) {
+ val clsForEncoder = classOf[ExpressionEncoder[_]]
+ val aggregator =
clazz.getConstructor().newInstance().asInstanceOf[Aggregator[_, _, _]]
+ // Construct the input encoder
+ val mirror = runtimeMirror(clazz.getClassLoader)
+ val classType = mirror.classSymbol(clazz)
+ val baseClassType = typeOf[Aggregator[_, _, _]].typeSymbol.asClass
+ val baseType = internal.thisType(classType).baseType(baseClassType)
+ val tpe = baseType.typeArgs.head
+ val cls = mirror.runtimeClass(tpe)
+ val serializer = ScalaReflection.serializerForType(tpe)
+ val deserializer = ScalaReflection.deserializerForType(tpe)
+ val inputEncoder = new ExpressionEncoder(
+ serializer,
+ deserializer,
+ ClassTag(cls))
+
+ val e = classOf[ScalaAggregator[_, _,
_]].getConstructor(classOf[Seq[Expression]],
Review comment:
can't we just `new ScalaAggregator`?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]