Accumulate aggregation values for a binding */
| 3556 | |
| 3557 | /* Accumulate aggregation values for a binding */ |
| 3558 | static void with_agg_accumulate(with_agg_t *agg, cbm_return_clause_t *wc, binding_t *b) { |
| 3559 | for (int ci = 0; ci < wc->count; ci++) { |
| 3560 | if (!wc->items[ci].func) { |
| 3561 | continue; |
| 3562 | } |
| 3563 | agg->counts[ci]++; |
| 3564 | const char *raw = binding_get_virtual(b, wc->items[ci].variable, wc->items[ci].property); |
| 3565 | if (wc->items[ci].distinct && strcmp(wc->items[ci].func, "COUNT") == 0) { |
| 3566 | distinct_list_add(&agg->distinct_lists[ci], &agg->distinct_n[ci], raw); |
| 3567 | } |
| 3568 | double dv = strtod(raw, NULL); |
| 3569 | agg->sums[ci] += dv; |
| 3570 | if (dv < agg->mins[ci]) { |
| 3571 | agg->mins[ci] = dv; |
| 3572 | } |
| 3573 | if (dv > agg->maxs[ci]) { |
| 3574 | agg->maxs[ci] = dv; |
| 3575 | } |
| 3576 | } |
| 3577 | } |
| 3578 | |
| 3579 | /* Format a WITH aggregation value into buf */ |
| 3580 | static void with_agg_format(const char *func, with_agg_t *agg, int ci, char *buf, size_t buf_sz) { |
no test coverage detected