icexelloss commented on code in PR #34311: URL: https://github.com/apache/arrow/pull/34311#discussion_r1117295168
########## cpp/src/arrow/compute/kernels/hash_aggregate_test.cc: ########## @@ -135,22 +141,84 @@ Result<Datum> NaiveGroupBy(std::vector<Datum> arguments, std::vector<Datum> keys return Take(struct_arr, sorted_indices); } +Result<Datum> MakeGroupByOutput(const std::vector<ExecBatch>& output_batches, + const std::shared_ptr<Schema> output_schema, + size_t num_aggregates, size_t num_keys, bool naive) { + ArrayVector out_arrays(num_aggregates + num_keys); + for (size_t i = 0; i < out_arrays.size(); ++i) { + std::vector<std::shared_ptr<Array>> arrays(output_batches.size()); + for (size_t j = 0; j < output_batches.size(); ++j) { + arrays[j] = output_batches[j].values[i].make_array(); + } + if (arrays.empty()) { + ARROW_ASSIGN_OR_RAISE( + out_arrays[i], + MakeArrayOfNull(output_schema->field(static_cast<int>(i))->type(), + /*length=*/0)); + } else { + ARROW_ASSIGN_OR_RAISE(out_arrays[i], Concatenate(arrays)); + } + } + + ARROW_ASSIGN_OR_RAISE( + std::shared_ptr<Array> struct_arr, + StructArray::Make(std::move(out_arrays), output_schema->fields())); + + bool need_sort = !naive; + for (size_t i = num_aggregates; need_sort && i < out_arrays.size(); i++) { + if (output_schema->field(i)->type()->id() == Type::DICTIONARY) { Review Comment: For my knowledge - why this? -- 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