@gscdump/engine 0.12.0 → 0.13.1

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.
@@ -199,6 +199,39 @@ function createSqlFragments(config) {
199
199
  }
200
200
  return preds;
201
201
  }
202
+ function prefilterPredicates(filters, tableKey) {
203
+ const t = schema[tableKey];
204
+ const preds = [];
205
+ for (const f of filters) {
206
+ const metric = f.dimension;
207
+ let col;
208
+ if (metric === "clicks") col = t.clicks;
209
+ else if (metric === "impressions") col = t.impressions;
210
+ else if (metric === "position") col = t.sum_position;
211
+ if (!col) continue;
212
+ const v = Number(f.expression);
213
+ switch (f.operator) {
214
+ case "metricGte":
215
+ preds.push(sql`${col} >= ${v}`);
216
+ break;
217
+ case "metricGt":
218
+ preds.push(sql`${col} > ${v}`);
219
+ break;
220
+ case "metricLte":
221
+ preds.push(sql`${col} <= ${v}`);
222
+ break;
223
+ case "metricLt":
224
+ preds.push(sql`${col} < ${v}`);
225
+ break;
226
+ case "metricBetween": {
227
+ const v2 = Number(f.expression2);
228
+ preds.push(sql`${col} >= ${v} AND ${col} <= ${v2}`);
229
+ break;
230
+ }
231
+ }
232
+ }
233
+ return preds;
234
+ }
202
235
  function dimensionPredicates(filters, tableKey) {
203
236
  const preds = [];
204
237
  for (const f of filters) {
@@ -250,6 +283,7 @@ function createSqlFragments(config) {
250
283
  dimExprSql,
251
284
  metricSql,
252
285
  havingPredicates,
286
+ prefilterPredicates,
253
287
  dimensionPredicates,
254
288
  topLevelPredicate
255
289
  };
@@ -272,6 +306,7 @@ function createResolverAdapter(config) {
272
306
  metricSql: runtime.metricSql,
273
307
  dimensionPredicates: runtime.dimensionPredicates,
274
308
  havingPredicates: runtime.havingPredicates,
309
+ prefilterPredicates: runtime.prefilterPredicates,
275
310
  topLevelPredicate: runtime.topLevelPredicate,
276
311
  compile: config.compile
277
312
  };
@@ -355,6 +390,7 @@ function buildScope(state, options) {
355
390
  const tableKey = adapter.tableKeyForDataset(plan.dataset);
356
391
  const dimFilters = toInternalDimensionFilters(plan.dimensionFilters);
357
392
  const metricFilters = toInternalMetricFilters(plan.metricFilters);
393
+ const prefilters = toInternalMetricFilters(plan.prefilters);
358
394
  const groupByDims = plan.groupByDimensions;
359
395
  const hasDate = plan.hasDate;
360
396
  const metrics = plan.metrics;
@@ -362,6 +398,7 @@ function buildScope(state, options) {
362
398
  if (adapter.siteIdColRef && siteId != null) wherePredicates.push(sql`${adapter.siteIdColRef(tableKey)} = ${siteId}`);
363
399
  wherePredicates.push(sql`${adapter.dateColRef(tableKey)} >= ${plan.dateRange.startDate}`);
364
400
  wherePredicates.push(sql`${adapter.dateColRef(tableKey)} <= ${plan.dateRange.endDate}`);
401
+ wherePredicates.push(...adapter.prefilterPredicates(prefilters, tableKey));
365
402
  const dimSql = plan.dimensionFilterTree ? compileFilterTree(plan.dimensionFilterTree, adapter, tableKey) : void 0;
366
403
  if (dimSql) wherePredicates.push(dimSql);
367
404
  else if (!plan.dimensionFilterTree) wherePredicates.push(...adapter.dimensionPredicates(dimFilters, tableKey));
@@ -17,6 +17,7 @@ interface ResolverAdapter<TableKey extends string = string> {
17
17
  metricSql: (metric: Metric, tableKey: TableKey) => SQL;
18
18
  dimensionPredicates: (filters: InternalFilter[], tableKey: TableKey) => SQL[];
19
19
  havingPredicates: (filters: InternalFilter[], tableKey: TableKey) => SQL[];
20
+ prefilterPredicates: (filters: InternalFilter[], tableKey: TableKey) => SQL[];
20
21
  topLevelPredicate: (filters: InternalFilter[], tableKey: TableKey) => SQL | undefined;
21
22
  compile: (query: SQL) => {
22
23
  sql: string;
@@ -49,6 +49,7 @@ interface SqlFragments<TableKey extends string> {
49
49
  dimExprSql: (dim: Dimension, tableKey: TableKey) => SQL;
50
50
  metricSql: (metric: Metric, tableKey: TableKey) => SQL;
51
51
  havingPredicates: (filters: InternalFilter[], tableKey: TableKey) => SQL[];
52
+ prefilterPredicates: (filters: InternalFilter[], tableKey: TableKey) => SQL[];
52
53
  dimensionPredicates: (filters: InternalFilter[], tableKey: TableKey) => SQL[];
53
54
  topLevelPredicate: (filters: InternalFilter[], tableKey: TableKey) => SQL | undefined;
54
55
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gscdump/engine",
3
3
  "type": "module",
4
- "version": "0.12.0",
4
+ "version": "0.13.1",
5
5
  "description": "Append-only Parquet/DuckDB storage engine + planner + adapters for the gscdump pipeline. Node + edge runtimes; opt-in heavy peers.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -169,8 +169,8 @@
169
169
  "dependencies": {
170
170
  "drizzle-orm": "^0.45.2",
171
171
  "proper-lockfile": "^4.1.2",
172
- "gscdump": "0.12.0",
173
- "@gscdump/contracts": "0.12.0"
172
+ "@gscdump/contracts": "0.13.1",
173
+ "gscdump": "0.13.1"
174
174
  },
175
175
  "devDependencies": {
176
176
  "@duckdb/duckdb-wasm": "^1.32.0",