Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8747#discussion_r40959365
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateUnsafeProjection.scala
 ---
    @@ -393,10 +393,278 @@ object GenerateUnsafeProjection extends 
CodeGenerator[Seq[Expression], UnsafePro
         case _ => input
       }
     
    +  val rowWriterClass = classOf[UnsafeRowWriter].getName
    +  val arrayWriterClass = classOf[UnsafeArrayWriter].getName
    +
    +  // todo: if the nullability of field is correct, we can use it to save 
null check.
    +  private def writeStructToBuffer(
    +      ctx: CodeGenContext,
    +      input: String,
    +      fieldTypes: Seq[DataType],
    +      bufferHolder: String): String = {
    +    val fieldEvals = fieldTypes.zipWithIndex.map { case (dt, i) =>
    +      val fieldName = ctx.freshName("fieldName")
    +      val code = s"final ${ctx.javaType(dt)} $fieldName = 
${ctx.getValue(input, dt, i.toString)};"
    +      val isNull = s"$input.isNullAt($i)"
    +      GeneratedExpressionCode(code, isNull, fieldName)
    +    }
    +
    +    s"""
    +      if ($input instanceof UnsafeRow) {
    +        $rowWriterClass.directWrite($bufferHolder, (UnsafeRow) $input);
    +      } else {
    +        ${writeExpressionsToBuffer(ctx, input, fieldEvals, fieldTypes, 
bufferHolder)}
    +      }
    +    """
    +  }
    +
    +  private def writeExpressionsToBuffer(
    +      ctx: CodeGenContext,
    +      row: String,
    +      inputs: Seq[GeneratedExpressionCode],
    +      inputTypes: Seq[DataType],
    +      bufferHolder: String): String = {
    +    val rowWriter = ctx.freshName("rowWriter")
    +    ctx.addMutableState(rowWriterClass, rowWriter, s"this.$rowWriter = new 
$rowWriterClass();")
    +
    +    val writeFields = inputs.zip(inputTypes).zipWithIndex.map {
    +      case ((input, dt), index) =>
    +        val tmpCursor = ctx.freshName("tmpCursor")
    +
    +        val setNull = dt match {
    +          case t: DecimalType if t.precision > Decimal.MAX_LONG_DIGITS =>
    +            // Can't call setNullAt() for DecimalType with precision 
larger than 18.
    +            s"$rowWriter.write($index, null, 0, 0);"
    --- End diff --
    
    Pass the correct precision and scale, we may use it in future.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to