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

    https://github.com/apache/spark/pull/7689#discussion_r35613599
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateUnsafeProjection.scala
 ---
    @@ -99,24 +112,139 @@ object GenerateUnsafeProjection extends 
CodeGenerator[Seq[Expression], UnsafePro
     
         s"""
           $allExprs
    -      int $numBytesTerm = $fixedSize $additionalSize;
    -      if ($numBytesTerm > $bufferTerm.length) {
    -        $bufferTerm = new byte[$numBytesTerm];
    +      int $numBytes = $fixedSize $additionalSize;
    +      if ($numBytes > $buffer.length) {
    +        $buffer = new byte[$numBytes];
           }
     
           $ret.pointTo(
    -        $bufferTerm,
    +        $buffer,
             org.apache.spark.unsafe.PlatformDependent.BYTE_ARRAY_OFFSET,
             ${expressions.size},
    -        $numBytesTerm);
    -      int $cursorTerm = $fixedSize;
    -
    +        $numBytes);
    +      int $cursor = $fixedSize;
     
           $writers
           boolean ${ev.isNull} = false;
          """
       }
     
    +  /**
    +   * Generates the Java code to convert a struct (backed by InternalRow) 
to UnsafeRow.
    +   *
    +   * This function also handles nested structs by recursively generating 
the code to do conversion.
    +   *
    +   * @param ctx code generation context
    +   * @param input the input struct, identified by a 
[[GeneratedExpressionCode]]
    +   * @param schema schema of the struct field
    +   */
    +  // TODO: refactor createCode and this function to reduce code 
duplication.
    +  private def createCodeForStruct(
    +      ctx: CodeGenContext,
    +      input: GeneratedExpressionCode,
    +      schema: StructType): GeneratedExpressionCode = {
    +
    +    val isNull = input.isNull
    +    val primitive = ctx.freshName("structConvert")
    +    ctx.addMutableState("UnsafeRow", primitive, s"$primitive = new 
UnsafeRow();")
    +    val buffer = ctx.freshName("buffer")
    +    ctx.addMutableState("byte[]", buffer, s"$buffer = new byte[64];")
    +    val cursor = ctx.freshName("cursor")
    +
    +    val exprs: Seq[GeneratedExpressionCode] = 
schema.map(_.dataType).zipWithIndex.map {
    +      case (dt, i) => dt match {
    +      case st: StructType =>
    --- End diff --
    
    This looks underindented?


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