sunchao commented on a change in pull request #32407:
URL: https://github.com/apache/spark/pull/32407#discussion_r624094203
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -2164,24 +2165,30 @@ class Analyzer(override val catalogManager:
CatalogManager)
// may also want to check if the parameter types from the magic method
// match the input type through `BoundFunction.inputTypes`.
val argClasses = inputType.fields.map(_.dataType)
- findMethod(scalarFunc, MAGIC_METHOD_NAME, argClasses) match {
+ findMethod(scalarFunc, STATIC_MAGIC_METHOD_NAME, argClasses) match {
case Some(_) =>
- val caller = Literal.create(scalarFunc,
ObjectType(scalarFunc.getClass))
- Invoke(caller, MAGIC_METHOD_NAME, scalarFunc.resultType(),
- arguments, returnNullable = scalarFunc.isResultNullable)
+ StaticInvoke(scalarFunc.getClass, scalarFunc.resultType(),
Review comment:
Yes that's correct. The `StaticInvoke` calls the static method on the
non-anonymous class which just forward to the non-static method defined in
anonymous/singleton Java class (i.e., the class with `$` at the end of its
name).
For instance, for the `LongAddWithStatic` class, this is the method defined
in `LongAddWithStaticMagic.class`:
```
public static long staticInvoke(long, long);
Code:
0: getstatic #16 // Field
org/apache/spark/sql/connector/functions/LongAddWithStaticMagic$.MODULE$:Lorg/apache/spark/sql/connector/functions/LongAddWithStaticMagic$;
3: lload_0
4: lload_2
5: invokevirtual #51 // Method
org/apache/spark/sql/connector/functions/LongAddWithStaticMagic$.staticInvoke:(JJ)J
8: lreturn
```
and the same method defined in the singleton class `LongAddWithStaticMagic$`:
```
public long staticInvoke(long, long);
Code:
0: lload_1
1: lload_3
2: ladd
3: lreturn
```
So I was expecting worse performance from Scala since it calls
`invokevirtual` underneath while Java uses `invoke static`, but the result
doesn't look so. It could be that the performance is dominated by other factors.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]