Github user kiszk commented on a diff in the pull request:
https://github.com/apache/spark/pull/20797#discussion_r178761075
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
---
@@ -263,11 +295,21 @@ case class Invoke(
propagateNull: Boolean = true,
returnNullable : Boolean = true) extends InvokeLike {
+ lazy val argClasses = ScalaReflection.expressionJavaClasses(arguments)
+
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)
+ if (obj == null) {
+ // return null if obj is null
+ null
+ } else {
+ val method = obj.getClass.getDeclaredMethod(functionName, argClasses
: _*)
--- End diff --
We can know the base class beforehand. The `obj` class may be a subclass. I
think this is a kind of virtual table lookup based on the literal name?
Since JVM class resolution converts the literal name to a constant offset,
the code generation can perform a fast lookup based on the offset.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]