Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/22512#discussion_r222532952
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/InterpretedMutableProjection.scala
---
@@ -53,6 +55,47 @@ class InterpretedMutableProjection(expressions:
Seq[Expression]) extends Mutable
this
}
+ private[this] val fieldWriters = validExprs.map { case (e, i) =>
+ val writer = generateRowWriter(i, e.dataType)
+ if (!e.nullable) {
+ (v: Any) => writer(v)
+ } else {
+ (v: Any) => {
+ if (v == null) {
+ mutableRow.setNullAt(i)
+ } else {
+ writer(v)
+ }
+ }
+ }
+ }
+
+ private def generateRowWriter(ordinal: Int, dt: DataType): Any => Unit =
dt match {
+ case BooleanType =>
+ v => mutableRow.setBoolean(ordinal, v.asInstanceOf[Boolean])
+ case ByteType =>
+ v => mutableRow.setByte(ordinal, v.asInstanceOf[Byte])
+ case ShortType =>
+ v => mutableRow.setShort(ordinal, v.asInstanceOf[Short])
+ case IntegerType | DateType =>
+ v => mutableRow.setInt(ordinal, v.asInstanceOf[Int])
+ case LongType | TimestampType =>
+ v => mutableRow.setLong(ordinal, v.asInstanceOf[Long])
+ case FloatType =>
+ v => mutableRow.setFloat(ordinal, v.asInstanceOf[Float])
+ case DoubleType =>
+ v => mutableRow.setDouble(ordinal, v.asInstanceOf[Double])
+ case DecimalType.Fixed(precision, _) =>
+ v => mutableRow.setDecimal(ordinal, v.asInstanceOf[Decimal],
precision)
+ case CalendarIntervalType | BinaryType | _: ArrayType | StringType |
_: StructType |
+ _: MapType | _: UserDefinedType[_] =>
+ v => mutableRow.update(ordinal, v)
--- End diff --
`UnsafeRow` doesn't support it, right?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]