@@ -62,71 +62,71 @@ SelectionVector sliceSelection(std::span<int64_t const> const& mSelectedRows, in
6262 auto start_iterator = std::lower_bound (mSelectedRows .begin (), mSelectedRows .end (), start);
6363 auto stop_iterator = std::lower_bound (start_iterator, mSelectedRows .end (), end);
6464 SelectionVector slicedSelection{start_iterator, stop_iterator};
65- std::transform (slicedSelection.begin (), slicedSelection.end (), slicedSelection.begin (),
66- [&start](int64_t idx) {
67- return idx - static_cast <int64_t >(start);
68- });
65+ std::ranges:: transform (slicedSelection.begin (), slicedSelection.end (), slicedSelection.begin (),
66+ [&start](int64_t idx) {
67+ return idx - static_cast <int64_t >(start);
68+ });
6969 return slicedSelection;
7070}
7171
72- std::shared_ptr<arrow::Table> ArrowHelpers::joinTables (std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span< const char * const > labels )
72+ std::shared_ptr<arrow::Table> ArrowHelpers::joinTables (std::vector<std::shared_ptr<arrow::Table>>&& tables)
7373{
74- if (tables.size () == 1 ) {
75- return tables[0 ];
76- }
77- for (auto i = 0U ; i < tables.size () - 1 ; ++i) {
78- if (tables[i]->num_rows () != tables[i + 1 ]->num_rows ()) {
79- throw o2::framework::runtime_error_f (" Tables %s and %s have different sizes (%d vs %d) and cannot be joined!" ,
80- labels[i], labels[i + 1 ], tables[i]->num_rows (), tables[i + 1 ]->num_rows ());
81- }
82- }
8374 std::vector<std::shared_ptr<arrow::Field>> fields;
8475 std::vector<std::shared_ptr<arrow::ChunkedArray>> columns;
85-
86- for (auto & t : tables) {
87- auto tf = t->fields ();
88- std::copy (tf.begin (), tf.end (), std::back_inserter (fields));
89- }
90-
91- auto schema = std::make_shared<arrow::Schema>(fields);
92-
93- if (tables[0 ]->num_rows () != 0 ) {
94- for (auto & t : tables) {
95- auto tc = t->columns ();
96- std::copy (tc.begin (), tc.end (), std::back_inserter (columns));
76+ bool notEmpty = (tables[0 ]->num_rows () != 0 );
77+ std::ranges::for_each (tables, [&fields, &columns, notEmpty](auto const & t) {
78+ std::ranges::copy (t->fields (), std::back_inserter (fields));
79+ if (notEmpty) {
80+ std::ranges::copy (t->columns (), std::back_inserter (columns));
9781 }
98- }
82+ });
83+ auto schema = std::make_shared<arrow::Schema>(fields);
9984 return arrow::Table::Make (schema, columns);
10085}
10186
102- std::shared_ptr<arrow::Table> ArrowHelpers::joinTables (std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<const std::string> labels)
87+ namespace
88+ {
89+ template <typename T>
90+ requires (std::same_as<T, std::string>)
91+ auto makeString (T const & str)
92+ {
93+ return str.c_str ();
94+ }
95+ template <typename T>
96+ requires (std::same_as<T, const char *>)
97+ auto makeString (T const & str)
98+ {
99+ return str;
100+ }
101+
102+ template <typename T>
103+ void canNotJoin (std::vector<std::shared_ptr<arrow::Table>> const & tables, std::span<T> labels)
103104{
104- if (tables.size () == 1 ) {
105- return tables[0 ];
106- }
107105 for (auto i = 0U ; i < tables.size () - 1 ; ++i) {
108106 if (tables[i]->num_rows () != tables[i + 1 ]->num_rows ()) {
109107 throw o2::framework::runtime_error_f (" Tables %s and %s have different sizes (%d vs %d) and cannot be joined!" ,
110- labels[i]. c_str ( ), labels[i + 1 ]. c_str ( ), tables[i]->num_rows (), tables[i + 1 ]->num_rows ());
108+ makeString ( labels[i]), makeString ( labels[i + 1 ]), tables[i]->num_rows (), tables[i + 1 ]->num_rows ());
111109 }
112110 }
113- std::vector<std::shared_ptr<arrow::Field>> fields;
114- std::vector<std::shared_ptr<arrow::ChunkedArray>> columns;
111+ }
112+ } // namespace
115113
116- for (auto & t : tables) {
117- auto tf = t->fields ();
118- std::copy (tf.begin (), tf.end (), std::back_inserter (fields));
114+ std::shared_ptr<arrow::Table> ArrowHelpers::joinTables (std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<const char * const > labels)
115+ {
116+ if (tables.size () == 1 ) {
117+ return tables[0 ];
119118 }
119+ canNotJoin (tables, labels);
120+ return joinTables (std::forward<std::vector<std::shared_ptr<arrow::Table>>>(tables));
121+ }
120122
121- auto schema = std::make_shared<arrow::Schema>(fields);
122-
123- if (tables[0 ]->num_rows () != 0 ) {
124- for (auto & t : tables) {
125- auto tc = t->columns ();
126- std::copy (tc.begin (), tc.end (), std::back_inserter (columns));
127- }
123+ std::shared_ptr<arrow::Table> ArrowHelpers::joinTables (std::vector<std::shared_ptr<arrow::Table>>&& tables, std::span<const std::string> labels)
124+ {
125+ if (tables.size () == 1 ) {
126+ return tables[0 ];
128127 }
129- return arrow::Table::Make (schema, columns);
128+ canNotJoin (tables, labels);
129+ return joinTables (std::forward<std::vector<std::shared_ptr<arrow::Table>>>(tables));
130130}
131131
132132std::shared_ptr<arrow::Table> ArrowHelpers::concatTables (std::vector<std::shared_ptr<arrow::Table>>&& tables)
@@ -135,7 +135,6 @@ std::shared_ptr<arrow::Table> ArrowHelpers::concatTables(std::vector<std::shared
135135 return tables[0 ];
136136 }
137137 std::vector<std::shared_ptr<arrow::ChunkedArray>> columns;
138- assert (tables.size () > 1 );
139138 std::vector<std::shared_ptr<arrow::Field>> resultFields = tables[0 ]->schema ()->fields ();
140139 auto compareFields = [](std::shared_ptr<arrow::Field> const & f1, std::shared_ptr<arrow::Field> const & f2) {
141140 // Let's do this with stable sorting.
@@ -165,13 +164,12 @@ std::shared_ptr<arrow::Table> ArrowHelpers::concatTables(std::vector<std::shared
165164 columns.push_back (std::make_shared<arrow::ChunkedArray>(chunks));
166165 }
167166
168- auto result = arrow::Table::Make (std::make_shared<arrow::Schema>(resultFields), columns);
169- return result;
167+ return arrow::Table::Make (std::make_shared<arrow::Schema>(resultFields), columns);
170168}
171169
172170arrow::ChunkedArray* getIndexFromLabel (arrow::Table* table, std::string_view label)
173171{
174- auto field = std::find_if (table->schema ()->fields (). begin (), table-> schema ()-> fields (). end (), [&](std::shared_ptr<arrow::Field> const & f) {
172+ auto field = std::ranges:: find_if (table->schema ()->fields (), [&](std::shared_ptr<arrow::Field> const & f) {
175173 auto caseInsensitiveCompare = [](const std::string_view& str1, const std::string& str2) {
176174 return std::ranges::equal (
177175 str1, str2,
0 commit comments