18#include "gandiva/tree_expr_builder.h"
19#include "arrow/status.h"
20#include "gandiva/filter.h"
21#include <catch_amalgamated.hpp>
22#include <arrow/util/key_value_metadata.h>
64DECLARE_SOA_TABLE(Segments,
"TEST",
"SEGMENTS", test::N, test::PointAId, test::PointBId, test::InfoId);
79 auto pwriter = b1.
cursor<o2::aod::Points3Ds>();
80 for (
auto i = 0;
i < 20; ++
i) {
81 pwriter(0, -1 *
i, (
int)(
i / 2), 2 *
i);
85 auto pt = o2::aod::Points3Ds{
t1};
86 auto pt1 = o2::aod::Points3DMk1s{
t1};
87 auto pt2 = o2::aod::Points3DMk2s{
t1};
88 auto pt3 = o2::aod::Points3DMk3s{
t1};
89 REQUIRE(pt1.begin().mark() == (
size_t)1);
90 REQUIRE(pt2.begin().mark() == (
size_t)2);
91 REQUIRE(pt3.begin().mark() == (
size_t)3);
97 auto rowWriter = builder.
persist<int32_t, int32_t>({
"fX",
"fY"});
111 i.mCurrentPos = &
pos;
129 arrow::ChunkedArray* chunks[2] = {
130 table->column(0).get(),
131 table->column(1).get()};
132 o2::aod::Points::iterator tests(chunks, {table->num_rows(), 0});
133 REQUIRE(tests.x() == 0);
134 REQUIRE(tests.y() == 0);
136 REQUIRE(tests.x() == 0);
137 REQUIRE(tests.y() == 1);
142 auto e = tests2.end();
156 REQUIRE(((
b + 1) == (
b + 1)));
157 REQUIRE(((
b + 7) !=
b));
158 REQUIRE(((
b + 7) != e));
159 REQUIRE(((
b + 8) == e));
161 for (
auto& t : tests2) {
162 REQUIRE(t.x() ==
value / 4);
163 REQUIRE((
size_t)t.y() ==
value);
168 for (
auto t1 = tests2.begin();
t1 != tests2.end(); ++
t1) {
169 for (
auto t2 =
t1 + 1; t2 != tests2.end(); ++t2) {
177 auto rowWriter = builder.
persist<int32_t, int32_t>({
"fX",
"fY"});
188 using Test1 =
InPlaceTable<
"A"_h, o2::aod::test::X, o2::aod::test::Y, o2::aod::test::Sum<o2::aod::test::X, o2::aod::test::Y>>;
191 for (
auto&
test : tests1) {
195 using Test2 =
InPlaceTable<
"B"_h, o2::aod::test::X, o2::aod::test::Y, o2::aod::test::Sum<o2::aod::test::Y, o2::aod::test::Y>>;
198 for (
auto&
test : tests2) {
206 auto rowWriter = builder.
persist<int32_t, int32_t>({
"fX",
"fY"});
220 foo.mCurrentPos = &index1;
222 bar.mCurrentPos = &index2;
223 REQUIRE(
foo.mCurrent == bar.mCurrent);
224 REQUIRE(
foo.mLast == bar.mLast);
225 REQUIRE(
foo.mColumn == bar.mColumn);
226 REQUIRE(
foo.mFirstIndex == bar.mFirstIndex);
227 REQUIRE(
foo.mCurrentChunk == bar.mCurrentChunk);
229 auto foobar = std::move(
foo);
230 REQUIRE(foobar.mCurrent == bar.mCurrent);
231 REQUIRE(foobar.mLast == bar.mLast);
232 REQUIRE(foobar.mColumn == bar.mColumn);
233 REQUIRE(foobar.mFirstIndex == bar.mFirstIndex);
234 REQUIRE(foobar.mCurrentChunk == bar.mCurrentChunk);
240 auto rowWriterX = builderX.
persist<int32_t>({
"fX"});
252 auto rowWriterY = builderY.
persist<int32_t>({
"fY"});
264 auto rowWriterZ = builderZ.
persist<int32_t>({
"fZ"});
276 auto rowWriterW = builderW.
persist<int32_t>({
"fW"});
288 REQUIRE(Test::contains<TestX>());
289 REQUIRE(Test::contains<TestY>());
290 REQUIRE(!Test::contains<TestZ>());
292 Test tests{{tableX, tableY}};
294 REQUIRE(tests.contains<TestX>());
295 REQUIRE(tests.contains<TestY>());
296 REQUIRE(!tests.contains<TestZ>());
298 for (
auto&
test : tests) {
302 auto tests2 =
join(TestX{tableX}, TestY{tableY});
303 static_assert(std::same_as<Test::self_t,
decltype(tests2)>,
"Joined tables should have the same type, regardless how we construct them");
304 for (
auto&
test : tests2) {
308 auto tests3 =
join(TestX{tableX}, TestY{tableY}, TestZ{tableZ});
310 for (
auto&
test : tests3) {
314 TestMoreThanTwo tests4{{tableX, tableY, tableZ}};
315 for (
auto&
test : tests4) {
320 auto testF =
join(TestZ{tableZ}, TestW{tableW});
322 REQUIRE(std::string{
error_from_ref(
ref).
what} ==
"Tables TEST and TEST have different sizes (8 vs 3) and cannot be joined!");
329 auto rowWriterA = builderA.
persist<int32_t, int32_t>({
"fX",
"fY"});
339 REQUIRE(tableA->num_rows() == 8);
342 auto rowWriterB = builderB.
persist<int32_t>({
"fX"});
354 auto rowWriterC = builderC.
persist<int32_t>({
"fZ"});
366 auto rowWriterD = builderD.
persist<int32_t, int32_t>({
"fX",
"fZ"});
367 rowWriterD(0, 16, 8);
368 rowWriterD(0, 17, 9);
369 rowWriterD(0, 18, 10);
370 rowWriterD(0, 19, 11);
371 rowWriterD(0, 20, 12);
372 rowWriterD(0, 21, 13);
373 rowWriterD(0, 22, 14);
374 rowWriterD(0, 23, 15);
386 static_assert(std::same_as<NestedJoinTest::columns_t, o2::framework::pack<o2::soa::Index<>, o2::aod::test::Y, o2::aod::test::X, o2::aod::test::Z>>,
"Bad nested join");
388 static_assert(std::same_as<ConcatTest::columns_t, o2::framework::pack<o2::soa::Index<>, o2::aod::test::X>>,
"Bad intersection of columns");
389 ConcatTest tests{{tableA, tableB}};
390 REQUIRE(16 == tests.size());
391 for (
auto&
test : tests) {
395 static_assert(std::same_as<NestedConcatTest::columns_t, o2::framework::pack<o2::aod::test::X>>,
"Bad nested concat");
402 auto status = gandiva::SelectionVector::MakeInt64(tests.size(), arrow::default_memory_pool(), &selection);
403 REQUIRE(status.ok());
405 auto fptr = tableA->schema()->GetFieldByName(
"fX");
406 REQUIRE(fptr !=
nullptr);
407 REQUIRE(fptr->name() ==
"fX");
408 REQUIRE(fptr->type()->id() == arrow::Type::INT32);
410 auto node_x = gandiva::TreeExprBuilder::MakeField(fptr);
411 auto literal_1 = gandiva::TreeExprBuilder::MakeLiteral(
static_cast<int32_t
>(1));
412 auto literal_3 = gandiva::TreeExprBuilder::MakeLiteral(
static_cast<int32_t
>(3));
413 auto equals_to_1 = gandiva::TreeExprBuilder::MakeFunction(
"equal", {node_x, literal_1}, arrow::boolean());
414 auto equals_to_3 = gandiva::TreeExprBuilder::MakeFunction(
"equal", {node_x, literal_3}, arrow::boolean());
415 auto node_or = gandiva::TreeExprBuilder::MakeOr({equals_to_1, equals_to_3});
416 auto condition = gandiva::TreeExprBuilder::MakeCondition(node_or);
417 REQUIRE(condition->ToString() ==
"bool equal((int32) fX, (const int32) 1) || bool equal((int32) fX, (const int32) 3)");
418 std::shared_ptr<gandiva::Filter>
filter;
419 status = gandiva::Filter::Make(tableA->schema(), condition, &
filter);
420 REQUIRE(status.ToString() ==
"OK");
422 arrow::TableBatchReader reader(*tableA);
423 std::shared_ptr<RecordBatch> batch;
424 auto s = reader.ReadNext(&batch);
426 REQUIRE(batch !=
nullptr);
427 REQUIRE(batch->num_rows() == 8);
428 auto st =
filter->Evaluate(*batch, selection);
429 REQUIRE(
st.ToString() ==
"OK");
434 FilteredTest filtered{{testA.asArrowTableRef()}, selection_f};
435 REQUIRE(2 == filtered.size());
438 REQUIRE(filtered.begin() != filtered.end());
439 for (
auto&
f : filtered) {
440 REQUIRE(
i * 2 + 1 ==
f.x());
441 REQUIRE(
i * 2 + 1 ==
f.index());
450 status = gandiva::SelectionVector::MakeInt64(tests.size(), arrow::default_memory_pool(), &selectionConcat);
451 REQUIRE(status.ok() ==
true);
452 selectionConcat->SetIndex(0, 0);
453 selectionConcat->SetIndex(1, 5);
454 selectionConcat->SetIndex(2, 10);
455 selectionConcat->SetNumSlots(3);
456 ConcatTest concatTest{tableA, tableB};
457 FilteredConcatTest concatTestTable{{concatTest.asArrowTableRef()}, selectionConcat};
458 REQUIRE(3 == concatTestTable.size());
461 auto b = concatTestTable.begin();
462 auto e = concatTestTable.end();
464 REQUIRE(
b.mRowIndex == 0);
465 REQUIRE(
b.getSelectionRow() == 0);
466 REQUIRE(e.index == 3);
468 REQUIRE(concatTestTable.begin() != concatTestTable.end());
469 for (
auto&
f : concatTestTable) {
470 REQUIRE(
i * 5 ==
f.x());
471 REQUIRE(
i * 5 ==
f.index());
472 REQUIRE(
i ==
f.filteredIndex());
480 status = gandiva::SelectionVector::MakeInt64(tests.size(), arrow::default_memory_pool(), &selectionJoin);
481 REQUIRE(status.ok() ==
true);
482 selectionJoin->SetIndex(0, 0);
483 selectionJoin->SetIndex(1, 2);
484 selectionJoin->SetIndex(2, 4);
485 selectionJoin->SetNumSlots(3);
486 JoinedTest testJoin{{tableA, tableC}};
487 FilteredJoinTest filteredJoin{{testJoin.asArrowTableRef()}, selectionJoin};
490 REQUIRE(filteredJoin.begin() != filteredJoin.end());
491 for (
auto&
f : filteredJoin) {
492 REQUIRE(
i * 2 ==
f.x());
493 REQUIRE(
i * 2 ==
f.index());
502 auto pointsWriter = builderA.
cursor<o2::aod::Points>();
503 pointsWriter(0, 0, 0);
504 pointsWriter(0, 3, 4);
506 o2::aod::Points points{pointsT};
507 REQUIRE(pointsT->num_rows() == 2);
510 auto infoWriter = builderA2.
cursor<o2::aod::Infos>();
511 infoWriter(0, 0,
true);
512 infoWriter(0, 1,
false);
513 infoWriter(0, 4,
true);
515 o2::aod::Infos infos{infosT};
516 REQUIRE(infos.begin().someBool() ==
true);
517 REQUIRE((infos.begin() + 1).someBool() ==
false);
518 REQUIRE((infos.begin() + 2).someBool() ==
true);
519 REQUIRE((infos.begin() + 2).color() == 4);
520 REQUIRE(infosT->num_rows() == 3);
523 auto segmentsWriter = builderB.
cursor<o2::aod::Segments>();
524 segmentsWriter(0, 10, 0, 1, 2);
525 auto segmentsT = builderB.
finalize();
526 o2::aod::Segments
segments{segmentsT};
527 REQUIRE(segmentsT->num_rows() == 1);
530 auto segmentsExtraWriter = builderC.
cursor<o2::aod::SegmentsExtras>();
531 segmentsExtraWriter(0, 1);
532 auto segmentsExtraT = builderC.
finalize();
533 o2::aod::SegmentsExtras segmentsExtras{segmentsExtraT};
534 REQUIRE(segmentsExtraT->num_rows() == 1);
536 REQUIRE(
segments.begin().pointAId() == 0);
537 REQUIRE(
segments.begin().pointBId() == 1);
538 static_assert(std::same_as<
decltype(
segments.begin().pointA()), o2::aod::Points::iterator>);
541 i.bindExternalIndices(&points, &infos);
542 REQUIRE(
i.n() == 10);
543 REQUIRE(
i.info().color() == 4);
544 REQUIRE(
i.info().someBool() ==
true);
545 REQUIRE(
i.pointA().x() == 0);
546 REQUIRE(
i.pointA().y() == 0);
547 REQUIRE(
i.pointB().x() == 3);
548 REQUIRE(
i.pointB().y() == 4);
550 segments.bindExternalIndices(&points, &infos);
552 REQUIRE(
j.n() == 10);
553 REQUIRE(
j.info().color() == 4);
554 REQUIRE(
j.info().someBool() ==
true);
555 REQUIRE(
j.pointA().x() == 0);
556 REQUIRE(
j.pointA().y() == 0);
557 REQUIRE(
j.pointB().x() == 3);
558 REQUIRE(
j.pointB().y() == 4);
561 joined.bindExternalIndices(&points, &infos);
562 auto se = joined.begin();
563 REQUIRE(se.n() == 10);
564 REQUIRE(se.info().color() == 4);
565 REQUIRE(se.pointA().x() == 0);
566 REQUIRE(se.pointA().y() == 0);
567 REQUIRE(se.pointB().x() == 3);
568 REQUIRE(se.pointB().y() == 4);
569 REQUIRE(se.thickness() == 1);
575 REQUIRE(
schema->num_fields() == 2);
576 REQUIRE(
schema->field(0)->name() ==
"fX");
577 REQUIRE(
schema->field(1)->name() ==
"fY");
583 auto rowWriterA = builderA.
persist<int32_t, int32_t>({
"fX",
"fY"});
586 rowWriterA(0, 2, 10);
587 rowWriterA(0, 3, 11);
588 rowWriterA(0, 4, 12);
589 rowWriterA(0, 5, 13);
590 rowWriterA(0, 6, 14);
591 rowWriterA(0, 7, 15);
593 REQUIRE(tableA->num_rows() == 8);
603 auto s1 = expressions::createSelection(testA.asArrowTable(), f1);
604 FilteredTest filtered1{{testA.asArrowTableRef()},
s1};
605 REQUIRE(4 == filtered1.size());
606 REQUIRE(filtered1.begin() != filtered1.end());
608 auto s2 = expressions::createSelection(testA.asArrowTable(), f2);
609 FilteredTest filtered2{{testA.asArrowTableRef()}, s2};
610 REQUIRE(2 == filtered2.size());
611 REQUIRE(filtered2.begin() != filtered2.end());
613 FilteredTest filteredUnion = filtered1 + filtered2;
614 REQUIRE(6 == filteredUnion.size());
616 std::vector<std::tuple<int32_t, int32_t>> expectedUnion{{0, 8}, {1, 9}, {2, 10}, {3, 11}, {6, 14}, {7, 15}};
618 for (
auto&
f : filteredUnion) {
619 REQUIRE(std::get<0>(expectedUnion[
i]) ==
f.x());
620 REQUIRE(std::get<1>(expectedUnion[
i]) ==
f.y());
621 REQUIRE(std::get<0>(expectedUnion[
i]) ==
f.index());
626 FilteredTest filteredIntersection = filtered1 * filtered2;
627 REQUIRE(0 == filteredIntersection.size());
629 REQUIRE(filteredIntersection.size() == 0);
632 auto s3 = expressions::createSelection(testA.asArrowTable(), f3);
633 FilteredTest filtered3{{testA.asArrowTableRef()}, s3};
634 REQUIRE(3 == filtered3.size());
635 REQUIRE(filtered3.begin() != filtered3.end());
637 FilteredTest unionIntersection = (filtered1 + filtered2) * filtered3;
638 REQUIRE(3 == unionIntersection.size());
641 for (
auto&
f : unionIntersection) {
643 REQUIRE(
i + 8 ==
f.y());
644 REQUIRE(
i ==
f.index());
653 auto rowWriterA = builderA.
persist<int32_t, int32_t>({
"fX",
"fY"});
656 rowWriterA(0, 2, 10);
657 rowWriterA(0, 3, 11);
658 rowWriterA(0, 4, 12);
659 rowWriterA(0, 5, 13);
660 rowWriterA(0, 6, 14);
661 rowWriterA(0, 7, 15);
663 REQUIRE(tableA->num_rows() == 8);
676 auto s1 = expressions::createSelection(testA.asArrowTable(), f1);
677 FilteredTest filtered{{testA.asArrowTableRef()},
s1};
678 REQUIRE(4 == filtered.size());
679 REQUIRE(filtered.begin() != filtered.end());
681 auto s2 = expressions::createSelection(filtered.asArrowTable(), f2);
682 NestedFilteredTest nestedFiltered{{filtered}, s2};
683 REQUIRE(2 == nestedFiltered.size());
685 for (
auto&
f : nestedFiltered) {
686 REQUIRE(
i + 2 ==
f.x());
687 REQUIRE(
i + 10 ==
f.y());
688 REQUIRE(
i + 2 ==
f.index());
693 auto s3 = expressions::createSelection(nestedFiltered.asArrowTable(), f3);
694 TripleNestedFilteredTest tripleFiltered{{nestedFiltered}, s3};
695 REQUIRE(1 == tripleFiltered.size());
697 for (
auto&
f : tripleFiltered) {
698 REQUIRE(
i + 2 ==
f.x());
699 REQUIRE(
i + 10 ==
f.y());
700 REQUIRE(
i + 2 ==
f.index());
709 [[maybe_unused]]
auto pwriter = bPoints.
cursor<o2::aod::Points>();
713 [[maybe_unused]]
auto iwriter = bInfos.
cursor<o2::aod::Infos>();
716 o2::aod::Points p{pempty};
717 o2::aod::Infos
i{iempty};
720 PI pi{{pempty, iempty}};
721 REQUIRE(pi.size() == 0);
722 auto spawned = Extend<o2::aod::Points, o2::aod::test::ESum>(p);
723 REQUIRE(spawned.size() == 0);
744 auto writer =
b.
cursor<o2::aod::Origints>();
745 for (
auto i = 0;
i < 20; ++
i) {
746 writer(0,
i,
i % 3 == 0);
748 auto origins =
b.finalize();
749 o2::aod::Origints o{origins};
752 auto writer_z =
z.
cursor<o2::aod::ManyReferences>();
753 std::vector<int>
ids;
754 for (
auto i = 0;
i < 5; ++
i) {
756 for (
auto j = 0;
j < 20; ++
j) {
761 auto mrefs =
z.finalize();
762 o2::aod::ManyReferences
m{mrefs};
765 auto writer_w =
w.
cursor<o2::aod::References>();
766 for (
auto i = 0;
i < 5 * 20; ++
i) {
769 auto refs =
w.finalize();
770 o2::aod::References
r{refs};
773 auto selection = expressions::createSelection(o.asArrowTable(), flt);
774 Flt
f{{o.asArrowTableRef()}, selection};
775 r.bindExternalIndices(&
f);
778 REQUIRE(it.origint_as<Flt>().globalIndex() == 3);
780 REQUIRE(it.origint_as<Flt>().globalIndex() == 4);
782 REQUIRE(it.origint_as<Flt>().globalIndex() == 5);
784 m.bindExternalIndices(&
f);
785 for (
auto const&
row :
m) {
786 auto os =
row.origints_as<Flt>();
787 auto fos =
row.filtered_origints_as<Flt>();
788 REQUIRE(os.size() == 20);
789 REQUIRE(fos.size() == 6);
805DECLARE_SOA_TABLE(PointsRefF,
"TEST",
"PTSREFF", test::SinglePointId, test::Points3DIdSlice, test::Points3DIds);
807 test::PointSeqIdSlice, test::PointSetIds);
813 auto pwriter = b1.
persist<
int,
int,
int>({
"fX",
"fY",
"fZ"});
814 for (
auto i = 0;
i < 20; ++
i) {
815 pwriter(0, -1 *
i, (
int)(
i / 2), 2 *
i);
820 auto prwriter = b2.
cursor<o2::aod::PointsRef>();
821 auto a = std::array{0, 1};
822 auto aa = std::vector{2, 3, 4};
823 prwriter(0, &
a[0], aa);
826 prwriter(0, &
a[0], aa);
829 auto pt = o2::aod::Points3Ds{tpts1};
830 auto prt = o2::aod::PointsRef{t2};
831 prt.bindExternalIndices(&pt);
833 auto it = prt.begin();
834 auto s1 = it.pointSlice();
835 auto g1 = it.pointGroup();
836 auto bb = std::same_as<
decltype(
s1), o2::aod::Points3Ds>;
838 REQUIRE(
s1.size() == 2);
840 for (
int i = 0;
i < 3; ++
i) {
841 REQUIRE(g1[
i].globalIndex() == aa[
i]);
846 for (
auto& p : it.pointGroup_as<o2::aod::Points3Ds>()) {
847 REQUIRE(p.x() == -1 * p.globalIndex());
851 auto s2 = it.pointSlice();
852 auto g2 = it.pointGroup();
853 REQUIRE(s2.size() == 7);
855 for (
int i = 0;
i < 3; ++
i) {
856 REQUIRE(g2[
i].globalIndex() == aa[
i]);
861 Flt
f{{tpts1}, expressions::createSelection(tpts1, fltx)};
862 prt.bindExternalIndices(&
f);
864 auto it2 = prt.begin();
865 auto s1f = it2.pointSlice_as<Flt>();
866 auto g1f = it2.pointGroup_as<Flt>();
867 REQUIRE(s1f.size() == 2);
869 for (
int i = 0;
i < 3; ++
i) {
870 REQUIRE(g1f[
i].globalIndex() == aa[
i]);
874 auto s2f = it2.pointSlice_as<Flt>();
875 auto g2f = it2.pointGroup_as<Flt>();
876 REQUIRE(s2f.size() == 7);
878 for (
int i = 0;
i < 3; ++
i) {
879 REQUIRE(g2f[
i].globalIndex() == aa[
i]);
883 auto pswriter = b3.
cursor<o2::aod::PointsSelfIndex>();
884 int references[] = {19, 2, 0, 13, 4, 6, 5, 5, 11, 9, 3, 8, 16, 14, 1, 18, 12, 18, 2, 7};
885 int slice[2] = {-1, -1};
886 std::vector<int> pset;
887 std::array<int, 4> withSlices = {3, 6, 13, 19};
888 std::array<std::pair<int, int>, 4> bounds = {std::pair{1, 5}, std::pair{3, 3}, std::pair{11, 11}, std::pair{10, 18}};
889 std::array<int, 4> withSets = {0, 1, 13, 14};
890 unsigned const int sizes[] = {3, 1, 5, 4};
893 for (
auto i = 0;
i < 20; ++
i) {
897 if (c1 < withSlices.size() &&
i == withSlices[c1]) {
898 slice[0] = bounds[c1].first;
899 slice[1] = bounds[c1].second;
902 if (c2 < withSets.size() &&
i == withSets[c2]) {
903 for (
auto z = 0U;
z <
sizes[c2]; ++
z) {
904 pset.push_back(
i + 1 +
z);
908 pswriter(0, -1 *
i, 0.5 *
i, 2 *
i, references[
i], slice, pset);
911 auto pst = o2::aod::PointsSelfIndex{t3};
912 pst.bindInternalIndicesTo(&pst);
916 for (
auto& p : pst) {
917 auto op = p.otherPoint_as<o2::aod::PointsSelfIndex>();
918 auto bbb = std::same_as<
decltype(
op), o2::aod::PointsSelfIndex::iterator>;
920 REQUIRE(
op.globalIndex() == references[
i]);
922 auto ops = p.pointSeq_as<o2::aod::PointsSelfIndex>();
923 auto bbbs = std::same_as<
decltype(ops), o2::aod::PointsSelfIndex>;
926 if (
i == withSlices[c1]) {
927 auto lit = ops.begin();
928 REQUIRE(ops.size() == bounds[c1].second - bounds[c1].first + 1);
929 REQUIRE(lit.globalIndex() == bounds[c1].first);
930 lit.moveByIndex(ops.size() - 1);
931 REQUIRE(lit.globalIndex() == bounds[c1].second);
934 REQUIRE(ops.size() == 0);
937 auto opss = p.pointSet_as<o2::aod::PointsSelfIndex>();
938 auto bbba = std::same_as<
decltype(opss), std::vector<o2::aod::PointsSelfIndex::iterator>>;
941 auto opss_ids = p.pointSetIds();
942 if (c2 < withSets.size() &&
i == withSets[c2]) {
943 REQUIRE(opss.size() ==
sizes[c2]);
944 REQUIRE(opss.begin()->globalIndex() ==
i + 1);
945 REQUIRE(opss.back().globalIndex() ==
i +
sizes[c2]);
947 for (
auto const&
id : opss_ids) {
948 REQUIRE(
id ==
i + 1 + c3);
953 REQUIRE(opss.size() == 0);
961DECLARE_SOA_TABLE(PointsSelfRef,
"TEST",
"PTSSR", test::OtherPointId, test::PointSeqIdSlice, test::PointSetIds);
967 auto pswriter = b3.
cursor<o2::aod::PointsSelfIndex>();
968 int references[] = {19, 2, 0, 13, 4, 6, 5, 5, 11, 9, 3, 8, 16, 14, 1, 18, 12, 18, 2, 7};
969 int slice[2] = {-1, -1};
970 std::vector<int> pset;
971 std::array<int, 4> withSlices = {3, 6, 13, 19};
972 std::array<std::pair<int, int>, 4> bounds = {std::pair{1, 5}, std::pair{3, 3}, std::pair{11, 11}, std::pair{10, 18}};
973 std::array<int, 4> withSets = {0, 1, 13, 14};
974 unsigned const int sizes[] = {3, 1, 5, 4};
977 for (
auto i = 0;
i < 20; ++
i) {
981 if (c1 < withSlices.size() &&
i == withSlices[c1]) {
982 slice[0] = bounds[c1].first;
983 slice[1] = bounds[c1].second;
986 if (c2 < withSets.size() &&
i == withSets[c2]) {
987 for (
auto z = 0U;
z <
sizes[c2]; ++
z) {
988 pset.push_back(
i + 1 +
z);
992 pswriter(0, -1 *
i, 0.5 *
i, 2 *
i, references[
i], slice, pset);
995 auto pst = o2::aod::PointsSelfIndex{t3};
996 pst.bindInternalIndicesTo(&pst);
999 for (
auto& p : pst) {
1000 auto ops = p.pointSeq_as<o2::aod::PointsSelfIndex>();
1001 for (
auto& pp : ops) {
1002 auto bpp = std::same_as<std::decay_t<
decltype(pp)>, o2::aod::PointsSelfIndex::iterator>;
1004 auto opps = pp.pointSeq_as<o2::aod::PointsSelfIndex>();
1005 for (
auto& ppp : opps) {
1006 auto bppp = std::same_as<std::decay_t<
decltype(ppp)>, o2::aod::PointsSelfIndex::iterator>;
1008 auto oppps = ppp.pointSeq_as<o2::aod::PointsSelfIndex>();
1009 for (
auto& pppp : oppps) {
1010 auto bpppp = std::same_as<std::decay_t<
decltype(pppp)>, o2::aod::PointsSelfIndex::iterator>;
1012 auto opppps = pppp.pointSeq_as<o2::aod::PointsSelfIndex>();
1020 auto corewriter =
b.
cursor<o2::aod::Points3Ds>();
1021 for (
auto i = 0;
i < 20; ++
i) {
1022 corewriter(0, -1 *
i, 0.5 *
i, 2 *
i);
1024 auto t1 =
b.finalize();
1029 auto extwriter = be.
cursor<o2::aod::PointsSelfRef>();
1030 for (
auto i = 0;
i < 20; ++
i) {
1034 if (c1 < withSlices.size() &&
i == withSlices[c1]) {
1035 slice[0] = bounds[c1].first;
1036 slice[1] = bounds[c1].second;
1039 if (c2 < withSets.size() &&
i == withSets[c2]) {
1040 for (
auto z = 0U;
z <
sizes[c2]; ++
z) {
1041 pset.push_back(
i + 1 +
z);
1045 extwriter(0, references[
i], slice, pset);
1049 FullPoints fp({
t1, t2});
1050 fp.bindInternalIndicesTo(&fp);
1054 for (
auto& p : fp) {
1055 REQUIRE(std::same_as<std::decay_t<
decltype(p)>, FullPoints::iterator>);
1056 auto ops = p.pointSeq_as<FullPoints>();
1057 for (
auto& pp : ops) {
1058 REQUIRE(std::same_as<std::decay_t<
decltype(pp)>, FullPoints::iterator>);
1059 auto opps = pp.pointSeq_as<FullPoints>();
1060 for (
auto& ppp : opps) {
1061 REQUIRE(std::same_as<std::decay_t<
decltype(ppp)>, FullPoints::iterator>);
1062 auto oppps = ppp.pointSeq_as<FullPoints>();
1063 for (
auto& pppp : oppps) {
1064 REQUIRE(std::same_as<std::decay_t<
decltype(pppp)>, FullPoints::iterator>);
1065 auto opppps = pppp.pointSeq_as<FullPoints>();
1071 auto const& fpa = fp;
1074 for (
auto const& it1 : fpa) {
1075 [[maybe_unused]]
auto it2 = fpa.rawIteratorAt(0);
1076 [[maybe_unused]]
auto it3 = fpa.iteratorAt(0);
1077 auto bit1 = std::same_as<std::decay_t<
decltype(it1)>, std::decay_t<
decltype(it2)>>;
1079 auto bit2 = std::same_as<std::decay_t<
decltype(it1)>, std::decay_t<
decltype(it3)>>;
1088 for (
auto& p : ffp) {
1089 REQUIRE(std::same_as<std::decay_t<
decltype(p)>, FilteredPoints::iterator>);
1090 REQUIRE(std::same_as<std::decay_t<
decltype(p)>::parent_t, FilteredPoints>);
1091 auto ops = p.pointSeq_as<
typename std::decay_t<
decltype(p)>::parent_t>();
1092 for (
auto& pp : ops) {
1093 REQUIRE(std::same_as<std::decay_t<
decltype(pp)>::parent_t, FilteredPoints>);
1094 auto opps = pp.pointSeq_as<FilteredPoints>();
1095 for (
auto& ppp : opps) {
1096 REQUIRE(std::same_as<std::decay_t<
decltype(ppp)>, FilteredPoints::iterator>);
1097 auto oppps = ppp.pointSeq_as<FilteredPoints>();
1098 for (
auto& pppp : oppps) {
1099 REQUIRE(std::same_as<std::decay_t<
decltype(pppp)>, FilteredPoints::iterator>);
1100 auto opppps = pppp.pointSeq_as<FilteredPoints>();
1106 auto const& ffpa = ffp;
1109 for (
auto const& it1 : ffpa) {
1110 [[maybe_unused]]
auto it2 = ffpa.rawIteratorAt(0);
1111 [[maybe_unused]]
auto it3 = ffpa.iteratorAt(0);
1112 using T1 = std::decay_t<
decltype(it1)>;
1113 using T2 = std::decay_t<
decltype(it2)>;
1114 using T3 = std::decay_t<
decltype(it3)>;
1115 auto bit1 = !std::same_as<T1, T2>;
1117 auto bit2 = !std::same_as<T1, T3>;
1119 auto bit3 = std::same_as<typename T1::policy_t, typename T3::policy_t>;
1121 auto bit4 = std::same_as<typename T1::policy_t, o2::soa::FilteredIndexPolicy>;
1123 auto bit5 = std::same_as<typename T2::policy_t, o2::soa::DefaultIndexPolicy>;
1131 auto writer =
b.
cursor<o2::aod::Lists>();
1132 std::vector<float> floats;
1133 std::vector<int> ints;
1134 for (
auto i = 1;
i < 11; ++
i) {
1137 for (
auto j = 0;
j <
i; ++
j) {
1138 floats.push_back(0.1231233f * (
float)
j + 0.1982798f);
1139 ints.push_back(
j + 10);
1142 writer(0, floats, ints);
1144 auto lt =
b.finalize();
1145 o2::aod::Lists tbl{lt};
1147 for (
auto&
row : tbl) {
1150 auto constexpr bf = std::same_as<
decltype(
f), gsl::span<
const float, (
size_t)-1>>;
1151 auto constexpr bi = std::same_as<
decltype(
i), gsl::span<
const int, (
size_t)-1>>;
1154 REQUIRE(
f.size() == s);
1155 REQUIRE(
i.size() == s);
1157 for (
auto j = 0u;
j <
f.size(); ++
j) {
1158 REQUIRE(
f[
j] == 0.1231233f * (
float)
j + 0.1982798f);
1159 REQUIRE(
i[
j] == (
int)
j + 10);
1168 auto writer =
b.
cursor<o2::aod::Origints>();
1169 for (
auto i = 0;
i < 20; ++
i) {
1170 writer(0,
i,
i % 3 == 0);
1172 auto origins =
b.finalize();
1173 o2::aod::Origints o{origins};
1176 auto writer_w =
w.
cursor<o2::aod::References>();
1178 for (
auto i = 0;
i < 5 * 20; ++
i) {
1184 auto refs =
w.finalize();
1185 o2::aod::References
r{refs};
1188 ArrowTableSlicingCache atscache({{o2::soa::getLabelFromType<o2::aod::References>(), o2::soa::getMatcherFromTypeForKey<o2::aod::References>(
key),
key}});
1189 auto s = atscache.updateCacheEntry(0, refs);
1192 for (
auto& oi : o) {
1193 auto cachedSlice =
r.sliceByCached(o2::aod::test::origintId, oi.globalIndex(), cache);
1194 REQUIRE(cachedSlice.size() == 5);
1195 for (
auto& ri : cachedSlice) {
1196 REQUIRE(ri.origintId() == oi.globalIndex());
1204 auto writer =
b.
cursor<o2::aod::Origints>();
1205 for (
auto i = 0;
i < 20; ++
i) {
1206 writer(0,
i,
i % 3 == 0);
1208 auto origins =
b.finalize();
1209 o2::aod::Origints o{origins};
1212 auto writer_w =
w.
cursor<o2::aod::References>();
1214 for (
auto i = 0;
i < 5 * 20; ++
i) {
1220 auto refs =
w.finalize();
1221 o2::aod::References
r{refs};
1224 auto writer_w2 = w2.
cursor<o2::aod::OtherReferences>();
1226 for (
auto i = 0;
i < 5 * 20; ++
i) {
1233 o2::aod::OtherReferences r2{refs2};
1236 J rr{{refs, refs2}};
1240 auto s = atscache.updateCacheEntry(0, refs2);
1243 for (
auto& oi : o) {
1244 auto cachedSlice = rr.sliceByCached(o2::aod::test::altOrigintId, oi.globalIndex(), cache);
1245 REQUIRE(cachedSlice.size() == 3);
1246 for (
auto& ri : cachedSlice) {
1247 REQUIRE(ri.altOrigintId() == oi.globalIndex());
1255 auto writer =
b.
cursor<o2::aod::Origints>();
1256 for (
auto i = 0;
i < 20; ++
i) {
1257 writer(0,
i,
i % 3 == 0);
1259 auto origins =
b.finalize();
1260 o2::aod::Origints o{origins};
1263 auto writer_w =
w.
cursor<o2::aod::References>();
1265 for (
auto i = 0;
i < 5 * 20; ++
i) {
1271 auto refs =
w.finalize();
1272 o2::aod::References
r{refs};
1275 auto writer_w2 = w2.
cursor<o2::aod::OtherReferences>();
1277 for (
auto i = 0;
i < 5 * 20; ++
i) {
1284 o2::aod::OtherReferences r2{refs2};
1287 J rr{{refs, refs2}};
1289 auto rrf = rr.
select(o2::aod::test::altOrigintId > 2 && o2::aod::test::altOrigintId < 15);
1293 auto s = atscache.updateCacheEntry(0, refs2);
1296 for (
auto& oi : o) {
1297 auto cachedSlice = rrf.sliceByCached(o2::aod::test::altOrigintId, oi.globalIndex(), cache);
1298 if (oi.globalIndex() <= 2 || oi.globalIndex() >= 15) {
1299 CHECK(cachedSlice.size() == 0);
1301 CHECK(cachedSlice.size() == 3);
1303 for (
auto& ri : cachedSlice) {
1304 REQUIRE(ri.altOrigintId() == oi.globalIndex());
1312 auto prwriter =
b.
cursor<o2::aod::PointsRefF>();
1313 auto a = std::array{0, 1};
1314 auto aa = std::vector{2, 3, 4};
1315 prwriter(0, 0, &
a[0], aa);
1318 prwriter(0, 1, &
a[0], aa);
1319 auto t =
b.finalize();
1320 auto prt = o2::aod::PointsRefF{t};
1322 for (
auto&
row : prt) {
1324 [[maybe_unused]]
auto sp =
row.singlePoint();
1326 REQUIRE(std::string{
error_from_ref(
ref).
what} ==
"Index pointing to Points3Ds is not bound! Did you subscribe to the table?");
1329 auto ps =
row.pointSlice();
1331 REQUIRE(std::string{
error_from_ref(
ref).
what} ==
"Index pointing to Points3Ds is not bound! Did you subscribe to the table?");
1334 auto pg =
row.pointGroup();
1336 REQUIRE(std::string{
error_from_ref(
ref).
what} ==
"Index pointing to Points3Ds is not bound! Did you subscribe to the table?");
1355 auto writer =
b.
cursor<o2::aod::BILists>();
1357 for (
auto i = 0;
i < 20; ++
i) {
1359 for (
auto j = 0;
j < 32; ++
j) {
1367 auto t =
b.finalize();
1369 o2::aod::BILists li{t};
1370 for (
auto const&
row : li) {
1371 auto iir =
row.smallIntArray();
1372 [[maybe_unused]]
auto bbrr =
row.boolArray_raw();
1373 REQUIRE(std::same_as<std::decay_t<
decltype(iir)>, int8_t
const*>);
1374 for (
auto i = 0;
i < 32; ++
i) {
1375 REQUIRE(iir[
i] ==
i);
1376 REQUIRE(
row.boolArray_bit(
i) == (
i % 2 == 0));
1393 table::One, table::Two, table::Three, table::Four,
1394 table::Five<table::Four>);
1400 auto writer =
b.
cursor<o2::aod::MixTest>();
1402 for (
auto i = 0;
i < 20; ++
i) {
1407 auto t =
b.finalize();
1408 o2::aod::MixTest mt{t};
1410 for (
auto const&
row : mt) {
1411 auto features1 =
row.getValues<float, o2::aod::table::One, o2::aod::table::Three>();
1412 auto features2 =
row.getValues<double, o2::aod::table::One, o2::aod::table::Two, o2::aod::table::Three>();
1413 auto features3 =
row.getValues<float, o2::aod::table::Two, o2::aod::table::Five<o2::aod::table::Four>>();
1414 auto b1 = std::same_as<std::array<float, 2>,
decltype(features1)>;
1416 auto b2 = std::same_as<std::array<double, 3>,
decltype(features2)>;
1418 auto b3 = std::same_as<std::array<float, 2>,
decltype(features3)>;
1420 REQUIRE(features1[0] == (
float)
count);
1423 REQUIRE(features2[0] == (
double)
count);
1428 REQUIRE(features3[1] == (
float)((
float)
count / (
float)(
count + 1)));
1471 REQUIRE(cursor.
lastIndex() + 1 <= reserved);
1473 auto table = builder->finalize();
1474 REQUIRE(table->num_rows() == 5);
1475 REQUIRE(table->num_columns() == 2);
1497 auto max8 = std::numeric_limits<uint8_t>::max();
1498 auto max16 = std::numeric_limits<uint8_t>::max();
1499 auto max32 = std::numeric_limits<uint8_t>::max();
1500 auto max64 = std::numeric_limits<uint8_t>::max();
1503 auto writer8 = b8.
cursor<o2::aod::UnsignedIntTest8>();
1504 for (uint64_t
i = 0;
i < max8;
i += (max8 / 100)) {
1508 o2::aod::UnsignedIntTest8 at8{{t8}};
1510 uint8_t limit8 = max8 / 2 + 1;
1516 REQUIRE(at8.size() == 128);
1517 REQUIRE(fat8.size() == 64);
1520 auto writer16 = b16.
cursor<o2::aod::UnsignedIntTest16>();
1521 for (uint64_t
i = 0;
i < max16;
i += (max16 / 100)) {
1525 o2::aod::UnsignedIntTest16 at16{{t16}};
1527 uint16_t limit16 = max16 / 2 + 1;
1533 REQUIRE(at16.size() == 128);
1534 REQUIRE(fat16.size() == 64);
1537 auto writer32 = b32.
cursor<o2::aod::UnsignedIntTest32>();
1538 for (uint64_t
i = 0;
i < max32;
i += (max32 / 100)) {
1542 o2::aod::UnsignedIntTest32 at32{{t32}};
1544 uint32_t limit32 = max32 / 2 + 1;
1550 REQUIRE(at32.size() == 128);
1551 REQUIRE(fat32.size() == 64);
1554 auto writer64 = b64.
cursor<o2::aod::UnsignedIntTest64>();
1555 for (uint64_t
i = 0;
i < max64;
i += (max64 / 100)) {
1559 o2::aod::UnsignedIntTest64 at64{{t64}};
1561 uint64_t limit64 = max64 / 2 + 1;
1567 REQUIRE(at64.size() == 128);
1568 REQUIRE(fat64.size() == 64);
#define DECLARE_SOA_ARRAY_INDEX_COLUMN(_Name_, _Getter_)
#define DECLARE_SOA_SLICE_INDEX_COLUMN(_Name_, _Getter_)
#define DECLARE_SOA_DYNAMIC_COLUMN(_Name_, _Getter_,...)
#define DECLARE_SOA_SELF_INDEX_COLUMN(_Name_, _Getter_)
#define DECLARE_SOA_TABLE(_Name_, _Origin_, _Desc_,...)
#define DECLARE_SOA_EXPRESSION_COLUMN(_Name_, _Getter_, _Type_, _Expression_)
#define DECLARE_SOA_COLUMN(_Name_, _Getter_, _Type_)
#define DECLARE_SOA_INDEX_COLUMN_FULL(_Name_, _Getter_, _Type_, _Table_, _Suffix_)
#define DECLARE_SOA_SELF_SLICE_INDEX_COLUMN(_Name_, _Getter_)
#define DECLARE_SOA_COLUMN_FULL(_Name_, _Getter_, _Type_, _Label_)
#define DECLARE_SOA_TABLE_VERSIONED(_Name_, _Origin_, _Desc_, _Version_,...)
#define DECLARE_SOA_INDEX_COLUMN(_Name_, _Getter_)
#define DECLARE_SOA_BITMAP_COLUMN(_Name_, _Getter_, _Size_)
#define DECLARE_SOA_SELF_ARRAY_INDEX_COLUMN(_Name_, _Getter_)
std::shared_ptr< arrow::Schema > schema
std::shared_ptr< T > get(const HistName &histName)
auto persist(std::array< char const *, sizeof...(ARGS)+1 > const &columnNames)
std::shared_ptr< arrow::Table > finalize()
void bindInternalIndicesTo(I const *ptr)
unfiltered_iterator begin()
auto select(framework::expressions::Filter const &f) const
float sum(float s, o2::dcs::DataPointValue v)
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * value
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLboolean GLboolean GLboolean GLboolean a
GLubyte GLubyte GLubyte GLubyte w
GLdouble GLdouble GLdouble z
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
std::shared_ptr< gandiva::SelectionVector > Selection
gandiva::Selection createSelection(std::shared_ptr< arrow::Table > const &table, Filter const &expression)
Function for creating gandiva selection from our internal filter tree.
Defining ITS Vertex explicitly as messageable.
RuntimeError & error_from_ref(RuntimeErrorRef)
std::string cutString(std::string &&str)
auto createFieldsFromColumns(framework::pack< C... >)
constexpr auto join(Ts const &... t)
std::vector< int64_t > SelectionVector
FIXME: do not use data model tables.
char what[MAX_RUNTIME_ERROR_SIZE]
int64_t lastIndex()
Last index inserted in the table.
bool resetCursor(LifetimeHolder< TableBuilder > builder)
void reserve(int64_t size)
A struct, containing the root of the expression tree.