StaticInvoke Non-SQL Expression

StaticInvoke is an expression with no SQL representation that represents a static method call in Scala or Java.

StaticInvoke supports Java code generation (aka whole-stage codegen) to evaluate itself.

StaticInvoke is created when:

  • ScalaReflection is requested for the deserializer or serializer for a Scala type

  • RowEncoder is requested for deserializerFor or serializer for a Scala type

  • JavaTypeInference is requested for deserializerFor or serializerFor

import org.apache.spark.sql.types.StructType
val schema = new StructType()
  .add($"id".long.copy(nullable = false))
  .add($"name".string.copy(nullable = false))

import org.apache.spark.sql.catalyst.encoders.RowEncoder
val encoder = RowEncoder(schema)
scala> println(encoder.serializer(0).numberedTreeString)
00 validateexternaltype(getexternalrowfield(assertnotnull(input[0, org.apache.spark.sql.Row, true]), 0, id), LongType) AS id#1640L
01 +- validateexternaltype(getexternalrowfield(assertnotnull(input[0, org.apache.spark.sql.Row, true]), 0, id), LongType)
02    +- getexternalrowfield(assertnotnull(input[0, org.apache.spark.sql.Row, true]), 0, id)
03       +- assertnotnull(input[0, org.apache.spark.sql.Row, true])
04          +- input[0, org.apache.spark.sql.Row, true]
Note
StaticInvoke is similar to CallMethodViaReflection expression.

Creating StaticInvoke Instance

StaticInvoke takes the following when created:

  • Target object of the static call

  • Data type of the return value of the method

  • Name of the method to call on the static object

  • Optional expressions to pass as input arguments to the function

  • Flag to control whether to propagate nulls or not (enabled by default). If any of the arguments is null, null is returned instead of calling the function

results matching ""

    No results matching ""