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

    https://github.com/apache/spark/pull/20850#discussion_r175397262
  
    --- Diff: 
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/UnsafeRowWriter.java
 ---
    @@ -40,29 +37,45 @@
      */
     public final class UnsafeRowWriter extends UnsafeWriter {
     
    -  private final BufferHolder holder;
    -  // The offset of the global buffer where we start to write this row.
    -  private int startingOffset;
    +  private final UnsafeRow row;
    +
       private final int nullBitsSize;
       private final int fixedSize;
     
    -  public UnsafeRowWriter(BufferHolder holder, int numFields) {
    -    this.holder = holder;
    +  public UnsafeRowWriter(UnsafeRow row, int initialBufferSize) {
    +    this(row, new BufferHolder(row, initialBufferSize), row.numFields());
    +  }
    +
    +  public UnsafeRowWriter(UnsafeRow row) {
    +    this(row, new BufferHolder(row), row.numFields());
    +  }
    +
    +  public UnsafeRowWriter(UnsafeWriter writer, int numFields) {
    +    this(null, writer.getBufferHolder(), numFields);
    +  }
    +
    +  private UnsafeRowWriter(UnsafeRow row, BufferHolder holder, int 
numFields) {
    +    super(holder);
    +    this.row = row;
         this.nullBitsSize = UnsafeRow.calculateBitSetWidthInBytes(numFields);
         this.fixedSize = nullBitsSize + 8 * numFields;
    -    this.startingOffset = holder.cursor;
    +    this.startingOffset = cursor();
    +  }
    +
    +  public void setTotalSize() {
    --- End diff --
    
    How about renaming `flip` along with java `ByteBuffer`? If we call 
`row.setTotalSize(totalSize)` and reset `BufferHolder` positions inside `flip`, 
can we remove `UnsafeWriter.reset` in the head?


---

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

Reply via email to