sparrow
2.4.0
C++20 idiomatic APIs for the Apache Arrow Columnar Format
Toggle main menu visibility
Loading...
Searching...
No Matches
record_batch_example.cpp
Go to the documentation of this file.
1
4
5
6
#include <cassert>
7
8
#include "
sparrow/primitive_array.hpp
"
9
#include "
sparrow/record_batch.hpp
"
10
11
std::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)};
14
sparrow::primitive_array<std::uint16_t>
pr0(
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)};
24
sparrow::primitive_array<std::int32_t>
pr1(iota2);
25
auto
iota3 = std::ranges::iota_view{std::int32_t(2), 2 + std::int32_t(data_size)};
26
sparrow::primitive_array<std::int32_t>
pr2(iota3);
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
36
int
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
}
main
int main()
Definition
builder_example.cpp:202
sparrow::array
Dynamically typed array encapsulating an Arrow layout.
Definition
array_api.hpp:50
sparrow::record_batch
Definition
record_batch.hpp:79
sparrow::record_batch::name
SPARROW_API const std::optional< name_type > & name() const
Gets the name of the record batch.
sparrow::record_batch::get_column
SPARROW_API const array & get_column(const name_type &key) const
Gets the column with the specified name.
sparrow::record_batch::names
SPARROW_API name_range names() const
Gets a range view of the column names.
sparrow::record_batch::contains_column
SPARROW_API bool contains_column(const name_type &key) const
Checks if the record batch contains a column with the specified name.
sparrow::record_batch::get_column_name
SPARROW_API const name_type & get_column_name(size_type index) const
Gets the name of the column at the specified index.
sparrow::record_batch::nb_rows
SPARROW_API size_type nb_rows() const
Gets the number of rows in the record batch.
sparrow::record_batch::nb_columns
SPARROW_API size_type nb_columns() const
Gets the number of columns in the record batch.
sparrow::record_batch::columns
auto columns() const
Gets a range view of the columns.
Definition
record_batch.hpp:407
sparrow::primitive_array
primitive_array_impl< T, Ext, T2 > primitive_array
Array of values of whose type has fixed binary size.
Definition
primitive_array.hpp:61
primitive_array.hpp
record_batch.hpp
make_array_list
std::vector< sparrow::array > make_array_list(const std::size_t data_size)
Definition
record_batch_example.cpp:11
examples
record_batch_example.cpp
Generated by
1.17.0