sparrow 2.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Loading...
Searching...
No Matches
record_batch_example.cpp
Go to the documentation of this file.
1
4
5
6#include <cassert>
7
10
11std::vector<sparrow::array> make_array_list(const std::size_t data_size)
12{
13 auto iota = std::ranges::iota_view{std::size_t(0), std::size_t(data_size)};
15 iota
16 | std::views::transform(
17 [](auto i)
18 {
19 return static_cast<std::uint16_t>(i);
20 }
21 )
22 );
23 auto iota2 = std::ranges::iota_view{std::int32_t(4), 4 + std::int32_t(data_size)};
25 auto iota3 = std::ranges::iota_view{std::int32_t(2), 2 + std::int32_t(data_size)};
27
28 std::vector<sparrow::array> arr_list = {
29 sparrow::array{std::move(pr0)},
30 sparrow::array{std::move(pr1)},
31 sparrow::array{std::move(pr2)}
32 };
33 return arr_list;
34}
35
36int main()
37{
39 const std::vector<std::string> name_list = {"first", "second", "third"};
40 constexpr std::size_t data_size = 10;
41 const std::vector<sparrow::array> array_list = make_array_list(data_size);
42 const sparrow::record_batch record{name_list, array_list, "record batch name"};
43 assert(record.name() == "record batch name");
44 assert(record.nb_columns() == array_list.size());
45 assert(record.nb_rows() == data_size);
46 assert(record.contains_column(name_list[0]));
47 assert(record.get_column_name(0) == name_list[0]);
48 assert(record.get_column(0) == array_list[0]);
49 assert(std::ranges::equal(record.names(), name_list));
50 assert(std::ranges::equal(record.columns(), array_list));
52 return EXIT_SUCCESS;
53}
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)