Class AbstractFixedWidthWriter
java.lang.Object
org.apache.drill.exec.vector.accessor.writer.AbstractScalarWriter
org.apache.drill.exec.vector.accessor.writer.AbstractScalarWriterImpl
org.apache.drill.exec.vector.accessor.writer.BaseScalarWriter
org.apache.drill.exec.vector.accessor.writer.AbstractFixedWidthWriter
- All Implemented Interfaces:
ColumnWriter
,ScalarWriter
,ValueWriter
,WriterEvents
,WriterPosition
- Direct Known Subclasses:
AbstractFixedWidthWriter.BaseFixedWidthWriter
,BitColumnWriter
,OffsetVectorWriterImpl
Base class for writers for fixed-width vectors. Handles common
tasks, leaving the generated code to handle only type-specific
operations.
Fixed-width writers provide default values for empty (unused) slots. Suppose a client writes to slot 0, skips a few rows, then writes to slot 5. We could leave the intermediate values unwritten. But, since Drill reuses buffers, the slots may contain garbage. Instead, we implement "fill empties" logic. When we write to slot 5, we notice that the last slot written was 0, and we fill in slots 1, 2, 3 and 4 with values.
The fill value defaults to 0, and is defined as a block of zero-bytes (at least) the same length as each data value. Derived classes also allow setting a default value. In this case, the default value is encoded into a byte array, and that array is copied to each slot as the fill value.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
Base class for writers that use the Java int type as their native type.Nested classes/interfaces inherited from class org.apache.drill.exec.vector.accessor.writer.AbstractScalarWriterImpl
AbstractScalarWriterImpl.ScalarObjectWriter
Nested classes/interfaces inherited from interface org.apache.drill.exec.vector.accessor.writer.WriterEvents
WriterEvents.ColumnWriterListener, WriterEvents.State
-
Field Summary
Modifier and TypeFieldDescriptionprotected int
The largest position to which the writer has written data.Fields inherited from class org.apache.drill.exec.vector.accessor.writer.BaseScalarWriter
capacity, drillBuf, emptyValue, listener, MIN_BUFFER_SIZE
Fields inherited from class org.apache.drill.exec.vector.accessor.writer.AbstractScalarWriterImpl
schema, vectorIndex
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
dump
(HierarchicalFormatter format) void
endWrite()
End a batch: finalize any vector values.protected abstract void
fillEmpties
(int writeIndex) int
Return the last write position in the vector.protected final void
mandatoryResize
(int writeIndex) void
The vectors backing this writer rolled over.void
The vectors backing this vector are about to roll over.protected final int
resize
(int writeIndex) void
During a writer to a row, rewind the the current index position to restart the row.protected final void
All change of buffer comes through this function to allow capturing the buffer address and capacity.void
setLastWriteIndex
(int index) For internal use only to update the write position on those very rare occasions in which the vector is written to outside of this writer framework.void
setValueCount
(int valueCount) void
void
Start a write (batch) operation.abstract int
width()
Methods inherited from class org.apache.drill.exec.vector.accessor.writer.BaseScalarWriter
appendBytes, bindListener, bindSchema, canExpand, nullable, overflowed, realloc, setBoolean, setBytes, setDate, setDecimal, setDouble, setFloat, setInt, setLong, setNull, setPeriod, setString, setTime, setTimestamp
Methods inherited from class org.apache.drill.exec.vector.accessor.writer.AbstractScalarWriterImpl
bindIndex, endArrayValue, isProjected, rowStartIndex, saveRow, schema, startRow, type, vector, writeIndex
Methods inherited from class org.apache.drill.exec.vector.accessor.writer.AbstractScalarWriter
conversionError, extendedType, setObject, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.drill.exec.vector.accessor.ColumnWriter
copy
Methods inherited from interface org.apache.drill.exec.vector.accessor.ScalarWriter
setDefaultValue, valueType
Methods inherited from interface org.apache.drill.exec.vector.accessor.ValueWriter
setValue
-
Field Details
-
lastWriteIndex
protected int lastWriteIndexThe largest position to which the writer has written data. Used to allow "fill-empties" (AKA "back-fill") of missing values one each value write and at the end of a batch. Note that this is the position of the last write, not the next write position. Starts at -1 (no last write).
-
-
Constructor Details
-
AbstractFixedWidthWriter
public AbstractFixedWidthWriter()
-
-
Method Details
-
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
- Overrides:
startWrite
in classAbstractScalarWriterImpl
-
width
public abstract int width() -
setBuffer
protected final void setBuffer()Description copied from class:BaseScalarWriter
All change of buffer comes through this function to allow capturing the buffer address and capacity. Only two ways to set the buffer: by binding to a vector in bindVector(), or by resizing the vector in prepareWrite().- Specified by:
setBuffer
in classBaseScalarWriter
-
mandatoryResize
protected final void mandatoryResize(int writeIndex) -
resize
protected final int resize(int writeIndex) -
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.- Returns:
- index of the last valid value in the vector
-
setLastWriteIndex
public void setLastWriteIndex(int index) For internal use only to update the write position on those very rare occasions in which the vector is written to outside of this writer framework. Not to be called by application code!- Parameters:
index
- new last write index
-
skipNulls
public void skipNulls()- Specified by:
skipNulls
in classBaseScalarWriter
-
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. -
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. -
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. -
endWrite
public void endWrite()Description copied from interface:WriterEvents
End a batch: finalize any vector values. -
fillEmpties
protected abstract void fillEmpties(int writeIndex) -
setValueCount
public void setValueCount(int valueCount) -
dump
- Specified by:
dump
in interfaceWriterEvents
- Overrides:
dump
in classBaseScalarWriter
-