Skip to content


CodeGenerator is a base class for generators of JVM bytecode for expression evaluation.

[[internal-properties]] .CodeGenerator's Internal Properties [cols="1,2",options="header",width="100%"] |=== | Name | Description

| [[cache]] cache | Guava's[LoadingCache] with at most 100 pairs of CodeAndComment and GeneratedClass.

[[genericMutableRowType]] genericMutableRowType

[[logging]] [TIP] ==== Enable INFO or DEBUG logging level for org.apache.spark.sql.catalyst.expressions.codegen.CodeGenerator logger to see what happens inside.

Add the following line to conf/

Refer to[Logging].

=== [[contract]] CodeGenerator Contract

[source, scala]

package org.apache.spark.sql.catalyst.expressions.codegen

abstract class CodeGenerator[InType, OutType] { def create(in: InType): OutType def canonicalize(in: InType): InType def bind(in: InType, inputSchema: Seq[Attribute]): InType def generate(expressions: InType, inputSchema: Seq[Attribute]): OutType def generate(expressions: InType): OutType }

.CodeGenerator Contract [cols="1,2",options="header",width="100%"] |=== | Method | Description

| [[generate]] generate a| Generates an evaluator for expression(s) that may (optionally) have expression(s) bound to a schema (i.e. a collection of[Attribute]).

Used in:


=== [[doCompile]] Compiling Java Source Code using Janino -- doCompile Internal Method


=== [[compile]] Finding or Compiling Java Source Code -- compile Method


=== [[create]] create Method

[source, scala]

create(references: Seq[Expression]): UnsafeProjection



create is used when:

  • CodeGenerator <>
  • GenerateOrdering creates a code gen ordering for SortOrder expressions

Creating CodegenContext

newCodeGenContext(): CodegenContext

newCodeGenContext simply creates a new CodegenContext.

newCodeGenContext is used when:

Back to top