Class SingleVectorState
java.lang.Object
org.apache.drill.exec.physical.resultSet.impl.SingleVectorState
- All Implemented Interfaces:
VectorState
- Direct Known Subclasses:
SingleVectorState.OffsetVectorState,SingleVectorState.SimpleVectorState
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classState for a scalar value vector.static classstatic classSpecial case for an offset vector.static classstatic classState for a scalar value vector. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ValueVectorprotected final ValueVectorprotected final WriterEvents -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintallocate(int cardinality) Allocate a new vector with the number of elements given.protected abstract intallocateVector(ValueVector vector, int cardinality) voidclose()Clear the vector(s) associated with this state.protected abstract voidcopyOverflow(int sourceStartIndex, int sourceEndIndex) voiddump(HierarchicalFormatter format) voidExchange 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.booleanReport whether this column is projected (has materialized vectors), or is unprojected (has no materialized backing.)protected static TypeProtos.MajorTypeparseVectorType(ValueVector vector) The vector mechanism here relies on the vector metadata.voidrollover(int cardinality) A column within the row batch overflowed.voidThe previous full batch has been sent downstream and the client is now ready to start writing to the next batch.<T extends ValueVector>
Tvector()Underlying vector: the one presented to the consumer of the result set loader.vectorState(ColumnMetadata schema, WriterEvents writer, ValueVector mainVector)
-
Field Details
-
writer
-
mainVector
-
backupVector
-
-
Constructor Details
-
SingleVectorState
-
-
Method Details
-
vector
Description copied from interface:VectorStateUnderlying vector: the one presented to the consumer of the result set loader.- Specified by:
vectorin interfaceVectorState
-
allocate
public int allocate(int cardinality) Description copied from interface:VectorStateAllocate 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:
allocatein interfaceVectorState- Parameters:
cardinality- number of elements desired in the allocated vector- Returns:
- the number of bytes allocated
-
allocateVector
-
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:
rolloverin interfaceVectorState- Parameters:
cardinality- the number of unique columns in the row
-
parseVectorType
The vector mechanism here relies on the vector metadata. However, if the main vector is nullable, it will contain avaluesvector which is required. But thevaluesvector 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.- Parameters:
vector- the vector to clone, the type of which may not match the metadata declared within that vector- Returns:
- 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:
harvestWithLookAheadin interfaceVectorState
-
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:
startBatchWithLookAheadin interfaceVectorState
-
close
public void close()Description copied from interface:VectorStateClear the vector(s) associated with this state.- Specified by:
closein interfaceVectorState
-
isProjected
public boolean isProjected()Description copied from interface:VectorStateReport whether this column is projected (has materialized vectors), or is unprojected (has no materialized backing.)- Specified by:
isProjectedin interfaceVectorState- Returns:
- 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
- Specified by:
dumpin interfaceVectorState
-