* One dimension unnested from a JSON array prop — one row per element, so an index * of a TypeScript+Go repo counts once under each language. `json_each` over a path * the props do not have yields no rows, which is exactly the wanted behaviour for * events that omit the array.
(dim: string, path: string, events: readonly string[])
| 130 | * events that omit the array. |
| 131 | */ |
| 132 | function arrayDimStatement(dim: string, path: string, events: readonly string[]): string { |
| 133 | return `INSERT INTO daily_dim_counts (day, event, dim, value, count, machines) |
| 134 | SELECT e.day, e.event, '${dim}', CAST(j.value AS TEXT), count(*), count(DISTINCT e.machine_id) |
| 135 | FROM events e, json_each(e.props, '${path}') j |
| 136 | WHERE e.day = ? AND e.event IN (${quoted(events)}) AND j.value <> '' |
| 137 | GROUP BY e.day, e.event, j.value |
| 138 | ${DIM_CONFLICT}`; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Rebuilt from `machine_days`, not from `events`: that table is never purged, so this |