felipecrv commented on code in PR #35129:
URL: https://github.com/apache/arrow/pull/35129#discussion_r1179831741
##########
cpp/src/arrow/compute/kernels/hash_aggregate.cc:
##########
@@ -305,6 +306,56 @@ struct GroupedCountImpl : public GroupedAggregator {
return Status::OK();
}
+ template <bool count_valid>
+ struct RunEndEncodedCountImpl {
+ /// Count the number of valid or invalid values in a run-end-encoded array.
+ ///
+ /// \param[in] input the run-end-encoded array
+ /// \param[out] counts the counts being accumulated
+ /// \param[in] g the group ids of the values in the array
+ template <typename RunEndCType>
+ void DoCount(const ArraySpan& input, int64_t* counts, const uint32_t* g) {
+ ree_util::RunEndEncodedArraySpan<RunEndCType> ree_span(input);
+ const auto* physical_validity =
ree_util::ValuesArray(input).GetValues<uint8_t>(0);
+ auto end = ree_span.end();
+ for (auto it = ree_span.begin(); it != end; ++it) {
+ const bool is_valid = bit_util::GetBit(physical_validity,
it.index_into_array());
+ if constexpr (count_valid) {
+ if (is_valid) {
+ for (int64_t i = 0; i < it.run_length(); ++i, ++g) {
+ counts[*g] += 1;
+ }
+ } else {
+ g += it.run_length();
+ }
+ } else {
+ if (!is_valid) {
+ for (int64_t i = 0; i < it.run_length(); ++i, ++g) {
+ counts[*g] += 1;
+ }
+ } else {
+ g += it.run_length();
+ }
+ }
Review Comment:
Interesting catch. `count_valid` is a template param, so the compiler will
generate the same code `if (is_valid)` in one instantiation and `if
(!is_valid)` on another. No problem there. The final code is quite a logic
exercise though :-)
```cpp
if (is_valid == count_valid) {
for (int64_t i = 0; i < it.run_length(); ++i, ++g) {
counts[*g] += 1;
}
} else {
g += it.run_length();
}
```
I will change it.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]