PengleiShi commented on code in PR #34340:
URL: https://github.com/apache/spark/pull/34340#discussion_r1759688689


##########
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:
   @cloud-fan in prior spark version,  it will convert decimal to double when 
exception occuring, #13930  .  At now, some hive udfs which receive double 
throw UDFArgumentException



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