Class AbstractFixedWidthWriter

All Implemented Interfaces:
ColumnWriter, ScalarWriter, ValueWriter, WriterEvents, WriterPosition
Direct Known Subclasses:
AbstractFixedWidthWriter.BaseFixedWidthWriter, BitColumnWriter, OffsetVectorWriterImpl

public abstract class AbstractFixedWidthWriter extends BaseScalarWriter
Base class for writers for fixed-width vectors. Handles common tasks, leaving the generated code to handle only type-specific operations.

Fixed-width writers provide default values for empty (unused) slots. Suppose a client writes to slot 0, skips a few rows, then writes to slot 5. We could leave the intermediate values unwritten. But, since Drill reuses buffers, the slots may contain garbage. Instead, we implement "fill empties" logic. When we write to slot 5, we notice that the last slot written was 0, and we fill in slots 1, 2, 3 and 4 with values.

The fill value defaults to 0, and is defined as a block of zero-bytes (at least) the same length as each data value. Derived classes also allow setting a default value. In this case, the default value is encoded into a byte array, and that array is copied to each slot as the fill value.

  • Field Details

    • lastWriteIndex

      protected int lastWriteIndex
      The largest position to which the writer has written data. Used to allow "fill-empties" (AKA "back-fill") of missing values one each value write and at the end of a batch. Note that this is the position of the last write, not the next write position. Starts at -1 (no last write).
  • Constructor Details

    • AbstractFixedWidthWriter

      public AbstractFixedWidthWriter()
  • Method Details

    • startWrite

      public void startWrite()
      Description copied from interface: WriterEvents
      Start a write (batch) operation. Performs any vector initialization required at the start of a batch (especially for offset vectors.)
      Specified by:
      startWrite in interface WriterEvents
      startWrite in class AbstractScalarWriterImpl
    • width

      public abstract int width()
    • setBuffer

      protected final void setBuffer()
      Description copied from class: BaseScalarWriter
      All change of buffer comes through this function to allow capturing the buffer address and capacity. Only two ways to set the buffer: by binding to a vector in bindVector(), or by resizing the vector in prepareWrite().
      Specified by:
      setBuffer in class BaseScalarWriter
    • mandatoryResize

      protected final void mandatoryResize(int writeIndex)
    • resize

      protected final int resize(int writeIndex)
    • lastWriteIndex

      public int lastWriteIndex()
      Description copied from interface: WriterPosition
      Return the last write position in the vector. This may be the same as the writer index position (if the vector was written at that point), or an earlier point. In either case, this value points to the last valid value in the vector.
      index of the last valid value in the vector
    • setLastWriteIndex

      public void setLastWriteIndex(int index)
      For internal use only to update the write position on those very rare occasions in which the vector is written to outside of this writer framework. Not to be called by application code!
      index - new last write index
    • skipNulls

      public void skipNulls()
      Specified by:
      skipNulls in class BaseScalarWriter
    • restartRow

      public void restartRow()
      Description copied from interface: WriterEvents
      During a writer to a row, rewind the the current index position to restart the row. Done when abandoning the current row, such as when filtering out a row at read time.
    • preRollover

      public void preRollover()
      Description copied from interface: WriterEvents
      The vectors backing this vector are about to roll over. Finish the current batch up to, but not including, the current row.
    • postRollover

      public void postRollover()
      Description copied from interface: WriterEvents
      The vectors backing this writer rolled over. This means that data for the current row has been rolled over into a new vector. Offsets and indexes should be shifted based on the understanding that data for the current row now resides at the start of a new vector instead of its previous location elsewhere in an old vector.
    • endWrite

      public void endWrite()
      Description copied from interface: WriterEvents
      End a batch: finalize any vector values.
    • fillEmpties

      protected abstract void fillEmpties(int writeIndex)
    • setValueCount

      public void setValueCount(int valueCount)
    • dump

      public void dump(HierarchicalFormatter format)
      Specified by:
      dump in interface WriterEvents
      dump in class BaseScalarWriter