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

Method Finalize

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

Source from the content-addressed store, hash-verified

298}
299
300Result<ExecBatch> GroupByNode::Finalize() {
301 arrow::util::tracing::Span span;
302 START_COMPUTE_SPAN(span, "Finalize",
303 {{"group_by", ToStringExtra(0)}, {"node.label", label()}});
304
305 ThreadLocalState* state = &local_states_[0];
306 // If we never got any batches, then state won't have been initialized
307 RETURN_NOT_OK(InitLocalStateIfNeeded(state));
308
309 // Allocate a batch for output
310 ExecBatch out_data{{}, state->grouper->num_groups()};
311 out_data.values.resize(agg_kernels_.size() + key_field_ids_.size() +
312 segment_key_field_ids_.size());
313
314 // Segment keys come first
315 PlaceFields(out_data, 0, segmenter_values_);
316 // Followed by keys
317 ARROW_ASSIGN_OR_RAISE(ExecBatch out_keys, state->grouper->GetUniques());
318 std::move(out_keys.values.begin(), out_keys.values.end(),
319 out_data.values.begin() + segment_key_field_ids_.size());
320 // And finally, the aggregates themselves
321 std::size_t base = segment_key_field_ids_.size() + key_field_ids_.size();
322 for (size_t i = 0; i < agg_kernels_.size(); ++i) {
323 arrow::util::tracing::Span span_item;
324 START_COMPUTE_SPAN(span_item, aggs_[i].function,
325 {{"function.name", aggs_[i].function},
326 {"function.options",
327 aggs_[i].options ? aggs_[i].options->ToString() : "<NULLPTR>"},
328 {"function.kind", std::string(kind_name()) + "::Finalize"}});
329 KernelContext batch_ctx{plan_->query_context()->exec_context()};
330 batch_ctx.SetState(state->agg_states[i].get());
331 RETURN_NOT_OK(agg_kernels_[i]->finalize(&batch_ctx, &out_data.values[i + base]));
332 state->agg_states[i].reset();
333 }
334 state->grouper.reset();
335
336 return out_data;
337}
338
339Status GroupByNode::OutputNthBatch(int64_t n) {
340 int64_t batch_size = output_batch_size();

Callers 2

getNextBatchMethod · 0.45
EmplaceFunction · 0.45

Calls 12

PlaceFieldsFunction · 0.85
resizeMethod · 0.80
exec_contextMethod · 0.80
query_contextMethod · 0.80
finalizeMethod · 0.80
num_groupsMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
ToStringMethod · 0.45
getMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected