One projected row per aggregation group, in first-seen group order. */
| 4800 | |
| 4801 | /* One projected row per aggregation group, in first-seen group order. */ |
| 4802 | static binding_t *with_agg_rows(with_sink_t *s, int *vcount) { |
| 4803 | cbm_return_clause_t *wc = s->wc; |
| 4804 | with_agg_t *aggs = s->aggs; |
| 4805 | int agg_cnt = s->agg_cnt; |
| 4806 | binding_t *vbindings = |
| 4807 | cbm_alloc(CBM_MEM_CLASS_OTHER, ((size_t)agg_cnt + SKIP_ONE) * sizeof(binding_t)); |
| 4808 | if (!vbindings) { |
| 4809 | return NULL; |
| 4810 | } |
| 4811 | for (int a = 0; a < agg_cnt; a++) { |
| 4812 | binding_t vb = {0}; |
| 4813 | /* Carry the store so node_prop can re-fetch a carried node's properties |
| 4814 | * (and compute in_degree/out_degree) on the projected virtual binding. */ |
| 4815 | vb.store = s->store; |
| 4816 | for (int ci = 0; ci < wc->count; ci++) { |
| 4817 | char name_buf[CBM_SZ_256]; |
| 4818 | const char *alias = resolve_item_alias(&wc->items[ci], name_buf, sizeof(name_buf)); |
| 4819 | if (is_aggregate_func(wc->items[ci].func)) { |
| 4820 | char vbuf[CBM_SZ_64]; |
| 4821 | if (wc->items[ci].distinct && strcmp(wc->items[ci].func, "COUNT") == 0) { |
| 4822 | snprintf(vbuf, sizeof(vbuf), "%d", aggs[a].distinct_n[ci]); /* #239 */ |
| 4823 | } else { |
| 4824 | with_agg_format(wc->items[ci].func, &aggs[a], ci, vbuf, sizeof(vbuf)); |
| 4825 | } |
| 4826 | with_add_vbinding_var(&vb, alias, vbuf); |
| 4827 | } else if (aggs[a].group_nodes[ci].id > 0) { |
| 4828 | binding_set(&vb, with_item_node_alias(&wc->items[ci]), &aggs[a].group_nodes[ci]); |
| 4829 | } else { |
| 4830 | with_add_vbinding_var(&vb, alias, aggs[a].group_vals[ci]); |
| 4831 | } |
| 4832 | } |
| 4833 | vbindings[(*vcount)++] = vb; |
| 4834 | } |
| 4835 | return vbindings; |
| 4836 | } |
| 4837 | |
| 4838 | /* Execute WITH simple (non-aggregate) projection */ |
| 4839 | static void execute_with_simple(cbm_return_clause_t *wc, binding_t *bindings, int bind_count, |
no test coverage detected