Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20850#discussion_r178023931
  
    --- Diff: 
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/UnsafeWriter.java
 ---
    @@ -17,17 +17,86 @@
     package org.apache.spark.sql.catalyst.expressions.codegen;
     
     import org.apache.spark.sql.types.Decimal;
    +import org.apache.spark.unsafe.Platform;
    +import org.apache.spark.unsafe.array.ByteArrayMethods;
     import org.apache.spark.unsafe.types.CalendarInterval;
     import org.apache.spark.unsafe.types.UTF8String;
     
     /**
      * Base class for writing Unsafe* structures.
      */
     public abstract class UnsafeWriter {
    +  // Keep internal buffer holder
    +  protected final BufferHolder holder;
    +
    +  // The offset of the global buffer where we start to write this 
structure.
    +  protected int startingOffset;
    +
    +  protected UnsafeWriter(BufferHolder holder) {
    +    this.holder = holder;
    +  }
    +
    +  /**
    +   * Accessor methods are delegated from BufferHolder class
    +   */
    +  public final BufferHolder getBufferHolder() {
    +    return holder;
    +  }
    +
    +  public final byte[] buffer() {
    +    return holder.buffer();
    +  }
    +
    +  public final void reset() {
    +    holder.reset();
    +  }
    +
    +  public final int totalSize() {
    +    return holder.totalSize();
    +  }
    +
    +  public final void grow(int neededSize) {
    +    holder.grow(neededSize);
    +  }
    +
    +  public final int cursor() {
    +    return holder.getCursor();
    +  }
    +
    +  public final void incrementCursor(int val) {
    +    holder.incrementCursor(val);
    +  }
    +
    +  public abstract void setOffsetAndSizeFromMark(int ordinal, int mark);
    --- End diff --
    
    Why do we even have this method? I feel it's cleaner if the caller side 
just do `writer.setOffsetAndSize(ordinal, tmpCursor, currentCursor - 
tmpCursor);`


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to