MCPcopy Create free account
hub / github.com/apache/arrow / Merge

Method Merge

cpp/src/arrow/acero/groupby_aggregate_node.cc:255–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253}
254
255Status GroupByNode::Merge() {
256 arrow::util::tracing::Span span;
257 START_COMPUTE_SPAN(span, "Merge",
258 {{"group_by", ToStringExtra(0)}, {"node.label", label()}});
259 ThreadLocalState* state0 = &local_states_[0];
260 for (size_t i = 1; i < local_states_.size(); ++i) {
261 ThreadLocalState* state = &local_states_[i];
262 if (!state->grouper) {
263 continue;
264 }
265
266 ARROW_ASSIGN_OR_RAISE(ExecBatch other_keys, state->grouper->GetUniques());
267 ARROW_ASSIGN_OR_RAISE(Datum transposition,
268 state0->grouper->Consume(ExecSpan(other_keys)));
269 state->grouper.reset();
270
271 for (size_t span_i = 0; span_i < agg_kernels_.size(); ++span_i) {
272 arrow::util::tracing::Span span_item;
273 START_COMPUTE_SPAN(
274 span_item, aggs_[span_i].function,
275 {{"function.name", aggs_[span_i].function},
276 {"function.options",
277 aggs_[span_i].options ? aggs_[span_i].options->ToString() : "<NULLPTR>"},
278 {"function.kind", std::string(kind_name()) + "::Merge"}});
279
280 auto ctx = plan_->query_context()->exec_context();
281 KernelContext batch_ctx{ctx};
282 DCHECK(state0->agg_states[span_i]);
283 batch_ctx.SetState(state0->agg_states[span_i].get());
284
285 // XXX this resizes each KernelState (state0->agg_states[span_i]) multiple times.
286 // An alternative would be a two-pass algorithm:
287 // 1. Compute all transpositions (one per local state) and the final number of
288 // groups.
289 // 2. Process all agg kernels, resizing each KernelState only once.
290 RETURN_NOT_OK(
291 agg_kernels_[span_i]->resize(&batch_ctx, state0->grouper->num_groups()));
292 RETURN_NOT_OK(agg_kernels_[span_i]->merge(
293 &batch_ctx, std::move(*state->agg_states[span_i]), *transposition.array()));
294 state->agg_states[span_i].reset();
295 }
296 }
297 return Status::OK();
298}
299
300Result<ExecBatch> GroupByNode::Finalize() {
301 arrow::util::tracing::Span span;

Callers

nothing calls this directly

Calls 11

exec_contextMethod · 0.80
query_contextMethod · 0.80
resizeMethod · 0.80
OKFunction · 0.50
sizeMethod · 0.45
resetMethod · 0.45
ToStringMethod · 0.45
getMethod · 0.45
num_groupsMethod · 0.45
mergeMethod · 0.45
arrayMethod · 0.45

Tested by

no test coverage detected