Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22512#discussion_r227238888
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/InterpretedMutableProjection.scala
 ---
    @@ -49,10 +51,54 @@ class InterpretedMutableProjection(expressions: 
Seq[Expression]) extends Mutable
       def currentValue: InternalRow = mutableRow
     
       override def target(row: InternalRow): MutableProjection = {
    +    // If `mutableRow` is `UnsafeRow`, `MutableProjection` accepts 
fixed-length types only
    +    assert(!row.isInstanceOf[UnsafeRow] ||
    +      validExprs.forall { case (e, _) => 
UnsafeRow.isFixedLength(e.dataType) })
         mutableRow = row
         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)
    +    case NullType =>
    +      v => {}
    --- End diff --
    
    the corresponding logic in the codegen version is simply call 
`row.update(null, i)`.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to