@gscdump/engine 0.31.5 → 0.31.6

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.
Files changed (2) hide show
  1. package/dist/rollups.mjs +47 -30
  2. package/package.json +3 -3
package/dist/rollups.mjs CHANGED
@@ -603,44 +603,61 @@ const queryCanonicalVariantsRollup = {
603
603
  });
604
604
  if (parts.length === 0) return [];
605
605
  const partitions = parts.map((p) => p.partition);
606
- return (await runPagedQuery({
607
- engine,
608
- ctx,
609
- table: "queries",
610
- ...searchType !== void 0 ? { searchType } : {},
611
- fileSets: { FILES: {
606
+ const byCanonical = /* @__PURE__ */ new Map();
607
+ let cursor = null;
608
+ for (;;) {
609
+ const after = cursor === null ? "" : `AND query > '${cursor.replace(/'/g, "''")}'`;
610
+ const { rows } = await engine.runSQL({
611
+ ctx,
612
612
  table: "queries",
613
- partitions
614
- } },
615
- orderBy: "joinKey",
616
- pageRows: ROLLUP_PAGE_ROWS_WIDE,
617
- coreSql: `
618
- WITH per_variant AS (
613
+ ...searchType !== void 0 ? { searchType } : {},
614
+ fileSets: { FILES: {
615
+ table: "queries",
616
+ partitions
617
+ } },
618
+ sql: `
619
619
  SELECT
620
620
  COALESCE(NULLIF(query_canonical, ''), query) AS joinKey,
621
621
  query AS query,
622
622
  SUM(clicks) AS clicks,
623
623
  SUM(impressions) AS impressions,
624
- SUM(sum_position) AS sum_pos,
625
- ROW_NUMBER() OVER (PARTITION BY COALESCE(NULLIF(query_canonical, ''), query) ORDER BY SUM(clicks) DESC) AS rn,
626
- COUNT(*) OVER (PARTITION BY COALESCE(NULLIF(query_canonical, ''), query)) AS variantCount
624
+ SUM(sum_position) AS sum_pos
627
625
  FROM read_parquet({{FILES}}, union_by_name = true)
626
+ WHERE query IS NOT NULL ${after}
628
627
  GROUP BY COALESCE(NULLIF(query_canonical, ''), query), query
629
- )
630
- SELECT
631
- joinKey,
632
- MAX(variantCount)::BIGINT AS variantCount,
633
- MAX(CASE WHEN rn = 1 THEN query END) AS canonicalName,
634
- GROUP_CONCAT(CASE WHEN rn <= 10 THEN query || ':::' || clicks || ':::' || impressions || ':::' || CAST(ROUND(CAST(sum_pos AS REAL) / NULLIF(impressions, 0) + 1, 1) AS TEXT) END, '||') AS variants
635
- FROM per_variant
636
- GROUP BY joinKey
637
- `
638
- })).map((r) => ({
639
- joinKey: String(r.joinKey),
640
- variantCount: BigInt(r.variantCount),
641
- canonicalName: r.canonicalName == null ? null : String(r.canonicalName),
642
- variants: r.variants == null ? null : String(r.variants)
643
- }));
628
+ ORDER BY query
629
+ LIMIT ${ROLLUP_PAGE_ROWS_WIDE}
630
+ `
631
+ });
632
+ for (const r of rows) {
633
+ const joinKey = String(r.joinKey);
634
+ const list = byCanonical.get(joinKey);
635
+ const v = {
636
+ query: String(r.query),
637
+ clicks: Number(r.clicks),
638
+ impressions: Number(r.impressions),
639
+ sumPos: Number(r.sum_pos)
640
+ };
641
+ if (list) list.push(v);
642
+ else byCanonical.set(joinKey, [v]);
643
+ }
644
+ if (rows.length < 2e4) break;
645
+ cursor = String(rows[rows.length - 1].query);
646
+ }
647
+ const out = [];
648
+ for (const [joinKey, variants] of byCanonical) {
649
+ variants.sort((a, b) => b.clicks - a.clicks || a.query.localeCompare(b.query));
650
+ const canonicalName = variants[0]?.query ?? null;
651
+ const top = variants.slice(0, 10).filter((v) => v.impressions > 0);
652
+ const variantsStr = top.length === 0 ? null : top.map((v) => `${v.query}:::${v.clicks}:::${v.impressions}:::${(v.sumPos / v.impressions + 1).toFixed(1)}`).join("||");
653
+ out.push({
654
+ joinKey,
655
+ variantCount: BigInt(variants.length),
656
+ canonicalName,
657
+ variants: variantsStr
658
+ });
659
+ }
660
+ return out;
644
661
  }
645
662
  };
646
663
  const queryCanonicalDailyRollup = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gscdump/engine",
3
3
  "type": "module",
4
- "version": "0.31.5",
4
+ "version": "0.31.6",
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",
@@ -181,8 +181,8 @@
181
181
  "dependencies": {
182
182
  "drizzle-orm": "1.0.0-rc.3",
183
183
  "proper-lockfile": "^4.1.2",
184
- "gscdump": "0.31.5",
185
- "@gscdump/contracts": "0.31.5"
184
+ "gscdump": "0.31.6",
185
+ "@gscdump/contracts": "0.31.6"
186
186
  },
187
187
  "devDependencies": {
188
188
  "@duckdb/duckdb-wasm": "^1.32.0",