Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12051#discussion_r57826243
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUDFs.scala 
---
    @@ -65,55 +67,97 @@ private[hive] class HiveFunctionRegistry(
     
           val functionClassName = functionInfo.getFunctionClass.getName
     
    -      // When we instantiate hive UDF wrapper class, we may throw 
exception if the input expressions
    -      // don't satisfy the hive UDF, such as type mismatch, input number 
mismatch, etc. Here we
    -      // catch the exception and throw AnalysisException instead.
    +      // Make an expression of the appropriate type based on the function 
class.
           try {
             if 
(classOf[GenericUDFMacro].isAssignableFrom(functionInfo.getFunctionClass)) {
               val udf = HiveGenericUDF(
                 name, new HiveFunctionWrapper(functionClassName, 
functionInfo.getGenericUDF), children)
               udf.dataType // Force it to check input data types.
               udf
    -        } else if 
(classOf[UDF].isAssignableFrom(functionInfo.getFunctionClass)) {
    -          val udf = HiveSimpleUDF(name, new 
HiveFunctionWrapper(functionClassName), children)
    +        } else {
    +          makeFunctionBuilder(name, 
functionInfo.getFunctionClass)(children)
    +        }
    +      } catch {
    +        case ae: AnalysisException =>
    +          throw ae
    +        case NonFatal(e) =>
    +          // TODO: don't swallow stack trace here
    +          throw new AnalysisException(
    +            s"No handler for Hive UDF 
'${functionInfo.getFunctionClass.getCanonicalName}': $e")
    +      }
    +    }
    +  }
    +
    +  /**
    +   * Construct a [[FunctionBuilder]] based on the provided class that 
represents a function.
    +   *
    +   * This performs reflection to decide what type of [[Expression]] to 
return in the builder.
    +   * This is useful for creating temporary functions.
    +   */
    +  override def makeFunctionBuilder(funcName: String, funcClassName: 
String): FunctionBuilder = {
    +    makeFunctionBuilder(funcName, Utils.classForName(funcClassName))
    +  }
    --- End diff --
    
    Yay! It's great to avoid of letting Hive load the classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to