This is an automated email from the ASF dual-hosted git repository. dongjoon 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 5b65d8a [SPARK-35347][SQL] Use MethodUtils for looking up methods in Invoke and StaticInvoke 5b65d8a is described below commit 5b65d8a129a63ac5c9ad482842901a1a0d1420ad Author: Liang-Chi Hsieh <vii...@gmail.com> AuthorDate: Sat May 8 15:17:30 2021 -0700 [SPARK-35347][SQL] Use MethodUtils for looking up methods in Invoke and StaticInvoke ### What changes were proposed in this pull request? This patch proposes to use `MethodUtils` for looking up methods `Invoke` and `StaticInvoke` expressions. ### Why are the changes needed? Currently we wrote our logic in `Invoke` and `StaticInvoke` expressions for looking up methods. It is tricky to consider all the cases and there is already existing utility package for this purpose. We should reuse the utility package. ### Does this PR introduce _any_ user-facing change? No, internal change only. ### How was this patch tested? Existing tests. Closes #32474 from viirya/invoke-util. Authored-by: Liang-Chi Hsieh <vii...@gmail.com> Signed-off-by: Dongjoon Hyun <dongj...@apache.org> --- .../sql/catalyst/expressions/objects/objects.scala | 31 +++++----------------- 1 file changed, 7 insertions(+), 24 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 5d79774..a967dc4 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 @@ -24,6 +24,8 @@ import scala.collection.mutable.{Builder, WrappedArray} import scala.reflect.ClassTag import scala.util.{Properties, Try} +import org.apache.commons.lang3.reflect.MethodUtils + import org.apache.spark.{SparkConf, SparkEnv} import org.apache.spark.serializer._ import org.apache.spark.sql.Row @@ -147,30 +149,11 @@ trait InvokeLike extends Expression with NonSQLExpression { } final def findMethod(cls: Class[_], functionName: String, argClasses: Seq[Class[_]]): Method = { - // Looking with function name + argument classes first. - try { - cls.getMethod(functionName, argClasses: _*) - } catch { - case _: NoSuchMethodException => - // For some cases, e.g. arg class is Object, `getMethod` cannot find the method. - // We look at function name + argument length - val m = cls.getMethods.filter { m => - m.getName == functionName && m.getParameterCount == arguments.length - } - if (m.isEmpty) { - sys.error(s"Couldn't find $functionName on $cls") - } else if (m.length > 1) { - // More than one matched method signature. Exclude synthetic one, e.g. generic one. - val realMethods = m.filter(!_.isSynthetic) - if (realMethods.length > 1) { - // Ambiguous case, we don't know which method to choose, just fail it. - sys.error(s"Found ${realMethods.length} $functionName on $cls") - } else { - realMethods.head - } - } else { - m.head - } + val method = MethodUtils.getMatchingAccessibleMethod(cls, functionName, argClasses: _*) + if (method == null) { + sys.error(s"Couldn't find $functionName on $cls") + } else { + method } } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org