This is an automated email from the ASF dual-hosted git repository.

gurwls223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 9a79779  [SPARK-34724][SQL] Fix Interpreted evaluation by using 
getMethod instead of getDeclaredMethod
9a79779 is described below

commit 9a7977933fd08d0e95ffa59161bed3b10bc9ca61
Author: Dongjoon Hyun <dh...@apple.com>
AuthorDate: Fri Mar 12 21:30:46 2021 +0900

    [SPARK-34724][SQL] Fix Interpreted evaluation by using getMethod instead of 
getDeclaredMethod
    
    ### What changes were proposed in this pull request?
    
    This bug was introduced by SPARK-23583 at Apache Spark 2.4.0.
    
    This PR aims to use `getMethod` instead of `getDeclaredMethod`.
    ```scala
    - obj.getClass.getDeclaredMethod(functionName, argClasses: _*)
    + obj.getClass.getMethod(functionName, argClasses: _*)
    ```
    
    ### Why are the changes needed?
    
    `getDeclaredMethod` does not search the super class's method. To invoke 
`GenericArrayData.toIntArray`, we need to use `getMethod` because it's declared 
at the super class `ArrayData`.
    
    ```
    [info] - encode/decode for array of int: [I74655d03 (interpreted path) *** 
FAILED *** (14 milliseconds)
    [info]   Exception thrown while decoding
    [info]   Converted: [0,1000000020,3,0,ffffff850000001f,4]
    [info]   Schema: value#680
    [info]   root
    [info]   -- value: array (nullable = true)
    [info]       |-- element: integer (containsNull = false)
    [info]
    [info]
    [info]   Encoder:
    [info]   class[value[0]: array<int>] (ExpressionEncoderSuite.scala:578)
    [info]   org.scalatest.exceptions.TestFailedException:
    [info]   at 
org.scalatest.Assertions.newAssertionFailedException(Assertions.scala:472)
    [info]   at 
org.scalatest.Assertions.newAssertionFailedException$(Assertions.scala:471)
    [info]   at 
org.scalatest.funsuite.AnyFunSuite.newAssertionFailedException(AnyFunSuite.scala:1563)
    [info]   at org.scalatest.Assertions.fail(Assertions.scala:949)
    [info]   at org.scalatest.Assertions.fail$(Assertions.scala:945)
    [info]   at org.scalatest.funsuite.AnyFunSuite.fail(AnyFunSuite.scala:1563)
    [info]   at 
org.apache.spark.sql.catalyst.encoders.ExpressionEncoderSuite.$anonfun$encodeDecodeTest$1(ExpressionEncoderSuite.scala:578)
    [info]   at 
org.apache.spark.sql.catalyst.encoders.ExpressionEncoderSuite.verifyNotLeakingReflectionObjects(ExpressionEncoderSuite.scala:656)
    [info]   at 
org.apache.spark.sql.catalyst.encoders.ExpressionEncoderSuite.$anonfun$testAndVerifyNotLeakingReflectionObjects$2(ExpressionEncoderSuite.scala:669)
    [info]   at 
org.apache.spark.sql.catalyst.plans.CodegenInterpretedPlanTest.$anonfun$test$4(PlanTest.scala:50)
    [info]   at 
org.apache.spark.sql.catalyst.plans.SQLHelper.withSQLConf(SQLHelper.scala:54)
    [info]   at 
org.apache.spark.sql.catalyst.plans.SQLHelper.withSQLConf$(SQLHelper.scala:38)
    [info]   at 
org.apache.spark.sql.catalyst.encoders.ExpressionEncoderSuite.withSQLConf(ExpressionEncoderSuite.scala:118)
    [info]   at 
org.apache.spark.sql.catalyst.plans.CodegenInterpretedPlanTest.$anonfun$test$3(PlanTest.scala:50)
    ...
    [info]   Cause: java.lang.RuntimeException: Error while decoding: 
java.lang.NoSuchMethodException: 
org.apache.spark.sql.catalyst.util.GenericArrayData.toIntArray()
    [info] mapobjects(lambdavariable(MapObject, IntegerType, false, -1), 
assertnotnull(lambdavariable(MapObject, IntegerType, false, -1)), input[0, 
array<int>, true], None).toIntArray
    [info]   at 
org.apache.spark.sql.catalyst.encoders.ExpressionEncoder$Deserializer.apply(ExpressionEncoder.scala:186)
    [info]   at 
org.apache.spark.sql.catalyst.encoders.ExpressionEncoderSuite.$anonfun$encodeDecodeTest$1(ExpressionEncoderSuite.scala:576)
    [info]   at 
org.apache.spark.sql.catalyst.encoders.ExpressionEncoderSuite.verifyNotLeakingReflectionObjects(ExpressionEncoderSuite.scala:656)
    [info]   at 
org.apache.spark.sql.catalyst.encoders.ExpressionEncoderSuite.$anonfun$testAndVerifyNotLeakingReflectionObjects$2(ExpressionEncoderSuite.scala:669)
    ```
    
    ### Does this PR introduce _any_ user-facing change?
    
    This causes a runtime exception when we use the interpreted mode.
    
    ### How was this patch tested?
    
    Pass the modified unit test case.
    
    Closes #31816 from dongjoon-hyun/SPARK-34724.
    
    Authored-by: Dongjoon Hyun <dh...@apple.com>
    Signed-off-by: HyukjinKwon <gurwls...@apache.org>
---
 .../org/apache/spark/sql/catalyst/expressions/objects/objects.scala   | 2 +-
 .../apache/spark/sql/catalyst/encoders/ExpressionEncoderSuite.scala   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
index 48d1fdb..8ff1193 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
@@ -333,7 +333,7 @@ case class Invoke(
       val invokeMethod = if (method.isDefined) {
         method.get
       } else {
-        obj.getClass.getDeclaredMethod(functionName, argClasses: _*)
+        obj.getClass.getMethod(functionName, argClasses: _*)
       }
       invoke(obj, invokeMethod, arguments, input, dataType)
     }
diff --git 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/ExpressionEncoderSuite.scala
 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/ExpressionEncoderSuite.scala
index 6c2da4d3..1a70e06 100644
--- 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/ExpressionEncoderSuite.scala
+++ 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/ExpressionEncoderSuite.scala
@@ -161,10 +161,10 @@ class ExpressionEncoderSuite extends 
CodegenInterpretedPlanTest with AnalysisTes
   encodeDecodeTest(Seq(Seq("abc", "xyz"), Seq[String](null), null, Seq("1", 
null, "2")),
     "seq of seq of string")
 
-  encodeDecodeTest(Array(31, -123, 4), "array of int", useFallback = true)
+  encodeDecodeTest(Array(31, -123, 4), "array of int")
   encodeDecodeTest(Array("abc", "xyz"), "array of string")
   encodeDecodeTest(Array("a", null, "x"), "array of string with null")
-  encodeDecodeTest(Array.empty[Int], "empty array of int", useFallback = true)
+  encodeDecodeTest(Array.empty[Int], "empty array of int")
   encodeDecodeTest(Array.empty[String], "empty array of string")
 
   encodeDecodeTest(Array(Array(31, -123), null, Array(4, 67)), "array of array 
of int",


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

Reply via email to