Two-dimensional Datasets — Apache Arrow v20.0.0 (original) (raw)

Record Batches#

class RecordBatch#

Collection of equal-length arrays matching a particular Schema.

A record batch is table-like data structure that is semantically a sequence of fields, each a contiguous Arrow array

Public Functions

Result<std::shared_ptr<StructArray>> ToStructArray() const#

Convert record batch to struct array.

Create a struct array whose child arrays are the record batch’s columns. Note that the record batch’s top-level field metadata cannot be reflected in the resulting struct array.

Result<std::shared_ptr<Tensor>> ToTensor(bool null_to_nan = false, bool row_major = true, MemoryPool *pool = default_memory_pool()) const#

Convert record batch with one data type to Tensor.

Create a Tensor object with shape (number of rows, number of columns) and strides (type size in bytes, type size in bytes * number of rows). Generated Tensor will have column-major layout.

Parameters:

Returns:

the resulting Tensor

bool Equals(const RecordBatch &other, bool check_metadata = false, const EqualOptions &opts = EqualOptions::Defaults()) const#

Determine if two record batches are exactly equal.

Parameters:

Returns:

true if batches are equal

bool ApproxEquals(const RecordBatch &other, const EqualOptions &opts = EqualOptions::Defaults()) const#

Determine if two record batches are approximately equal.

Parameters:

Returns:

true if batches are approximately equal

inline const std::shared_ptr<Schema> &schema() const#

Returns:

the record batch’s schema

Result<std::shared_ptr<RecordBatch>> ReplaceSchema(std::shared_ptr<Schema> schema) const#

Replace the schema with another schema with the same types, but potentially different field names and/or metadata.

virtual const std::vector<std::shared_ptr<Array>> &columns() const = 0#

Retrieve all columns at once.

virtual std::shared_ptr<Array> column(int i) const = 0#

Retrieve an array from the record batch.

Parameters:

i[in] field index, does not boundscheck

Returns:

an Array object

std::shared_ptr<Array> GetColumnByName(const std::string &name) const#

Retrieve an array from the record batch.

Parameters:

name[in] field name

Returns:

an Array or null if no field was found

virtual std::shared_ptr<ArrayData> column_data(int i) const = 0#

Retrieve an array’s internal data from the record batch.

Parameters:

i[in] field index, does not boundscheck

Returns:

an internal ArrayData object

virtual const ArrayDataVector &column_data() const = 0#

Retrieve all arrays’ internal data from the record batch.

virtual Result<std::shared_ptr<RecordBatch>> AddColumn(int i, const std::shared_ptr<Field> &field, const std::shared_ptr<Array> &column) const = 0#

Add column to the record batch, producing a new RecordBatch.

Parameters:

virtual Result<std::shared_ptr<RecordBatch>> AddColumn(int i, std::string field_name, const std::shared_ptr<Array> &column) const#

Add new nullable column to the record batch, producing a new RecordBatch.

For non-nullable columns, use the Field-based version of this method.

Parameters:

virtual Result<std::shared_ptr<RecordBatch>> SetColumn(int i, const std::shared_ptr<Field> &field, const std::shared_ptr<Array> &column) const = 0#

Replace a column in the record batch, producing a new RecordBatch.

Parameters:

virtual Result<std::shared_ptr<RecordBatch>> RemoveColumn(int i) const = 0#

Remove column from the record batch, producing a new RecordBatch.

Parameters:

i[in] field index, does boundscheck

const std::string &column_name(int i) const#

Name in i-th column.

int num_columns() const#

Returns:

the number of columns in the table

inline int64_t num_rows() const#

Returns:

the number of rows (the corresponding length of each column)

Result<std::shared_ptr<RecordBatch>> CopyTo(const std::shared_ptr<MemoryManager> &to) const#

Copy the entire RecordBatch to destination MemoryManager.

This uses Array::CopyTo on each column of the record batch to create a new record batch where all underlying buffers for the columns have been copied to the destination MemoryManager. This uses MemoryManager::CopyBuffer under the hood.

Result<std::shared_ptr<RecordBatch>> ViewOrCopyTo(const std::shared_ptr<MemoryManager> &to) const#

View or Copy the entire RecordBatch to destination MemoryManager.

This uses Array::ViewOrCopyTo on each column of the record batch to create a new record batch where all underlying buffers for the columns have been zero-copy viewed on the destination MemoryManager, falling back to performing a copy if it can’t be viewed as a zero-copy buffer. This uses Buffer::ViewOrCopy under the hood.

virtual std::shared_ptr<RecordBatch> Slice(int64_t offset) const#

Slice each of the arrays in the record batch.

Parameters:

offset[in] the starting offset to slice, through end of batch

