westonpace commented on code in PR #35129:
URL: https://github.com/apache/arrow/pull/35129#discussion_r1179605685
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -427,6 +428,24 @@ std::shared_ptr<Table> TableFromJSON(const
std::shared_ptr<Schema>& schema,
return *Table::FromRecordBatches(schema, std::move(batches));
}
+Result<std::shared_ptr<Table>> RunEndEncodeTableColumns(
+ const Table& table, const std::vector<int>& column_indices) {
+ const int num_columns = table.num_columns();
+ std::vector<std::shared_ptr<ChunkedArray>> encoded_columns;
+ encoded_columns.reserve(num_columns);
+ for (int i = 0; i < num_columns; i++) {
+ if (std::find(column_indices.begin(), column_indices.end(), i) !=
+ column_indices.end()) {
+ EXPECT_OK_AND_ASSIGN(auto run_end_encoded,
compute::RunEndEncode(table.column(i)));
+ EXPECT_EQ(run_end_encoded.kind(), Datum::CHUNKED_ARRAY);
Review Comment:
Given you're returning a result anyways you could just use
ARROW_ASSIGN_OR_RAISE and ARROW_RETURN_NOT_OK here right?
##########
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:
Can you collapse these two branches?
```
if (is_valid == count_valid) {
...
}
```
Or does that not somehow generate the same benefit? Seems like either way
there is a single if comparison. I expect the compiler would generate the same
for `if (x == true)` that it does for `if (x)`.
--
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]