sparrow 2.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Loading...
Searching...
No Matches
record_batch_example.cpp

Example of usage of the record_batch class.

Example of usage of the record_batch class.

#include <cassert>
std::vector<sparrow::array> make_array_list(const std::size_t data_size)
{
auto iota = std::ranges::iota_view{std::size_t(0), std::size_t(data_size)};
iota
| std::views::transform(
[](auto i)
{
return static_cast<std::uint16_t>(i);
}
)
);
auto iota2 = std::ranges::iota_view{std::int32_t(4), 4 + std::int32_t(data_size)};
auto iota3 = std::ranges::iota_view{std::int32_t(2), 2 + std::int32_t(data_size)};
std::vector<sparrow::array> arr_list = {
sparrow::array{std::move(pr0)},
sparrow::array{std::move(pr1)},
sparrow::array{std::move(pr2)}
};
return arr_list;
}
int main()
{
const std::vector<std::string> name_list = {"first", "second", "third"};
constexpr std::size_t data_size = 10;
const std::vector<sparrow::array> array_list = make_array_list(data_size);
const sparrow::record_batch record{name_list, array_list, "record batch name"};
assert(record.name() == "record batch name");
assert(record.nb_columns() == array_list.size());
assert(record.nb_rows() == data_size);
assert(record.contains_column(name_list[0]));
assert(record.get_column_name(0) == name_list[0]);
assert(record.get_column(0) == array_list[0]);
assert(std::ranges::equal(record.names(), name_list));
assert(std::ranges::equal(record.columns(), array_list));
return EXIT_SUCCESS;
}
int main()
Dynamically typed array encapsulating an Arrow layout.
Definition array_api.hpp:50
SPARROW_API const std::optional< name_type > & name() const
Gets the name of the record batch.
SPARROW_API const array & get_column(const name_type &key) const
Gets the column with the specified name.
SPARROW_API name_range names() const
Gets a range view of the column names.
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 size_type nb_rows() const
Gets the number of rows in the record batch.
SPARROW_API size_type nb_columns() const
Gets the number of columns in the record batch.
auto columns() const
Gets a range view of the columns.
primitive_array_impl< T, Ext, T2 > primitive_array
Array of values of whose type has fixed binary size.
std::vector< sparrow::array > make_array_list(const std::size_t data_size)