12#include <catch_amalgamated.hpp>
16#include <arrow/table.h>
17#include <arrow/ipc/writer.h>
18#include <arrow/io/memory.h>
19#include <arrow/ipc/writer.h>
20#include <arrow/ipc/reader.h>
44 auto rowWriter = builder.
persist<uint64_t, uint64_t>({
"x",
"y"});
54 REQUIRE(table->num_columns() == 2);
55 REQUIRE(table->num_rows() == 8);
56 REQUIRE(table->schema()->field(0)->name() ==
"x");
57 REQUIRE(table->schema()->field(1)->name() ==
"y");
58 REQUIRE(table->schema()->field(0)->type()->id() == arrow::uint64()->id());
59 REQUIRE(table->schema()->field(1)->type()->id() == arrow::uint64()->id());
64 REQUIRE(readBackTable->num_columns() == 2);
65 REQUIRE(readBackTable->num_rows() == 8);
66 REQUIRE(readBackTable->schema()->field(0)->name() ==
"x");
67 REQUIRE(readBackTable->schema()->field(1)->name() ==
"y");
68 REQUIRE(readBackTable->schema()->field(0)->type()->id() == arrow::uint64()->id());
69 REQUIRE(readBackTable->schema()->field(1)->type()->id() == arrow::uint64()->id());
73 for (
auto const&
row : readBack) {
74 REQUIRE(
row.x() ==
i * 10);
75 REQUIRE(
row.y() ==
i);
85 const int numElem = 4;
86 auto rowWriter = builder.
persist<
int[numElem]>({
"pos"});
87 int a[numElem] = {1, 10, 300, 350};
88 int b[numElem] = {0, 20, 30, 40};
91 using v3 = std::array<int, numElem>;
92 rowWriter(0,
v3{0, 11, 123, 256}.data());
95 REQUIRE(table->num_columns() == 1);
96 REQUIRE(table->num_rows() == 3);
97 REQUIRE(table->schema()->field(0)->name() ==
"pos");
98 REQUIRE(table->schema()->field(0)->type()->id() == arrow::fixed_size_list(arrow::int32(), numElem)->id());
100 auto chunkToUse = table->column(0)->chunk(0);
101 chunkToUse = std::static_pointer_cast<arrow::FixedSizeListArray>(chunkToUse)->values();
102 auto data = chunkToUse->data();
104 REQUIRE(
data->GetValues<
int>(1)[0] == 1);
105 REQUIRE(
data->GetValues<
int>(1)[1] == 10);
106 REQUIRE(
data->GetValues<
int>(1)[2] == 300);
107 REQUIRE(
data->GetValues<
int>(1)[3] == 350);
108 REQUIRE(
data->GetValues<
int>(1)[4] == 0);
109 REQUIRE(
data->GetValues<
int>(1)[5] == 20);
110 REQUIRE(
data->GetValues<
int>(1)[6] == 30);
111 REQUIRE(
data->GetValues<
int>(1)[7] == 40);
116 REQUIRE(
row.pos()[0] == 1);
117 REQUIRE(
row.pos()[1] == 10);
118 REQUIRE(
row.pos()[2] == 300);
119 REQUIRE(
row.pos()[3] == 350);
122 REQUIRE(
row.pos()[0] == 0);
123 REQUIRE(
row.pos()[1] == 20);
124 REQUIRE(
row.pos()[2] == 30);
125 REQUIRE(
row.pos()[3] == 40);
128 REQUIRE(
row.pos()[0] == 0);
129 REQUIRE(
row.pos()[1] == 11);
130 REQUIRE(
row.pos()[2] == 123);
131 REQUIRE(
row.pos()[3] == 256);
142 auto rowWriter = builder.
persist<
Foo>({
"x",
"y"});
143 rowWriter(0,
Foo{0, 0});
144 rowWriter(0,
Foo{10, 1});
145 rowWriter(0,
Foo{20, 2});
146 rowWriter(0,
Foo{30, 3});
147 rowWriter(0,
Foo{40, 4});
148 rowWriter(0,
Foo{50, 5});
149 rowWriter(0,
Foo{60, 6});
150 rowWriter(0,
Foo{70, 7});
152 REQUIRE(table->num_columns() == 2);
153 REQUIRE(table->num_rows() == 8);
154 REQUIRE(table->schema()->field(0)->name() ==
"x");
155 REQUIRE(table->schema()->field(1)->name() ==
"y");
156 REQUIRE(table->schema()->field(0)->type()->id() == arrow::uint64()->id());
157 REQUIRE(table->schema()->field(1)->type()->id() == arrow::uint64()->id());
162 for (
auto&
row : readBack) {
163 REQUIRE(
row.x() ==
i * 10);
164 REQUIRE(
row.y() ==
i);
173 auto rowWriter = builder.
persist<
int, float, std::string,
bool>({
"x",
"y",
"s",
"b"});
175 rowWriter(0, 0, 0.,
"foo",
true);
176 rowWriter(0, 1, 1.,
"bar",
false);
177 rowWriter(0, 2, 2.,
"fbr",
false);
178 rowWriter(0, 3, 3.,
"bar",
false);
179 rowWriter(0, 4, 4.,
"abr",
true);
180 rowWriter(0, 5, 5.,
"aaa",
false);
181 rowWriter(0, 6, 6.,
"bbb",
true);
182 rowWriter(0, 7, 7.,
"ccc",
false);
184 REQUIRE(table->num_columns() == 4);
185 REQUIRE(table->num_rows() == 8);
186 REQUIRE(table->schema()->field(0)->name() ==
"x");
187 REQUIRE(table->schema()->field(1)->name() ==
"y");
188 REQUIRE(table->schema()->field(2)->name() ==
"s");
189 REQUIRE(table->schema()->field(3)->name() ==
"b");
190 REQUIRE(table->schema()->field(0)->type()->id() == arrow::int32()->id());
191 REQUIRE(table->schema()->field(1)->type()->id() == arrow::float32()->id());
192 REQUIRE(table->schema()->field(2)->type()->id() == arrow::utf8()->id());
193 REQUIRE(table->schema()->field(3)->type()->id() == arrow::boolean()->id());
199 std::vector<std::byte>
buffer{10, std::byte{
'c'}};
200 std::vector<std::byte> buffer1{10, std::byte{
'a'}};
202 auto rowWriter = builder.
persist<std::span<std::byte>>({
"blob"});
203 rowWriter(0, std::span(
buffer));
204 rowWriter(0, std::span(
buffer.data() + 1, 9));
205 rowWriter(0, std::span(buffer1.data(), 3));
206 rowWriter(0, std::span(buffer1.data(), 1));
209 REQUIRE(table->num_columns() == 1);
210 REQUIRE(table->num_rows() == 4);
211 REQUIRE(table->schema()->field(0)->name() ==
"blob");
212 REQUIRE(table->schema()->field(0)->type()->id() == arrow::binary_view()->id());
216 REQUIRE(
row.blob() ==
"cccccccccc");
218 REQUIRE(
row.blob() ==
"ccccccccc");
220 REQUIRE(
row.blob() ==
"aaa");
222 REQUIRE(
row.blob() ==
"a");
239 for (
auto&
row : readBack) {
240 REQUIRE(
row.x() ==
i * 10);
241 REQUIRE(
row.y() ==
i);
259 rowWriter(0,
A{0, 0});
260 rowWriter(0,
A{10, 1});
261 rowWriter(0,
A{20, 2});
262 rowWriter(0,
A{30, 3});
263 rowWriter(0,
A{40, 4});
264 rowWriter(0,
A{50, 5});
269 for (
auto&
row : readBack) {
270 REQUIRE(
row.x() ==
i * 10);
271 REQUIRE(
row.y() ==
i);
292 REQUIRE(TableBuilder::countColumns<Foo>() == 2);
293 REQUIRE(TableBuilder::countColumns<Bar>() == 3);
294 REQUIRE(TableBuilder::countColumns<FooBar>() == 3);
295 int count = TableBuilder::countColumns<float, int>();
297 int count2 = TableBuilder::countColumns<float, int, char[3]>();
298 REQUIRE(count2 == 3);
#define DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_)
auto reserve(o2::framework::pack< ARGS... > &&, int s)
auto persist(std::array< char const *, sizeof...(ARGS)+1 > const &columnNames)
std::shared_ptr< arrow::Table > finalize()
unfiltered_iterator begin()
std::shared_ptr< arrow::Table > asArrowTable() const
Return a type erased arrow table backing store for / the type safe table.
GLboolean GLboolean GLboolean b
GLfloat GLfloat GLfloat GLfloat v3
GLboolean GLboolean GLboolean GLboolean a
Defining PrimaryVertex explicitly as messageable.
TEST_CASE("test_prepareArguments")
o2::soa::InPlaceTable< 0, test2::X, test2::Y > TestTable