Skip to content

Commit f017821

Browse files
authored
DPL Analysis: fix bug in soa::Table::sliceBy(), add a test (#7357)
1 parent 02a7b25 commit f017821

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

Framework/Core/src/ASoA.cxx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,14 @@ arrow::Status getSliceFor(int value, char const* key, std::shared_ptr<arrow::Tab
111111
auto values = static_cast<arrow::NumericArray<arrow::Int32Type>>(pair.field(0)->data());
112112
auto counts = static_cast<arrow::NumericArray<arrow::Int64Type>>(pair.field(1)->data());
113113

114-
int slice;
115-
for (slice = 0; slice < values.length(); ++slice) {
114+
for (auto slice = 0; slice < values.length(); ++slice) {
116115
if (values.Value(slice) == value) {
117-
offset = slice;
118-
output = input->Slice(slice, counts.Value(slice));
116+
output = input->Slice(offset, counts.Value(slice));
119117
return arrow::Status::OK();
120118
}
119+
offset += counts.Value(slice);
121120
}
122-
output = input->Slice(0, 0);
121+
output = input->Slice(offset, 0);
123122
return arrow::Status::OK();
124123
}
125124

Framework/Core/test/test_ASoA.cxx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,3 +826,34 @@ BOOST_AUTO_TEST_CASE(TestListColumns)
826826
++s;
827827
}
828828
}
829+
830+
BOOST_AUTO_TEST_CASE(TestSliceBy)
831+
{
832+
TableBuilder b;
833+
auto writer = b.cursor<Origins>();
834+
for (auto i = 0; i < 20; ++i) {
835+
writer(0, i, i % 3 == 0);
836+
}
837+
auto origins = b.finalize();
838+
Origins o{origins};
839+
840+
TableBuilder w;
841+
auto writer_w = w.cursor<References>();
842+
auto step = -1;
843+
for (auto i = 0; i < 5 * 20; ++i) {
844+
if (i % 5 == 0) {
845+
++step;
846+
}
847+
writer_w(0, step);
848+
}
849+
auto refs = w.finalize();
850+
References r{refs};
851+
852+
for (auto& oi : o) {
853+
auto slice = r.sliceBy(test::originId, oi.globalIndex());
854+
BOOST_CHECK_EQUAL(slice.size(), 5);
855+
for (auto& ri : slice) {
856+
BOOST_CHECK_EQUAL(ri.originId(), oi.globalIndex());
857+
}
858+
}
859+
}

0 commit comments

Comments
 (0)