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

    https://github.com/apache/spark/pull/6806#discussion_r32375350
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala
 ---
    @@ -158,27 +158,23 @@ object FunctionRegistry {
       /** See usage above. */
       private def expression[T <: Expression](name: String)
           (implicit tag: ClassTag[T]): (String, FunctionBuilder) = {
    -    // Use the companion class to find apply methods.
    -    val objectClass = Class.forName(tag.runtimeClass.getName + "$")
    -    val companionObj = objectClass.getDeclaredField("MODULE$").get(null)
    -
    -    // See if we can find an apply that accepts Seq[Expression]
    -    val varargApply = Try(objectClass.getDeclaredMethod("apply", 
classOf[Seq[_]])).toOption
     
    +    // See if we can find a constructor that accepts Seq[Expression]
    +    val varargCtor = 
Try(tag.runtimeClass.getDeclaredConstructor(classOf[Seq[_]])).toOption
         val builder = (expressions: Seq[Expression]) => {
    -      if (varargApply.isDefined) {
    +      if (varargCtor.isDefined) {
             // If there is an apply method that accepts Seq[Expression], use 
that one.
    -        varargApply.get.invoke(companionObj, 
expressions).asInstanceOf[Expression]
    +        varargCtor.get.newInstance(expressions).asInstanceOf[Expression]
           } else {
    -        // Otherwise, find an apply method that matches the number of 
arguments, and use that.
    +        // Otherwise, find an ctor method that matches the number of 
arguments, and use that.
             val params = Seq.fill(expressions.size)(classOf[Expression])
    -        val f = Try(objectClass.getDeclaredMethod("apply", params : _*)) 
match {
    +        val f = Try(tag.runtimeClass.getDeclaredConstructor(params : _*)) 
match {
               case Success(e) =>
                 e
               case Failure(e) =>
                 throw new AnalysisException(s"Invalid number of arguments for 
function $name")
             }
    --- End diff --
    
    ```scala
    val f = try tag.runtimeClass.getDeclaredConstructor(params : _*) catch {
      case _: NoSuchMethodError =>
        throw new AnalysisException(s"Invalid number of arguments for function 
$name")
    }
    ```
    
    :smile: 


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