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

    https://github.com/apache/spark/pull/8044#discussion_r36575818
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateUnsafeProjection.scala
 ---
    @@ -125,64 +125,68 @@ object GenerateUnsafeProjection extends 
CodeGenerator[Seq[Expression], UnsafePro
        */
       private def createCodeForStruct(
           ctx: CodeGenContext,
    +      row: String,
           inputs: Seq[GeneratedExpressionCode],
           inputTypes: Seq[DataType]): GeneratedExpressionCode = {
     
    +    val fixedSize = 8 * inputTypes.length + 
UnsafeRow.calculateBitSetWidthInBytes(inputTypes.length)
    +
         val output = ctx.freshName("convertedStruct")
    -    ctx.addMutableState("UnsafeRow", output, s"$output = new UnsafeRow();")
    +    ctx.addMutableState("UnsafeRow", output, s"this.$output = new 
UnsafeRow();")
         val buffer = ctx.freshName("buffer")
    -    ctx.addMutableState("byte[]", buffer, s"$buffer = new byte[64];")
    -    val numBytes = ctx.freshName("numBytes")
    +    ctx.addMutableState("byte[]", buffer, s"this.$buffer = new 
byte[$fixedSize];")
         val cursor = ctx.freshName("cursor")
    +    ctx.addMutableState("int", cursor, s"this.$cursor = 0;")
    +    val tmp = ctx.freshName("tmpBuffer")
     
    -    val convertedFields = inputTypes.zip(inputs).map { case (dt, input) =>
    -      createConvertCode(ctx, input, dt)
    -    }
    -
    -    val fixedSize = 8 * inputTypes.length + 
UnsafeRow.calculateBitSetWidthInBytes(inputTypes.length)
    -    val additionalSize = inputTypes.zip(convertedFields).map { case (dt, 
ev) =>
    -      genAdditionalSize(dt, ev)
    -    }.mkString("")
    -
    -    val fieldWriters = inputTypes.zip(convertedFields).zipWithIndex.map { 
case ((dt, ev), i) =>
    -      val update = genFieldWriter(ctx, dt, ev, output, i, cursor)
    -      if (dt.isInstanceOf[DecimalType]) {
    -        // Can't call setNullAt() for DecimalType
    +    val convertedFields = inputTypes.zip(inputs).zipWithIndex.map { case 
((dt, input), i) =>
    +      val ev = createConvertCode(ctx, input, dt)
    +      val growBuffer = if (!UnsafeRow.isFixedLength(dt)) {
    +        val numBytes = ctx.freshName("numBytes")
             s"""
    +          int $numBytes = $cursor + (${genAdditionalSize(dt, ev)});
    +          if ($buffer.length < $numBytes) {
    +            // This will not happen frequently, because the buffer is 
re-used.
    +            byte[] $tmp = new byte[$numBytes * 3 / 2];
    +            System.arraycopy($buffer, 0, $tmp, 0, $buffer.length);
    --- End diff --
    
    and use PlatformDependent.copyMemory


---
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