@gscdump/engine-duckdb-wasm 0.32.12 → 0.33.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.
- package/dist/index.mjs +12 -7
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -20,11 +20,16 @@ const METRIC_SQL = {
|
|
|
20
20
|
const DIM_COLUMN = {
|
|
21
21
|
page: "url",
|
|
22
22
|
query: "query",
|
|
23
|
-
queryCanonical: "query_canonical",
|
|
24
23
|
country: "country",
|
|
25
24
|
date: "date",
|
|
26
25
|
searchAppearance: "search_appearance"
|
|
27
26
|
};
|
|
27
|
+
function queryCanonicalExpr(queryRef = "query") {
|
|
28
|
+
return `COALESCE((SELECT qd.query_canonical FROM query_dim qd WHERE qd.query = ${queryRef} LIMIT 1), ${queryRef})`;
|
|
29
|
+
}
|
|
30
|
+
function dimExpr(dim) {
|
|
31
|
+
return dim === "queryCanonical" ? queryCanonicalExpr() : DIM_COLUMN[dim] ?? dim;
|
|
32
|
+
}
|
|
28
33
|
function tableForDimensions(dims) {
|
|
29
34
|
const set = new Set(dims.filter((d) => d !== "date"));
|
|
30
35
|
if (set.has("page") && (set.has("query") || set.has("queryCanonical"))) return "page_queries";
|
|
@@ -128,7 +133,7 @@ function facetPredicate(query) {
|
|
|
128
133
|
const parts = [];
|
|
129
134
|
const params = [];
|
|
130
135
|
for (const f of facets) {
|
|
131
|
-
const col =
|
|
136
|
+
const col = dimExpr(f.column);
|
|
132
137
|
switch (f.op) {
|
|
133
138
|
case "eq":
|
|
134
139
|
parts.push(`${col} = ?`);
|
|
@@ -163,7 +168,7 @@ function compileArchetypeSql(query) {
|
|
|
163
168
|
}
|
|
164
169
|
case "entity-daily-timeseries": {
|
|
165
170
|
const table = tableForDimensions([query.entity.dimension]);
|
|
166
|
-
const col =
|
|
171
|
+
const col = dimExpr(query.entity.dimension);
|
|
167
172
|
const where = rangePredicate(query);
|
|
168
173
|
return {
|
|
169
174
|
table,
|
|
@@ -173,7 +178,7 @@ function compileArchetypeSql(query) {
|
|
|
173
178
|
}
|
|
174
179
|
case "entity-daily-sparkline": {
|
|
175
180
|
const table = tableForDimensions([query.dimension]);
|
|
176
|
-
const col =
|
|
181
|
+
const col = dimExpr(query.dimension);
|
|
177
182
|
const where = rangePredicate(query);
|
|
178
183
|
if (query.entities.length === 0) throw new Error("[archetype-sql] entity-daily-sparkline requires resolved entities");
|
|
179
184
|
const placeholders = query.entities.map(() => "?").join(", ");
|
|
@@ -231,7 +236,7 @@ function compileArchetypeSql(query) {
|
|
|
231
236
|
params
|
|
232
237
|
};
|
|
233
238
|
}
|
|
234
|
-
const col =
|
|
239
|
+
const col = dimExpr(query.dimension);
|
|
235
240
|
const facet = facetPredicate(query);
|
|
236
241
|
const totalCol = query.includeTotal ? ", COUNT(*) OVER() AS __total" : "";
|
|
237
242
|
if (cmp) {
|
|
@@ -281,7 +286,7 @@ function compileArchetypeSql(query) {
|
|
|
281
286
|
const matchParts = [];
|
|
282
287
|
const matchParams = [];
|
|
283
288
|
for (const [dim, value] of Object.entries(query.match)) {
|
|
284
|
-
const col =
|
|
289
|
+
const col = dimExpr(dim);
|
|
285
290
|
if (!col) throw new Error(`[archetype-sql] single-row-lookup: unknown dimension ${dim}`);
|
|
286
291
|
matchParts.push(`${col} = ?`);
|
|
287
292
|
matchParams.push(value);
|
|
@@ -305,7 +310,7 @@ function compileArchetypeSql(query) {
|
|
|
305
310
|
...where.params
|
|
306
311
|
]
|
|
307
312
|
};
|
|
308
|
-
const col =
|
|
313
|
+
const col = dimExpr(query.seriesDimension);
|
|
309
314
|
return {
|
|
310
315
|
table,
|
|
311
316
|
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}`,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gscdump/engine-duckdb-wasm",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.33.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",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"drizzle-orm": "1.0.0-rc.3",
|
|
48
|
-
"
|
|
49
|
-
"@gscdump/
|
|
50
|
-
"gscdump": "0.
|
|
48
|
+
"gscdump": "0.33.0",
|
|
49
|
+
"@gscdump/engine": "0.33.0",
|
|
50
|
+
"@gscdump/contracts": "0.33.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@duckdb/duckdb-wasm": "^1.32.0",
|