@gscdump/engine-duckdb-wasm 5.3.0 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -159,37 +159,63 @@ function facetPredicate(query, table) {
159
159
  params
160
160
  };
161
161
  }
162
+ const DAILY_FACET_COLUMNS = /* @__PURE__ */ new Set([
163
+ "page",
164
+ "query",
165
+ "queryCanonical",
166
+ "country"
167
+ ]);
168
+ function dailyTable(query, seriesDimension, unfaceted) {
169
+ const facets = query.facets ?? [];
170
+ if (!facets.length) return unfaceted;
171
+ const dims = [...seriesDimension ? [seriesDimension] : [], ...facets.map((facet) => facet.column)];
172
+ const unsupported = dims.find((dim) => !DAILY_FACET_COLUMNS.has(dim));
173
+ if (unsupported) throw new Error(`[archetype-sql] ${query.archetype}: a daily read cannot combine a facet with the ${unsupported} dimension`);
174
+ if (dims.includes("country") && dims.some((dim) => dim !== "country")) throw new Error(`[archetype-sql] ${query.archetype}: no fact table stores country with page or query, so a daily read cannot apply this facet`);
175
+ return tableForDimensions(dims);
176
+ }
162
177
  function compileArchetypeSql(query) {
163
178
  switch (query.archetype) {
164
179
  case "site-daily-timeseries": {
165
- const table = "dates";
180
+ const table = dailyTable(query, void 0, "dates");
166
181
  const where = rangePredicate(query);
182
+ const facet = facetPredicate(query, table);
167
183
  return {
168
184
  table,
169
- sql: `SELECT date, ${query.metrics.map((m) => `${metricExpr(m)} AS ${m}`).join(", ")} FROM ${table} WHERE ${where.sql} GROUP BY date ORDER BY date`,
170
- params: where.params
185
+ sql: `SELECT date, ${query.metrics.map((m) => `${metricExpr(m)} AS ${m}`).join(", ")} FROM ${table} WHERE ${where.sql}${facet.sql} GROUP BY date ORDER BY date`,
186
+ params: [...where.params, ...facet.params]
171
187
  };
172
188
  }
173
189
  case "entity-daily-timeseries": {
174
- const table = tableForDimensions([query.entity.dimension]);
190
+ const table = dailyTable(query, query.entity.dimension, tableForDimensions([query.entity.dimension]));
175
191
  const col = dimExpr(query.entity.dimension, table);
176
192
  const where = rangePredicate(query);
193
+ const facet = facetPredicate(query, table);
177
194
  return {
178
195
  table,
179
- sql: `SELECT date, ${metricSelectList(query.metrics)} FROM ${table} WHERE ${where.sql} AND ${col} = ? GROUP BY date ORDER BY date`,
180
- params: [...where.params, query.entity.value]
196
+ sql: `SELECT date, ${metricSelectList(query.metrics)} FROM ${table} WHERE ${where.sql}${facet.sql} AND ${col} = ? GROUP BY date ORDER BY date`,
197
+ params: [
198
+ ...where.params,
199
+ ...facet.params,
200
+ query.entity.value
201
+ ]
181
202
  };
182
203
  }
183
204
  case "entity-daily-sparkline": {
184
- const table = tableForDimensions([query.dimension]);
205
+ const table = dailyTable(query, query.dimension, tableForDimensions([query.dimension]));
185
206
  const col = dimExpr(query.dimension, table);
186
207
  const where = rangePredicate(query);
208
+ const facet = facetPredicate(query, table);
187
209
  if (query.entities.length === 0) throw new Error("[archetype-sql] entity-daily-sparkline requires resolved entities");
188
210
  const placeholders = query.entities.map(() => "?").join(", ");
189
211
  return {
190
212
  table,
191
- sql: `SELECT ${col} AS entity, date, ${metricExpr(query.metric)} AS ${query.metric} FROM ${table} WHERE ${where.sql} AND ${col} IN (${placeholders}) GROUP BY ${col}, date ORDER BY ${col}, date`,
192
- params: [...where.params, ...query.entities]
213
+ sql: `SELECT ${col} AS entity, date, ${metricExpr(query.metric)} AS ${query.metric} FROM ${table} WHERE ${where.sql}${facet.sql} AND ${col} IN (${placeholders}) GROUP BY ${col}, date ORDER BY ${col}, date`,
214
+ params: [
215
+ ...where.params,
216
+ ...facet.params,
217
+ ...query.entities
218
+ ]
193
219
  };
194
220
  }
195
221
  case "top-n-breakdown": {
@@ -304,7 +330,7 @@ function compileArchetypeSql(query) {
304
330
  };
305
331
  }
306
332
  case "multi-series-stacked-daily": {
307
- const table = tableForDimensions([query.seriesDimension]);
333
+ const table = dailyTable(query, query.seriesDimension, tableForDimensions([query.seriesDimension]));
308
334
  const where = rangePredicate(query);
309
335
  if (query.seriesDimension === "device") return {
310
336
  table,
@@ -316,10 +342,11 @@ function compileArchetypeSql(query) {
316
342
  ]
317
343
  };
318
344
  const col = dimExpr(query.seriesDimension, table);
345
+ const facet = facetPredicate(query, table);
319
346
  return {
320
347
  table,
321
- sql: `SELECT date, ${col} AS ${query.seriesDimension}, ${metricExpr(query.metric)} AS ${query.metric} FROM ${table} WHERE ${where.sql} GROUP BY date, ${col} ORDER BY date, ${col}`,
322
- params: where.params
348
+ sql: `SELECT date, ${col} AS ${query.seriesDimension}, ${metricExpr(query.metric)} AS ${query.metric} FROM ${table} WHERE ${where.sql}${facet.sql} GROUP BY date, ${col} ORDER BY date, ${col}`,
349
+ params: [...where.params, ...facet.params]
323
350
  };
324
351
  }
325
352
  case "two-dimension-detail": {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gscdump/engine-duckdb-wasm",
3
3
  "type": "module",
4
- "version": "5.3.0",
4
+ "version": "5.7.0",
5
5
  "description": "DuckDB-WASM engine adapter for @gscdump/analysis — typed browser analytics against parquet via R2.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -44,10 +44,10 @@
44
44
  }
45
45
  },
46
46
  "dependencies": {
47
- "@gscdump/contracts": "^5.3.0",
48
- "@gscdump/engine": "^5.3.0",
47
+ "@gscdump/contracts": "^5.7.0",
48
+ "@gscdump/engine": "^5.7.0",
49
49
  "drizzle-orm": "1.0.0-rc.4",
50
- "gscdump": "^5.3.0"
50
+ "gscdump": "^5.7.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@duckdb/duckdb-wasm": "1.33.1-dev57.0",