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

    https://github.com/apache/spark/pull/18787#discussion_r130680847
  
    --- Diff: 
sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/ColumnarBatch.java
 ---
    @@ -65,15 +65,42 @@
       final Row row;
     
       public static ColumnarBatch allocate(StructType schema, MemoryMode 
memMode) {
    -    return new ColumnarBatch(schema, DEFAULT_BATCH_SIZE, memMode);
    +    return allocate(schema, memMode, DEFAULT_BATCH_SIZE);
       }
     
       public static ColumnarBatch allocate(StructType type) {
    -    return new ColumnarBatch(type, DEFAULT_BATCH_SIZE, 
DEFAULT_MEMORY_MODE);
    +    return allocate(type, DEFAULT_MEMORY_MODE, DEFAULT_BATCH_SIZE);
       }
     
       public static ColumnarBatch allocate(StructType schema, MemoryMode 
memMode, int maxRows) {
    -    return new ColumnarBatch(schema, maxRows, memMode);
    +    ColumnVector[] columns = allocateVectors(schema, maxRows, memMode);
    +    return create(schema, columns, maxRows);
    +  }
    +
    +  private static ColumnVector[] allocateVectors(StructType schema, int 
maxRows, MemoryMode memMode) {
    +    ColumnVector[] columns = new ColumnVector[schema.size()];
    +    for (int i = 0; i < schema.fields().length; ++i) {
    +      StructField field = schema.fields()[i];
    +      columns[i] = ColumnVector.allocate(maxRows, field.dataType(), 
memMode);
    +    }
    +    return columns;
    +  }
    +
    +  public static ColumnarBatch createReadOnly(
    +      StructType schema,
    +      ReadOnlyColumnVector[] columns,
    +      int numRows) {
    +    for (ReadOnlyColumnVector c: columns) {
    +      assert(c.capacity >= numRows);
    +    }
    +    ColumnarBatch batch = create(schema, columns, numRows);
    +    batch.setNumRows(numRows);
    +    return batch;
    +  }
    +
    +  private static ColumnarBatch create(StructType schema, ColumnVector[] 
columns, int capacity) {
    --- End diff --
    
    @ueshin , if we want to allow creating a `ColumnarBatch` from any Array of 
`ColumnVector`s then we could make this public as it doesn't call `setNumRows` 
and assume they are allocated already


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to