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.UndefinedColumnException
WriterEvents.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, wait
schema
protected 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()
ColumnWriter
type
in interface ColumnWriter
protected void bindIndex(ColumnWriterIndex index, ColumnWriterIndex childIndex)
public void bindIndex(ColumnWriterIndex index)
WriterEvents
bindIndex
in interface WriterEvents
index
- the writer index (top level or nested for
arrays)public int rowStartIndex()
WriterPosition
rowStartIndex
in interface WriterPosition
public int addColumnWriter(AbstractObjectWriter colWriter)
colWriter
- the column writer to addpublic boolean isProjected(String columnName)
TupleWriter
isProjected
in interface TupleWriter
public int addColumn(ColumnMetadata column)
TupleWriter
addColumn
in interface TupleWriter
column
- the metadata for the column to addpublic int addColumn(MaterializedField field)
addColumn
in interface TupleWriter
public TupleMetadata tupleSchema()
tupleSchema
in interface TupleWriter
public int size()
size
in interface TupleWriter
public boolean nullable()
ColumnWriter
TypeProtos.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 ColumnWriter
ColumnWriter.setNull()
is supported, false
if notpublic void setNull()
ColumnWriter
setNull
in interface ColumnWriter
public void startWrite()
WriterEvents
startWrite
in interface WriterEvents
public void startRow()
WriterEvents
WriterEvents.restartRow()
instead.startRow
in interface WriterEvents
public void endArrayValue()
WriterEvents
WriterEvents.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 WriterEvents
public void restartRow()
WriterEvents
restartRow
in interface WriterEvents
public void saveRow()
WriterEvents
saveRow
in interface WriterEvents
public void preRollover()
WriterEvents
preRollover
in interface WriterEvents
public void postRollover()
WriterEvents
postRollover
in interface WriterEvents
public void endWrite()
WriterEvents
endWrite
in interface WriterEvents
public void copy(ColumnReader from)
ColumnWriter
copy
in interface ColumnWriter
from
- reader to provide the datapublic ObjectWriter column(int colIndex)
column
in interface TupleWriter
public ObjectWriter column(String colName)
column
in interface TupleWriter
public void set(int colIndex, Object value)
TupleWriter
setType
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 TupleWriter
colIndex
- 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)
ColumnWriter
setObject
in interface ColumnWriter
value
- value to write to the vector. The Java type of the
object indicates the Drill storage typepublic ScalarWriter scalar(int colIndex)
scalar
in interface TupleWriter
public ScalarWriter scalar(String colName)
scalar
in interface TupleWriter
public TupleWriter tuple(int colIndex)
tuple
in interface TupleWriter
public TupleWriter tuple(String colName)
tuple
in interface TupleWriter
public ArrayWriter array(int colIndex)
array
in interface TupleWriter
public ArrayWriter array(String colName)
array
in interface TupleWriter
public VariantWriter variant(int colIndex)
variant
in interface TupleWriter
public VariantWriter variant(String colName)
variant
in interface TupleWriter
public DictWriter dict(int colIndex)
dict
in interface TupleWriter
public DictWriter dict(String colName)
dict
in interface TupleWriter
public ObjectType type(int colIndex)
type
in interface TupleWriter
public ObjectType type(String colName)
type
in interface TupleWriter
public boolean isProjected()
ColumnWriter
isProjected
in interface ColumnWriter
public int lastWriteIndex()
WriterPosition
lastWriteIndex
in interface WriterPosition
public int writeIndex()
WriterPosition
writeIndex
in interface WriterPosition
public void bindListener(AbstractTupleWriter.TupleWriterListener listener)
public AbstractTupleWriter.TupleWriterListener listener()
public void bindListener(WriterEvents.ColumnWriterListener listener)
WriterEvents
bindListener
in interface WriterEvents
listener
- the vector event listener to bindpublic void dump(HierarchicalFormatter format)
dump
in interface WriterEvents
Copyright © 1970 The Apache Software Foundation. All rights reserved.