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>
40 auto rowWriter = builder.
persist<uint64_t, uint64_t>({
"x",
"y"});
50 REQUIRE(table->num_columns() == 2);
51 REQUIRE(table->num_rows() == 8);
52 REQUIRE(table->schema()->field(0)->name() ==
"x");
53 REQUIRE(table->schema()->field(1)->name() ==
"y");
54 REQUIRE(table->schema()->field(0)->type()->id() == arrow::uint64()->id());
55 REQUIRE(table->schema()->field(1)->type()->id() == arrow::uint64()->id());
60 REQUIRE(readBackTable->num_columns() == 2);
61 REQUIRE(readBackTable->num_rows() == 8);
62 REQUIRE(readBackTable->schema()->field(0)->name() ==
"x");
63 REQUIRE(readBackTable->schema()->field(1)->name() ==
"y");
64 REQUIRE(readBackTable->schema()->field(0)->type()->id() == arrow::uint64()->id());
65 REQUIRE(readBackTable->schema()->field(1)->type()->id() == arrow::uint64()->id());
69 for (
auto const&
row : readBack) {
70 REQUIRE(
row.x() ==
i * 10);
71 REQUIRE(
row.y() ==
i);
81 const int numElem = 4;
82 auto rowWriter = builder.
persist<
int[numElem]>({
"pos"});
83 int a[numElem] = {1, 10, 300, 350};
84 int b[numElem] = {0, 20, 30, 40};
87 using v3 = std::array<int, numElem>;
88 rowWriter(0,
v3{0, 11, 123, 256}.data());
91 REQUIRE(table->num_columns() == 1);
92 REQUIRE(table->num_rows() == 3);
93 REQUIRE(table->schema()->field(0)->name() ==
"pos");
94 REQUIRE(table->schema()->field(0)->type()->id() == arrow::fixed_size_list(arrow::int32(), numElem)->id());
96 auto chunkToUse = table->column(0)->chunk(0);
97 chunkToUse = std::static_pointer_cast<arrow::FixedSizeListArray>(chunkToUse)->values();
98 auto data = chunkToUse->data();
100 REQUIRE(
data->GetValues<
int>(1)[0] == 1);
101 REQUIRE(
data->GetValues<
int>(1)[1] == 10);
102 REQUIRE(
data->GetValues<
int>(1)[2] == 300);
103 REQUIRE(
data->GetValues<
int>(1)[3] == 350);
104 REQUIRE(
data->GetValues<
int>(1)[4] == 0);
105 REQUIRE(
data->GetValues<
int>(1)[5] == 20);
106 REQUIRE(
data->GetValues<
int>(1)[6] == 30);
107 REQUIRE(
data->GetValues<
int>(1)[7] == 40);
112 REQUIRE(
row.pos()[0] == 1);
113 REQUIRE(
row.pos()[1] == 10);
114 REQUIRE(
row.pos()[2] == 300);
115 REQUIRE(
row.pos()[3] == 350);
118 REQUIRE(
row.pos()[0] == 0);
119 REQUIRE(
row.pos()[1] == 20);
120 REQUIRE(
row.pos()[2] == 30);
121 REQUIRE(
row.pos()[3] == 40);
124 REQUIRE(
row.pos()[0] == 0);
125 REQUIRE(
row.pos()[1] == 11);
126 REQUIRE(
row.pos()[2] == 123);
127 REQUIRE(
row.pos()[3] == 256);
138 auto rowWriter = builder.
persist<
Foo>({
"x",
"y"});
139 rowWriter(0,
Foo{0, 0});
140 rowWriter(0,
Foo{10, 1});
141 rowWriter(0,
Foo{20, 2});
142 rowWriter(0,
Foo{30, 3});
143 rowWriter(0,
Foo{40, 4});
144 rowWriter(0,
Foo{50, 5});
145 rowWriter(0,
Foo{60, 6});
146 rowWriter(0,
Foo{70, 7});
148 REQUIRE(table->num_columns() == 2);
149 REQUIRE(table->num_rows() == 8);
150 REQUIRE(table->schema()->field(0)->name() ==
"x");
151 REQUIRE(table->schema()->field(1)->name() ==
"y");
152 REQUIRE(table->schema()->field(0)->type()->id() == arrow::uint64()->id());
153 REQUIRE(table->schema()->field(1)->type()->id() == arrow::uint64()->id());
158 for (
auto&
row : readBack) {
159 REQUIRE(
row.x() ==
i * 10);
160 REQUIRE(
row.y() ==
i);
169 auto rowWriter = builder.
persist<
int, float, std::string,
bool>({
"x",
"y",
"s",
"b"});
171 rowWriter(0, 0, 0.,
"foo",
true);
172 rowWriter(0, 1, 1.,
"bar",
false);
173 rowWriter(0, 2, 2.,
"fbr",
false);
174 rowWriter(0, 3, 3.,
"bar",
false);
175 rowWriter(0, 4, 4.,
"abr",
true);
176 rowWriter(0, 5, 5.,
"aaa",
false);
177 rowWriter(0, 6, 6.,
"bbb",
true);
178 rowWriter(0, 7, 7.,
"ccc",
false);
180 REQUIRE(table->num_columns() == 4);
181 REQUIRE(table->num_rows() == 8);
182 REQUIRE(table->schema()->field(0)->name() ==
"x");
183 REQUIRE(table->schema()->field(1)->name() ==
"y");
184 REQUIRE(table->schema()->field(2)->name() ==
"s");
185 REQUIRE(table->schema()->field(3)->name() ==
"b");
186 REQUIRE(table->schema()->field(0)->type()->id() == arrow::int32()->id());
187 REQUIRE(table->schema()->field(1)->type()->id() == arrow::float32()->id());
188 REQUIRE(table->schema()->field(2)->type()->id() == arrow::utf8()->id());
189 REQUIRE(table->schema()->field(3)->type()->id() == arrow::boolean()->id());
206 for (
auto&
row : readBack) {
207 REQUIRE(
row.x() ==
i * 10);
208 REQUIRE(
row.y() ==
i);
226 rowWriter(0,
A{0, 0});
227 rowWriter(0,
A{10, 1});
228 rowWriter(0,
A{20, 2});
229 rowWriter(0,
A{30, 3});
230 rowWriter(0,
A{40, 4});
231 rowWriter(0,
A{50, 5});
236 for (
auto&
row : readBack) {
237 REQUIRE(
row.x() ==
i * 10);
238 REQUIRE(
row.y() ==
i);
259 REQUIRE(TableBuilder::countColumns<Foo>() == 2);
260 REQUIRE(TableBuilder::countColumns<Bar>() == 3);
261 REQUIRE(TableBuilder::countColumns<FooBar>() == 3);
262 int count = TableBuilder::countColumns<float, int>();
264 int count2 = TableBuilder::countColumns<float, int, char[3]>();
265 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