17#include "gandiva/tree_expr_builder.h"
18#include "arrow/status.h"
19#include "gandiva/filter.h"
20#include <catch_amalgamated.hpp>
21#include <arrow/util/key_value_metadata.h>
63DECLARE_SOA_TABLE(Segments,
"TEST",
"SEGMENTS", test::N, test::PointAId, test::PointBId, test::InfoId);
78 auto pwriter = b1.
cursor<o2::aod::Points3Ds>();
79 for (
auto i = 0;
i < 20; ++
i) {
80 pwriter(0, -1 *
i, (
int)(
i / 2), 2 *
i);
84 auto pt = o2::aod::Points3Ds{
t1};
85 auto pt1 = o2::aod::Points3DMk1s{
t1};
86 auto pt2 = o2::aod::Points3DMk2s{
t1};
87 auto pt3 = o2::aod::Points3DMk3s{
t1};
88 REQUIRE(pt1.begin().mark() == (
size_t)1);
89 REQUIRE(pt2.begin().mark() == (
size_t)2);
90 REQUIRE(pt3.begin().mark() == (
size_t)3);
96 auto rowWriter = builder.
persist<int32_t, int32_t>({
"fX",
"fY"});
110 i.mCurrentPos = &
pos;
128 arrow::ChunkedArray* chunks[2] = {
129 table->column(0).get(),
130 table->column(1).get()};
131 o2::aod::Points::iterator tests(chunks, {table->num_rows(), 0});
132 REQUIRE(tests.x() == 0);
133 REQUIRE(tests.y() == 0);
135 REQUIRE(tests.x() == 0);
136 REQUIRE(tests.y() == 1);
141 auto e = tests2.end();
155 REQUIRE(((
b + 1) == (
b + 1)));
156 REQUIRE(((
b + 7) !=
b));
157 REQUIRE(((
b + 7) != e));
158 REQUIRE(((
b + 8) == e));
160 for (
auto& t : tests2) {
161 REQUIRE(t.x() ==
value / 4);
162 REQUIRE((
size_t)t.y() ==
value);
167 for (
auto t1 = tests2.begin();
t1 != tests2.end(); ++
t1) {
168 for (
auto t2 =
t1 + 1; t2 != tests2.end(); ++t2) {
176 auto rowWriter = builder.
persist<int32_t, int32_t>({
"fX",
"fY"});
187 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>>;
190 for (
auto&
test : tests1) {
194 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>>;
197 for (
auto&
test : tests2) {
205 auto rowWriter = builder.
persist<int32_t, int32_t>({
"fX",
"fY"});
219 foo.mCurrentPos = &index1;
221 bar.mCurrentPos = &index2;
222 REQUIRE(
foo.mCurrent == bar.mCurrent);
223 REQUIRE(
foo.mLast == bar.mLast);
224 REQUIRE(
foo.mColumn == bar.mColumn);
225 REQUIRE(
foo.mFirstIndex == bar.mFirstIndex);
226 REQUIRE(
foo.mCurrentChunk == bar.mCurrentChunk);
228 auto foobar = std::move(
foo);
229 REQUIRE(foobar.mCurrent == bar.mCurrent);
230 REQUIRE(foobar.mLast == bar.mLast);
231 REQUIRE(foobar.mColumn == bar.mColumn);
232 REQUIRE(foobar.mFirstIndex == bar.mFirstIndex);
233 REQUIRE(foobar.mCurrentChunk == bar.mCurrentChunk);
239 auto rowWriterX = builderX.
persist<int32_t>({
"fX"});
251 auto rowWriterY = builderY.
persist<int32_t>({
"fY"});
263 auto rowWriterZ = builderZ.
persist<int32_t>({
"fZ"});
275 auto rowWriterW = builderW.
persist<int32_t>({
"fW"});
287 REQUIRE(Test::contains<TestX>());
288 REQUIRE(Test::contains<TestY>());
289 REQUIRE(!Test::contains<TestZ>());
291 Test tests{{tableX, tableY}};
293 REQUIRE(tests.contains<TestX>());
294 REQUIRE(tests.contains<TestY>());
295 REQUIRE(!tests.contains<TestZ>());
297 for (
auto&
test : tests) {
301 auto tests2 =
join(TestX{tableX}, TestY{tableY});
302 static_assert(std::same_as<Test::self_t,
decltype(tests2)>,
"Joined tables should have the same type, regardless how we construct them");
303 for (
auto&
test : tests2) {
307 auto tests3 =
join(TestX{tableX}, TestY{tableY}, TestZ{tableZ});
309 for (
auto&
test : tests3) {
313 TestMoreThanTwo tests4{{tableX, tableY, tableZ}};
314 for (
auto&
test : tests4) {
319 auto testF =
join(TestZ{tableZ}, TestW{tableW});
321 REQUIRE(std::string{
error_from_ref(
ref).
what} ==
"Tables TEST and TEST have different sizes (8 vs 3) and cannot be joined!");
328 auto rowWriterA = builderA.
persist<int32_t, int32_t>({
"fX",
"fY"});
338 REQUIRE(tableA->num_rows() == 8);
341 auto rowWriterB = builderB.
persist<int32_t>({
"fX"});
353 auto rowWriterC = builderC.
persist<int32_t>({
"fZ"});
365 auto rowWriterD = builderD.
persist<int32_t, int32_t>({
"fX",
"fZ"});
366 rowWriterD(0, 16, 8);
367 rowWriterD(0, 17, 9);
368 rowWriterD(0, 18, 10);
369 rowWriterD(0, 19, 11);
370 rowWriterD(0, 20, 12);
371 rowWriterD(0, 21, 13);
372 rowWriterD(0, 22, 14);
373 rowWriterD(0, 23, 15);
385 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");
387 static_assert(std::same_as<ConcatTest::columns_t, o2::framework::pack<o2::soa::Index<>, o2::aod::test::X>>,
"Bad intersection of columns");
388 ConcatTest tests{{tableA, tableB}};
389 REQUIRE(16 == tests.size());
390 for (
auto&
test : tests) {
394 static_assert(std::same_as<NestedConcatTest::columns_t, o2::framework::pack<o2::aod::test::X>>,
"Bad nested concat");
401 auto status = gandiva::SelectionVector::MakeInt64(tests.size(), arrow::default_memory_pool(), &selection);
402 REQUIRE(status.ok());
404 auto fptr = tableA->schema()->GetFieldByName(
"fX");
405 REQUIRE(fptr !=
nullptr);
406 REQUIRE(fptr->name() ==
"fX");
407 REQUIRE(fptr->type()->id() == arrow::Type::INT32);
409 auto node_x = gandiva::TreeExprBuilder::MakeField(fptr);
410 auto literal_1 = gandiva::TreeExprBuilder::MakeLiteral(
static_cast<int32_t
>(1));
411 auto literal_3 = gandiva::TreeExprBuilder::MakeLiteral(
static_cast<int32_t
>(3));
412 auto equals_to_1 = gandiva::TreeExprBuilder::MakeFunction(
"equal", {node_x, literal_1}, arrow::boolean());
413 auto equals_to_3 = gandiva::TreeExprBuilder::MakeFunction(
"equal", {node_x, literal_3}, arrow::boolean());
414 auto node_or = gandiva::TreeExprBuilder::MakeOr({equals_to_1, equals_to_3});
415 auto condition = gandiva::TreeExprBuilder::MakeCondition(node_or);
416 REQUIRE(condition->ToString() ==
"bool equal((int32) fX, (const int32) 1) || bool equal((int32) fX, (const int32) 3)");
417 std::shared_ptr<gandiva::Filter>
filter;
418 status = gandiva::Filter::Make(tableA->schema(), condition, &
filter);
419 REQUIRE(status.ToString() ==
"OK");
421 arrow::TableBatchReader reader(*tableA);
422 std::shared_ptr<RecordBatch> batch;
423 auto s = reader.ReadNext(&batch);
425 REQUIRE(batch !=
nullptr);
426 REQUIRE(batch->num_rows() == 8);
427 auto st =
filter->Evaluate(*batch, selection);
428 REQUIRE(
st.ToString() ==
"OK");
433 FilteredTest filtered{{testA.asArrowTableRef()}, selection_f};
434 REQUIRE(2 == filtered.size());
437 REQUIRE(filtered.begin() != filtered.end());
438 for (
auto&
f : filtered) {
439 REQUIRE(
i * 2 + 1 ==
f.x());
440 REQUIRE(
i * 2 + 1 ==
f.index());
449 status = gandiva::SelectionVector::MakeInt64(tests.size(), arrow::default_memory_pool(), &selectionConcat);
450 REQUIRE(status.ok() ==
true);
451 selectionConcat->SetIndex(0, 0);
452 selectionConcat->SetIndex(1, 5);
453 selectionConcat->SetIndex(2, 10);
454 selectionConcat->SetNumSlots(3);
455 ConcatTest concatTest{tableA, tableB};
456 FilteredConcatTest concatTestTable{{concatTest.asArrowTableRef()}, selectionConcat};
457 REQUIRE(3 == concatTestTable.size());
460 auto b = concatTestTable.begin();
461 auto e = concatTestTable.end();
463 REQUIRE(
b.mRowIndex == 0);
464 REQUIRE(
b.getSelectionRow() == 0);
465 REQUIRE(e.index == 3);
467 REQUIRE(concatTestTable.begin() != concatTestTable.end());
468 for (
auto&
f : concatTestTable) {
469 REQUIRE(
i * 5 ==
f.x());
470 REQUIRE(
i * 5 ==
f.index());
471 REQUIRE(
i ==
f.filteredIndex());
479 status = gandiva::SelectionVector::MakeInt64(tests.size(), arrow::default_memory_pool(), &selectionJoin);
480 REQUIRE(status.ok() ==
true);
481 selectionJoin->SetIndex(0, 0);
482 selectionJoin->SetIndex(1, 2);
483 selectionJoin->SetIndex(2, 4);
484 selectionJoin->SetNumSlots(3);
485 JoinedTest testJoin{{tableA, tableC}};
486 FilteredJoinTest filteredJoin{{testJoin.asArrowTableRef()}, selectionJoin};
489 REQUIRE(filteredJoin.begin() != filteredJoin.end());
490 for (
auto&
f : filteredJoin) {
491 REQUIRE(
i * 2 ==
f.x());
492 REQUIRE(
i * 2 ==
f.index());
501 auto pointsWriter = builderA.
cursor<o2::aod::Points>();
502 pointsWriter(0, 0, 0);
503 pointsWriter(0, 3, 4);
505 o2::aod::Points points{pointsT};
506 REQUIRE(pointsT->num_rows() == 2);
509 auto infoWriter = builderA2.
cursor<o2::aod::Infos>();
510 infoWriter(0, 0,
true);
511 infoWriter(0, 1,
false);
512 infoWriter(0, 4,
true);
514 o2::aod::Infos infos{infosT};
515 REQUIRE(infos.begin().someBool() ==
true);
516 REQUIRE((infos.begin() + 1).someBool() ==
false);
517 REQUIRE((infos.begin() + 2).someBool() ==
true);
518 REQUIRE((infos.begin() + 2).color() == 4);
519 REQUIRE(infosT->num_rows() == 3);
522 auto segmentsWriter = builderB.
cursor<o2::aod::Segments>();
523 segmentsWriter(0, 10, 0, 1, 2);
524 auto segmentsT = builderB.
finalize();
525 o2::aod::Segments
segments{segmentsT};
526 REQUIRE(segmentsT->num_rows() == 1);
529 auto segmentsExtraWriter = builderC.
cursor<o2::aod::SegmentsExtras>();
530 segmentsExtraWriter(0, 1);
531 auto segmentsExtraT = builderC.
finalize();
532 o2::aod::SegmentsExtras segmentsExtras{segmentsExtraT};
533 REQUIRE(segmentsExtraT->num_rows() == 1);
535 REQUIRE(
segments.begin().pointAId() == 0);
536 REQUIRE(
segments.begin().pointBId() == 1);
537 static_assert(std::same_as<
decltype(
segments.begin().pointA()), o2::aod::Points::iterator>);
540 i.bindExternalIndices(&points, &infos);
541 REQUIRE(
i.n() == 10);
542 REQUIRE(
i.info().color() == 4);
543 REQUIRE(
i.info().someBool() ==
true);
544 REQUIRE(
i.pointA().x() == 0);
545 REQUIRE(
i.pointA().y() == 0);
546 REQUIRE(
i.pointB().x() == 3);
547 REQUIRE(
i.pointB().y() == 4);
549 segments.bindExternalIndices(&points, &infos);
551 REQUIRE(
j.n() == 10);
552 REQUIRE(
j.info().color() == 4);
553 REQUIRE(
j.info().someBool() ==
true);
554 REQUIRE(
j.pointA().x() == 0);
555 REQUIRE(
j.pointA().y() == 0);
556 REQUIRE(
j.pointB().x() == 3);
557 REQUIRE(
j.pointB().y() == 4);
560 joined.bindExternalIndices(&points, &infos);
561 auto se = joined.begin();
562 REQUIRE(se.n() == 10);
563 REQUIRE(se.info().color() == 4);
564 REQUIRE(se.pointA().x() == 0);
565 REQUIRE(se.pointA().y() == 0);
566 REQUIRE(se.pointB().x() == 3);
567 REQUIRE(se.pointB().y() == 4);
568 REQUIRE(se.thickness() == 1);
574 REQUIRE(
schema->num_fields() == 2);
575 REQUIRE(
schema->field(0)->name() ==
"fX");
576 REQUIRE(
schema->field(1)->name() ==
"fY");
582 auto rowWriterA = builderA.
persist<int32_t, int32_t>({
"fX",
"fY"});
585 rowWriterA(0, 2, 10);
586 rowWriterA(0, 3, 11);
587 rowWriterA(0, 4, 12);
588 rowWriterA(0, 5, 13);
589 rowWriterA(0, 6, 14);
590 rowWriterA(0, 7, 15);
592 REQUIRE(tableA->num_rows() == 8);
602 auto s1 = expressions::createSelection(testA.asArrowTable(), f1);
603 FilteredTest filtered1{{testA.asArrowTableRef()},
s1};
604 REQUIRE(4 == filtered1.size());
605 REQUIRE(filtered1.begin() != filtered1.end());
607 auto s2 = expressions::createSelection(testA.asArrowTable(), f2);
608 FilteredTest filtered2{{testA.asArrowTableRef()}, s2};
609 REQUIRE(2 == filtered2.size());
610 REQUIRE(filtered2.begin() != filtered2.end());
612 FilteredTest filteredUnion = filtered1 + filtered2;
613 REQUIRE(6 == filteredUnion.size());
615 std::vector<std::tuple<int32_t, int32_t>> expectedUnion{{0, 8}, {1, 9}, {2, 10}, {3, 11}, {6, 14}, {7, 15}};
617 for (
auto&
f : filteredUnion) {
618 REQUIRE(std::get<0>(expectedUnion[
i]) ==
f.x());
619 REQUIRE(std::get<1>(expectedUnion[
i]) ==
f.y());
620 REQUIRE(std::get<0>(expectedUnion[
i]) ==
f.index());
625 FilteredTest filteredIntersection = filtered1 * filtered2;
626 REQUIRE(0 == filteredIntersection.size());
629 for (
auto const& _ : filteredIntersection) {
635 auto s3 = expressions::createSelection(testA.asArrowTable(), f3);
636 FilteredTest filtered3{{testA.asArrowTableRef()}, s3};
637 REQUIRE(3 == filtered3.size());
638 REQUIRE(filtered3.begin() != filtered3.end());
640 FilteredTest unionIntersection = (filtered1 + filtered2) * filtered3;
641 REQUIRE(3 == unionIntersection.size());
644 for (
auto&
f : unionIntersection) {
646 REQUIRE(
i + 8 ==
f.y());
647 REQUIRE(
i ==
f.index());
656 auto rowWriterA = builderA.
persist<int32_t, int32_t>({
"fX",
"fY"});
659 rowWriterA(0, 2, 10);
660 rowWriterA(0, 3, 11);
661 rowWriterA(0, 4, 12);
662 rowWriterA(0, 5, 13);
663 rowWriterA(0, 6, 14);
664 rowWriterA(0, 7, 15);
666 REQUIRE(tableA->num_rows() == 8);
679 auto s1 = expressions::createSelection(testA.asArrowTable(), f1);
680 FilteredTest filtered{{testA.asArrowTableRef()},
s1};
681 REQUIRE(4 == filtered.size());
682 REQUIRE(filtered.begin() != filtered.end());
684 auto s2 = expressions::createSelection(filtered.asArrowTable(), f2);
685 NestedFilteredTest nestedFiltered{{filtered}, s2};
686 REQUIRE(2 == nestedFiltered.size());
688 for (
auto&
f : nestedFiltered) {
689 REQUIRE(
i + 2 ==
f.x());
690 REQUIRE(
i + 10 ==
f.y());
691 REQUIRE(
i + 2 ==
f.index());
696 auto s3 = expressions::createSelection(nestedFiltered.asArrowTable(), f3);
697 TripleNestedFilteredTest tripleFiltered{{nestedFiltered}, s3};
698 REQUIRE(1 == tripleFiltered.size());
700 for (
auto&
f : tripleFiltered) {
701 REQUIRE(
i + 2 ==
f.x());
702 REQUIRE(
i + 10 ==
f.y());
703 REQUIRE(
i + 2 ==
f.index());
712 [[maybe_unused]]
auto pwriter = bPoints.
cursor<o2::aod::Points>();
716 [[maybe_unused]]
auto iwriter = bInfos.
cursor<o2::aod::Infos>();
719 o2::aod::Points p{pempty};
720 o2::aod::Infos
i{iempty};
723 PI pi{{pempty, iempty}};
724 REQUIRE(pi.size() == 0);
725 auto spawned = Extend<o2::aod::Points, o2::aod::test::ESum>(p);
726 REQUIRE(spawned.size() == 0);
747 auto writer =
b.
cursor<o2::aod::Origints>();
748 for (
auto i = 0;
i < 20; ++
i) {
749 writer(0,
i,
i % 3 == 0);
751 auto origins =
b.finalize();
752 o2::aod::Origints o{origins};
755 auto writer_z =
z.
cursor<o2::aod::ManyReferences>();
756 std::vector<int>
ids;
757 for (
auto i = 0;
i < 5; ++
i) {
759 for (
auto j = 0;
j < 20; ++
j) {
764 auto mrefs =
z.finalize();
765 o2::aod::ManyReferences
m{mrefs};
768 auto writer_w =
w.
cursor<o2::aod::References>();
769 for (
auto i = 0;
i < 5 * 20; ++
i) {
772 auto refs =
w.finalize();
773 o2::aod::References
r{refs};
776 auto selection = expressions::createSelection(o.asArrowTable(), flt);
777 Flt
f{{o.asArrowTableRef()}, selection};
778 r.bindExternalIndices(&
f);
781 REQUIRE(it.origint_as<Flt>().globalIndex() == 3);
783 REQUIRE(it.origint_as<Flt>().globalIndex() == 4);
785 REQUIRE(it.origint_as<Flt>().globalIndex() == 5);
787 m.bindExternalIndices(&
f);
788 for (
auto const&
row :
m) {
789 auto os =
row.origints_as<Flt>();
790 auto fos =
row.filtered_origints_as<Flt>();
791 REQUIRE(os.size() == 20);
792 REQUIRE(fos.size() == 6);
808DECLARE_SOA_TABLE(PointsRefF,
"TEST",
"PTSREFF", test::SinglePointId, test::Points3DIdSlice, test::Points3DIds);
810 test::PointSeqIdSlice, test::PointSetIds);
816 auto pwriter = b1.
persist<
int,
int,
int>({
"fX",
"fY",
"fZ"});
817 for (
auto i = 0;
i < 20; ++
i) {
818 pwriter(0, -1 *
i, (
int)(
i / 2), 2 *
i);
823 auto prwriter = b2.
cursor<o2::aod::PointsRef>();
824 auto a = std::array{0, 1};
825 auto aa = std::vector{2, 3, 4};
826 prwriter(0, &
a[0], aa);
829 prwriter(0, &
a[0], aa);
832 auto pt = o2::aod::Points3Ds{tpts1};
833 auto prt = o2::aod::PointsRef{t2};
834 prt.bindExternalIndices(&pt);
836 auto it = prt.begin();
837 auto s1 = it.pointSlice();
838 auto g1 = it.pointGroup();
839 auto bb = std::same_as<
decltype(
s1), o2::aod::Points3Ds>;
841 REQUIRE(
s1.size() == 2);
843 for (
int i = 0;
i < 3; ++
i) {
844 REQUIRE(g1[
i].globalIndex() == aa[
i]);
849 for (
auto& p : it.pointGroup_as<o2::aod::Points3Ds>()) {
850 REQUIRE(p.x() == -1 * p.globalIndex());
854 auto s2 = it.pointSlice();
855 auto g2 = it.pointGroup();
856 REQUIRE(s2.size() == 7);
858 for (
int i = 0;
i < 3; ++
i) {
859 REQUIRE(g2[
i].globalIndex() == aa[
i]);
864 Flt
f{{tpts1}, expressions::createSelection(tpts1, fltx)};
865 prt.bindExternalIndices(&
f);
867 auto it2 = prt.begin();
868 auto s1f = it2.pointSlice_as<Flt>();
869 auto g1f = it2.pointGroup_as<Flt>();
870 REQUIRE(s1f.size() == 2);
872 for (
int i = 0;
i < 3; ++
i) {
873 REQUIRE(g1f[
i].globalIndex() == aa[
i]);
877 auto s2f = it2.pointSlice_as<Flt>();
878 auto g2f = it2.pointGroup_as<Flt>();
879 REQUIRE(s2f.size() == 7);
881 for (
int i = 0;
i < 3; ++
i) {
882 REQUIRE(g2f[
i].globalIndex() == aa[
i]);
886 auto pswriter = b3.
cursor<o2::aod::PointsSelfIndex>();
887 int references[] = {19, 2, 0, 13, 4, 6, 5, 5, 11, 9, 3, 8, 16, 14, 1, 18, 12, 18, 2, 7};
888 int slice[2] = {-1, -1};
889 std::vector<int> pset;
890 std::array<int, 4> withSlices = {3, 6, 13, 19};
891 std::array<std::pair<int, int>, 4> bounds = {std::pair{1, 5}, std::pair{3, 3}, std::pair{11, 11}, std::pair{10, 18}};
892 std::array<int, 4> withSets = {0, 1, 13, 14};
893 unsigned int sizes[] = {3, 1, 5, 4};
896 for (
auto i = 0;
i < 20; ++
i) {
900 if (c1 < withSlices.size() &&
i == withSlices[c1]) {
901 slice[0] = bounds[c1].first;
902 slice[1] = bounds[c1].second;
905 if (c2 < withSets.size() &&
i == withSets[c2]) {
906 for (
auto z = 0U;
z <
sizes[c2]; ++
z) {
907 pset.push_back(
i + 1 +
z);
911 pswriter(0, -1 *
i, 0.5 *
i, 2 *
i, references[
i], slice, pset);
914 auto pst = o2::aod::PointsSelfIndex{t3};
915 pst.bindInternalIndicesTo(&pst);
919 for (
auto& p : pst) {
920 auto op = p.otherPoint_as<o2::aod::PointsSelfIndex>();
921 auto bbb = std::same_as<
decltype(
op), o2::aod::PointsSelfIndex::iterator>;
923 REQUIRE(
op.globalIndex() == references[
i]);
925 auto ops = p.pointSeq_as<o2::aod::PointsSelfIndex>();
926 auto bbbs = std::same_as<
decltype(ops), o2::aod::PointsSelfIndex>;
929 if (
i == withSlices[c1]) {
930 auto it = ops.begin();
931 REQUIRE(ops.size() == bounds[c1].second - bounds[c1].first + 1);
932 REQUIRE(it.globalIndex() == bounds[c1].first);
933 for (
auto j = 1;
j < ops.size(); ++
j) {
936 REQUIRE(it.globalIndex() == bounds[c1].second);
939 REQUIRE(ops.size() == 0);
942 auto opss = p.pointSet_as<o2::aod::PointsSelfIndex>();
943 auto bbba = std::same_as<
decltype(opss), std::vector<o2::aod::PointsSelfIndex::iterator>>;
946 auto opss_ids = p.pointSetIds();
947 if (c2 < withSets.size() &&
i == withSets[c2]) {
948 REQUIRE(opss.size() ==
sizes[c2]);
949 REQUIRE(opss.begin()->globalIndex() ==
i + 1);
950 REQUIRE(opss.back().globalIndex() ==
i +
sizes[c2]);
952 for (
auto&
id : opss_ids) {
953 REQUIRE(
id ==
i + 1 + c3);
958 REQUIRE(opss.size() == 0);
966DECLARE_SOA_TABLE(PointsSelfRef,
"TEST",
"PTSSR", test::OtherPointId, test::PointSeqIdSlice, test::PointSetIds);
972 auto pswriter = b3.
cursor<o2::aod::PointsSelfIndex>();
973 int references[] = {19, 2, 0, 13, 4, 6, 5, 5, 11, 9, 3, 8, 16, 14, 1, 18, 12, 18, 2, 7};
974 int slice[2] = {-1, -1};
975 std::vector<int> pset;
976 std::array<int, 4> withSlices = {3, 6, 13, 19};
977 std::array<std::pair<int, int>, 4> bounds = {std::pair{1, 5}, std::pair{3, 3}, std::pair{11, 11}, std::pair{10, 18}};
978 std::array<int, 4> withSets = {0, 1, 13, 14};
979 unsigned int sizes[] = {3, 1, 5, 4};
982 for (
auto i = 0;
i < 20; ++
i) {
986 if (c1 < withSlices.size() &&
i == withSlices[c1]) {
987 slice[0] = bounds[c1].first;
988 slice[1] = bounds[c1].second;
991 if (c2 < withSets.size() &&
i == withSets[c2]) {
992 for (
auto z = 0U;
z <
sizes[c2]; ++
z) {
993 pset.push_back(
i + 1 +
z);
997 pswriter(0, -1 *
i, 0.5 *
i, 2 *
i, references[
i], slice, pset);
1000 auto pst = o2::aod::PointsSelfIndex{t3};
1001 pst.bindInternalIndicesTo(&pst);
1004 for (
auto& p : pst) {
1005 auto ops = p.pointSeq_as<o2::aod::PointsSelfIndex>();
1006 for (
auto& pp : ops) {
1007 auto bpp = std::same_as<std::decay_t<
decltype(pp)>, o2::aod::PointsSelfIndex::iterator>;
1009 auto opps = pp.pointSeq_as<o2::aod::PointsSelfIndex>();
1010 for (
auto& ppp : opps) {
1011 auto bppp = std::same_as<std::decay_t<
decltype(ppp)>, o2::aod::PointsSelfIndex::iterator>;
1013 auto oppps = ppp.pointSeq_as<o2::aod::PointsSelfIndex>();
1014 for (
auto& pppp : oppps) {
1015 auto bpppp = std::same_as<std::decay_t<
decltype(pppp)>, o2::aod::PointsSelfIndex::iterator>;
1017 auto opppps = pppp.pointSeq_as<o2::aod::PointsSelfIndex>();
1025 auto corewriter =
b.
cursor<o2::aod::Points3Ds>();
1026 for (
auto i = 0;
i < 20; ++
i) {
1027 corewriter(0, -1 *
i, 0.5 *
i, 2 *
i);
1029 auto t1 =
b.finalize();
1034 auto extwriter = be.
cursor<o2::aod::PointsSelfRef>();
1035 for (
auto i = 0;
i < 20; ++
i) {
1039 if (c1 < withSlices.size() &&
i == withSlices[c1]) {
1040 slice[0] = bounds[c1].first;
1041 slice[1] = bounds[c1].second;
1044 if (c2 < withSets.size() &&
i == withSets[c2]) {
1045 for (
auto z = 0U;
z <
sizes[c2]; ++
z) {
1046 pset.push_back(
i + 1 +
z);
1050 extwriter(0, references[
i], slice, pset);
1054 FullPoints fp({
t1, t2});
1055 fp.bindInternalIndicesTo(&fp);
1059 for (
auto& p : fp) {
1060 REQUIRE(std::same_as<std::decay_t<
decltype(p)>, FullPoints::iterator>);
1061 auto ops = p.pointSeq_as<FullPoints>();
1062 for (
auto& pp : ops) {
1063 REQUIRE(std::same_as<std::decay_t<
decltype(pp)>, FullPoints::iterator>);
1064 auto opps = pp.pointSeq_as<FullPoints>();
1065 for (
auto& ppp : opps) {
1066 REQUIRE(std::same_as<std::decay_t<
decltype(ppp)>, FullPoints::iterator>);
1067 auto oppps = ppp.pointSeq_as<FullPoints>();
1068 for (
auto& pppp : oppps) {
1069 REQUIRE(std::same_as<std::decay_t<
decltype(pppp)>, FullPoints::iterator>);
1070 auto opppps = pppp.pointSeq_as<FullPoints>();
1076 auto const& fpa = fp;
1079 for (
auto& it1 : fpa) {
1080 [[maybe_unused]]
auto it2 = fpa.rawIteratorAt(0);
1081 [[maybe_unused]]
auto it3 = fpa.iteratorAt(0);
1082 auto bit1 = std::same_as<std::decay_t<
decltype(it1)>, std::decay_t<
decltype(it2)>>;
1084 auto bit2 = std::same_as<std::decay_t<
decltype(it1)>, std::decay_t<
decltype(it3)>>;
1093 for (
auto& p : ffp) {
1094 REQUIRE(std::same_as<std::decay_t<
decltype(p)>, FilteredPoints::iterator>);
1095 REQUIRE(std::same_as<std::decay_t<
decltype(p)>::parent_t, FilteredPoints>);
1096 auto ops = p.pointSeq_as<
typename std::decay_t<
decltype(p)>::parent_t>();
1097 for (
auto& pp : ops) {
1098 REQUIRE(std::same_as<std::decay_t<
decltype(pp)>::parent_t, FilteredPoints>);
1099 auto opps = pp.pointSeq_as<FilteredPoints>();
1100 for (
auto& ppp : opps) {
1101 REQUIRE(std::same_as<std::decay_t<
decltype(ppp)>, FilteredPoints::iterator>);
1102 auto oppps = ppp.pointSeq_as<FilteredPoints>();
1103 for (
auto& pppp : oppps) {
1104 REQUIRE(std::same_as<std::decay_t<
decltype(pppp)>, FilteredPoints::iterator>);
1105 auto opppps = pppp.pointSeq_as<FilteredPoints>();
1111 auto const& ffpa = ffp;
1114 for (
auto& it1 : ffpa) {
1115 [[maybe_unused]]
auto it2 = ffpa.rawIteratorAt(0);
1116 [[maybe_unused]]
auto it3 = ffpa.iteratorAt(0);
1117 using T1 = std::decay_t<
decltype(it1)>;
1118 using T2 = std::decay_t<
decltype(it2)>;
1119 using T3 = std::decay_t<
decltype(it3)>;
1120 auto bit1 = !std::same_as<T1, T2>;
1122 auto bit2 = !std::same_as<T1, T3>;
1124 auto bit3 = std::same_as<typename T1::policy_t, typename T3::policy_t>;
1126 auto bit4 = std::same_as<typename T1::policy_t, o2::soa::FilteredIndexPolicy>;
1128 auto bit5 = std::same_as<typename T2::policy_t, o2::soa::DefaultIndexPolicy>;
1136 auto writer =
b.
cursor<o2::aod::Lists>();
1137 std::vector<float> floats;
1138 std::vector<int> ints;
1139 for (
auto i = 1;
i < 11; ++
i) {
1142 for (
auto j = 0;
j <
i; ++
j) {
1143 floats.push_back(0.1231233f * (
float)
j + 0.1982798f);
1144 ints.push_back(
j + 10);
1147 writer(0, floats, ints);
1149 auto lt =
b.finalize();
1150 o2::aod::Lists tbl{lt};
1152 for (
auto&
row : tbl) {
1155 auto constexpr bf = std::same_as<
decltype(
f), gsl::span<
const float, (
size_t)-1>>;
1156 auto constexpr bi = std::same_as<
decltype(
i), gsl::span<
const int, (
size_t)-1>>;
1159 REQUIRE(
f.size() == s);
1160 REQUIRE(
i.size() == s);
1162 for (
auto j = 0u;
j <
f.size(); ++
j) {
1163 REQUIRE(
f[
j] == 0.1231233f * (
float)
j + 0.1982798f);
1164 REQUIRE(
i[
j] == (
int)
j + 10);
1173 auto writer =
b.
cursor<o2::aod::Origints>();
1174 for (
auto i = 0;
i < 20; ++
i) {
1175 writer(0,
i,
i % 3 == 0);
1177 auto origins =
b.finalize();
1178 o2::aod::Origints o{origins};
1181 auto writer_w =
w.
cursor<o2::aod::References>();
1183 for (
auto i = 0;
i < 5 * 20; ++
i) {
1189 auto refs =
w.finalize();
1190 o2::aod::References
r{refs};
1193 ArrowTableSlicingCache atscache({{o2::soa::getLabelFromType<o2::aod::References>(), o2::soa::getMatcherFromTypeForKey<o2::aod::References>(
key),
key}});
1194 auto s = atscache.updateCacheEntry(0, refs);
1197 for (
auto& oi : o) {
1198 auto cachedSlice =
r.sliceByCached(o2::aod::test::origintId, oi.globalIndex(), cache);
1199 REQUIRE(cachedSlice.size() == 5);
1200 for (
auto& ri : cachedSlice) {
1201 REQUIRE(ri.origintId() == oi.globalIndex());
1209 auto writer =
b.
cursor<o2::aod::Origints>();
1210 for (
auto i = 0;
i < 20; ++
i) {
1211 writer(0,
i,
i % 3 == 0);
1213 auto origins =
b.finalize();
1214 o2::aod::Origints o{origins};
1217 auto writer_w =
w.
cursor<o2::aod::References>();
1219 for (
auto i = 0;
i < 5 * 20; ++
i) {
1225 auto refs =
w.finalize();
1226 o2::aod::References
r{refs};
1229 auto writer_w2 = w2.
cursor<o2::aod::OtherReferences>();
1231 for (
auto i = 0;
i < 5 * 20; ++
i) {
1238 o2::aod::OtherReferences r2{refs2};
1241 J rr{{refs, refs2}};
1245 auto s = atscache.updateCacheEntry(0, refs2);
1248 for (
auto& oi : o) {
1249 auto cachedSlice = rr.sliceByCached(o2::aod::test::altOrigintId, oi.globalIndex(), cache);
1250 REQUIRE(cachedSlice.size() == 3);
1251 for (
auto& ri : cachedSlice) {
1252 REQUIRE(ri.altOrigintId() == oi.globalIndex());
1260 auto writer =
b.
cursor<o2::aod::Origints>();
1261 for (
auto i = 0;
i < 20; ++
i) {
1262 writer(0,
i,
i % 3 == 0);
1264 auto origins =
b.finalize();
1265 o2::aod::Origints o{origins};
1268 auto writer_w =
w.
cursor<o2::aod::References>();
1270 for (
auto i = 0;
i < 5 * 20; ++
i) {
1276 auto refs =
w.finalize();
1277 o2::aod::References
r{refs};
1280 auto writer_w2 = w2.
cursor<o2::aod::OtherReferences>();
1282 for (
auto i = 0;
i < 5 * 20; ++
i) {
1289 o2::aod::OtherReferences r2{refs2};
1292 J rr{{refs, refs2}};
1294 auto rrf = rr.
select(o2::aod::test::altOrigintId > 2 && o2::aod::test::altOrigintId < 15);
1298 auto s = atscache.updateCacheEntry(0, refs2);
1301 for (
auto& oi : o) {
1302 auto cachedSlice = rrf.sliceByCached(o2::aod::test::altOrigintId, oi.globalIndex(), cache);
1303 if (oi.globalIndex() <= 2 || oi.globalIndex() >= 15) {
1304 CHECK(cachedSlice.size() == 0);
1306 CHECK(cachedSlice.size() == 3);
1308 for (
auto& ri : cachedSlice) {
1309 REQUIRE(ri.altOrigintId() == oi.globalIndex());
1317 auto prwriter =
b.
cursor<o2::aod::PointsRefF>();
1318 auto a = std::array{0, 1};
1319 auto aa = std::vector{2, 3, 4};
1320 prwriter(0, 0, &
a[0], aa);
1323 prwriter(0, 1, &
a[0], aa);
1324 auto t =
b.finalize();
1325 auto prt = o2::aod::PointsRefF{t};
1327 for (
auto&
row : prt) {
1329 [[maybe_unused]]
auto sp =
row.singlePoint();
1331 REQUIRE(std::string{
error_from_ref(
ref).
what} ==
"Index pointing to Points3Ds is not bound! Did you subscribe to the table?");
1334 auto ps =
row.pointSlice();
1336 REQUIRE(std::string{
error_from_ref(
ref).
what} ==
"Index pointing to Points3Ds is not bound! Did you subscribe to the table?");
1339 auto pg =
row.pointGroup();
1341 REQUIRE(std::string{
error_from_ref(
ref).
what} ==
"Index pointing to Points3Ds is not bound! Did you subscribe to the table?");
1360 auto writer =
b.
cursor<o2::aod::BILists>();
1363 for (
auto i = 0;
i < 20; ++
i) {
1365 for (
auto j = 0;
j < 32; ++
j) {
1373 auto t =
b.finalize();
1375 o2::aod::BILists li{t};
1376 for (
auto const&
row : li) {
1377 auto iir =
row.smallIntArray();
1378 [[maybe_unused]]
auto bbrr =
row.boolArray_raw();
1379 REQUIRE(std::same_as<std::decay_t<
decltype(iir)>, int8_t
const*>);
1380 for (
auto i = 0;
i < 32; ++
i) {
1381 REQUIRE(iir[
i] ==
i);
1382 REQUIRE(
row.boolArray_bit(
i) == (
i % 2 == 0));
1399 table::One, table::Two, table::Three, table::Four,
1400 table::Five<table::Four>);
1406 auto writer =
b.
cursor<o2::aod::MixTest>();
1408 for (
auto i = 0;
i < 20; ++
i) {
1413 auto t =
b.finalize();
1414 o2::aod::MixTest mt{t};
1416 for (
auto const&
row : mt) {
1417 auto features1 =
row.getValues<float, o2::aod::table::One, o2::aod::table::Three>();
1418 auto features2 =
row.getValues<double, o2::aod::table::One, o2::aod::table::Two, o2::aod::table::Three>();
1419 auto features3 =
row.getValues<float, o2::aod::table::Two, o2::aod::table::Five<o2::aod::table::Four>>();
1420 auto b1 = std::same_as<std::array<float, 2>,
decltype(features1)>;
1422 auto b2 = std::same_as<std::array<double, 3>,
decltype(features2)>;
1424 auto b3 = std::same_as<std::array<float, 2>,
decltype(features3)>;
1426 REQUIRE(features1[0] == (
float)
count);
1429 REQUIRE(features2[0] == (
double)
count);
1434 REQUIRE(features3[1] == (
float)((
float)
count / (
float)(
count + 1)));
1477 REQUIRE(cursor.
lastIndex() + 1 <= reserved);
1479 auto table = builder->finalize();
1480 REQUIRE(table->num_rows() == 5);
1481 REQUIRE(table->num_columns() == 2);
#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
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.