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
Modifier and TypeClassDescriptionstatic class
State for a scalar value vector.static class
static class
Special case for an offset vector.static class
static class
State for a scalar value vector. -
Field Summary
Modifier and TypeFieldDescriptionprotected ValueVector
protected final ValueVector
protected final WriterEvents
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
allocate
(int cardinality) Allocate a new vector with the number of elements given.protected abstract int
allocateVector
(ValueVector vector, int cardinality) void
close()
Clear the vector(s) associated with this state.protected abstract void
copyOverflow
(int sourceStartIndex, int sourceEndIndex) void
dump
(HierarchicalFormatter format) void
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.boolean
Report whether this column is projected (has materialized vectors), or is unprojected (has no materialized backing.)protected static TypeProtos.MajorType
parseVectorType
(ValueVector vector) The vector mechanism here relies on the vector metadata.void
rollover
(int cardinality) A column within the row batch overflowed.void
The 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:VectorState
Underlying vector: the one presented to the consumer of the result set loader.- Specified by:
vector
in interfaceVectorState
-
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 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:
rollover
in 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 avalues
vector which is required. But thevalues
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.- 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:
harvestWithLookAhead
in 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:
startBatchWithLookAhead
in interfaceVectorState
-
close
public void close()Description copied from interface:VectorState
Clear the vector(s) associated with this state.- Specified by:
close
in interfaceVectorState
-
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 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:
dump
in interfaceVectorState
-