12#define BOOST_TEST_MODULE Test Framework TableBuilder
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
16#include <boost/test/unit_test.hpp>
24#include <arrow/table.h>
26#include <ROOT/RDataFrame.hxx>
27#include <ROOT/RArrowDS.hxx>
28#include <arrow/ipc/writer.h>
29#include <arrow/io/memory.h>
30#include <arrow/ipc/writer.h>
31#include <arrow/ipc/reader.h>
32#include "../src/ArrowDebugHelpers.h"
50 auto rowWriter = builder.
persist<uint64_t, uint64_t>({
"x",
"y"});
60 BOOST_REQUIRE_EQUAL(table->num_columns(), 2);
61 BOOST_REQUIRE_EQUAL(table->num_rows(), 8);
62 BOOST_REQUIRE_EQUAL(table->schema()->field(0)->name(),
"x");
63 BOOST_REQUIRE_EQUAL(table->schema()->field(1)->name(),
"y");
64 BOOST_REQUIRE_EQUAL(table->schema()->field(0)->type()->id(), arrow::uint64()->id());
65 BOOST_REQUIRE_EQUAL(table->schema()->field(1)->type()->id(), arrow::uint64()->id());
70 for (
auto&
row : readBack) {
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 BOOST_REQUIRE_EQUAL(table->num_columns(), 1);
92 BOOST_REQUIRE_EQUAL(table->num_rows(), 3);
93 BOOST_REQUIRE_EQUAL(table->schema()->field(0)->name(),
"pos");
94 BOOST_REQUIRE_EQUAL(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 BOOST_REQUIRE_EQUAL(
data->GetValues<
int>(1)[0], 1);
101 BOOST_REQUIRE_EQUAL(
data->GetValues<
int>(1)[1], 10);
102 BOOST_REQUIRE_EQUAL(
data->GetValues<
int>(1)[2], 300);
103 BOOST_REQUIRE_EQUAL(
data->GetValues<
int>(1)[3], 350);
104 BOOST_REQUIRE_EQUAL(
data->GetValues<
int>(1)[4], 0);
105 BOOST_REQUIRE_EQUAL(
data->GetValues<
int>(1)[5], 20);
106 BOOST_REQUIRE_EQUAL(
data->GetValues<
int>(1)[6], 30);
107 BOOST_REQUIRE_EQUAL(
data->GetValues<
int>(1)[7], 40);
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 BOOST_REQUIRE_EQUAL(table->num_columns(), 2);
149 BOOST_REQUIRE_EQUAL(table->num_rows(), 8);
150 BOOST_REQUIRE_EQUAL(table->schema()->field(0)->name(),
"x");
151 BOOST_REQUIRE_EQUAL(table->schema()->field(1)->name(),
"y");
152 BOOST_REQUIRE_EQUAL(table->schema()->field(0)->type()->id(), arrow::uint64()->id());
153 BOOST_REQUIRE_EQUAL(table->schema()->field(1)->type()->id(), arrow::uint64()->id());
158 for (
auto&
row : readBack) {
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 BOOST_REQUIRE_EQUAL(table->num_columns(), 2);
177 BOOST_REQUIRE_EQUAL(table->num_rows(), 8);
178 BOOST_REQUIRE_EQUAL(table->schema()->field(0)->name(),
"x");
179 BOOST_REQUIRE_EQUAL(table->schema()->field(1)->name(),
"y");
180 BOOST_REQUIRE_EQUAL(table->schema()->field(0)->type()->id(), arrow::int32()->id());
181 BOOST_REQUIRE_EQUAL(table->schema()->field(1)->type()->id(), arrow::int32()->id());
183 for (
size_t i = 0;
i < 8; ++
i) {
184 auto p = std::dynamic_pointer_cast<arrow::NumericArray<arrow::Int32Type>>(table->column(0)->chunk(0));
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 BOOST_REQUIRE_EQUAL(table->num_columns(), 4);
205 BOOST_REQUIRE_EQUAL(table->num_rows(), 8);
206 BOOST_REQUIRE_EQUAL(table->schema()->field(0)->name(),
"x");
207 BOOST_REQUIRE_EQUAL(table->schema()->field(1)->name(),
"y");
208 BOOST_REQUIRE_EQUAL(table->schema()->field(2)->name(),
"s");
209 BOOST_REQUIRE_EQUAL(table->schema()->field(3)->name(),
"b");
210 BOOST_REQUIRE_EQUAL(table->schema()->field(0)->type()->id(), arrow::int32()->id());
211 BOOST_REQUIRE_EQUAL(table->schema()->field(1)->type()->id(), arrow::float32()->id());
212 BOOST_REQUIRE_EQUAL(table->schema()->field(2)->type()->id(), arrow::utf8()->id());
213 BOOST_REQUIRE_EQUAL(table->schema()->field(3)->type()->id(), arrow::boolean()->id());
263 auto rowWriter1 = builder1.
persist<
int,
int,
int>({
"x",
"y",
"event"});
264 for (
size_t i = 0;
i < 8; ++
i) {
265 rowWriter1(0,
i,
i,
i / 4);
270 auto rowWriter2 = builder2.
persist<
int,
int>({
"x",
"y"});
271 for (
size_t i = 0;
i < 8; ++
i) {
275 BOOST_REQUIRE_EQUAL(table2->num_columns(), 2);
276 BOOST_REQUIRE_EQUAL(table2->num_rows(), 8);
277 for (
size_t i = 0;
i < 8; ++
i) {
278 auto p2 = std::dynamic_pointer_cast<arrow::NumericArray<arrow::Int32Type>>(table2->column(0)->chunk(0));
282 auto source1 = std::make_unique<ROOT::RDF::RArrowDS>(table1, std::vector<std::string>{});
283 auto source2 = std::make_unique<ROOT::RDF::RArrowDS>(table2, std::vector<std::string>{});
285 auto source3 = std::make_unique<ROOT::RDF::RArrowDS>(table1, std::vector<std::string>{});
286 auto source4 = std::make_unique<ROOT::RDF::RArrowDS>(table2, std::vector<std::string>{});
288 auto source5 = std::make_unique<ROOT::RDF::RArrowDS>(table1, std::vector<std::string>{});
289 auto source6 = std::make_unique<ROOT::RDF::RArrowDS>(table2, std::vector<std::string>{});
291 auto source7 = std::make_unique<ROOT::RDF::RArrowDS>(table1, std::vector<std::string>{});
292 auto source8 = std::make_unique<ROOT::RDF::RArrowDS>(table1, std::vector<std::string>{});
295 ROOT::RDataFrame finalDF{std::move(cross)};
296 ROOT::RDataFrame indexedDF{std::move(indexed)};
297 ROOT::RDataFrame unionDF{std::move(unionDS)};
298 ROOT::RDataFrame blockDF{std::move(blockDS)};
308 auto sum = [](
int lx,
int rx) {
return lx + rx; };
309 auto left = [](
int lx,
int) {
return lx; };
310 auto right = [](
int,
int rx) {
return rx; };
335 for (
auto&
row : readBack) {
344 const Output output{
"TST",
"DUMMY", 0, Lifetime::Timeframe};
356 rowWriter(0,
A{0, 0});
357 rowWriter(0,
A{10, 1});
358 rowWriter(0,
A{20, 2});
359 rowWriter(0,
A{30, 3});
360 rowWriter(0,
A{40, 4});
361 rowWriter(0,
A{50, 5});
366 for (
auto&
row : readBack) {
389 BOOST_REQUIRE_EQUAL(TableBuilder::countColumns<Foo>(), 2);
390 BOOST_REQUIRE_EQUAL(TableBuilder::countColumns<Bar>(), 3);
391 BOOST_REQUIRE_EQUAL(TableBuilder::countColumns<FooBar>(), 3);
392 int count = TableBuilder::countColumns<float, int>();
393 BOOST_REQUIRE_EQUAL(
count, 2);
394 int count2 = TableBuilder::countColumns<float, int, char[3]>();
395 BOOST_REQUIRE_EQUAL(count2, 3);
400 auto fields = TableBuilderHelpers::makeFields<int, float>({
"i",
"f"});
401 BOOST_REQUIRE_EQUAL(fields.size(), 2);
402 BOOST_REQUIRE_EQUAL(fields[0]->
name(),
"i");
403 BOOST_REQUIRE_EQUAL(fields[1]->
name(),
"f");
404 BOOST_REQUIRE_EQUAL(fields[0]->
type()->
name(),
"int32");
405 BOOST_REQUIRE_EQUAL(fields[1]->
type()->
name(),
"float");
413 ROOT::RDataFrame rdf(100);
414 auto t = rdf.Define(
"x",
"1")
417 t.ForeachSlot(builder.
persist<
int,
int>({
"x",
"z"}), {
"x",
"z"});
420 auto transport = fair::mq::TransportFactory::CreateTransportFactory(
"zeromq");
421 auto creator = [&transport](
size_t size) -> std::unique_ptr<fair::mq::Message> {
422 return transport->CreateMessage(
size);
424 auto buffer = std::make_shared<FairMQResizableBuffer>(creator);
426 auto stream = std::make_shared<arrow::io::BufferOutputStream>(
buffer);
427 auto outBatch = arrow::ipc::MakeStreamWriter(
stream.get(), table->schema());
428 auto outStatus = outBatch.ValueOrDie()->WriteTable(*table);
429 if (outStatus.ok() ==
false) {
430 throw std::runtime_error(
"Unable to Write table");
433 std::unique_ptr<fair::mq::Message> payload =
buffer->Finalise();
#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()
float sum(float s, o2::dcs::DataPointValue v)
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
RDataFrame MakeColumnIndexedDataFrame(std::unique_ptr< RDataSource > left, std::unique_ptr< RDataSource >, std::string indexColName, std::string leftPrefix="left_", std::string rightPrefix="right_")
RDataFrame MakeBlockAntiDataFrame(std::unique_ptr< RDataSource > left, std::unique_ptr< RDataSource > right, std::string indexColumnName, std::string leftPrefix="left_", std::string rightPrefix="right_")
RDataFrame MakeFriendDataFrame(std::unique_ptr< RDataSource > left, std::unique_ptr< RDataSource > right, std::string leftPrefix="left_", std::string rightPrefix="right_")
RDataFrame MakeCrossProductDataFrame(std::unique_ptr< RDataSource > left, std::unique_ptr< RDataSource >, std::string leftPrefix="left_", std::string rightPrefix="right_")
Defining PrimaryVertex explicitly as messageable.
FIXME: do not use data model tables.
BOOST_AUTO_TEST_CASE(TestTableBuilder)
o2::soa::Table< test::X, test::Y > TestTable
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())