cloud-fan commented on code in PR #34340:
URL: https://github.com/apache/spark/pull/34340#discussion_r1759967041


##########
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveSessionStateBuilder.scala:
##########
@@ -133,3 +143,68 @@ class HiveSessionResourceLoader(
     }
   }
 }
+
+object HiveUDFExpressionBuilder extends SparkUDFExpressionBuilder {
+  override def makeExpression(name: String, clazz: Class[_], input: 
Seq[Expression]): Expression = {
+    // Current thread context classloader may not be the one loaded the class. 
Need to switch
+    // context classloader to initialize instance properly.
+    Utils.withContextClassLoader(clazz.getClassLoader) {
+      try {
+        super.makeExpression(name, clazz, input)
+      } catch {
+        // If `super.makeFunctionExpression` throw `InvalidUDFClassException`, 
we construct
+        // Hive UDF/UDAF/UDTF with function definition. Otherwise, we just 
throw it earlier.
+        case _: InvalidUDFClassException =>
+          makeHiveFunctionExpression(name, clazz, input)

Review Comment:
   Was it already broken before this PR? The removed code in this PR does not 
have this handling. Anyway, I'm happy to review the fix if you can create a PR, 
thanks!



-- 
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]

Reply via email to