Class RowSetLoaderImpl
- All Implemented Interfaces:
RowSetLoader
,ColumnWriter
,TupleWriter
,WriterEvents
,WriterPosition
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.drill.exec.vector.accessor.writer.AbstractTupleWriter
AbstractTupleWriter.TupleObjectWriter, AbstractTupleWriter.TupleWriterListener
Nested classes/interfaces inherited from interface org.apache.drill.exec.vector.accessor.TupleWriter
TupleWriter.UndefinedColumnException
Nested classes/interfaces inherited from interface org.apache.drill.exec.vector.accessor.writer.WriterEvents
WriterEvents.ColumnWriterListener, WriterEvents.State
-
Field Summary
Fields inherited from class org.apache.drill.exec.vector.accessor.writer.AbstractTupleWriter
childIndex, listener, logger, state, tupleSchema, vectorIndex, writers
-
Constructor Summary
ModifierConstructorDescriptionprotected
RowSetLoaderImpl
(ResultSetLoaderImpl rsLoader, TupleMetadata schema) -
Method Summary
Modifier and TypeMethodDescriptionWrite a row of values, given by Java objects.addSingleCol
(Object value) Similar toRowSetLoader.addRow(Object...)
, but for the odd case in which a row consists of a single column that is an object array (such as for a list or map) and so is ambiguous.void
endBatch()
boolean
isFull()
Indicates that no more rows fit into the current row batch and that the row batch should be harvested and sent downstream.boolean
limitReached
(int maxRecords) Used to push a limit down to the file reader.loader()
int
rowCount()
The number of rows in the current row set.int
rowIndex()
The index of the current row.void
save()
Saves the current row and moves to the next row.schema()
Returns the schema of the column associated with this writer.boolean
start()
Prepare a new row for writing.Methods inherited from class org.apache.drill.exec.vector.accessor.writer.AbstractTupleWriter
addColumn, addColumn, addColumnWriter, array, array, bindIndex, bindIndex, bindListener, bindListener, column, column, copy, dict, dict, dump, endArrayValue, endWrite, isProjected, isProjected, lastWriteIndex, listener, nullable, postRollover, preRollover, restartRow, rowStartIndex, saveRow, scalar, scalar, set, setNull, setObject, size, startRow, startWrite, tuple, tuple, tupleSchema, type, type, type, variant, variant, writeIndex
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.drill.exec.vector.accessor.ColumnWriter
copy, isProjected, nullable, setNull, setObject, type
-
Constructor Details
-
RowSetLoaderImpl
-
-
Method Details
-
loader
- Specified by:
loader
in interfaceRowSetLoader
-
addRow
Description copied from interface:RowSetLoader
Write a row of values, given by Java objects. Object type must match expected column type. Stops writing, and returns false, if any value causes vector overflow. Value format:- For scalars, the value as a suitable Java type (int or Integer, say, for INTEGER values.)
- For scalar arrays, an array of a suitable Java primitive type for scalars. For example, int[] for an INTEGER column.
- For a Map, an Object array with values encoded as above. (In fact, the list here is the same as the map format.
- For a list (repeated map, list of list), an Object array with values encoded as above. (So, for a repeated map, an outer Object map encodes the array, an inner one encodes the map members.
- Specified by:
addRow
in interfaceRowSetLoader
- Parameters:
values
- variable-length argument list of column values- Returns:
- this writer
-
addSingleCol
Description copied from interface:RowSetLoader
Similar toRowSetLoader.addRow(Object...)
, but for the odd case in which a row consists of a single column that is an object array (such as for a list or map) and so is ambiguous.- Specified by:
addSingleCol
in interfaceRowSetLoader
- Parameters:
value
- value of the one and only column- Returns:
- this writer
-
rowIndex
public int rowIndex()Description copied from interface:RowSetLoader
The index of the current row. Same as the row count except in an overflow row in which case the row index will revert to zero as soon as any vector overflows. Note: this means that the index can change between columns in a single row. Applications usually don't use this index directly; rely on the writers to write to the proper location.- Specified by:
rowIndex
in interfaceRowSetLoader
- Returns:
- the current write index
-
save
public void save()Description copied from interface:RowSetLoader
Saves the current row and moves to the next row. Failing to call this method effectively abandons the in-flight row; something that may be useful to recover from partially-written rows that turn out to contain errors. Done automatically if using setRow().- Specified by:
save
in interfaceRowSetLoader
-
start
public boolean start()Description copied from interface:RowSetLoader
Prepare a new row for writing. Call this before each row.Handles a very special case: that of discarding the last row written. A reader can read a row into vectors, then "sniff" the row to check, for example, against a filter. If the row is not wanted, simply omit the call to save() and the next all to start() will discard the unsaved row.
Note that the vectors still contain values in the discarded position; just the various pointers are unset. If the batch ends before the discarded values are overwritten, the discarded values just exist at the end of the vector. Since vectors start with garbage contents, the discarded values are simply a different kind of garbage. But, if the client writes a new row, then the new row overwrites the discarded row. This works because we only change the tail part of a vector; never the internals.
- Specified by:
start
in interfaceRowSetLoader
- Returns:
- true if another row can be added, false if the batch is full
-
endBatch
public void endBatch() -
limitReached
public boolean limitReached(int maxRecords) Description copied from interface:RowSetLoader
Used to push a limit down to the file reader. This method checks to see whether the maxRecords parameter is not zero (for no limit) and is not greater than the current record count.- Specified by:
limitReached
in interfaceRowSetLoader
- Parameters:
maxRecords
- Maximum rows to be returned. (From the limit clause of the query)- Returns:
- True if the row count exceeds the maxRecords, false if not.
-
isFull
public boolean isFull()Description copied from interface:RowSetLoader
Indicates that no more rows fit into the current row batch and that the row batch should be harvested and sent downstream. Any overflow row is automatically saved for the next cycle. The value is undefined when a batch is not active.Will be false on the first row, and all subsequent rows until either the maximum number of rows are written, or a vector overflows. After that, will return true. The method returns false as soon as any column writer overflows even in the middle of a row write. That is, this writer does not automatically handle overflow rows because that added complexity is seldom needed for tests.
- Specified by:
isFull
in interfaceRowSetLoader
- Returns:
- true if another row can be written, false if not
-
rowCount
public int rowCount()Description copied from interface:RowSetLoader
The number of rows in the current row set. Does not count any overflow row saved for the next batch.- Specified by:
rowCount
in interfaceRowSetLoader
- Returns:
- number of rows to be sent downstream
-
schema
Description copied from interface:ColumnWriter
Returns the schema of the column associated with this writer.- Specified by:
schema
in interfaceColumnWriter
- Returns:
- schema for this writer's column
-