Returns:

new record batch

virtual std::shared_ptr<RecordBatch> Slice(int64_t offset, int64_t length) const = 0#

Slice each of the arrays in the record batch.

Parameters:

Returns:

new record batch

std::string ToString() const#

Returns:

PrettyPrint representation suitable for debugging

std::vectorstd::string\ ColumnNames() const#

Return names of all columns.

Result<std::shared_ptr<RecordBatch>> RenameColumns(const std::vectorstd::string\ &names) const#

Rename columns with provided names.

Result<std::shared_ptr<RecordBatch>> SelectColumns(const std::vector<int> &indices) const#

Return new record batch with specified columns.

virtual Status Validate() const#

Perform cheap validation checks to determine obvious inconsistencies within the record batch’s schema and internal data.

This is O(k) where k is the total number of fields and array descendents.

Returns:

Status

virtual Status ValidateFull() const#

Perform extensive validation checks to determine inconsistencies within the record batch’s schema and internal data.

This is potentially O(k*n) where n is the number of rows.

Returns:

Status

virtual const std::shared_ptr<Device::SyncEvent> &GetSyncEvent() const = 0#

EXPERIMENTAL: Return a top-level sync event object for this record batch.

If all of the data for this record batch is in CPU memory, then this will return null. If the data for this batch is on a device, then if synchronization is needed before accessing the data the returned sync event will allow for it.

Returns:

null or a Device::SyncEvent

Result<std::shared_ptr<Array>> MakeStatisticsArray(MemoryPool *pool = default_memory_pool()) const#

Create a statistics array of this record batch.

The created array follows the C data interface statistics specification. See https://arrow.apache.org/docs/format/StatisticsSchema.html for details.

Parameters:

pool[in] the memory pool to allocate memory from

Returns:

the statistics array of this record batch

Public Static Functions

static std::shared_ptr<RecordBatch> Make(std::shared_ptr<Schema> schema, int64_t num_rows, std::vector<std::shared_ptr<Array>> columns, std::shared_ptr<Device::SyncEvent> sync_event = NULLPTR)#

Parameters:

static std::shared_ptr<RecordBatch> Make(std::shared_ptr<Schema> schema, int64_t num_rows, std::vector<std::shared_ptr<ArrayData>> columns, DeviceAllocationType device_type = DeviceAllocationType::kCPU, std::shared_ptr<Device::SyncEvent> sync_event = NULLPTR)#

Construct record batch from vector of internal data structures.

This class is intended for internal use, or advanced users.

Since

0.5.0

Parameters:

static Result<std::shared_ptr<RecordBatch>> MakeEmpty(std::shared_ptr<Schema> schema, MemoryPool *pool = default_memory_pool())#

Create an empty RecordBatch of a given schema.

The output RecordBatch will be created with DataTypes from the given schema.

Parameters:

Returns:

the resulting RecordBatch

static Result<std::shared_ptr<RecordBatch>> FromStructArray(const std::shared_ptr<Array> &array, MemoryPool *pool = default_memory_pool())#

Construct record batch from struct array.

This constructs a record batch using the child arrays of the given array, which must be a struct array.

This operation will usually be zero-copy. However, if the struct array has an offset or a validity bitmap then these will need to be pushed into the child arrays. Pushing the offset is zero-copy but pushing the validity bitmap is not.

Parameters:

class RecordBatchReader#

Abstract interface for reading stream of record batches.

Subclassed by arrow::TableBatchReader, arrow::csv::StreamingReader, arrow:🪶:sql::example::SqliteStatementBatchReader, arrow:🪶:sql::example::SqliteTablesWithSchemaBatchReader, arrow::ipc::RecordBatchStreamReader, arrow::json::StreamingReader

Public Functions

virtual std::shared_ptr<Schema> schema() const = 0#

Returns:

the shared schema of the record batches in the stream

virtual Status ReadNext(std::shared_ptr<RecordBatch> *batch) = 0#

Read the next record batch in the stream.

Return null for batch when reaching end of stream

Example:

