* 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 = '')
| 115 | * the rows further — name_error keeps only counters that saw an error. |
| 116 | */ |
| 117 | function usageDimStatement(dim: string, column: string, total = 'count', where = ''): string { |
| 118 | return `INSERT INTO daily_dim_counts (day, event, dim, value, count, machines) |
| 119 | SELECT day, 'usage_rollup', '${dim}', ${column}, sum(${total}), count(DISTINCT machine_id) |
| 120 | FROM usage_daily |
| 121 | WHERE day = ? AND ${column} <> ''${where} |
| 122 | GROUP BY day, ${column} |
| 123 | ${DIM_CONFLICT}`; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * One dimension unnested from a JSON array prop — one row per element, so an index |