Skip to content

CodeGenerator

CodeGenerator is an abstraction of JVM bytecode generators for expression evaluation.

The Scala definition of this abstract class is as follows:

CodeGenerator[InType <: AnyRef, OutType <: AnyRef]

Contract

bind

bind(
  in: InType,
  inputSchema: Seq[Attribute]): InType

Used when:

  • CodeGenerator is requested to generate

canonicalize

canonicalize(
  in: InType): InType

Used when:

  • CodeGenerator is requested to generate

create

create(
  in: InType): OutType

Used when:

  • CodeGenerator is requested to generate

Implementations

generate

generate(
  expressions: InType): OutType
generate(
  expressions: InType,
  inputSchema: Seq[Attribute]): OutType // (1)!
  1. Binds the input expressions to the given input schema

generate creates a class for the input expressions (after canonicalization).

generate is used when:

  • Serializer (of ExpressionEncoder) is requested to apply
  • RowOrdering utility is used to createCodeGeneratedObject
  • SafeProjection utility is used to createCodeGeneratedObject
  • LazilyGeneratedOrdering is requested for generatedOrdering
  • ObjectOperator utility is used to deserializeRowToObject and serializeObjectToRow
  • ComplexTypedAggregateExpression is requested for inputRowToObj and bufferRowToObject
  • DefaultCachedBatchSerializer is requested to convertCachedBatchToInternalRow

Creating CodegenContext

newCodeGenContext(): CodegenContext

newCodeGenContext creates a new CodegenContext.

newCodeGenContext is used when:

Logging

CodeGenerator is an abstract class and logging is configured using the logger of the implementations.