Emit one aggregated row into the result builder */
| 4372 | |
| 4373 | /* Emit one aggregated row into the result builder */ |
| 4374 | static void ret_agg_emit_row(cbm_return_clause_t *ret, ret_agg_entry_t *agg, result_builder_t *rb) { |
| 4375 | const char *row[CBM_SZ_32]; |
| 4376 | char bufs[CBM_SZ_32][CBM_SZ_64]; |
| 4377 | for (int ci = 0; ci < ret->count; ci++) { |
| 4378 | if (!is_aggregate_func(ret->items[ci].func)) { |
| 4379 | row[ci] = agg->group_vals[ci]; |
| 4380 | continue; |
| 4381 | } |
| 4382 | if (ret->items[ci].distinct && strcmp(ret->items[ci].func, "COUNT") == 0) { |
| 4383 | /* COUNT(DISTINCT x) — number of unique values accumulated (#239). */ |
| 4384 | snprintf(bufs[ci], sizeof(bufs[ci]), "%d", agg->collect_counts[ci]); |
| 4385 | row[ci] = bufs[ci]; |
| 4386 | continue; |
| 4387 | } |
| 4388 | format_agg_value(ret->items[ci].func, agg->counts[ci], agg->sums[ci], agg->mins[ci], |
| 4389 | agg->maxs[ci], agg->collect_lists, agg->collect_counts, ci, bufs[ci], |
| 4390 | sizeof(bufs[ci])); |
| 4391 | row[ci] = bufs[ci]; |
| 4392 | } |
| 4393 | rb_add_row(rb, row); |
| 4394 | } |
| 4395 | |
| 4396 | static void execute_return_agg(cbm_return_clause_t *ret, binding_t *bindings, int bind_count, |
| 4397 | result_builder_t *rb) { |
no test coverage detected