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);
170 int x[] = {0, 1, 2, 3, 4, 5, 6, 7};
171 int y[] = {0, 1, 2, 3, 4, 5, 6, 7};
173 bulkWriter(0, 8,
x,
y);
176 REQUIRE(table->num_columns() == 2);
177 REQUIRE(table->num_rows() == 8);
178 REQUIRE(table->schema()->field(0)->name() ==
"x");
179 REQUIRE(table->schema()->field(1)->name() ==
"y");
180 REQUIRE(table->schema()->field(0)->type()->id() == arrow::int32()->id());
181 REQUIRE(table->schema()->field(1)->type()->id() == arrow::int32()->id());
183 for (int64_t
i = 0;
i < 8; ++
i) {
184 auto p = std::dynamic_pointer_cast<arrow::NumericArray<arrow::Int32Type>>(table->column(0)->chunk(0));
185 REQUIRE(p->Value(
i) ==
i);
193 auto rowWriter = builder.
persist<
int, float, std::string,
bool>({
"x",
"y",
"s",
"b"});
195 rowWriter(0, 0, 0.,
"foo",
true);
196 rowWriter(0, 1, 1.,
"bar",
false);
197 rowWriter(0, 2, 2.,
"fbr",
false);
198 rowWriter(0, 3, 3.,
"bar",
false);
199 rowWriter(0, 4, 4.,
"abr",
true);
200 rowWriter(0, 5, 5.,
"aaa",
false);
201 rowWriter(0, 6, 6.,
"bbb",
true);
202 rowWriter(0, 7, 7.,
"ccc",
false);
204 REQUIRE(table->num_columns() == 4);
205 REQUIRE(table->num_rows() == 8);
206 REQUIRE(table->schema()->field(0)->name() ==
"x");
207 REQUIRE(table->schema()->field(1)->name() ==
"y");
208 REQUIRE(table->schema()->field(2)->name() ==
"s");
209 REQUIRE(table->schema()->field(3)->name() ==
"b");
210 REQUIRE(table->schema()->field(0)->type()->id() == arrow::int32()->id());
211 REQUIRE(table->schema()->field(1)->type()->id() == arrow::float32()->id());
212 REQUIRE(table->schema()->field(2)->type()->id() == arrow::utf8()->id());
213 REQUIRE(table->schema()->field(3)->type()->id() == arrow::boolean()->id());
230 for (
auto&
row : readBack) {
231 REQUIRE(
row.x() ==
i * 10);
232 REQUIRE(
row.y() ==
i);
250 rowWriter(0,
A{0, 0});
251 rowWriter(0,
A{10, 1});
252 rowWriter(0,
A{20, 2});
253 rowWriter(0,
A{30, 3});
254 rowWriter(0,
A{40, 4});
255 rowWriter(0,
A{50, 5});
260 for (
auto&
row : readBack) {
261 REQUIRE(
row.x() ==
i * 10);
262 REQUIRE(
row.y() ==
i);
283 REQUIRE(TableBuilder::countColumns<Foo>() == 2);
284 REQUIRE(TableBuilder::countColumns<Bar>() == 3);
285 REQUIRE(TableBuilder::countColumns<FooBar>() == 3);
286 int count = TableBuilder::countColumns<float, int>();
288 int count2 = TableBuilder::countColumns<float, int, char[3]>();
289 REQUIRE(count2 == 3);
294 auto fields = TableBuilderHelpers::makeFields<int, float>({
"i",
"f"});
295 REQUIRE(fields.size() == 2);
296 REQUIRE(fields[0]->
name() ==
"i");
297 REQUIRE(fields[1]->
name() ==
"f");
298 REQUIRE(fields[0]->
type()->
name() ==
"int32");
299 REQUIRE(fields[1]->
type()->
name() ==
"float");
#define DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_)
auto bulkPersist(std::array< char const *, NCOLUMNS > const &columnNames, size_t nRows)
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.
GLuint const GLchar * name
GLboolean GLboolean GLboolean b
GLint GLint GLsizei GLint GLenum GLenum type
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