Skip to main content

Array Classes

Array classes in Apache Arrow C++ provide container classes for columnar data of various types.

Base Array Classes

Array

Base class for all array types. Immutable data array with some logical type and length.
class Array

Methods

length
int64_t
Returns the number of elements in the array
offset
int64_t
Returns the relative position into another array’s data for zero-copy slicing
null_count
int64_t
Returns the number of null entries in the array. Computed and cached on first call if not known at construction time
type
std::shared_ptr<DataType>
Returns the data type of the array
IsNull
bool
i
int64_t
required
Index to check
Returns true if the value at index is null. Does not perform bounds checking
IsValid
bool
i
int64_t
required
Index to check
Returns true if the value at index is valid (not null). Does not perform bounds checking
GetScalar
Result<std::shared_ptr<Scalar>>
i
int64_t
required
Index of element to retrieve
Returns a Scalar containing the value of this array at index i
Slice
std::shared_ptr<Array>
offset
int64_t
required
Position of the first element in the slice
length
int64_t
Length of the slice. Adjusted if not enough elements available
Constructs a zero-copy slice of the array with the indicated offset and length
SliceSafe
Result<std::shared_ptr<Array>>
offset
int64_t
required
Position of the first element
length
int64_t
Length of the slice
Input-checking variant of Slice that validates parameters
Equals
bool
other
const Array&
required
Array to compare with
options
const EqualOptions&
Equality comparison options
Performs equality comparison with another array. Does not include ArrayStatistics in comparison
View
Result<std::shared_ptr<Array>>
type
std::shared_ptr<DataType>
required
Target data type
Constructs a zero-copy view of this array with the given type. Checks if types are layout-compatible
Validate
Status
Performs cheap validation checks to determine obvious inconsistencies within the array’s internal data. O(k) where k is the number of descendants
ValidateFull
Status
Performs extensive validation checks. Potentially O(k*n) where k is the number of descendants and n is the array length

Numeric Arrays

NumericArray

Template class for numeric data arrays with a corresponding C type.
template <typename TYPE>
class NumericArray : public PrimitiveArray

Type Aliases

  • Int8Array - Array of signed 8-bit integers
  • Int16Array - Array of signed 16-bit integers
  • Int32Array - Array of signed 32-bit integers
  • Int64Array - Array of signed 64-bit integers
  • UInt8Array - Array of unsigned 8-bit integers
  • UInt16Array - Array of unsigned 16-bit integers
  • UInt32Array - Array of unsigned 32-bit integers
  • UInt64Array - Array of unsigned 64-bit integers
  • FloatArray - Array of 32-bit floating-point values
  • DoubleArray - Array of 64-bit floating-point values

Methods

Value
value_type
i
int64_t
required
Index to retrieve
Returns the value at index i
raw_values
const value_type*
Returns pointer to the raw value data
operator[]
std::optional<value_type>
i
int64_t
required
Index to retrieve
Returns the value at index i, or nullopt if null

BooleanArray

Array class for boolean data.
class BooleanArray : public PrimitiveArray
Value
bool
i
int64_t
required
Index to retrieve
Returns the boolean value at index i
false_count
int64_t
Returns the number of false (0) values among the valid values. Not cached
true_count
int64_t
Returns the number of true (1) values among the valid values. Not cached

Binary Arrays

BinaryArray

Array class for variable-size binary data.
class BinaryArray : public BaseBinaryArray<BinaryType>
GetView
std::string_view
i
int64_t
required
Index to retrieve
Returns binary value as a string_view
GetString
std::string
i
int64_t
required
Index to retrieve
Returns binary value copied into a std::string
value_offset
offset_type
i
int64_t
required
Index
Returns the data buffer absolute offset of the data for the value at the passed index
value_length
offset_type
i
int64_t
required
Index
Returns the length of the data for the value at the passed index

StringArray

Array class for variable-size UTF-8 string data.
class StringArray : public BinaryArray
Inherits all methods from BinaryArray.
ValidateUTF8
Status
Validates that this array contains only valid UTF-8 entries. Also implied by ValidateFull()

FixedSizeBinaryArray

Array class for fixed-size binary data.
class FixedSizeBinaryArray : public PrimitiveArray
GetValue
const uint8_t*
i
int64_t
required
Index to retrieve
Returns pointer to the binary value at index i
GetView
std::string_view
i
int64_t
required
Index to retrieve
Returns binary value as a string_view
byte_width
int32_t
Returns the fixed byte width of each value

Nested Arrays

ListArray

Array class for variable-length list data.
class ListArray : public BaseListArray<ListType>
values
std::shared_ptr<Array>
Returns array object containing the list’s values
value_offset
offset_type
i
int64_t
required
Index
Returns the offset into values array for list at index i
value_length
offset_type
i
int64_t
required
Index
Returns the length of the list at index i. Requires IsValid(i)
value_slice
std::shared_ptr<Array>
i
int64_t
required
Index
Returns a slice of the values array for list at index i. Requires IsValid(i)
Flatten
Result<std::shared_ptr<Array>>
memory_pool
MemoryPool*
Memory pool to use
Returns an Array that is a concatenation of the lists in this array, taking into account offsets and skipping null elements
FromArrays
Result<std::shared_ptr<ListArray>>
offsets
const Array&
required
Array containing n+1 offsets (int32 type)
values
const Array&
required
Array containing list values
pool
MemoryPool*
Memory pool for allocations
Constructs a ListArray from arrays of offsets and child values

StructArray

Array class for struct data.
class StructArray : public Array
field
std::shared_ptr<Array>
pos
int
required
Field index
Returns the field at the given position with offset, length and null count adjusted
GetFieldByName
std::shared_ptr<Array>
name
const std::string&
required
Field name
Returns the field with the given name, or nullptr if not found
Flatten
Result<ArrayVector>
pool
MemoryPool*
Memory pool for allocations
Flattens this array as a vector of arrays, one for each field
GetFlattenedField
Result<std::shared_ptr<Array>>
index
int
required
Field index
pool
MemoryPool*
Memory pool for allocations
Gets one of the child arrays, combining its null bitmap with the parent struct array’s bitmap
Make
Result<std::shared_ptr<StructArray>>
children
const ArrayVector&
required
Child arrays
field_names
const std::vector<std::string>&
required
Field names
null_bitmap
std::shared_ptr<Buffer>
Validity bitmap
Returns a StructArray from child arrays and field names. Length and type are inferred

MapArray

Array class for map data (key-value pairs).
class MapArray : public ListArray
keys
std::shared_ptr<Array>
Returns array object containing all map keys
items
std::shared_ptr<Array>
Returns array object containing all mapped items
FromArrays
Result<std::shared_ptr<Array>>
offsets
const std::shared_ptr<Array>&
required
Array containing n+1 offsets (int32 type)
keys
const std::shared_ptr<Array>&
required
Array containing key values
items
const std::shared_ptr<Array>&
required
Array containing item values
pool
MemoryPool*
Memory pool for allocations
Constructs a MapArray from arrays of offsets, keys, and items

Build docs developers (and LLMs) love