Interface RowSetWriter

All Superinterfaces:
ColumnWriter, TupleWriter
All Known Implementing Classes:
RowSetWriterImpl

public interface RowSetWriter extends TupleWriter
Interface for writing values to a row set. Only available for newly-created, single, direct row sets. Eventually, if we want to allow updating a row set, we have to create a new row set with the updated columns, then merge the new and old row sets to create a new immutable row set.

Typical usage:


 void writeABatch() {
   RowSetWriter writer = ...
   while (! writer.isFull()) {
     writer.scalar(0).setInt(10);
     writer.scalar(1).setString("foo");
     ...
     writer.save();
   }
 }
The above writes until the batch is full, based on size. If values are large enough to potentially cause vector overflow, do the following instead:

 void writeABatch() {
   RowSetWriter writer = ...
   while (! writer.isFull()) {
     writer.column(0).setInt(10);
     try {
        writer.column(1).setString("foo");
     } catch (VectorOverflowException e) { break; }
     ...
     writer.save();
   }
   // Do something with the partially-written last row.
 }

This writer is for testing, so no provision is available to handle a partial last row. (Elsewhere n Drill there are classes that handle that case.)

  • Method Details

    • addRow

      RowSetWriter addRow(Object... values)
      Write a row of values, given by Java objects. Object type must match expected column type. Stops writing, and returns false, if any value causes vector overflow. Value format:
      • For scalars, the value as a suitable Java type (int or Integer, say, for INTEGER values.)
      • For scalar arrays, an array of a suitable Java primitive type for scalars. For example, int[] for an INTEGER column.
      • For a Map, an Object array with values encoded as above. (In fact, the list here is the same as the map format.
      • For a list (repeated map, list of list), an Object array with values encoded as above. (So, for a repeated map, an outer Object map encodes the array, an inner one encodes the map members.
      Parameters:
      values - variable-length argument list of column values
    • addSingleCol

      RowSetWriter addSingleCol(Object value)
    • isFull

      boolean isFull()
      Indicates if the current row position is valid for writing. Will be false on the first row, and all subsequent rows until either the maximum number of rows are written, or a vector overflows. After that, will return true. The method returns false as soon as any column writer overflows even in the middle of a row write. That is, this writer does not automatically handle overflow rows because that added complexity is seldom needed for tests.
      Returns:
      true if the current row can be written, false if not
    • rowIndex

      int rowIndex()
    • save

      void save()
      Saves the current row and moves to the next row. Done automatically if using setRow().
    • done

      Finish writing and finalize the row set being written.
      Returns:
      the completed, read-only row set without a selection vector