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

    https://github.com/apache/spark/pull/20753#discussion_r173326718
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
 ---
    @@ -188,8 +189,30 @@ case class StaticInvoke(
       override def nullable: Boolean = needNullCheck || returnNullable
       override def children: Seq[Expression] = arguments
     
    -  override def eval(input: InternalRow): Any =
    -    throw new UnsupportedOperationException("Only code-generated 
evaluation is supported.")
    +  override def eval(input: InternalRow): Any = {
    +    val args = arguments.map(e => e.eval(input).asInstanceOf[Object])
    +    val argClasses = 
CallMethodViaReflection.expressionJavaClasses(arguments)
    +    val cls = if (staticObject.getName == objectName) {
    +      staticObject
    +    } else {
    +      Utils.classForName(objectName)
    +    }
    +    val method = cls.getDeclaredMethod(functionName, argClasses : _*)
    +    if (needNullCheck && args.exists(_ == null)) {
    +      // return null if one of arguments is null
    +      null
    +    } else {
    +      val ret = method.invoke(null, args: _*)
    +
    +      if (CodeGenerator.defaultValue(dataType) == "null") {
    +        ret
    +      } else {
    +        // cast a primitive value using Boxed class
    +        val boxedClass = 
CallMethodViaReflection.typeBoxedJavaMapping(dataType)
    --- End diff --
    
    nit: I think we can directly do like this without the `if`.
    ```scala
    val boxedClass = CallMethodViaReflection.typeBoxedJavaMapping.get(dataType)
    boxedClass.map(_.cast(ret)).getOrElse(ret)
    ```


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to