* One usage dimension, from a `usage_daily` column. Absent values are stored as '' * (they are part of the primary key), so '' is what gets skipped. `where` narrows * the rows further — name_error keeps only counters that saw an error.
(dim: string, column: string, total = 'count', where = '')
| 164 | * the rows further — name_error keeps only counters that saw an error. |
| 165 | */ |
| 166 | function usageDimStatement(dim: string, column: string, total = 'count', where = ''): string { |
| 167 | return `INSERT INTO daily_dim_counts (day, event, dim, value, count, machines) |
| 168 | SELECT day, 'usage_rollup', '${dim}', ${column}, sum(${total}), count(DISTINCT machine_id) |
| 169 | FROM usage_daily |
| 170 | WHERE day = ? AND ${column} <> ''${where} |
| 171 | GROUP BY day, ${column} |
| 172 | ${DIM_CONFLICT}`; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * One dimension unnested from a JSON array prop — one row per element, so an index |