Skip to content

BoundReference Leaf Expression -- Reference to Value in Internal Binary Row

BoundReference is a leaf expression that <> at a specified <> and of a given <>.

import org.apache.spark.sql.catalyst.expressions.BoundReference
import org.apache.spark.sql.types.LongType
val boundRef = BoundReference(ordinal = 0, dataType = LongType, nullable = true)

scala> println(boundRef.toString)
input[0, bigint, true]

import org.apache.spark.sql.catalyst.InternalRow
val row = InternalRow(1L, "hello")

val value = boundRef.eval(row).asInstanceOf[Long]

You can also create a BoundReference using Catalyst DSL's at method.

import org.apache.spark.sql.catalyst.dsl.expressions._
val boundRef = '
scala> println(boundRef)
input[4, string, true]

=== [[eval]] Evaluating Expression -- eval Method

[source, scala]

eval(input: InternalRow): Any

eval is part of the Expression abstraction.

eval gives the value at <> from the given InternalRow that is of a correct type.

Internally, eval returns null if the value at the <> is null.

Otherwise, eval uses the methods of InternalRow per the defined <> to access the value.

.eval's DataType to InternalRow's Methods Mapping (in execution order) [cols="1,m",options="header",width="100%"] |=== | DataType | InternalRow's Method

| BooleanType | getBoolean

| ByteType | getByte

| ShortType | getShort

| IntegerType or DateType | getInt

| LongType or TimestampType | getLong

| FloatType | getFloat

| DoubleType | getDouble

| StringType | getUTF8String

| BinaryType | getBinary

| CalendarIntervalType | getInterval

| DecimalType | getDecimal

| StructType | getStruct

| ArrayType | getArray

| MapType | getMap

| others | get(ordinal, dataType) |===

Creating Instance

BoundReference takes the following to be created:

  • [[ordinal]] Ordinal, i.e. the position
  • [[dataType]] Data type of the value
  • [[nullable]] nullable flag that controls whether the value can be null or not

=== [[doGenCode]] Generating Java Source Code (ExprCode) For Code-Generated Expression Evaluation -- doGenCode Method

[source, scala]

doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode

NOTE: doGenCode is part of <> to generate a Java source code (ExprCode) for code-generated expression evaluation.


=== [[BindReferences]][[bindReference]] BindReferences.bindReference Method

[source, scala]

bindReferenceA <: Expression: A


NOTE: bindReference is used when...FIXME

Last update: 2020-11-16