spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiszk <...@git.apache.org>
Subject [GitHub] spark pull request #20797: [SPARK-23583][SQL] Invoke should support interpre...
Date Mon, 12 Mar 2018 18:56:46 GMT
Github user kiszk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20797#discussion_r173910172
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
---
    @@ -266,8 +266,26 @@ case class Invoke(
       override def nullable: Boolean = targetObject.nullable || needNullCheck || returnNullable
       override def children: Seq[Expression] = targetObject +: arguments
     
    -  override def eval(input: InternalRow): Any =
    -    throw new UnsupportedOperationException("Only code-generated evaluation is supported.")
    +  override def eval(input: InternalRow): Any = {
    +    val obj = targetObject.eval(input)
    +    val args = arguments.map(e => e.eval(input).asInstanceOf[Object])
    +    val argClasses = CallMethodViaReflection.expressionJavaClasses(arguments)
    +    val method = obj.getClass.getDeclaredMethod(functionName, argClasses : _*)
    +    if (needNullCheck && args.exists(_ == null)) {
    +      // return null if one of arguments is null
    +      null
    +    } else {
    +      val ret = method.invoke(obj, args: _*)
    +
    +      if (CodeGenerator.defaultValue(dataType) == "null") {
    +        ret
    +      } else {
    +        // cast a primitive value using Boxed class
    +        val boxedClass = CallMethodViaReflection.typeBoxedJavaMapping(dataType)
    +        boxedClass.cast(ret)
    --- End diff --
    
    It would work without this cast in Scala. I tried to follow [this cast|https://github.com/kiszk/spark/blob/d81c9502a94b30a13afe284fc7e389edd9da02a0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala#L336]
that may throw an exception.


---

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


Mime
View raw message