Skip to content

Commit 387fdc7

Browse files
committed
DPL: move out of line helper code for templates
1 parent 860d9b5 commit 387fdc7

2 files changed

Lines changed: 38 additions & 31 deletions

File tree

Framework/Core/include/Framework/ASoA.h

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -865,31 +865,7 @@ auto select(T const& t, framework::expressions::Filter&& f)
865865
t.asArrowTable()->schema()));
866866
}
867867

868-
namespace
869-
{
870-
auto getSliceFor(int value, char const* key, std::shared_ptr<arrow::Table> const& input, std::shared_ptr<arrow::Table>& output, uint64_t& offset)
871-
{
872-
arrow::Datum value_counts;
873-
auto options = arrow::compute::CountOptions::Defaults();
874-
ARROW_ASSIGN_OR_RAISE(value_counts,
875-
arrow::compute::CallFunction("value_counts", {input->GetColumnByName(key)},
876-
&options));
877-
auto pair = static_cast<arrow::StructArray>(value_counts.array());
878-
auto values = static_cast<arrow::NumericArray<arrow::Int32Type>>(pair.field(0)->data());
879-
auto counts = static_cast<arrow::NumericArray<arrow::Int64Type>>(pair.field(1)->data());
880-
881-
int slice;
882-
for (slice = 0; slice < values.length(); ++slice) {
883-
if (values.Value(slice) == value) {
884-
offset = slice;
885-
output = input->Slice(slice, counts.Value(slice));
886-
return arrow::Status::OK();
887-
}
888-
}
889-
output = input->Slice(0, 0);
890-
return arrow::Status::OK();
891-
}
892-
} // namespace
868+
arrow::Status getSliceFor(int value, char const* key, std::shared_ptr<arrow::Table> const& input, std::shared_ptr<arrow::Table>& output, uint64_t& offset);
893869

894870
template <typename T>
895871
auto sliceBy(T const& t, framework::expressions::BindingNode const& node, int value)
@@ -900,9 +876,12 @@ auto sliceBy(T const& t, framework::expressions::BindingNode const& node, int va
900876
if (status.ok()) {
901877
return T({result}, offset);
902878
}
903-
throw std::runtime_error("Failed to slice table");
879+
o2::framework::throw_error(o2::framework::runtime_error("Failed to slice table"));
880+
O2_BUILTIN_UNREACHABLE();
904881
}
905882

883+
arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, const char* label);
884+
906885
/// A Table class which observes an arrow::Table and provides
907886
/// It is templated on a set of Column / DynamicColumn types.
908887
template <typename... C>
@@ -1137,11 +1116,7 @@ class Table
11371116
{
11381117
if constexpr (T::persistent::value) {
11391118
auto label = T::columnLabel();
1140-
auto index = mTable->schema()->GetAllFieldIndices(label);
1141-
if (index.empty() == true) {
1142-
throw o2::framework::runtime_error_f("Unable to find column with label %s", label);
1143-
}
1144-
return mTable->column(index[0]).get();
1119+
return getIndexFromLabel(mTable.get(), label);
11451120
} else {
11461121
return nullptr;
11471122
}

Framework/Core/src/ASoA.cxx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,36 @@ std::shared_ptr<arrow::Table> ArrowHelpers::concatTables(std::vector<std::shared
8181
return result;
8282
}
8383

84+
arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, const char* label)
85+
{
86+
auto index = table->schema()->GetAllFieldIndices(label);
87+
if (index.empty() == true) {
88+
o2::framework::throw_error(o2::framework::runtime_error_f("Unable to find column with label %s", label));
89+
}
90+
return table->column(index[0]).get();
91+
}
92+
93+
arrow::Status getSliceFor(int value, char const* key, std::shared_ptr<arrow::Table> const& input, std::shared_ptr<arrow::Table>& output, uint64_t& offset)
94+
{
95+
arrow::Datum value_counts;
96+
auto options = arrow::compute::CountOptions::Defaults();
97+
ARROW_ASSIGN_OR_RAISE(value_counts,
98+
arrow::compute::CallFunction("value_counts", {input->GetColumnByName(key)},
99+
&options));
100+
auto pair = static_cast<arrow::StructArray>(value_counts.array());
101+
auto values = static_cast<arrow::NumericArray<arrow::Int32Type>>(pair.field(0)->data());
102+
auto counts = static_cast<arrow::NumericArray<arrow::Int64Type>>(pair.field(1)->data());
103+
104+
int slice;
105+
for (slice = 0; slice < values.length(); ++slice) {
106+
if (values.Value(slice) == value) {
107+
offset = slice;
108+
output = input->Slice(slice, counts.Value(slice));
109+
return arrow::Status::OK();
110+
}
111+
}
112+
output = input->Slice(0, 0);
113+
return arrow::Status::OK();
114+
}
115+
84116
} // namespace o2::soa

0 commit comments

Comments
 (0)