while (true) { std::shared_ptr batch; ARROW_RETURN_NOT_OK(reader->ReadNext(&batch)); if (!batch) { break; } // handling the batch, the batch->num_rows() // might be 0. }

Parameters:

batch[out] the next loaded batch, null at end of stream. Returning an empty batch doesn’t mean the end of stream because it is valid data.

Returns:

Status

inline Result<std::shared_ptr<RecordBatch>> Next()#

Iterator interface.

inline virtual Status Close()#

finalize reader

inline virtual DeviceAllocationType device_type() const#

EXPERIMENTAL: Get the device type for record batches this reader produces.

default implementation is to return DeviceAllocationType::kCPU

inline RecordBatchReaderIterator begin()#

Return an iterator to the first record batch in the stream.

inline RecordBatchReaderIterator end()#

Return an iterator to the end of the stream.

Result<RecordBatchVector> ToRecordBatches()#

Consume entire stream as a vector of record batches.

Result<std::shared_ptr<Table>> ToTable()#

Read all batches and concatenate as arrow::Table.

Public Static Functions

static Result<std::shared_ptr<RecordBatchReader>> Make(RecordBatchVector batches, std::shared_ptr<Schema> schema = NULLPTR, DeviceAllocationType device_type = DeviceAllocationType::kCPU)#

Create a RecordBatchReader from a vector of RecordBatch.

Parameters:

static Result<std::shared_ptr<RecordBatchReader>> MakeFromIterator(Iterator<std::shared_ptr<RecordBatch>> batches, std::shared_ptr<Schema> schema, DeviceAllocationType device_type = DeviceAllocationType::kCPU)#

Create a RecordBatchReader from an Iterator of RecordBatch.

Parameters:

class RecordBatchReaderIterator#

class TableBatchReader : public arrow::RecordBatchReader#

Compute a stream of record batches from a (possibly chunked) Table.

The conversion is zero-copy: each record batch is a view over a slice of the table’s columns.

The table is expected to be valid prior to using it with the batch reader.

Public Functions

explicit TableBatchReader(const Table &table)#

Construct a TableBatchReader for the given table.

virtual std::shared_ptr<Schema> schema() const override#

Returns:

the shared schema of the record batches in the stream

virtual Status ReadNext(std::shared_ptr<RecordBatch> *out) override#

Read the next record batch in the stream.

Return null for batch when reaching end of stream

Example:

while (true) { std::shared_ptr batch; ARROW_RETURN_NOT_OK(reader->ReadNext(&batch)); if (!batch) { break; } // handling the batch, the batch->num_rows() // might be 0. }

Parameters:

batch[out] the next loaded batch, null at end of stream. Returning an empty batch doesn’t mean the end of stream because it is valid data.

Returns:

Status

void set_chunksize(int64_t chunksize)#

Set the desired maximum number of rows for record batches.

The actual number of rows in each record batch may be smaller, depending on actual chunking characteristics of each table column.

Tables#

class Table#

Logical table as sequence of chunked arrays.

Public Functions

inline const std::shared_ptr<Schema> &schema() const#

Return the table schema.

virtual std::shared_ptr<ChunkedArray> column(int i) const = 0#

Return a column by index.

virtual const std::vector<std::shared_ptr<ChunkedArray>> &columns() const = 0#

Return vector of all columns for table.

inline std::shared_ptr<Field> field(int i) const#

Return a column’s field by index.

std::vector<std::shared_ptr<Field>> fields() const#

Return vector of all fields for table.

virtual std::shared_ptr<Table> Slice(int64_t offset, int64_t length) const = 0#

Construct a zero-copy slice of the table with the indicated offset and length.

Parameters:

Returns:

a new object wrapped in std::shared_ptr

inline std::shared_ptr<Table> Slice(int64_t offset) const#

Slice from first row at offset until end of the table.

inline std::shared_ptr<ChunkedArray> GetColumnByName(const std::string &name) const#

Return a column by name.

Parameters:

name[in] field name

Returns:

an Array or null if no field was found

virtual Result<std::shared_ptr<Table>> RemoveColumn(int i) const = 0#

Remove column from the table, producing a new Table.

virtual Result<std::shared_ptr<Table>> AddColumn(int i, std::shared_ptr<Field> field_arg, std::shared_ptr<ChunkedArray> column) const = 0#

Add column to the table, producing a new Table.

virtual Result<std::shared_ptr<Table>> SetColumn(int i, std::shared_ptr<Field> field_arg, std::shared_ptr<ChunkedArray> column) const = 0#

Replace a column in the table, producing a new Table.

std::vectorstd::string\ ColumnNames() const#

Return names of all columns.

Result<std::shared_ptr<Table>> RenameColumns(const std::vectorstd::string\ &names) const#

Rename columns with provided names.

Result<std::shared_ptr<Table>> SelectColumns(const std::vector<int> &indices) const#

Return new table with specified columns.

virtual std::shared_ptr<Table> ReplaceSchemaMetadata(const std::shared_ptr<const KeyValueMetadata> &metadata) const = 0#

Replace schema key-value metadata with new metadata.

Since

0.5.0

Parameters:

metadata[in] new KeyValueMetadata

Returns:

new Table

virtual Result<std::shared_ptr<Table>> Flatten(MemoryPool *pool = default_memory_pool()) const = 0#

Flatten the table, producing a new Table.

Any column with a struct type will be flattened into multiple columns

Parameters:

pool[in] The pool for buffer allocations, if any

std::string ToString() const#

Returns:

PrettyPrint representation suitable for debugging

virtual Status Validate() const = 0#

Perform cheap validation checks to determine obvious inconsistencies within the table’s schema and internal data.

This is O(k*m) where k is the total number of field descendents, and m is the number of chunks.

Returns:

Status

virtual Status ValidateFull() const = 0#

Perform extensive validation checks to determine inconsistencies within the table’s schema and internal data.

This is O(k*n) where k is the total number of field descendents, and n is the number of rows.

Returns:

Status

inline int num_columns() const#

Return the number of columns in the table.

inline int64_t num_rows() const#

Return the number of rows (equal to each column’s logical length)

bool Equals(const Table &other, bool check_metadata = false) const#

Determine if tables are equal.

Two tables can be equal only if they have equal schemas. However, they may be equal even if they have different chunkings.

Result<std::shared_ptr<Table>> CombineChunks(MemoryPool *pool = default_memory_pool()) const#

Make a new table by combining the chunks this table has.

All the underlying chunks in the ChunkedArray of each column are concatenated into zero or one chunk.

Parameters:

pool[in] The pool for buffer allocations

Result<std::shared_ptr<RecordBatch>> CombineChunksToBatch(MemoryPool *pool = default_memory_pool()) const#

Make a new record batch by combining the chunks this table has.

All the underlying chunks in the ChunkedArray of each column are concatenated into a single chunk.

Parameters:

pool[in] The pool for buffer allocations

Public Static Functions

static std::shared_ptr<Table> Make(std::shared_ptr<Schema> schema, std::vector<std::shared_ptr<ChunkedArray>> columns, int64_t num_rows = -1)#

Construct a Table from schema and columns.

If columns is zero-length, the table’s number of rows is zero

Parameters:

static std::shared_ptr<Table> Make(std::shared_ptr<Schema> schema, const std::vector<std::shared_ptr<Array>> &arrays, int64_t num_rows = -1)#

Construct a Table from schema and arrays.

Parameters:

static Result<std::shared_ptr<Table>> MakeEmpty(std::shared_ptr<Schema> schema, MemoryPool *pool = default_memory_pool())#

Create an empty Table of a given schema.

The output Table will be created with a single empty chunk per column.

Parameters:

Returns:

the resulting Table

static Result<std::shared_ptr<Table>> FromRecordBatchReader(RecordBatchReader *reader)#

Construct a Table from a RecordBatchReader.

Parameters:

reader[in] the arrow::RecordBatchReader that produces batches

static Result<std::shared_ptr<Table>> FromRecordBatches(const std::vector<std::shared_ptr<RecordBatch>> &batches)#

Construct a Table from RecordBatches, using schema supplied by the first RecordBatch.

Parameters:

batches[in] a std::vector of record batches

static Result<std::shared_ptr<Table>> FromRecordBatches(std::shared_ptr<Schema> schema, const std::vector<std::shared_ptr<RecordBatch>> &batches)#

Construct a Table from RecordBatches, using supplied schema.

There may be zero record batches

Parameters:

static Result<std::shared_ptr<Table>> FromChunkedStructArray(const std::shared_ptr<ChunkedArray> &array)#

Construct a Table from a chunked StructArray.

One column will be produced for each field of the StructArray.

Parameters:

array[in] a chunked StructArray

Result<std::shared_ptr<Table>> arrow::ConcatenateTables(const std::vector<std::shared_ptr<Table>> &tables, ConcatenateTablesOptions options = ConcatenateTablesOptions::Defaults(), MemoryPool *memory_pool = default_memory_pool())#

Construct a new table from multiple input tables.

The new table is assembled from existing column chunks without copying, if schemas are identical. If schemas do not match exactly and unify_schemas is enabled in options (off by default), an attempt is made to unify them, and then column chunks are converted to their respective unified datatype, which will probably incur a copy. :func:arrow::PromoteTableToSchema is used to unify schemas.

Tables are concatenated in order they are provided in and the order of rows within tables will be preserved.

Parameters:

Returns:

new Table

Warning

doxygenfunction: Unable to resolve function “arrow::PromoteTableToSchema” with arguments None in doxygen xml output for project “arrow_cpp” from directory: /build/cpp/apidoc/xml. Potential matches:

> PromoteTableToSchema(const std::shared_ptr
&table, const std::shared_ptr &schema, MemoryPool *pool = default_memory_pool())
  • Result<std::shared_ptr> PromoteTableToSchema(const std::shared_ptr
    &table, const std::shared_ptr &schema, const compute::CastOptions &options, MemoryPool *pool = default_memory_pool())