Skip to content

Commit f045ccf

Browse files
authored
DPL Analysis: remove std::set from analysis task (#15640)
1 parent 2ed2a8c commit f045ccf

6 files changed

Lines changed: 29 additions & 21 deletions

File tree

Framework/Core/include/Framework/ASoA.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,12 @@ class Table
17591759

17601760
using columns_t = decltype(getColumns<ref, Ts...>());
17611761

1762+
static constexpr auto column_hashes = []<typename... C>(framework::pack<C...>) consteval {
1763+
auto hashes = std::array{C::hash...};
1764+
std::ranges::sort(hashes);
1765+
return hashes;
1766+
}(columns_t{});
1767+
17621768
using persistent_columns_t = decltype([]<typename... C>(framework::pack<C...>&&) -> framework::selected_pack<soa::is_persistent_column_t, C...> {}(columns_t{}));
17631769
using column_types = decltype([]<typename... C>(framework::pack<C...>) -> framework::pack<typename C::type...> {}(persistent_columns_t{}));
17641770

@@ -1942,11 +1948,6 @@ class Table
19421948
using const_iterator = iterator;
19431949
using unfiltered_const_iterator = unfiltered_iterator;
19441950

1945-
static constexpr auto hashes()
1946-
{
1947-
return []<typename... C>(framework::pack<C...>) { return std::set{{C::hash...}}; }(columns_t{});
1948-
}
1949-
19501951
Table(o2::soa::ArrowTableRef tableRef)
19511952
: mArrowTableRef(tableRef),
19521953
mEnd{tableRef.range.size}

Framework/Core/include/Framework/AnalysisHelpers.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ auto getTableFromFilter(soa::is_not_filtered_table auto const& table, soa::Selec
953953
return std::make_unique<o2::soa::Filtered<std::decay_t<decltype(table)>>>(std::vector{table.asArrowTableRef()}, std::forward<soa::SelectionVector>(selection));
954954
}
955955

956-
void initializePartitionCaches(std::set<uint32_t> const& hashes, std::shared_ptr<arrow::Schema> const& schema, expressions::Filter const& filter, gandiva::NodePtr& tree, gandiva::FilterPtr& gfilter);
956+
void initializePartitionCaches(std::span<const uint32_t> hashes, std::shared_ptr<arrow::Schema> const& schema, expressions::Filter const& filter, gandiva::NodePtr& tree, gandiva::FilterPtr& gfilter);
957957

958958
/// Partition ties directly to the argument type
959959
/// in a case with several origins in subscriptions it will get the correct input, as the type contains the origin
@@ -975,14 +975,14 @@ struct Partition {
975975
setTable(table);
976976
}
977977

978-
void intializeCaches(std::set<uint32_t> const& hashes, std::shared_ptr<arrow::Schema> const& schema)
978+
void intializeCaches(std::span<const uint32_t> hashes, std::shared_ptr<arrow::Schema> const& schema)
979979
{
980980
initializePartitionCaches(hashes, schema, filter, tree, gfilter);
981981
}
982982

983983
void bindTable(T const& table)
984984
{
985-
intializeCaches(T::table_t::hashes(), table.asArrowTableRef()->schema());
985+
intializeCaches(T::table_t::column_hashes, table.asArrowTableRef()->schema());
986986
if (dataframeChanged) {
987987
mFiltered = getTableFromFilter(table, soa::selectionToVector(framework::expressions::createSelection(table.asArrowTable(), gfilter)));
988988
dataframeChanged = false;

Framework/Core/include/Framework/AnalysisTask.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ struct AnalysisDataProcessorBuilder {
126126
static void addExpression(int ai, uint32_t hash, std::vector<ExpressionInfo>& eInfos)
127127
{
128128
auto fields = soa::createFieldsFromColumns(typename std::decay_t<A>::persistent_columns_t{});
129-
eInfos.emplace_back(ai, hash, std::decay_t<A>::hashes(), std::make_shared<arrow::Schema>(fields));
129+
eInfos.emplace_back(ai, hash, std::span{std::decay_t<A>::column_hashes}, std::make_shared<arrow::Schema>(fields));
130130
}
131131

132132
template <soa::is_iterator A>

Framework/Core/include/Framework/Expressions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class Projector;
3939
#include <variant>
4040
#include <string>
4141
#include <memory>
42-
#include <set>
4342
#include <stack>
4443
namespace gandiva
4544
{
@@ -49,7 +48,8 @@ using FilterPtr = std::shared_ptr<gandiva::Filter>;
4948

5049
using atype = arrow::Type;
5150
struct ExpressionInfo {
52-
ExpressionInfo(int ai, size_t hash, std::set<uint32_t>&& hs, gandiva::SchemaPtr sc)
51+
template <typename T>
52+
ExpressionInfo(int ai, size_t hash, T hs, gandiva::SchemaPtr sc)
5353
: argumentIndex(ai),
5454
processHash(hash),
5555
hashes(hs),
@@ -58,7 +58,7 @@ struct ExpressionInfo {
5858
}
5959
int argumentIndex;
6060
size_t processHash;
61-
std::set<uint32_t> hashes;
61+
std::span<const uint32_t> hashes;
6262
gandiva::SchemaPtr schema;
6363
gandiva::NodePtr tree = nullptr;
6464
gandiva::FilterPtr filter = nullptr;
@@ -681,7 +681,7 @@ using Operations = std::vector<ColumnOperationSpec>;
681681
Operations createOperations(Filter const& expression);
682682

683683
/// Function to check compatibility of a given arrow schema with operation sequence
684-
bool isTableCompatible(std::set<uint32_t> const& hashes, Operations const& specs);
684+
bool isTableCompatible(std::span<const uint32_t> hashes, Operations const& specs);
685685
/// Function to create gandiva expression tree from operation sequence
686686
gandiva::NodePtr createExpressionTree(Operations const& opSpecs,
687687
gandiva::SchemaPtr const& Schema);

Framework/Core/src/AnalysisHelpers.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ std::shared_ptr<arrow::Table> spawnerHelper(std::shared_ptr<arrow::Table> const&
155155
return arrow::Table::Make(newSchema, arrays);
156156
}
157157

158-
void initializePartitionCaches(std::set<uint32_t> const& hashes, std::shared_ptr<arrow::Schema> const& schema, expressions::Filter const& filter, gandiva::NodePtr& tree, gandiva::FilterPtr& gfilter)
158+
void initializePartitionCaches(std::span<const uint32_t> hashes, std::shared_ptr<arrow::Schema> const& schema, expressions::Filter const& filter, gandiva::NodePtr& tree, gandiva::FilterPtr& gfilter)
159159
{
160160
if (tree == nullptr) {
161161
expressions::Operations ops = createOperations(filter);

Framework/Core/src/Expressions.cxx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -768,20 +768,27 @@ gandiva::NodePtr createExpressionTree(Operations const& opSpecs,
768768
return tree;
769769
}
770770

771-
bool isTableCompatible(std::set<uint32_t> const& hashes, Operations const& specs)
771+
bool isTableCompatible(std::span<const uint32_t> hashes, Operations const& specs)
772772
{
773-
std::set<uint32_t> opHashes;
773+
std::vector<uint32_t> opHashes;
774774
for (auto const& spec : specs) {
775775
if (spec.left.datum.index() == 3) {
776-
opHashes.insert(spec.left.hash);
776+
opHashes.emplace_back(spec.left.hash);
777777
}
778778
if (spec.right.datum.index() == 3) {
779-
opHashes.insert(spec.right.hash);
779+
opHashes.emplace_back(spec.right.hash);
780780
}
781781
}
782-
783-
return std::includes(hashes.begin(), hashes.end(),
784-
opHashes.begin(), opHashes.end());
782+
std::ranges::sort(opHashes);
783+
auto [ret, last] = std::ranges::unique(opHashes);
784+
opHashes.erase(ret, last);
785+
bool contains = true;
786+
std::ranges::for_each(opHashes, [hashes, &contains](auto const& hash) {
787+
contains = contains && std::ranges::any_of(hashes, [hash](auto const& h) {
788+
return h == hash;
789+
});
790+
});
791+
return contains;
785792
}
786793

787794
void updateExpressionInfos(expressions::Filter const& filter, std::vector<ExpressionInfo>& eInfos)

0 commit comments

Comments
 (0)