Accumulate aggregation values for a binding */
| 3896 | |
| 3897 | /* Accumulate aggregation values for a binding */ |
| 3898 | static void with_agg_accumulate(with_agg_t *agg, cbm_return_clause_t *wc, binding_t *b) { |
| 3899 | for (int ci = 0; ci < wc->count; ci++) { |
| 3900 | if (!is_aggregate_func(wc->items[ci].func)) { |
| 3901 | continue; |
| 3902 | } |
| 3903 | agg->counts[ci]++; |
| 3904 | const char *raw = binding_get_virtual(b, wc->items[ci].variable, wc->items[ci].property); |
| 3905 | if (wc->items[ci].distinct && strcmp(wc->items[ci].func, "COUNT") == 0) { |
| 3906 | distinct_list_add(&agg->distinct_lists[ci], &agg->distinct_n[ci], raw); |
| 3907 | } |
| 3908 | double dv = strtod(raw, NULL); |
| 3909 | agg->sums[ci] += dv; |
| 3910 | if (dv < agg->mins[ci]) { |
| 3911 | agg->mins[ci] = dv; |
| 3912 | } |
| 3913 | if (dv > agg->maxs[ci]) { |
| 3914 | agg->maxs[ci] = dv; |
| 3915 | } |
| 3916 | } |
| 3917 | } |
| 3918 | |
| 3919 | /* Format a WITH aggregation value into buf */ |
| 3920 | static void with_agg_format(const char *func, with_agg_t *agg, int ci, char *buf, size_t buf_sz) { |
no test coverage detected