Class Var16CharVector.Mutator
- All Implemented Interfaces:
ValueVector.Mutator
,VariableWidthVector.VariableWidthMutator
- Enclosing class:
- Var16CharVector
Overview
MutableVar16Char implements a vector of variable width values. Elements in the vector are accessed by position from the logical start of the vector. A fixed width offsetVector is used to convert an element's position to it's offset from the start of the (0-based) DrillBuf. Size is inferred by adjacent elements. The width of each element is 4 byte(s) The equivalent Java primitive is 'int' NB: this class is automatically generated from ValueVectorTypes.tdd using FreeMarker.
Contract
-
Supported Writes:
VariableWidthVector
s do not support random writes. In contrastFixedWidthVector
s do allow random writes but special care is needed. -
Writing Values: All set methods must be called with a consecutive sequence of indices. With a few exceptions:
- You can update the last index you just set.
- You can reset a previous index (call it Idx), but you must assume all the data after Idx is corrupt. Also note that the memory consumed by data that came after Idx is not released.
-
Setting Value Count: Vectors aren't explicitly aware of how many values they contain. So you must keep track of the
number of values you've written to the vector and once you are done writing to the vector you must call
setValueCount(int)
. It is possible to trim the vector by setting the value count to be less than the number of values currently contained in the vector. Note the extra memory consumed in the data buffer is not freed when this is done. -
Memory Allocation: When setting a value at an index you must do one of the following to ensure you do not get an
IndexOutOfBoundsException
.-
Allocate the exact amount of memory you need when using the
set(int, byte[])
methods. If you do not manually allocate sufficient memory anIndexOutOfBoundsException
can be thrown when the data buffer runs out of space. -
Or you can use the
setSafe(int, byte[])
methods, which will automatically grow your data buffer to fit your data.
-
Allocate the exact amount of memory you need when using the
-
Immutability: Once a vector has been populated with data and
setValueCount(int)
has been called, it should be considered immutable.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
fillEmpties
(int lastWrite, int index) Backfill missing offsets from the given last written position up to, but not including the given current write position.void
generateTestData
(int size) protected void
set
(int index, byte[] bytes) Set the variable length element at the specified index to the supplied byte array.protected void
set
(int index, byte[] bytes, int start, int length) Set the variable length element at the specified index to the supplied byte array.protected void
protected void
set
(int index, NullableVar16CharHolder holder) protected void
set
(int index, Var16CharHolder holder) void
setSafe
(int index, byte[] bytes) void
setSafe
(int index, byte[] bytes, int start, int length) void
void
setSafe
(int index, ByteBuffer bytes, int start, int length) void
setSafe
(int index, NullableVar16CharHolder holder) void
setSafe
(int index, Var16CharHolder holder) <T extends VarLenBulkEntry>
voidsetSafe
(VarLenBulkInput<T> input) Copies the bulk input into this value vector and extends its capacity if necessary.<T extends VarLenBulkEntry>
voidsetSafe
(VarLenBulkInput<T> input, VarLenBulkInput.BulkInputCallback<T> callback) Copies the bulk input into this value vector and extends its capacity if necessary.void
setValueCount
(int valueCount) Notes on Usagevoid
setValueLengthSafe
(int index, int length) Methods inherited from class org.apache.drill.exec.vector.BaseValueVector.BaseMutator
exchange, reset
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.ValueVector.Mutator
exchange, reset
-
Constructor Details
-
Mutator
public Mutator()
-
-
Method Details
-
set
protected void set(int index, byte[] bytes) Set the variable length element at the specified index to the supplied byte array.- Parameters:
index
- position of the bit to setbytes
- array of bytes to write
-
setSafe
public void setSafe(int index, byte[] bytes) -
setSafe
Copies the bulk input into this value vector and extends its capacity if necessary.- Parameters:
input
- bulk input
-
setSafe
public <T extends VarLenBulkEntry> void setSafe(VarLenBulkInput<T> input, VarLenBulkInput.BulkInputCallback<T> callback) Copies the bulk input into this value vector and extends its capacity if necessary. The callback mechanism allows decoration as caller is invoked for each bulk entry.- Parameters:
input
- bulk inputcallback
- a bulk input callback object (optional)
-
set
protected void set(int index, byte[] bytes, int start, int length) Set the variable length element at the specified index to the supplied byte array.- Parameters:
index
- position of the bit to setbytes
- array of bytes to writestart
- start index of bytes to writelength
- length of bytes to write
-
setSafe
-
setSafe
public void setSafe(int index, byte[] bytes, int start, int length) -
setValueLengthSafe
public void setValueLengthSafe(int index, int length) - Specified by:
setValueLengthSafe
in interfaceVariableWidthVector.VariableWidthMutator
-
setSafe
-
setSafe
-
setSafe
-
fillEmpties
public void fillEmpties(int lastWrite, int index) Backfill missing offsets from the given last written position up to, but not including the given current write position. Used by nullable vectors to allow skipping values. The set() and setSafe() do not fill empties. See DRILL-5529.- Parameters:
lastWrite
- the position of the last valid write: the offset to be copied forwardindex
- the current write position filling occurs up to, but not including, this position
-
set
-
set
-
set
-
setValueCount
public void setValueCount(int valueCount) Notes on Usage
For
VariableWidthVector
s this method can be used in the following cases:- Setting the actual number of elements currently contained in the vector.
- Trimming the vector to have fewer elements than it current does.
Caveats
It is important to note that for
FixedWidthVector
s this method can also be used to expand the vector. However,VariableWidthVector
do not support this usage and this method will throw anIndexOutOfBoundsException
if you attempt to use it in this way. Expansion of valueCounts is not supported mainly because there is no benefit, since you would still have to rely on the setSafe methods to appropriately expand the data buffer and populate the vector anyway (since by definition we do not know the width of elements). See DRILL-6234 for details.Method Documentation
Sets the number of values that is stored in this vector to the given value count. WARNING! Once the valueCount is set, the vector should be considered immutable.- Specified by:
setValueCount
in interfaceValueVector.Mutator
- Parameters:
valueCount
- value count to set.
-
generateTestData
public void generateTestData(int size) - Specified by:
generateTestData
in interfaceValueVector.Mutator
- Overrides:
generateTestData
in classBaseValueVector.BaseMutator
-