Class SingleVectorState

All Implemented Interfaces:
Direct Known Subclasses:
SingleVectorState.OffsetVectorState, SingleVectorState.SimpleVectorState

public abstract class SingleVectorState extends Object implements VectorState
Base class for a single vector. Handles the bulk of work for that vector. Subclasses are specialized for offset vectors or values vectors. (The "single vector" name contrasts with classes that manage compound vectors, such as a data and offsets vector.) *

During overflow it is critical to update the various stored vector lengths so that serialization/deserialization works correctly.

  • Field Details

  • Constructor Details

  • Method Details

    • vector

      public <T extends ValueVector> T vector()
      Description copied from interface: VectorState
      Underlying vector: the one presented to the consumer of the result set loader.
      Specified by:
      vector in interface VectorState
    • allocate

      public int allocate(int cardinality)
      Description copied from interface: VectorState
      Allocate a new vector with the number of elements given. If the vector is an array, then the cardinality given is the number of arrays.
      Specified by:
      allocate in interface VectorState
      cardinality - number of elements desired in the allocated vector
      the number of bytes allocated
    • allocateVector

      protected abstract int allocateVector(ValueVector vector, int cardinality)
    • rollover

      public void rollover(int cardinality)
      A column within the row batch overflowed. Prepare to absorb the rest of the in-flight row by rolling values over to a new vector, saving the complete vector for later. This column could have a value for the overflow row, or for some previous row, depending on exactly when and where the overflow occurs. sourceStartIndex: the index of the row that caused the overflow, the values of which should be copied to a new "look-ahead" vector. If the vector is an array, then the overflowIndex is the position of the first element to be moved, and multiple elements may need to move
      Specified by:
      rollover in interface VectorState
      cardinality - the number of unique columns in the row
    • parseVectorType

      protected static TypeProtos.MajorType parseVectorType(ValueVector vector)
      The vector mechanism here relies on the vector metadata. However, if the main vector is nullable, it will contain a values vector which is required. But the values vector will carry metadata that declares it to be nullable. While this is clearly a bug, it is a bug that has become a "feature" and cannot be changed. This code works around this feature by parsing out the actual type of the vector.
      vector - the vector to clone, the type of which may not match the metadata declared within that vector
      the actual major type of the vector
    • copyOverflow

      protected abstract void copyOverflow(int sourceStartIndex, int sourceEndIndex)
    • harvestWithLookAhead

      public void harvestWithLookAhead()
      Exchange the data from the backup vector and the main vector, putting the completed buffers back into the main vectors, and stashing the overflow buffers away in the backup vector. Restore the main vector's last write position.
      Specified by:
      harvestWithLookAhead in interface VectorState
    • startBatchWithLookAhead

      public void startBatchWithLookAhead()
      The previous full batch has been sent downstream and the client is now ready to start writing to the next batch. Initialize that new batch with the look-ahead values saved during overflow of the previous batch.
      Specified by:
      startBatchWithLookAhead in interface VectorState
    • close

      public void close()
      Description copied from interface: VectorState
      Clear the vector(s) associated with this state.
      Specified by:
      close in interface VectorState
    • isProjected

      public boolean isProjected()
      Description copied from interface: VectorState
      Report whether this column is projected (has materialized vectors), or is unprojected (has no materialized backing.)
      Specified by:
      isProjected in interface VectorState
      true if the column is projected to the output, false if not
    • vectorState

      public static SingleVectorState.SimpleVectorState vectorState(ColumnMetadata schema, WriterEvents writer, ValueVector mainVector)
    • dump

      public void dump(HierarchicalFormatter format)
      Specified by:
      dump in interface VectorState