pitrou commented on code in PR #45822: URL: https://github.com/apache/arrow/pull/45822#discussion_r2003173724
########## cpp/src/arrow/compute/row/grouper.cc: ########## @@ -417,35 +433,91 @@ struct GrouperImpl : public Grouper { RETURN_NOT_OK(encoders_[i]->Encode(batch[i], batch.length, key_buf_ptrs.data())); } - TypedBufferBuilder<uint32_t> group_ids_batch(ctx_->memory_pool()); - RETURN_NOT_OK(group_ids_batch.Resize(batch.length)); + using MapIterator = typename decltype(map_)::iterator; - for (int64_t i = 0; i < batch.length; ++i) { - int32_t key_length = offsets_batch[i + 1] - offsets_batch[i]; - std::string key( - reinterpret_cast<const char*>(key_bytes_batch.data() + offsets_batch[i]), - key_length); - - auto it_success = map_.emplace(key, num_groups_); - auto group_id = it_success.first->second; - - if (it_success.second) { - // new key; update offsets and key_bytes - ++num_groups_; - // Skip if there are no keys - if (key_length > 0) { - auto next_key_offset = static_cast<int32_t>(key_bytes_.size()); - key_bytes_.resize(next_key_offset + key_length); - offsets_.push_back(next_key_offset + key_length); - memcpy(key_bytes_.data() + next_key_offset, key.c_str(), key_length); + struct LookupResult { + bool inserted; + bool found; + MapIterator it; + }; + + auto generate_keys = [&](auto&& lookup_key, auto&& visit_group, Review Comment: I'll try to, but given they also access local state, I don't know how ergonomic it will end up. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org