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]
// create an InternalRow using ExpressionEncoder
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
import spark.implicits.newLongEncoder
val longExprEnc = newLongEncoder.asInstanceOf[ExpressionEncoder[Long]]
val row = longExprEnc.toRow(5)
val five = boundRef.eval(row).asInstanceOf[Long]
BoundReference Leaf Expression — Reference to Value in Internal Binary Row
BoundReference
is a leaf expression that is a reference to a value in internal binary row at a specified position and of specified data type.
BoundReference
holds the following:
eval
Method
eval(input: InternalRow): Any
eval
gives the value at position in the input
internal binary row that is of a correct type.
Internally, eval
returns null
if the value at the position is null
.
Otherwise, eval
uses the methods of InternalRow
per the defined data type to access the value.
DataType | InternalRow’s Method |
---|---|
BooleanType |
getBoolean |
ByteType |
getByte |
ShortType |
getShort |
IntegerType |
getInt |
DateType |
getInt |
LongType |
getLong |
TimestampType |
getLong |
FloatType |
getFloat |
DoubleType |
getDouble |
StringType |
getUTF8String |
BinaryType |
getBinary |
CalendarIntervalType |
getInterval |
DecimalType |
getDecimal |
StructType |
getStruct |
ArrayType |
getArray |
MapType |
getMap |
others |
get(ordinal, dataType) |
Note
|
eval is a part of Expression Contract that evaluates the expression to a JVM object for a given internal binary row.
|