| 208 | } |
| 209 | |
| 210 | Status GroupByNode::Consume(ExecSpan batch) { |
| 211 | size_t thread_index = plan_->query_context()->GetThreadIndex(); |
| 212 | if (thread_index >= local_states_.size()) { |
| 213 | return Status::IndexError("thread index ", thread_index, " is out of range [0, ", |
| 214 | local_states_.size(), ")"); |
| 215 | } |
| 216 | |
| 217 | auto state = &local_states_[thread_index]; |
| 218 | RETURN_NOT_OK(InitLocalStateIfNeeded(state)); |
| 219 | |
| 220 | // Create a batch with key columns |
| 221 | std::vector<ExecValue> keys(key_field_ids_.size()); |
| 222 | for (size_t i = 0; i < key_field_ids_.size(); ++i) { |
| 223 | keys[i] = batch[key_field_ids_[i]]; |
| 224 | } |
| 225 | ExecSpan key_batch(std::move(keys), batch.length); |
| 226 | |
| 227 | // Create a batch with group ids |
| 228 | ARROW_ASSIGN_OR_RAISE(Datum id_batch, state->grouper->Consume(key_batch)); |
| 229 | |
| 230 | // Execute aggregate kernels |
| 231 | for (size_t i = 0; i < agg_kernels_.size(); ++i) { |
| 232 | arrow::util::tracing::Span span; |
| 233 | START_COMPUTE_SPAN(span, aggs_[i].function, |
| 234 | {{"function.name", aggs_[i].function}, |
| 235 | {"function.options", |
| 236 | aggs_[i].options ? aggs_[i].options->ToString() : "<NULLPTR>"}, |
| 237 | {"function.kind", std::string(kind_name()) + "::Consume"}}); |
| 238 | auto ctx = plan_->query_context()->exec_context(); |
| 239 | KernelContext kernel_ctx{ctx}; |
| 240 | kernel_ctx.SetState(state->agg_states[i].get()); |
| 241 | |
| 242 | std::vector<ExecValue> column_values; |
| 243 | for (const int field : agg_src_fieldsets_[i]) { |
| 244 | column_values.push_back(batch[field]); |
| 245 | } |
| 246 | column_values.emplace_back(*id_batch.array()); |
| 247 | ExecSpan agg_batch(std::move(column_values), batch.length); |
| 248 | RETURN_NOT_OK(agg_kernels_[i]->resize(&kernel_ctx, state->grouper->num_groups())); |
| 249 | RETURN_NOT_OK(agg_kernels_[i]->consume(&kernel_ctx, agg_batch)); |
| 250 | } |
| 251 | |
| 252 | return Status::OK(); |
| 253 | } |
| 254 | |
| 255 | Status GroupByNode::Merge() { |
| 256 | arrow::util::tracing::Span span; |
nothing calls this directly
no test coverage detected