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
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classBase 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.ScalarObjectWriterNested classes/interfaces inherited from interface org.apache.drill.exec.vector.accessor.writer.WriterEvents
WriterEvents.ColumnWriterListener, WriterEvents.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe 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_SIZEFields inherited from class org.apache.drill.exec.vector.accessor.writer.AbstractScalarWriterImpl
schema, vectorIndex -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddump(HierarchicalFormatter format) voidendWrite()End a batch: finalize any vector values.protected abstract voidfillEmpties(int writeIndex) intReturn the last write position in the vector.protected final voidmandatoryResize(int writeIndex) voidThe vectors backing this writer rolled over.voidThe vectors backing this vector are about to roll over.protected final intresize(int writeIndex) voidDuring a writer to a row, rewind the the current index position to restart the row.protected final voidAll change of buffer comes through this function to allow capturing the buffer address and capacity.voidsetLastWriteIndex(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.voidsetValueCount(int valueCount) voidvoidStart a write (batch) operation.abstract intwidth()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, setTimestampMethods inherited from class org.apache.drill.exec.vector.accessor.writer.AbstractScalarWriterImpl
bindIndex, endArrayValue, isProjected, rowStartIndex, saveRow, schema, startRow, type, vector, writeIndexMethods inherited from class org.apache.drill.exec.vector.accessor.writer.AbstractScalarWriter
conversionError, extendedType, setObject, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.drill.exec.vector.accessor.ColumnWriter
copyMethods inherited from interface org.apache.drill.exec.vector.accessor.ScalarWriter
setDefaultValue, valueTypeMethods 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:WriterEventsStart a write (batch) operation. Performs any vector initialization required at the start of a batch (especially for offset vectors.)- Specified by:
startWritein interfaceWriterEvents- Overrides:
startWritein classAbstractScalarWriterImpl
-
width
public abstract int width() -
setBuffer
protected final void setBuffer()Description copied from class:BaseScalarWriterAll 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:
setBufferin classBaseScalarWriter
-
mandatoryResize
protected final void mandatoryResize(int writeIndex) -
resize
protected final int resize(int writeIndex) -
lastWriteIndex
public int lastWriteIndex()Description copied from interface:WriterPositionReturn 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:
skipNullsin classBaseScalarWriter
-
restartRow
public void restartRow()Description copied from interface:WriterEventsDuring 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:WriterEventsThe 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:WriterEventsThe 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:WriterEventsEnd a batch: finalize any vector values. -
fillEmpties
protected abstract void fillEmpties(int writeIndex) -
setValueCount
public void setValueCount(int valueCount) -
dump
- Specified by:
dumpin interfaceWriterEvents- Overrides:
dumpin classBaseScalarWriter
-