felipecrv commented on code in PR #15083:
URL: https://github.com/apache/arrow/pull/15083#discussion_r1063480145
##########
cpp/src/arrow/compute/exec/aggregate.cc:
##########
@@ -121,21 +129,36 @@ Result<Datum> GroupBy(const std::vector<Datum>&
arguments, const std::vector<Dat
ExecSpanIterator argument_iterator;
ExecBatch args_batch;
- if (!arguments.empty()) {
+ if (!aggregates.empty()) {
ARROW_ASSIGN_OR_RAISE(args_batch, ExecBatch::Make(arguments));
// Construct and initialize HashAggregateKernels
- auto argument_types = args_batch.GetTypes();
+ std::vector<std::vector<TypeHolder>>
aggs_argument_types(aggregates.size());
+ {
+ // Contains the flattened list of aggregate arguments. We use the size of
+ // each Aggregate::target to re-group the aggregate argument types.
+ auto argument_types = args_batch.GetTypes();
Review Comment:
It can't be a reference because `GetTypes` doesn't return a reference.
(Technically it can, but won't really prevent the construction of the vector
within the stack).
I think moving the elements from the vector like this will give us more:
`TypeHolder` contains a `shared_ptr` -- cheaper to move than to copy.
```diff
for (size_t j = 0; j < aggregates.size(); j++) {
const size_t num_agg_args = aggregates[j].target.size();
for (size_t k = 0; k < num_agg_args && i < argument_types.size();
k++, i++) {
- aggs_argument_types[j].push_back(argument_types[i]);
+ aggs_argument_types[j].push_back(std::move(argument_types[i]));
}
}
```
--
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]