Package org.apache.arrow.vector
Class BaseFixedWidthVector
java.lang.Object
org.apache.arrow.vector.BaseValueVector
org.apache.arrow.vector.BaseFixedWidthVector
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterable<ValueVector>
,ElementAddressableVector
,FieldVector
,FixedWidthVector
,ValueVector
,VectorDefinitionSetter
- Direct Known Subclasses:
BigIntVector
,BitVector
,DateDayVector
,DateMilliVector
,Decimal256Vector
,DecimalVector
,DurationVector
,FixedSizeBinaryVector
,Float2Vector
,Float4Vector
,Float8Vector
,IntervalDayVector
,IntervalMonthDayNanoVector
,IntervalYearVector
,IntVector
,SmallIntVector
,TimeMicroVector
,TimeMilliVector
,TimeNanoVector
,TimeSecVector
,TimeStampVector
,TinyIntVector
,UInt1Vector
,UInt2Vector
,UInt4Vector
,UInt8Vector
public abstract class BaseFixedWidthVector
extends BaseValueVector
implements FixedWidthVector, FieldVector, VectorDefinitionSetter
BaseFixedWidthVector provides an abstract interface for implementing vectors of fixed width
values. The vectors are nullable implying that zero or more elements in the vector could be NULL.
-
Field Summary
Modifier and TypeFieldDescriptionprotected int
protected final Field
protected int
protected ArrowBuf
protected ArrowBuf
protected int
Fields inherited from class org.apache.arrow.vector.BaseValueVector
allocator, fieldReader, INITIAL_VALUE_ALLOCATION, MAX_ALLOCATION_SIZE, MAX_ALLOCATION_SIZE_PROPERTY
-
Constructor Summary
ConstructorDescriptionBaseFixedWidthVector
(Field field, BufferAllocator allocator, int typeWidth) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescription<OUT,
IN> OUT accept
(VectorVisitor<OUT, IN> visitor, IN value) Accept a genericVectorVisitor
and return the result.void
Same asallocateNewSafe()
.void
allocateNew
(int valueCount) Allocate memory for the vector to support storing at least the provided number of elements in the vector.boolean
Allocate memory for the vector.void
clear()
Same asclose()
.void
close()
Close the vector and release the associated buffers.void
copyFrom
(int fromIndex, int thisIndex, ValueVector from) Copy a cell value from a particular index in source vector to a particular position in this vector.void
copyFromSafe
(int fromIndex, int thisIndex, ValueVector from) Same ascopyFrom(int, int, ValueVector)
except that it handles the case when the capacity of the vector needs to be expanded before copy.protected void
ArrowBuf[]
getBuffers
(boolean clear) Return the underlying buffers associated with this vector.int
Get the size (number of bytes) of underlying buffers used by this vector.int
getBufferSizeFor
(int count) Get the potential buffer size for a particular number of records.Get the inner child vectors.Get the buffer that stores the data for elements in the vector.long
Get the memory address of buffer that stores the data for elements in the vector.getDataPointer
(int index) Gets the pointer for the data at the given index.getDataPointer
(int index, ArrowBufPointer reuse) Gets the pointer for the data at the given index.getField()
Get information about how this field is materialized.Get the buffers belonging to this vector.Deprecated.This API will be removed as the current implementations no longer support inner vectors.getName()
Gets the name of the vector.int
Get the number of elements that are null in the vector.buffer that stores the offsets for elements in the vector.long
Get the memory address of buffer that stores the offsets for elements in the vector.abstract TransferPair
getTransferPair
(String ref, BufferAllocator allocator) Construct a transfer pair of this vector and another vector of same type.getTransferPair
(String ref, BufferAllocator allocator, CallBack callBack) Construct a transfer pair of this vector and another vector of same type.getTransferPair
(BufferAllocator allocator) Construct a transfer pair of this vector and another vector of same type.abstract TransferPair
getTransferPair
(Field field, BufferAllocator allocator) Construct a transfer pair of this vector and another vector of same type.getTransferPair
(Field field, BufferAllocator allocator, CallBack callBack) Construct a transfer pair of this vector and another vector of same type.int
Get buffer that manages the validity (NULL or NON-NULL nature) of elements in the vector.long
Get the memory address of buffer that manages the validity (NULL or NON-NULL nature) of elements in the vector.protected int
protected int
int
Get the current value capacity for the vector.int
Get the value count of vector.protected void
handleSafe
(int index) int
hashCode
(int index) Returns hashCode of element in index with the default hasher.int
hashCode
(int index, ArrowBufHasher hasher) Returns hashCode of element in index with the given hasher.protected void
void
initializeChildrenFromFields
(List<Field> children) Initialize the children in schema for this Field.boolean
isNull
(int index) Check if element at given index is null.boolean
isSafe
(int index) Check if the given index is within the current value capacity of the vector.int
isSet
(int index) Same asisNull(int)
.void
loadFieldBuffers
(ArrowFieldNode fieldNode, List<ArrowBuf> ownBuffers) Load the buffers of this vector with provided source buffers.void
reAlloc()
Resize the vector to increase the capacity.protected void
Call this if you change the capacity of valueBuffer or validityBuffer.void
reset()
Reset the vector to initial state.void
set
(int index, byte[] value, int start, int length) void
set
(int index, ByteBuffer value, int start, int length) void
setIndexDefined
(int index) Mark the particular position in the vector as non-null.void
setInitialCapacity
(int valueCount) Sets the desired value capacity for the vector.void
setNull
(int index) Set the element at the given index to null.void
setSafe
(int index, byte[] value, int start, int length) void
setSafe
(int index, ByteBuffer value, int start, int length) void
setValueCount
(int valueCount) Set value count for the vector.void
splitAndTransferTo
(int startIndex, int length, BaseFixedWidthVector target) Slice this vector at desired index and length and transfer the corresponding data to the target vector.void
transferTo
(BaseFixedWidthVector target) Transfer this vector's data to another vector.void
Validate the scalar values held by this vector.void
zero out the vector and the data in associated buffers.Methods inherited from class org.apache.arrow.vector.BaseValueVector
checkBufRefs, getAllocator, getReader, getReaderImpl, getValidityBufferSizeFromCount, iterator, releaseBuffer, toString, transferBuffer
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.arrow.vector.FieldVector
exportBuffer, exportCDataBuffers, getExportedCDataBufferCount
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
Methods inherited from interface org.apache.arrow.vector.ValueVector
getAllocator, getMinorType, getObject, getReader, makeTransferPair, validate, validateFull
-
Field Details
-
lastValueCapacity
protected int lastValueCapacity -
actualValueCapacity
protected int actualValueCapacity -
field
-
validityBuffer
-
valueBuffer
-
valueCount
protected int valueCount
-
-
Constructor Details
-
BaseFixedWidthVector
Constructs a new instance.- Parameters:
field
- field materialized by this vectorallocator
- The allocator to use for allocating memory for the vector.typeWidth
- The width in bytes of the type.
-
-
Method Details
-
getTypeWidth
public int getTypeWidth() -
getName
Description copied from interface:ValueVector
Gets the name of the vector.- Specified by:
getName
in interfaceValueVector
- Specified by:
getName
in classBaseValueVector
- Returns:
- the name of the vector.
-
getValidityBufferAddress
public long getValidityBufferAddress()Get the memory address of buffer that manages the validity (NULL or NON-NULL nature) of elements in the vector.- Specified by:
getValidityBufferAddress
in interfaceFieldVector
- Returns:
- starting address of the buffer
-
getDataBufferAddress
public long getDataBufferAddress()Get the memory address of buffer that stores the data for elements in the vector.- Specified by:
getDataBufferAddress
in interfaceFieldVector
- Returns:
- starting address of the buffer
-
getOffsetBufferAddress
public long getOffsetBufferAddress()Get the memory address of buffer that stores the offsets for elements in the vector. This operation is not supported for fixed-width vectors.- Specified by:
getOffsetBufferAddress
in interfaceFieldVector
- Returns:
- starting address of the buffer
- Throws:
UnsupportedOperationException
- for fixed width vectors
-
getValidityBuffer
Get buffer that manages the validity (NULL or NON-NULL nature) of elements in the vector. Consider it as a buffer for internal bit vector data structure.- Specified by:
getValidityBuffer
in interfaceValueVector
- Returns:
- buffer
-
getDataBuffer
Get the buffer that stores the data for elements in the vector.- Specified by:
getDataBuffer
in interfaceValueVector
- Returns:
- buffer
-
getOffsetBuffer
buffer that stores the offsets for elements in the vector. This operation is not supported for fixed-width vectors.- Specified by:
getOffsetBuffer
in interfaceValueVector
- Returns:
- buffer
- Throws:
UnsupportedOperationException
- for fixed width vectors
-
setInitialCapacity
public void setInitialCapacity(int valueCount) Sets the desired value capacity for the vector. This function doesn't allocate any memory for the vector.- Specified by:
setInitialCapacity
in interfaceValueVector
- Parameters:
valueCount
- desired number of elements in the vector
-
getValueCapacity
public int getValueCapacity()Get the current value capacity for the vector.- Specified by:
getValueCapacity
in interfaceValueVector
- Returns:
- number of elements that vector can hold.
-
refreshValueCapacity
protected void refreshValueCapacity()Call this if you change the capacity of valueBuffer or validityBuffer. -
getValueBufferValueCapacity
protected int getValueBufferValueCapacity() -
getValidityBufferValueCapacity
protected int getValidityBufferValueCapacity() -
zeroVector
public void zeroVector()zero out the vector and the data in associated buffers.- Specified by:
zeroVector
in interfaceFixedWidthVector
-
reset
public void reset()Reset the vector to initial state. Same aszeroVector()
. Note that this method doesn't release any memory.- Specified by:
reset
in interfaceValueVector
-
close
public void close()Close the vector and release the associated buffers.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceValueVector
- Overrides:
close
in classBaseValueVector
-
clear
public void clear()Same asclose()
.- Specified by:
clear
in interfaceValueVector
- Overrides:
clear
in classBaseValueVector
-
incrementAllocationMonitor
protected void incrementAllocationMonitor() -
decrementAllocationMonitor
protected void decrementAllocationMonitor() -
allocateNew
public void allocateNew()Same asallocateNewSafe()
.- Specified by:
allocateNew
in interfaceValueVector
-
allocateNewSafe
public boolean allocateNewSafe()Allocate memory for the vector. We internally use a default value count of 4096 to allocate memory for at least these many elements in the vector. SeeallocateNew(int)
for allocating memory for specific number of elements in the vector.- Specified by:
allocateNewSafe
in interfaceValueVector
- Returns:
- false if memory allocation fails, true otherwise.
-
allocateNew
public void allocateNew(int valueCount) Allocate memory for the vector to support storing at least the provided number of elements in the vector. This method must be called prior to using the ValueVector.- Specified by:
allocateNew
in interfaceFixedWidthVector
- Parameters:
valueCount
- the desired number of elements in the vector- Throws:
OutOfMemoryException
- on error
-
getBufferSizeFor
public int getBufferSizeFor(int count) Get the potential buffer size for a particular number of records.- Specified by:
getBufferSizeFor
in interfaceValueVector
- Parameters:
count
- desired number of elements in the vector- Returns:
- estimated size of underlying buffers if the vector holds a given number of elements
-
getBufferSize
public int getBufferSize()Get the size (number of bytes) of underlying buffers used by this vector.- Specified by:
getBufferSize
in interfaceValueVector
- Returns:
- size of underlying buffers.
-
getField
Get information about how this field is materialized.- Specified by:
getField
in interfaceValueVector
- Returns:
- the field corresponding to this vector
-
getBuffers
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
- 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.
-
reAlloc
public void reAlloc()Resize the vector to increase the capacity. The internal behavior is to double the current value capacity.- Specified by:
reAlloc
in interfaceValueVector
-
getFieldInnerVectors
Deprecated.This API will be removed as the current implementations no longer support inner vectors.Get the inner vectors.- Specified by:
getFieldInnerVectors
in interfaceFieldVector
- Returns:
- the inner vectors for this field as defined by the TypeLayout
-
initializeChildrenFromFields
Initialize the children in schema for this Field. This operation is a NO-OP for scalar types since they don't have any children.- Specified by:
initializeChildrenFromFields
in interfaceFieldVector
- Parameters:
children
- the schema- Throws:
IllegalArgumentException
- if children is a non-empty list for scalar types.
-
getChildrenFromFields
Get the inner child vectors.- Specified by:
getChildrenFromFields
in interfaceFieldVector
- Returns:
- list of child vectors for complex types, empty list for scalar vector types
-
loadFieldBuffers
Load the buffers of this vector with provided source buffers. The caller manages the source buffers and populates them before invoking this method.- Specified by:
loadFieldBuffers
in interfaceFieldVector
- Parameters:
fieldNode
- the fieldNode indicating the value countownBuffers
- the buffers for this Field (own buffers only, children not included)
-
getFieldBuffers
Get the buffers belonging to this vector.- Specified by:
getFieldBuffers
in interfaceFieldVector
- Returns:
- the inner buffers.
-
validateScalars
public void validateScalars()Validate the scalar values held by this vector. -
getTransferPair
Construct a transfer pair of this vector and another vector of same type.- Specified by:
getTransferPair
in interfaceValueVector
- Parameters:
ref
- name of the target vectorallocator
- allocator for the target vectorcallBack
- not used- Returns:
- TransferPair
-
getTransferPair
Construct a transfer pair of this vector and another vector of same type.- Specified by:
getTransferPair
in interfaceValueVector
- Parameters:
field
- The field materialized by this vector.allocator
- allocator for the target vectorcallBack
- not used- Returns:
- TransferPair
-
getTransferPair
Construct a transfer pair of this vector and another vector of same type.- Specified by:
getTransferPair
in interfaceValueVector
- Overrides:
getTransferPair
in classBaseValueVector
- Parameters:
allocator
- allocator for the target vector- Returns:
- TransferPair
-
getTransferPair
Construct a transfer pair of this vector and another vector of same type.- Specified by:
getTransferPair
in interfaceValueVector
- Parameters:
ref
- name of the target vectorallocator
- allocator for the target vector- Returns:
- TransferPair
-
getTransferPair
Construct a transfer pair of this vector and another vector of same type.- Specified by:
getTransferPair
in interfaceValueVector
- Parameters:
field
- Field object used by the target vectorallocator
- allocator for the target vector- Returns:
- TransferPair
-
transferTo
Transfer this vector's data to another vector. The memory associated with this vector is transferred to the allocator of target vector for accounting and management purposes.- Parameters:
target
- destination vector for transfer
-
splitAndTransferTo
Slice this vector at desired index and length and transfer the corresponding data to the target vector.- Parameters:
startIndex
- start position of the split in source vector.length
- length of the split.target
- destination vector
-
getNullCount
public int getNullCount()Get the number of elements that are null in the vector.- Specified by:
getNullCount
in interfaceValueVector
- Returns:
- the number of null elements.
-
getValueCount
public int getValueCount()Get the value count of vector. This will always be zero unlesssetValueCount(int)
has been called prior to calling this.- Specified by:
getValueCount
in interfaceValueVector
- Returns:
- valueCount for the vector
-
setValueCount
public void setValueCount(int valueCount) Set value count for the vector.- Specified by:
setValueCount
in interfaceValueVector
- Parameters:
valueCount
- value count to set
-
isSafe
public boolean isSafe(int index) Check if the given index is within the current value capacity of the vector.- Parameters:
index
- position to check- Returns:
- true if index is within the current value capacity
-
isNull
public boolean isNull(int index) Check if element at given index is null.- Specified by:
isNull
in interfaceValueVector
- Parameters:
index
- position of element- Returns:
- true if element at given index is null, false otherwise
-
isSet
public int isSet(int index) Same asisNull(int)
.- Parameters:
index
- position of element- Returns:
- 1 if element at given index is not null, 0 otherwise
-
setIndexDefined
public void setIndexDefined(int index) Mark the particular position in the vector as non-null.- Specified by:
setIndexDefined
in interfaceVectorDefinitionSetter
- Parameters:
index
- position of the element.
-
set
public void set(int index, byte[] value, int start, int length) -
setSafe
public void setSafe(int index, byte[] value, int start, int length) -
set
-
setSafe
-
handleSafe
protected void handleSafe(int index) -
copyFrom
Copy a cell value from a particular index in source vector to a particular position in this vector. The source vector should be of the same type as this one.- Specified by:
copyFrom
in interfaceValueVector
- Overrides:
copyFrom
in classBaseValueVector
- Parameters:
fromIndex
- position to copy from in source vectorthisIndex
- position to copy to in this vectorfrom
- source vector
-
copyFromSafe
Same ascopyFrom(int, int, ValueVector)
except that it handles the case when the capacity of the vector needs to be expanded before copy.- Specified by:
copyFromSafe
in interfaceValueVector
- Overrides:
copyFromSafe
in classBaseValueVector
- Parameters:
fromIndex
- position to copy from in source vectorthisIndex
- position to copy to in this vectorfrom
- source vector
-
setNull
public void setNull(int index) Set the element at the given index to null.- Specified by:
setNull
in interfaceFieldVector
- Parameters:
index
- position of element
-
getDataPointer
Description copied from interface:ElementAddressableVector
Gets the pointer for the data at the given index.- Specified by:
getDataPointer
in interfaceElementAddressableVector
- Parameters:
index
- the index for the data.- Returns:
- the pointer to the data.
-
getDataPointer
Description copied from interface:ElementAddressableVector
Gets the pointer for the data at the given index.- Specified by:
getDataPointer
in interfaceElementAddressableVector
- Parameters:
index
- the index for the data.reuse
- the data pointer to fill, this avoids creating a new pointer object.- Returns:
- the pointer to the data, it should be the same one as the input parameter
-
hashCode
public int hashCode(int index) Description copied from interface:ValueVector
Returns hashCode of element in index with the default hasher.- Specified by:
hashCode
in interfaceValueVector
-
hashCode
Description copied from interface:ValueVector
Returns hashCode of element in index with the given hasher.- Specified by:
hashCode
in interfaceValueVector
-
accept
Description copied from interface:ValueVector
Accept a genericVectorVisitor
and return the result.- Specified by:
accept
in interfaceValueVector
- Type Parameters:
OUT
- the output result type.IN
- the input data together with visitor.
-