sparrow ..
|
#include <record_batch.hpp>
Public Types | |
using | name_type = std::string |
using | size_type = std::size_t |
using | initializer_type = std::initializer_list<std::pair<name_type, array>> |
using | name_range = std::ranges::ref_view<const std::vector<name_type>> |
using | column_range = std::ranges::ref_view<const std::vector<array>> |
Public Member Functions | |
template<std::ranges::input_range NR, std::ranges::input_range CR, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>> requires ( std::convertible_to<std::ranges::range_value_t<NR>, std::string> and std::same_as<std::ranges::range_value_t<CR>, array> ) | |
constexpr | record_batch (NR &&names, CR &&columns, std::optional< std::string_view > name=std::nullopt, std::optional< METADATA_RANGE > metadata=std::nullopt) |
Constructs a record_batch from separate name and array ranges. | |
template<std::ranges::input_range CR, input_metadata_container METADATA_RANGE = std::vector<metadata_pair>> requires std::same_as<std::ranges::range_value_t<CR>, array> | |
record_batch (CR &&columns, std::optional< std::string_view > name=std::nullopt, std::optional< METADATA_RANGE > metadata=std::nullopt) | |
Constructs a record_batch from arrays with existing names. | |
SPARROW_API | record_batch (initializer_type init) |
Constructs a record_batch from initializer list of name-array pairs. | |
SPARROW_API | record_batch (ArrowArray &&array, ArrowSchema &&schema) |
Constructs a record_batch from the given Arrow C structures, whose ownership is transferred to the record_batch. | |
SPARROW_API | record_batch (ArrowArray &&array, ArrowSchema *schema) |
Constructs an record_batch from the given Arrow C structures. | |
SPARROW_API | record_batch (ArrowArray &&array, const ArrowSchema *schema) |
Constructs an record_batch from the given Arrow C structures. | |
SPARROW_API | record_batch (ArrowArray *array, ArrowSchema *schema) |
Constructs an record_batch from the given Arrow C structures. | |
SPARROW_API | record_batch (const ArrowArray *array, const ArrowSchema *schema) |
Constructs an record_batch from the given Arrow C structures. | |
SPARROW_API | record_batch (struct_array &&ar) |
Constructs a record_batch from a struct_array. | |
SPARROW_API | record_batch (const record_batch &other) |
Copy constructor. | |
SPARROW_API record_batch & | operator= (const record_batch &other) |
Copy assignment operator. | |
record_batch (record_batch &&)=default | |
record_batch & | operator= (record_batch &&)=default |
SPARROW_API size_type | nb_columns () const |
Gets the number of columns in the record batch. | |
SPARROW_API size_type | nb_rows () const |
Gets the number of rows in the record batch. | |
SPARROW_API bool | contains_column (const name_type &key) const |
Checks if the record batch contains a column with the specified name. | |
SPARROW_API const name_type & | get_column_name (size_type index) const |
Gets the name of the column at the specified index. | |
SPARROW_API const array & | get_column (const name_type &key) const |
Gets the column with the specified name. | |
SPARROW_API array & | get_column (const name_type &key) |
Gets the column with the specified name. | |
SPARROW_API const array & | get_column (size_type index) const |
Gets the column at the specified index. | |
SPARROW_API array & | get_column (size_type index) |
Gets the column at the specified index. | |
SPARROW_API const std::optional< name_type > & | name () const |
Gets the name of the record batch. | |
SPARROW_API name_range | names () const |
Gets a range view of the column names. | |
SPARROW_API column_range | columns () const |
Gets a range view of the columns. | |
SPARROW_API struct_array | extract_struct_array () |
Moves the internal columns into a struct_array and empties the record batch. | |
SPARROW_API void | add_column (name_type name, array column) |
Adds a new column to the record batch with the specified name. | |
SPARROW_API void | add_column (array column) |
Adds a new column using the array's internal name. | |
Definition at line 69 of file record_batch.hpp.
using sparrow::record_batch::column_range = std::ranges::ref_view<const std::vector<array>> |
Definition at line 78 of file record_batch.hpp.
using sparrow::record_batch::initializer_type = std::initializer_list<std::pair<name_type, array>> |
Definition at line 75 of file record_batch.hpp.
using sparrow::record_batch::name_range = std::ranges::ref_view<const std::vector<name_type>> |
Definition at line 77 of file record_batch.hpp.
using sparrow::record_batch::name_type = std::string |
Definition at line 73 of file record_batch.hpp.
using sparrow::record_batch::size_type = std::size_t |
Definition at line 74 of file record_batch.hpp.
|
constexpr |
Constructs a record_batch from separate name and array ranges.
Each array is mapped to the name at the corresponding position in the names range. The ranges must have the same size, and all arrays must have equal length.
NR | Input range type for names (convertible to std::string) |
CR | Input range type for arrays |
METADATA_RANGE | Type of metadata container (default: std::vector<metadata_pair>) |
names | Input range of column names (must be unique) |
columns | Input range of arrays (must have equal lengths) |
name | Optional name for the record batch itself |
metadata | Optional metadata for the record batch |
std::invalid_argument | if preconditions are violated |
Definition at line 531 of file record_batch.hpp.
sparrow::record_batch::record_batch | ( | CR && | columns, |
std::optional< std::string_view > | name = std::nullopt, | ||
std::optional< METADATA_RANGE > | metadata = std::nullopt ) |
Constructs a record_batch from arrays with existing names.
Each array must have a non-empty name. The array names are extracted and used as column names in the record batch.
CR | Input range type for arrays |
METADATA_RANGE | Type of metadata container (default: std::vector<metadata_pair>) |
columns | Input range of named arrays |
name | Optional name for the record batch itself |
metadata | Optional metadata for the record batch |
std::invalid_argument | if any array lacks a name or names are not unique |
std::invalid_argument | if arrays have different lengths |
Definition at line 562 of file record_batch.hpp.
SPARROW_API sparrow::record_batch::record_batch | ( | initializer_type | init | ) |
Constructs a record_batch from initializer list of name-array pairs.
init | Initializer list of std::pair<name_type, array> |
std::invalid_argument | if names are not unique or arrays have different lengths |
SPARROW_API sparrow::record_batch::record_batch | ( | ArrowArray && | array, |
ArrowSchema && | schema ) |
Constructs a record_batch from the given Arrow C structures, whose ownership is transferred to the record_batch.
The user should not use array
nor schema
after calling this constructor.
array | The ArrowArray structure to transfer into the record_batch. |
schema | The ArrowSchema structure to transfer into the record_batch. |
SPARROW_API sparrow::record_batch::record_batch | ( | ArrowArray && | array, |
ArrowSchema * | schema ) |
Constructs an record_batch from the given Arrow C structures.
The record_batch takes the ownership of the ArrowArray only. The user should not use array
after calling this constructor. schema
can still be used normally.
array | The ArrowArray structure to transfer into the record_batch. |
schema | The ArrowSchema to reference in the record_batch. |
SPARROW_API sparrow::record_batch::record_batch | ( | ArrowArray && | array, |
const ArrowSchema * | schema ) |
Constructs an record_batch from the given Arrow C structures.
The record_batch takes the ownership of the ArrowArray only. The user should not use array
after calling this constructor. schema
can still be used normally.
array | The ArrowArray structure to transfer into the record_batch. |
schema | The const ArrowSchema to reference in the record_batch. |
SPARROW_API sparrow::record_batch::record_batch | ( | ArrowArray * | array, |
ArrowSchema * | schema ) |
Constructs an record_batch from the given Arrow C structures.
Both structures are referenced from the record_batch and can still be used normally after calling this constructor.
array | The ArrowArray structure to reference in the record_batch. |
schema | The ArrowSchema to reference in the record_batch. |
SPARROW_API sparrow::record_batch::record_batch | ( | const ArrowArray * | array, |
const ArrowSchema * | schema ) |
Constructs an record_batch from the given Arrow C structures.
Both structures are referenced from the record_batch and can still be used normally after calling this constructor.
array | The const ArrowArray structure to reference in the record_batch. |
schema | The const ArrowSchema to reference in the record_batch. |
SPARROW_API sparrow::record_batch::record_batch | ( | struct_array && | ar | ) |
Constructs a record_batch from a struct_array.
The struct array's fields become the columns of the record batch, with field names becoming column names.
ar | Struct array to convert (must own its internal Arrow structures) |
SPARROW_API sparrow::record_batch::record_batch | ( | const record_batch & | other | ) |
Copy constructor.
other | The record_batch to copy from |
|
default |
SPARROW_API void sparrow::record_batch::add_column | ( | array | column | ) |
Adds a new column using the array's internal name.
column | The array to add (must have a non-empty name) |
std::invalid_argument | if column lacks name, name exists, or size is incompatible |
SPARROW_API void sparrow::record_batch::add_column | ( | name_type | name, |
array | column ) |
Adds a new column to the record batch with the specified name.
name | The name for the new column (must be unique) |
column | The array to add as a column |
std::invalid_argument | if name already exists or column size is incompatible |
SPARROW_API column_range sparrow::record_batch::columns | ( | ) | const |
Gets a range view of the columns.
SPARROW_API bool sparrow::record_batch::contains_column | ( | const name_type & | key | ) | const |
Checks if the record batch contains a column with the specified name.
key | The name of the column to search for |
SPARROW_API struct_array sparrow::record_batch::extract_struct_array | ( | ) |
Moves the internal columns into a struct_array and empties the record batch.
After this operation, the record batch becomes empty and should not be used until new data is added.
SPARROW_API array & sparrow::record_batch::get_column | ( | const name_type & | key | ) |
Gets the column with the specified name.
key | The name of the column to retrieve |
std::out_of_range | if column with key does not exist |
SPARROW_API const array & sparrow::record_batch::get_column | ( | const name_type & | key | ) | const |
Gets the column with the specified name.
key | The name of the column to retrieve |
std::out_of_range | if column with key does not exist |
SPARROW_API array & sparrow::record_batch::get_column | ( | size_type | index | ) |
Gets the column at the specified index.
index | The index of the column (0-based) |
std::out_of_range | if index >= nb_columns() |
SPARROW_API const array & sparrow::record_batch::get_column | ( | size_type | index | ) | const |
Gets the column at the specified index.
index | The index of the column (0-based) |
std::out_of_range | if index >= nb_columns() |
SPARROW_API const name_type & sparrow::record_batch::get_column_name | ( | size_type | index | ) | const |
Gets the name of the column at the specified index.
index | The index of the column (0-based) |
std::out_of_range | if index >= nb_columns() |
SPARROW_API const std::optional< name_type > & sparrow::record_batch::name | ( | ) | const |
Gets the name of the record batch.
SPARROW_API name_range sparrow::record_batch::names | ( | ) | const |
Gets a range view of the column names.
SPARROW_API size_type sparrow::record_batch::nb_columns | ( | ) | const |
Gets the number of columns in the record batch.
SPARROW_API size_type sparrow::record_batch::nb_rows | ( | ) | const |
Gets the number of rows in the record batch.
SPARROW_API record_batch & sparrow::record_batch::operator= | ( | const record_batch & | other | ) |
Copy assignment operator.
other | The record_batch to copy from |
|
default |