Skip to content

Commit ede2d20

Browse files
committed
Case-insensitive index access
* fix the Binding node always using #_Table_ instead of _Label_ for custom index colums * use case-insensitive comparison for looking up index columns in soa::Table and arrow::Table, as the custom-declared index columns may have inconsistent capitalization in their names
1 parent f9f3798 commit ede2d20

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

Framework/Core/include/Framework/ASoA.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,15 @@ static constexpr std::string getLabelFromType()
13761376
template <typename... C>
13771377
static constexpr auto hasColumnForKey(framework::pack<C...>, std::string const& key)
13781378
{
1379-
return ((C::inherited_t::mLabel == key) || ...);
1379+
auto caseInsensitiveCompare = [](const std::string_view& str1, const std::string& str2) {
1380+
return std::ranges::equal(
1381+
str1, str2,
1382+
[](char c1, char c2) {
1383+
return std::tolower(static_cast<unsigned char>(c1)) ==
1384+
std::tolower(static_cast<unsigned char>(c2));
1385+
});
1386+
};
1387+
return (caseInsensitiveCompare(C::inherited_t::mLabel, key) || ...);
13801388
}
13811389

13821390
template <TableRef ref>
@@ -2866,7 +2874,7 @@ consteval auto getIndexTargets()
28662874
o2::soa::Binding getCurrentRaw() const { return mBinding; } \
28672875
o2::soa::Binding mBinding; \
28682876
}; \
2869-
[[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_##Id { "fIndex" #_Table_ _Suffix_, _Name_##Id::hash, o2::framework::expressions::selectArrowType<_Type_>() }
2877+
[[maybe_unused]] static constexpr o2::framework::expressions::BindingNode _Getter_##Id { "fIndex" _Label_ _Suffix_, _Name_##Id::hash, o2::framework::expressions::selectArrowType<_Type_>() }
28702878

28712879
#define DECLARE_SOA_INDEX_COLUMN_FULL(_Name_, _Getter_, _Type_, _Table_, _Suffix_) DECLARE_SOA_INDEX_COLUMN_FULL_CUSTOM(_Name_, _Getter_, _Type_, _Table_, #_Table_, _Suffix_)
28722880
#define DECLARE_SOA_INDEX_COLUMN(_Name_, _Getter_) DECLARE_SOA_INDEX_COLUMN_FULL(_Name_, _Getter_, int32_t, _Name_##s, "")

Framework/Core/src/ArrowTableSlicingCache.cxx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@
1919
namespace o2::framework
2020
{
2121

22+
namespace {
23+
std::shared_ptr<arrow::ChunkedArray> GetColumnByNameCI(std::shared_ptr<arrow::Table> const& table, std::string const& key)
24+
{
25+
auto const& fields = table->schema()->fields();
26+
auto target = std::find_if(fields.begin(), fields.end(), [&key](std::shared_ptr<arrow::Field> const& field){
27+
return [](std::string_view const& s1, std::string_view const& s2){
28+
return std::ranges::equal(
29+
s1, s2,
30+
[](char c1, char c2){
31+
return std::tolower(static_cast<unsigned char>(c1)) == std::tolower(static_cast<unsigned char>(c2));
32+
}
33+
);
34+
}(field->name(), key);
35+
});
36+
return table->column(std::distance(fields.begin(), target));
37+
}
38+
}
39+
2240
void updatePairList(Cache& list, std::string const& binding, std::string const& key, bool enabled = true)
2341
{
2442
auto locate = std::find_if(list.begin(), list.end(), [&binding, &key](auto const& entry) { return (entry.binding == binding) && (entry.key == key); });
@@ -99,7 +117,7 @@ arrow::Status ArrowTableSlicingCache::updateCacheEntry(int pos, std::shared_ptr<
99117
validateOrder(bindingsKeys[pos], table);
100118

101119
int maxValue = -1;
102-
auto column = table->GetColumnByName(k);
120+
auto column = GetColumnByNameCI(table, k);
103121

104122
// starting from the end, find the first positive value, in a sorted column it is the largest index
105123
for (auto iChunk = column->num_chunks() - 1; iChunk >= 0; --iChunk) {
@@ -155,7 +173,7 @@ arrow::Status ArrowTableSlicingCache::updateCacheEntryUnsorted(int pos, const st
155173
if (!e) {
156174
throw runtime_error_f("Disabled unsorted cache %s/%s update requested", b.c_str(), k.c_str());
157175
}
158-
auto column = table->GetColumnByName(k);
176+
auto column = GetColumnByNameCI(table, k);
159177
auto row = 0;
160178
for (auto iChunk = 0; iChunk < column->num_chunks(); ++iChunk) {
161179
auto chunk = static_cast<arrow::NumericArray<arrow::Int32Type>>(column->chunk(iChunk)->data());
@@ -252,7 +270,7 @@ SliceInfoUnsortedPtr ArrowTableSlicingCache::getCacheUnsortedForPos(int pos) con
252270
void ArrowTableSlicingCache::validateOrder(Entry const& bindingKey, const std::shared_ptr<arrow::Table>& input)
253271
{
254272
auto const& [target, key, enabled] = bindingKey;
255-
auto column = input->GetColumnByName(key);
273+
auto column = o2::framework::GetColumnByNameCI(input, key);
256274
auto array0 = static_cast<arrow::NumericArray<arrow::Int32Type>>(column->chunk(0)->data());
257275
int32_t prev = 0;
258276
int32_t cur = array0.Value(0);

0 commit comments

Comments
 (0)