Class RowSetBuilder

java.lang.Object
org.apache.drill.exec.physical.rowSet.RowSetBuilder

public final class RowSetBuilder extends Object
Fluent builder to quickly build up an row set (record batch) programmatically.
  • Constructor Details

  • Method Details

    • emptyBatch

      public static RowSet emptyBatch(BufferAllocator allocator, TupleMetadata schema)
    • writer

      public RowSetWriter writer()
    • addRow

      public RowSetBuilder addRow(Object... values)
      Add a new row using column values passed as variable-length arguments. Expects map values to be flattened. a schema of (a:int, b:map(c:varchar)) would be> set as
      add(10, "foo");
      Values of arrays can be expressed as a Java array. A schema of (a:int, b:int[]) can be set as
      add(10, new int[] {100, 200});
      Parameters:
      values - column values in column index order
      Returns:
      this builder
      Throws:
      IllegalStateException - if the batch, or any vector in the batch, becomes full. This method is designed to be used in tests where we will seldom create a full vector of data.
    • addSelection

      public RowSetBuilder addSelection(boolean selected, Object... values)
    • addSingleCol

      public RowSetBuilder addSingleCol(Object value)
      The addRow(Object...) method uses Java variable-length arguments to pass a row of values. But, when the row consists of a single array, Java gets confused: is that an array for variable-arguments or is it the value of the first argument? This method clearly states that the single value (including an array) is meant to be the value of the first (and only) column.

      Examples:

           RowSetBuilder twoColsBuilder = ...
           // Fine, second item is an array of strings for a repeated Varchar
           // column.
           twoColsBuilder.add("First", new String[] {"a", "b", "c"});
           ...
           RowSetBuilder oneColBuilder = ...
           // Ambiguous: is this a varargs array of three items?
           // That is how Java will perceive it.
           oneColBuilder.add(new String[] {"a", "b", "c"});
           // Unambiguous: this is a single column value for the
           // repeated Varchar column.
           oneColBuilder.addSingleCol(new String[] {"a", "b", "c"});
       
      Parameters:
      value - value of the first column, which may be an array for a repeated column
      Returns:
      this builder
    • addSingleCol

      public RowSetBuilder addSingleCol(boolean selected, Object value)
    • withSv2

      public RowSetBuilder withSv2()
      Build the row set with a selection vector 2. The SV2 is initialized to have a 1:1 index to the rows: SV2 0 points to row 1, SV2 position 1 points to row 1 and so on.
      Returns:
      this builder
    • build

      public RowSet.SingleRowSet build()