Class UnionVectorShim
java.lang.Object
org.apache.drill.exec.vector.accessor.writer.UnionVectorShim
- All Implemented Interfaces:
UnionShim
,WriterEvents
,WriterPosition
Lists can operate in three modes: no type, one type or many
types (that is, a list of unions.) This shim implements the
variant writer when the backing vector is a union or a list
backed by a union. It is a distinct class so that a List
writer can have a uniform variant-style interface even as the
list itself evolves from no type, to a single type and to
a union.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.drill.exec.vector.accessor.writer.UnionShim
UnionShim.AbstractUnionShim
Nested classes/interfaces inherited from interface org.apache.drill.exec.vector.accessor.writer.WriterEvents
WriterEvents.ColumnWriterListener, WriterEvents.State
-
Constructor Summary
ConstructorDescriptionUnionVectorShim
(UnionVector vector) UnionVectorShim
(UnionVector vector, AbstractObjectWriter[] variants) -
Method Summary
Modifier and TypeMethodDescriptionaddMember
(ColumnMetadata schema) void
addMember
(AbstractObjectWriter colWriter) Add a column writer to an existing union writer.void
addMemberWriter
(AbstractObjectWriter colWriter) Performs just the work of adding a vector to the list of existing variants.void
bindIndex
(ColumnWriterIndex index) Bind the writer to a writer index.void
Bind a listener to the underlying vector writer.void
bindWriter
(UnionWriterImpl writer) void
dump
(HierarchicalFormatter format) void
End a value.void
endWrite()
End a batch: finalize any vector values.boolean
hasType
(TypeProtos.MinorType type) void
initTypeIndex
(int typeFillCount) When promoting the list to a union, the union's type vector was initialized for any rows written thus far.boolean
int
Return the last write position in the vector.member
(TypeProtos.MinorType type) Return an existing writer for the given type, or create a new one if needed.void
The vectors backing this writer rolled over.void
The vectors backing this vector are about to roll over.void
During a writer to a row, rewind the the current index position to restart the row.int
Position within the vector of the first value for the current row.void
saveRow()
Saves a row.void
setNull()
void
setType
(TypeProtos.MinorType type) void
startRow()
Start a new row.void
Start a write (batch) operation.Return the writer for the types vector.int
Current write index for the writer.
-
Constructor Details
-
UnionVectorShim
-
UnionVectorShim
-
-
Method Details
-
bindWriter
- Specified by:
bindWriter
in interfaceUnionShim
-
bindIndex
Description copied from interface:WriterEvents
Bind the writer to a writer index.- Specified by:
bindIndex
in interfaceWriterEvents
- Parameters:
index
- the writer index (top level or nested for arrays)
-
bindListener
Description copied from interface:WriterEvents
Bind a listener to the underlying vector writer. This listener reports on vector events (overflow, growth), and so is called only when the writer is backed by a vector. The listener is ignored (and never called) for dummy (non-projected) columns. If the column is compound (such as for a nullable or repeated column, or for a map), then the writer is bound to the individual components.- Specified by:
bindListener
in interfaceWriterEvents
- Parameters:
listener
- the vector event listener to bind
-
setNull
public void setNull() -
hasType
-
member
Description copied from interface:UnionShim
Return an existing writer for the given type, or create a new one if needed. -
setType
-
addMember
-
addMember
-
addMember
Add a column writer to an existing union writer. Used for implementations that support "live" schema evolution: column discovery while writing. The corresponding metadata must already have been added to the schema. -
addMemberWriter
Performs just the work of adding a vector to the list of existing variants. Called when adding a type via the writer, but also when the result set loader promotes a list from single type to a union, and provides this shim with the writer from the single-list shim. In the latter case, the writer is already initialized and is already part of the metadata for this list; so we don't want to call the list'saddMember()
and repeat those operations.- Parameters:
colWriter
- the column (type) writer to add
-
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 interfaceWriterEvents
-
startRow
public void startRow()Description copied from interface:WriterEvents
Start a new row. To be called only when a row is not active. To restart a row, callWriterEvents.restartRow()
instead.- Specified by:
startRow
in interfaceWriterEvents
-
endArrayValue
public void endArrayValue()Description copied from interface:WriterEvents
End a value. Similar toWriterEvents.saveRow()
, but the save of a value is conditional on saving the row. This version is primarily of use in tuples nested inside arrays: it saves each tuple within the array, advancing to a new position in the array. The update of the array's offset vector based on the cumulative value saves is done when saving the row.- Specified by:
endArrayValue
in interfaceWriterEvents
-
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.- Specified by:
restartRow
in interfaceWriterEvents
-
saveRow
public void saveRow()Description copied from interface:WriterEvents
Saves a row. Commits offset vector locations and advances each to the next position. Can be called only when a row is active.- Specified by:
saveRow
in interfaceWriterEvents
-
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.- Specified by:
preRollover
in interfaceWriterEvents
-
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.- Specified by:
postRollover
in interfaceWriterEvents
-
endWrite
public void endWrite()Description copied from interface:WriterEvents
End a batch: finalize any vector values.- Specified by:
endWrite
in interfaceWriterEvents
-
typeWriter
Return the writer for the types vector. To be used only by the row set loader overflow logic; never by the application (which is why the method is not defined in the interface.)- Returns:
- the writer for the types vector
-
writeIndex
public int writeIndex()Description copied from interface:WriterPosition
Current write index for the writer. This is the global array location for arrays, same as the row index for top-level columns.- Specified by:
writeIndex
in interfaceWriterPosition
- Returns:
- current write index
-
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.- Specified by:
lastWriteIndex
in interfaceUnionShim
- Specified by:
lastWriteIndex
in interfaceWriterPosition
- Returns:
- index of the last valid value in the vector
-
rowStartIndex
public int rowStartIndex()Description copied from interface:WriterPosition
Position within the vector of the first value for the current row. Note that this is always the first value for the row, even for a writer deeply nested within a hierarchy of arrays. (The first position for the current array is not exposed in this API.)- Specified by:
rowStartIndex
in interfaceUnionShim
- Specified by:
rowStartIndex
in interfaceWriterPosition
- Returns:
- the vector offset of the first value for the current row
-
initTypeIndex
public void initTypeIndex(int typeFillCount) When promoting the list to a union, the union's type vector was initialized for any rows written thus far. Tell the type writer that those positions have been written so that they are not zero-filled. -
dump
- Specified by:
dump
in interfaceWriterEvents
-
isProjected
public boolean isProjected()- Specified by:
isProjected
in interfaceUnionShim
-