Package org.apache.drill.exec.vector
Class VarCharVector
java.lang.Object
org.apache.drill.exec.vector.BaseValueVector
org.apache.drill.exec.vector.BaseDataValueVector
org.apache.drill.exec.vector.VarCharVector
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterable<ValueVector>
,ValueVector
,VariableWidthVector
VarCharVector 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 from adjacent elements.
- The width of each element is 4 byte(s). Note that the actual width is variable, this width is used as a guess for certain calculations.
- The equivalent Java primitive is 'int'
-
Nested Class Summary
Modifier and TypeClassDescriptionfinal class
static final class
Helper class to buffer container mutation as a means to optimize native memory copy operations.final class
OverviewNested classes/interfaces inherited from class org.apache.drill.exec.vector.BaseValueVector
BaseValueVector.BaseAccessor, BaseValueVector.BaseMutator
Nested classes/interfaces inherited from interface org.apache.drill.exec.vector.VariableWidthVector
VariableWidthVector.VariableWidthAccessor, VariableWidthVector.VariableWidthMutator
-
Field Summary
Fields inherited from class org.apache.drill.exec.vector.BaseDataValueVector
data, emptyByteArray
Fields inherited from class org.apache.drill.exec.vector.BaseValueVector
allocator, field, INITIAL_VALUE_ALLOCATION, MAX_ALLOCATION_SIZE
Fields inherited from interface org.apache.drill.exec.vector.ValueVector
BITS_VECTOR_NAME, MAX_BUFFER_SIZE, MAX_ROW_COUNT, MIN_ROW_COUNT, OFFSETS_VECTOR_NAME, VALUES_VECTOR_NAME
Fields inherited from interface org.apache.drill.exec.vector.VariableWidthVector
DEFAULT_RECORD_BYTE_COUNT, MIN_BYTE_COUNT, offsetsField
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Allocate new buffers.void
allocateNew
(int totalBytes, int valueCount) Allocate a new memory space for this vector.boolean
Allocates new buffers.void
clear()
Release the underlying DrillBuf and reset the ValueVector to empty.void
collectLedgers
(Set<AllocationManager.BufferLedger> ledgers) Add the ledgers underlying the buffers underlying the components of the vector to the set provided.void
copyEntry
(int toIndex, ValueVector from, int fromIndex) protected void
copyFrom
(int fromIndex, int thisIndex, VarCharVector from) void
copyFromSafe
(int fromIndex, int thisIndex, VarCharVector from) void
void
exchange
(ValueVector other) Exchange state with another value vector of the same type.Returns anaccessor
that is used to read from this vector instance.int
Returns the total size of buffers allocated by this vector.DrillBuf[]
getBuffers
(boolean clear) Return the underlying buffers associated with this vector.int
Returns the number of bytes that is used by this vector instance.int
getBufferSizeFor
(int valueCount) Returns the number of bytes that is used by this vector if it holds the given number of values.int
Provide the maximum amount of variable width bytes that can be stored int his vector.int
Return the number of bytes contained in the current var len byte vector.Get the metadata for this field.Returns anmutator
that is used to write to this vector instance.long
int
getPayloadByteCount
(int valueCount) Return the number of value bytes consumed by actual data.Returns afield reader
that supports reading values from this vector.getTransferPair
(String ref, BufferAllocator allocator) getTransferPair
(BufferAllocator allocator) Returns atransfer pair
, creating a new target vector of the same type.int
Returns the maximum number of values that can be stored in this vector instance.int
Return the number of bytes contained in the current var len byte vector.void
load
(UserBitShared.SerializedField metadata, DrillBuf buffer) Load the data provided in the buffer.Returns a newtransfer pair
that is used to transfer underlying buffers into the target vector.void
reAlloc()
reallocRaw
(int newAllocationSize) Core of vector allocation.void
reset()
This method has a similar effect of allocateNew() without actually clearing and reallocating the value vector.void
setInitialCapacity
(int valueCount) Set the initial record capacityvoid
splitAndTransferTo
(int startIndex, int length, VarCharVector target) void
toNullable
(ValueVector nullableVector) Convert a non-nullable vector to nullable by shuffling the data from one to the other.void
transferTo
(VarCharVector target) Methods inherited from class org.apache.drill.exec.vector.BaseDataValueVector
close, getBuffer
Methods inherited from class org.apache.drill.exec.vector.BaseValueVector
checkBufRefs, fillBitsVector, getAllocator, getField, getField, getMetadataBuilder, iterator, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
Methods inherited from interface org.apache.drill.exec.vector.ValueVector
close, getAllocator, getField
-
Constructor Details
-
VarCharVector
-
-
Method Details
-
getReader
Description copied from interface:ValueVector
Returns afield reader
that supports reading values from this vector.- Specified by:
getReader
in interfaceValueVector
-
getBufferSize
public int getBufferSize()Description copied from interface:ValueVector
Returns the number of bytes that is used by this vector instance. This is a bit of a misnomer. Returns the number of bytes used by data in this instance.- Specified by:
getBufferSize
in interfaceValueVector
- Overrides:
getBufferSize
in classBaseDataValueVector
-
getAllocatedSize
public int getAllocatedSize()Description copied from interface:ValueVector
Returns the total size of buffers allocated by this vector. Has meaning only when vectors are directly allocated and each vector has its own buffer. Does not have meaning for vectors deserialized from the network or disk in which multiple vectors share the same vector.- Specified by:
getAllocatedSize
in interfaceValueVector
- Overrides:
getAllocatedSize
in classBaseDataValueVector
- Returns:
- allocated buffer size, in bytes
-
getBufferSizeFor
public int getBufferSizeFor(int valueCount) Description copied from interface:ValueVector
Returns the number of bytes that is used by this vector if it holds the given number of values. The result will be the same as if Mutator.setValueCount() were called, followed by calling getBufferSize(), but without any of the closing side-effects that setValueCount() implies wrt finishing off the population of a vector. Some operations might wish to use this to determine how much memory has been used by a vector so far, even though it is not finished being populated.- Specified by:
getBufferSizeFor
in interfaceValueVector
- Parameters:
valueCount
- the number of values to assume this vector contains- Returns:
- the buffer size if this vector is holding valueCount values
-
getValueCapacity
public int getValueCapacity()Description copied from interface:ValueVector
Returns the maximum number of values that can be stored in this vector instance.- Specified by:
getValueCapacity
in interfaceValueVector
-
getByteCapacity
public int getByteCapacity()Description copied from interface:VariableWidthVector
Provide the maximum amount of variable width bytes that can be stored int his vector.- Specified by:
getByteCapacity
in interfaceVariableWidthVector
- Returns:
-
getCurrentSizeInBytes
public int getCurrentSizeInBytes()Return the number of bytes contained in the current var len byte vector. TODO: Remove getVarByteLength with it's implementation after all client's are moved to using getCurrentSizeInBytes. It's kept as is to preserve backward compatibility- Specified by:
getCurrentSizeInBytes
in interfaceVariableWidthVector
- Returns:
-
getVarByteLength
public int getVarByteLength()Return the number of bytes contained in the current var len byte vector.- Returns:
-
getMetadata
Description copied from interface:ValueVector
Get the metadata for this field. Used in serialization- Specified by:
getMetadata
in interfaceValueVector
- Overrides:
getMetadata
in classBaseValueVector
- Returns:
- FieldMetadata for this field.
-
clear
public void clear()Description copied from interface:ValueVector
Release the underlying DrillBuf and reset the ValueVector to empty.- Specified by:
clear
in interfaceValueVector
- Overrides:
clear
in classBaseDataValueVector
-
getBuffers
Description copied from interface:ValueVector
Return the underlying buffers associated with this vector. Note that this doesn't impact the reference counts for this buffer so it only should be used for in-context access. Also note that this buffer changes regularly thus external classes shouldn't hold a reference to it (unless they change it).- Specified by:
getBuffers
in interfaceValueVector
- Overrides:
getBuffers
in classBaseDataValueVector
- Parameters:
clear
- Whether to clear vector before returning; the buffers will still be refcounted; but the returned array will be the only reference to them- Returns:
- The underlying
buffers
that is used by this vector instance.
-
getOffsetAddr
public long getOffsetAddr() -
getOffsetVector
- Specified by:
getOffsetVector
in interfaceVariableWidthVector
-
getTransferPair
Description copied from interface:ValueVector
Returns atransfer pair
, creating a new target vector of the same type.- Specified by:
getTransferPair
in interfaceValueVector
- Overrides:
getTransferPair
in classBaseValueVector
-
getTransferPair
- Specified by:
getTransferPair
in interfaceValueVector
-
makeTransferPair
Description copied from interface:ValueVector
Returns a newtransfer pair
that is used to transfer underlying buffers into the target vector.- Specified by:
makeTransferPair
in interfaceValueVector
-
transferTo
-
splitAndTransferTo
-
copyFrom
-
copyFromSafe
-
copyEntry
- Specified by:
copyEntry
in interfaceValueVector
-
collectLedgers
Description copied from interface:ValueVector
Add the ledgers underlying the buffers underlying the components of the vector to the set provided. Used to determine actual memory allocation.- Specified by:
collectLedgers
in interfaceValueVector
- Overrides:
collectLedgers
in classBaseDataValueVector
- Parameters:
ledgers
- set of ledgers to which to add ledgers for this vector
-
getPayloadByteCount
public int getPayloadByteCount(int valueCount) Description copied from interface:ValueVector
Return the number of value bytes consumed by actual data.- Specified by:
getPayloadByteCount
in interfaceValueVector
-
setInitialCapacity
public void setInitialCapacity(int valueCount) Description copied from interface:ValueVector
Set the initial record capacity- Specified by:
setInitialCapacity
in interfaceValueVector
-
allocateNew
public void allocateNew()Description copied from interface:ValueVector
Allocate new buffers. ValueVector implements logic to determine how much to allocate.- Specified by:
allocateNew
in interfaceValueVector
-
allocateNewSafe
public boolean allocateNewSafe()Description copied from interface:ValueVector
Allocates new buffers. ValueVector implements logic to determine how much to allocate.- Specified by:
allocateNewSafe
in interfaceValueVector
- Returns:
- Returns true if allocation was successful.
-
allocateNew
public void allocateNew(int totalBytes, int valueCount) Description copied from interface:VariableWidthVector
Allocate a new memory space for this vector. Must be called prior to using the ValueVector.- Specified by:
allocateNew
in interfaceVariableWidthVector
- Parameters:
totalBytes
- Desired size of the underlying data buffer.valueCount
- Number of values in the vector.
-
reset
public void reset()Description copied from class:BaseDataValueVector
This method has a similar effect of allocateNew() without actually clearing and reallocating the value vector. The purpose is to move the value vector to a "mutate" state- Overrides:
reset
in classBaseDataValueVector
-
reAlloc
public void reAlloc() -
reallocRaw
Description copied from class:BaseDataValueVector
Core of vector allocation. Given a new size (which must be a power of two), allocate the new buffer, copy the current values, and leave the unused parts garbage-filled.- Specified by:
reallocRaw
in classBaseDataValueVector
- Parameters:
newAllocationSize
- new buffer size as a power of two- Returns:
- the new buffer
-
decrementAllocationMonitor
public void decrementAllocationMonitor() -
getAccessor
Description copied from interface:ValueVector
Returns anaccessor
that is used to read from this vector instance.- Specified by:
getAccessor
in interfaceValueVector
- Specified by:
getAccessor
in interfaceVariableWidthVector
-
getMutator
Description copied from interface:ValueVector
Returns anmutator
that is used to write to this vector instance.- Specified by:
getMutator
in interfaceValueVector
- Specified by:
getMutator
in interfaceVariableWidthVector
-
exchange
Description copied from interface:ValueVector
Exchange state with another value vector of the same type. Used to implement look-ahead writers.- Specified by:
exchange
in interfaceValueVector
- Overrides:
exchange
in classBaseDataValueVector
-
toNullable
Description copied from interface:ValueVector
Convert a non-nullable vector to nullable by shuffling the data from one to the other. Avoids the need to generate copy code just to change mode. If this vector is non-nullable, accepts a nullable dual (same minor type, different mode.) If the vector is non-nullable, or non-scalar, then throws an exception.- Specified by:
toNullable
in interfaceValueVector
- Overrides:
toNullable
in classBaseValueVector
- Parameters:
nullableVector
- nullable vector of the same minor type as this vector
-