public abstract class BaseScalarWriter extends AbstractScalarWriterImpl
The only tricky part to this class is understanding the state of the write indexes as the write proceeds. There are two pointers to consider:
Let's illustrate the states. Let's focus on one column and illustrate the three states that can occur during write:
Behind Written Unwritten Restarted
|X| |X| |X| |X|
lw >|X| |X| |X| |X|
| | |0| |0| lw > |0|
v >| | lw, v > |X| lw > |X| v > |X|
v > | |
The illustrated state transitions are:
We've already noted that the Restarted state is identical to the Unwritten state (and was discussed just to make the flow a bit clearer.) The astute reader will have noticed that the Behind state is the same as the Unwritten state if we define the combined state as when the last write position is behind the vector index.
Further, if one simply treats the gap between last write and the vector indexes as the amount (which may be zero) to back-fill, then there is just one state. This is, in fact, how the code works: it always writes to the vector index (and can do so multiple times for a single row), back-filling as necessary.
The states, then, are more for our use in understanding the algorithm. They are also very useful when working through the logic of performing a roll-over when a vector overflows.
AbstractScalarWriterImpl.ScalarObjectWriter
WriterEvents.ColumnWriterListener, WriterEvents.State
Modifier and Type | Field and Description |
---|---|
protected int |
capacity
Capacity, in values, of the currently allocated buffer that backs
the vector.
|
protected DrillBuf |
drillBuf |
protected byte[] |
emptyValue
Value to use to fill empties.
|
protected WriterEvents.ColumnWriterListener |
listener
Listener invoked if the vector overflows.
|
static int |
MIN_BUFFER_SIZE |
schema, vectorIndex
Constructor and Description |
---|
BaseScalarWriter() |
Modifier and Type | Method and Description |
---|---|
void |
appendBytes(byte[] value,
int len) |
void |
bindListener(WriterEvents.ColumnWriterListener listener)
Bind a listener to the underlying vector writer.
|
void |
bindSchema(ColumnMetadata schema) |
protected boolean |
canExpand(int delta)
The vector is about to grow.
|
void |
dump(HierarchicalFormatter format) |
boolean |
nullable()
Whether this writer allows nulls.
|
protected void |
overflowed()
Handle vector overflow.
|
protected void |
realloc(int size) |
void |
setBoolean(boolean value) |
protected abstract void |
setBuffer()
All change of buffer comes through this function to allow capturing
the buffer address and capacity.
|
void |
setBytes(byte[] value,
int len) |
void |
setDate(LocalDate value) |
void |
setDecimal(BigDecimal value) |
void |
setDouble(double value) |
void |
setFloat(float value) |
void |
setInt(int value) |
void |
setLong(long value) |
void |
setNull()
Set the current value to null.
|
void |
setPeriod(org.joda.time.Period value) |
void |
setString(String value) |
void |
setTime(LocalTime value) |
void |
setTimestamp(Instant value) |
abstract void |
skipNulls() |
bindIndex, endArrayValue, isProjected, rowStartIndex, saveRow, schema, startRow, startWrite, type, vector, writeIndex
conversionError, extendedType, setObject, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
endWrite, postRollover, preRollover, restartRow
lastWriteIndex
setDefaultValue, valueType
copy
setValue
public static final int MIN_BUFFER_SIZE
protected WriterEvents.ColumnWriterListener listener
protected byte[] emptyValue
protected DrillBuf drillBuf
protected int capacity
public void bindListener(WriterEvents.ColumnWriterListener listener)
WriterEvents
bindListener
in interface WriterEvents
bindListener
in class AbstractScalarWriter
listener
- the vector event listener to bindpublic void bindSchema(ColumnMetadata schema)
bindSchema
in class AbstractScalarWriterImpl
protected abstract void setBuffer()
protected void realloc(int size)
protected boolean canExpand(int delta)
delta
- the new amount of memory to allocateprotected void overflowed()
public abstract void skipNulls()
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.ColumnWriter.setNull()
is supported, false
if notpublic void setNull()
ColumnWriter
public void setBoolean(boolean value)
public void setInt(int value)
public void setLong(long value)
public void setFloat(float value)
public void setDouble(double value)
public void setString(String value)
public void setBytes(byte[] value, int len)
public void appendBytes(byte[] value, int len)
public void setDecimal(BigDecimal value)
public void setPeriod(org.joda.time.Period value)
public void setDate(LocalDate value)
public void setTime(LocalTime value)
public void setTimestamp(Instant value)
public void dump(HierarchicalFormatter format)
dump
in interface WriterEvents
dump
in class AbstractScalarWriterImpl
Copyright © 1970 The Apache Software Foundation. All rights reserved.