public abstract class AbstractTupleWriter extends Object implements TupleWriter, WriterEvents
A tuple maintains an internal state needed to handle dynamic column additions. The state identifies the amount of "catch up" needed to get the new column into the same state as the existing columns. The state is also handy for understanding the tuple lifecycle. This lifecycle works for all three cases of:
| Public API | Tuple Event | State Transition | Child Event |
|---|---|---|---|
| (Start state) | — | IDLE | — |
| startBatch() | startWrite() | IDLE → IN_WRITE | startWrite() |
| start() (new row) | startRow() | IN_WRITE → IN_ROW | startRow() |
| start() (without save) | restartRow() | IN_ROW → IN_ROW | restartRow() |
| save() (array) | saveValue() | IN_ROW → IN_ROW | saveValue() |
| save() (row) | saveValue() | IN_ROW → IN_ROW | saveValue() |
| saveRow() | IN_ROW → IN_WRITE | saveRow() | |
| end batch | — | IN_ROW → IDLE | endWrite() |
| — | IN_WRITE → IDLE | endWrite() |
| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractTupleWriter.TupleObjectWriter
Generic object wrapper for the tuple writer.
|
static interface |
AbstractTupleWriter.TupleWriterListener
Listener (callback) to handle requests to add a new column to a tuple (row
or map).
|
TupleWriter.UndefinedColumnExceptionWriterEvents.ColumnWriterListener, WriterEvents.State| Modifier and Type | Field and Description |
|---|---|
protected ColumnWriterIndex |
childIndex |
protected AbstractTupleWriter.TupleWriterListener |
listener |
protected static org.slf4j.Logger |
logger |
protected WriterEvents.State |
state |
protected TupleMetadata |
tupleSchema |
protected ColumnWriterIndex |
vectorIndex |
protected List<AbstractObjectWriter> |
writers |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractTupleWriter(TupleMetadata schema) |
protected |
AbstractTupleWriter(TupleMetadata schema,
List<AbstractObjectWriter> writers) |
| Modifier and Type | Method and Description |
|---|---|
int |
addColumn(ColumnMetadata column)
Add a column to the tuple (row or map) that backs this writer.
|
int |
addColumn(MaterializedField field) |
int |
addColumnWriter(AbstractObjectWriter colWriter)
Add a column writer to an existing tuple writer.
|
ArrayWriter |
array(int colIndex) |
ArrayWriter |
array(String colName) |
void |
bindIndex(ColumnWriterIndex index)
Bind the writer to a writer index.
|
protected void |
bindIndex(ColumnWriterIndex index,
ColumnWriterIndex childIndex) |
void |
bindListener(AbstractTupleWriter.TupleWriterListener listener) |
void |
bindListener(WriterEvents.ColumnWriterListener listener)
Bind a listener to the underlying vector writer.
|
ObjectWriter |
column(int colIndex) |
ObjectWriter |
column(String colName) |
void |
copy(ColumnReader from)
Copy a single value from the given reader, which must be of the
same type as this writer.
|
DictWriter |
dict(int colIndex) |
DictWriter |
dict(String colName) |
void |
dump(HierarchicalFormatter format) |
void |
endArrayValue()
End a value.
|
void |
endWrite()
End a batch: finalize any vector values.
|
boolean |
isProjected()
Whether this writer is projected (is backed by a materialized vector),
or is unprojected (is just a dummy writer.) In most cases, clients can
ignore whether the column is projected and just write to the writer.
|
boolean |
isProjected(String columnName)
Reports whether the given column is projected.
|
int |
lastWriteIndex()
Return the last write position in the vector.
|
AbstractTupleWriter.TupleWriterListener |
listener() |
boolean |
nullable()
Whether this writer allows nulls.
|
void |
postRollover()
The vectors backing this writer rolled over.
|
void |
preRollover()
The vectors backing this vector are about to roll over.
|
void |
restartRow()
During a writer to a row, rewind the the current index position to
restart the row.
|
int |
rowStartIndex()
Position within the vector of the first value for the current row.
|
void |
saveRow()
Saves a row.
|
ScalarWriter |
scalar(int colIndex) |
ScalarWriter |
scalar(String colName) |
void |
set(int colIndex,
Object value)
Write a value to the given column, automatically calling the proper
setType method for the data. |
void |
setNull()
Set the current value to null.
|
void |
setObject(Object value)
Generic technique to write data as a generic Java object.
|
int |
size() |
void |
startRow()
Start a new row.
|
void |
startWrite()
Start a write (batch) operation.
|
TupleWriter |
tuple(int colIndex) |
TupleWriter |
tuple(String colName) |
TupleMetadata |
tupleSchema() |
ObjectType |
type()
Return the object (structure) type of this writer.
|
ObjectType |
type(int colIndex) |
ObjectType |
type(String colName) |
VariantWriter |
variant(int colIndex) |
VariantWriter |
variant(String colName) |
int |
writeIndex()
Current write index for the writer.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitschemaprotected static final org.slf4j.Logger logger
protected final TupleMetadata tupleSchema
protected final List<AbstractObjectWriter> writers
protected ColumnWriterIndex vectorIndex
protected ColumnWriterIndex childIndex
protected AbstractTupleWriter.TupleWriterListener listener
protected WriterEvents.State state
protected AbstractTupleWriter(TupleMetadata schema, List<AbstractObjectWriter> writers)
protected AbstractTupleWriter(TupleMetadata schema)
public ObjectType type()
ColumnWritertype in interface ColumnWriterprotected void bindIndex(ColumnWriterIndex index, ColumnWriterIndex childIndex)
public void bindIndex(ColumnWriterIndex index)
WriterEventsbindIndex in interface WriterEventsindex - the writer index (top level or nested for
arrays)public int rowStartIndex()
WriterPositionrowStartIndex in interface WriterPositionpublic int addColumnWriter(AbstractObjectWriter colWriter)
colWriter - the column writer to addpublic boolean isProjected(String columnName)
TupleWriterisProjected in interface TupleWriterpublic int addColumn(ColumnMetadata column)
TupleWriteraddColumn in interface TupleWritercolumn - the metadata for the column to addpublic int addColumn(MaterializedField field)
addColumn in interface TupleWriterpublic TupleMetadata tupleSchema()
tupleSchema in interface TupleWriterpublic int size()
size in interface TupleWriterpublic boolean nullable()
ColumnWriterTypeProtos.DataMode.OPTIONAL type in the schema. List entries
are nullable, if they are primitive, but not if they are maps or lists.
Unions are nullable, regardless of cardinality.nullable in interface ColumnWriterColumnWriter.setNull() is supported, false
if notpublic void setNull()
ColumnWritersetNull in interface ColumnWriterpublic void startWrite()
WriterEventsstartWrite in interface WriterEventspublic void startRow()
WriterEventsWriterEvents.restartRow() instead.startRow in interface WriterEventspublic void endArrayValue()
WriterEventsWriterEvents.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.endArrayValue in interface WriterEventspublic void restartRow()
WriterEventsrestartRow in interface WriterEventspublic void saveRow()
WriterEventssaveRow in interface WriterEventspublic void preRollover()
WriterEventspreRollover in interface WriterEventspublic void postRollover()
WriterEventspostRollover in interface WriterEventspublic void endWrite()
WriterEventsendWrite in interface WriterEventspublic void copy(ColumnReader from)
ColumnWritercopy in interface ColumnWriterfrom - reader to provide the datapublic ObjectWriter column(int colIndex)
column in interface TupleWriterpublic ObjectWriter column(String colName)
column in interface TupleWriterpublic void set(int colIndex,
Object value)
TupleWritersetType method for the data. While this method is
convenient for testing, it incurs quite a bit of type-checking overhead and
is not suitable for production code.set in interface TupleWritercolIndex - the index of the column to setvalue - the value to set. The type of the object must be compatible with
the type of the target columnpublic void setObject(Object value)
ColumnWritersetObject in interface ColumnWritervalue - value to write to the vector. The Java type of the
object indicates the Drill storage typepublic ScalarWriter scalar(int colIndex)
scalar in interface TupleWriterpublic ScalarWriter scalar(String colName)
scalar in interface TupleWriterpublic TupleWriter tuple(int colIndex)
tuple in interface TupleWriterpublic TupleWriter tuple(String colName)
tuple in interface TupleWriterpublic ArrayWriter array(int colIndex)
array in interface TupleWriterpublic ArrayWriter array(String colName)
array in interface TupleWriterpublic VariantWriter variant(int colIndex)
variant in interface TupleWriterpublic VariantWriter variant(String colName)
variant in interface TupleWriterpublic DictWriter dict(int colIndex)
dict in interface TupleWriterpublic DictWriter dict(String colName)
dict in interface TupleWriterpublic ObjectType type(int colIndex)
type in interface TupleWriterpublic ObjectType type(String colName)
type in interface TupleWriterpublic boolean isProjected()
ColumnWriterisProjected in interface ColumnWriterpublic int lastWriteIndex()
WriterPositionlastWriteIndex in interface WriterPositionpublic int writeIndex()
WriterPositionwriteIndex in interface WriterPositionpublic void bindListener(AbstractTupleWriter.TupleWriterListener listener)
public AbstractTupleWriter.TupleWriterListener listener()
public void bindListener(WriterEvents.ColumnWriterListener listener)
WriterEventsbindListener in interface WriterEventslistener - the vector event listener to bindpublic void dump(HierarchicalFormatter format)
dump in interface WriterEventsCopyright © 2021 The Apache Software Foundation. All rights reserved.