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

    https://github.com/apache/spark/pull/7689#discussion_r35613510
  
    --- Diff: 
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRowWriters.java
 ---
    @@ -81,6 +82,52 @@ public static int write(UnsafeRow target, int ordinal, 
int cursor, byte[] input)
         }
       }
     
    +  /**
    +   * Writer for struct type where the struct field is backed by an {@link 
UnsafeRow}.
    +   *
    +   * We throw UnsupportedOperationException for inputs that are not backed 
by {@link UnsafeRow}.
    +   * Non-UnsafeRow struct fields are handled directly in
    +   * {@link 
org.apache.spark.sql.catalyst.expressions.codegen.GenerateUnsafeProjection}
    +   * by generating the Java code needed to convert them into UnsafeRow.
    +   */
    +  public static class StructWriter {
    +    public static int getSize(InternalRow input) {
    +      int numBytes = 0;
    +      if (input instanceof UnsafeRow) {
    +        numBytes = ((UnsafeRow) input).getSizeInBytes();
    +      } else {
    +        // This is handled directly in GenerateUnsafeProjection.
    +        throw new UnsupportedOperationException();
    +      }
    +      return ByteArrayMethods.roundNumberOfBytesToNearestWord(numBytes);
    +    }
    +
    +    public static int write(UnsafeRow target, int ordinal, int cursor, 
InternalRow input) {
    +      int numBytes = 0;
    +      final long offset = target.getBaseOffset() + cursor;
    +      if (input instanceof UnsafeRow) {
    +        final UnsafeRow row = (UnsafeRow) input;
    +        numBytes = row.getSizeInBytes();
    +
    +        // zero-out the padding bytes
    +        if ((numBytes & 0x07) > 0) {
    +          PlatformDependent.UNSAFE.putLong(
    +            target.getBaseObject(), offset + ((numBytes >> 3) << 3), 0L);
    +        }
    +
    +        // Write the string to the variable length portion.
    --- End diff --
    
    Typo: string -> struct


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