@gscdump/engine-duckdb-wasm 0.31.3 → 0.31.4

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.d.mts CHANGED
@@ -222,6 +222,38 @@ declare function attachOpfsParquetTables(options: AttachOpfsTablesOptions): Prom
222
222
  * are ignored.
223
223
  */
224
224
  declare function clearOpfsSnapshotCache(): Promise<void>;
225
+ /**
226
+ * Browser-side recent-overlay merge-on-read SQL — shared by the OPFS attach path
227
+ * (`opfs.ts`) and the in-memory buffer attach path (consumers'
228
+ * `registerParquetView`).
229
+ *
230
+ * The lake serves every day it has; the overlay serves ONLY days the lake lacks
231
+ * (`date NOT IN (SELECT DISTINCT date FROM lake)`), unioned with
232
+ * `UNION ALL BY NAME`. This is the browser sibling of the server's
233
+ * `overlayMergeEnvelope` (in gscdump.com); kept SEPARATE because the browser path
234
+ * can read the lake once via a `MATERIALIZED` CTE (CPU-bound DuckDB-WASM, bounded
235
+ * per-site buffers) where the server's many-s3-file reads prefer projection
236
+ * pushdown over a re-scan.
237
+ *
238
+ * Both `lakeSelect` / `overlaySelect` must already expose a `date` column cast to
239
+ * DATE (the overlay stores ISO strings; `SELECT * REPLACE (CAST(date AS DATE) AS
240
+ * date)`), so `UNION ALL BY NAME` merges them type-uniformly.
241
+ */
242
+ /**
243
+ * The view BODY (no `CREATE VIEW` wrapper) merging a base lake relation and a
244
+ * recent overlay. Returns null when neither side exists; the lake verbatim with
245
+ * no overlay; the overlay verbatim with no lake (every recent row is wanted).
246
+ *
247
+ * `materializeLake` (default true): wrap the lake in a `MATERIALIZED` CTE so it is
248
+ * scanned ONCE and reused for both the served rows and the anti-join date set — a
249
+ * plain CTE inlines and re-scans the parquet, the dominant cost in DuckDB-WASM.
250
+ * Set false to keep the streaming re-scan shape (lower peak memory, two scans).
251
+ */
252
+ declare function overlayViewBody(args: {
253
+ lakeSelect: string | null;
254
+ overlaySelect: string | null;
255
+ materializeLake?: boolean;
256
+ }): string | null;
225
257
  interface QueryResult {
226
258
  rows: Record<string, unknown>[];
227
259
  queryMs: number;
@@ -427,4 +459,4 @@ declare function createBrowserAnalysisRuntime(boot: DuckDBWasmBootResult, option
427
459
  version?: number | string;
428
460
  attachedTables?: readonly string[];
429
461
  }): BrowserAnalysisRuntime;
430
- export { type AnalyzeResult, type AttachOpfsTablesOptions, type AttachParquetTablesOptions, type AttachParquetUrlTablesOptions, type AttachedTablesHandle, type BootDuckDBWasmOptions, type BrowserAnalysisRuntime, BrowserAttachBudgetExceededError, type BrowserAttachError, type BrowserParquetFile, type BrowserParquetTable, type BrowserParquetUrlTable, type ComparisonMode, type CompiledArchetypeSql, type DuckDBWasmBootResult, type DuckDBWasmClient, DuckDBWasmDatabase, type DuckDBWasmDrizzleDatabase, type InsightRunner, type InsightRunnerOptions, type OpfsAttachedHandle, type OpfsFileProgress, type OpfsParquetFile, type OpfsParquetTable, OpfsQuotaExceededError, type QueryResult, type ResolveWindowOptions, type ResolvedWindow, type Schema, type ScopedRunnerOptions, type StrikingMomentumOptions, type StrikingMomentumRow, type TableScope, type WindowPreset, attachOpfsParquetTables, attachParquetTables, attachParquetUrlTables, attachParquetUrlTablesResult, bootDuckDBWasm, browserAttachErrors, clearOpfsSnapshotCache, compileArchetypeSql, countries, createBrowserAnalysisRuntime, createClient, createInsightRunner, dates, drizzle, estimateOpfsStorage, hourly_pages, isBrowserAttachError, mergeScope, page_queries, pages, queries, requestPersistentStorage, resolveWindow, schema, scopeFor, strikingMomentum, tableForArchetype };
462
+ export { type AnalyzeResult, type AttachOpfsTablesOptions, type AttachParquetTablesOptions, type AttachParquetUrlTablesOptions, type AttachedTablesHandle, type BootDuckDBWasmOptions, type BrowserAnalysisRuntime, BrowserAttachBudgetExceededError, type BrowserAttachError, type BrowserParquetFile, type BrowserParquetTable, type BrowserParquetUrlTable, type ComparisonMode, type CompiledArchetypeSql, type DuckDBWasmBootResult, type DuckDBWasmClient, DuckDBWasmDatabase, type DuckDBWasmDrizzleDatabase, type InsightRunner, type InsightRunnerOptions, type OpfsAttachedHandle, type OpfsFileProgress, type OpfsParquetFile, type OpfsParquetTable, OpfsQuotaExceededError, type QueryResult, type ResolveWindowOptions, type ResolvedWindow, type Schema, type ScopedRunnerOptions, type StrikingMomentumOptions, type StrikingMomentumRow, type TableScope, type WindowPreset, attachOpfsParquetTables, attachParquetTables, attachParquetUrlTables, attachParquetUrlTablesResult, bootDuckDBWasm, browserAttachErrors, clearOpfsSnapshotCache, compileArchetypeSql, countries, createBrowserAnalysisRuntime, createClient, createInsightRunner, dates, drizzle, estimateOpfsStorage, hourly_pages, isBrowserAttachError, mergeScope, overlayViewBody, page_queries, pages, queries, requestPersistentStorage, resolveWindow, schema, scopeFor, strikingMomentum, tableForArchetype };
package/dist/index.mjs CHANGED
@@ -547,6 +547,15 @@ function createOpfsHandleRegistry(backend) {
547
547
  viewRefs: (key) => viewRefs.get(key) ?? 0
548
548
  };
549
549
  }
550
+ function overlayViewBody(args) {
551
+ const { lakeSelect, overlaySelect } = args;
552
+ const materialize = args.materializeLake ?? true;
553
+ if (!lakeSelect && !overlaySelect) return null;
554
+ if (!overlaySelect) return lakeSelect;
555
+ if (!lakeSelect) return overlaySelect;
556
+ if (materialize) return `WITH lake AS MATERIALIZED (${lakeSelect}), lake_dates AS (SELECT DISTINCT date FROM lake) SELECT * FROM lake UNION ALL BY NAME SELECT * FROM (${overlaySelect}) AS overlay WHERE overlay.date NOT IN (SELECT date FROM lake_dates)`;
557
+ return `${lakeSelect} UNION ALL BY NAME SELECT * FROM (${overlaySelect}) AS overlay WHERE overlay.date NOT IN (SELECT DISTINCT date FROM (${lakeSelect}))`;
558
+ }
550
559
  var OpfsQuotaExceededError = class extends Error {
551
560
  name = "OpfsQuotaExceededError";
552
561
  degradedTables;
@@ -680,8 +689,11 @@ function readParquetViewSql$1(schema, table, files) {
680
689
  }
681
690
  function readParquetViewWithOverlaySql(schema, table, lakeFiles, overlayFile) {
682
691
  const overlay = `SELECT * REPLACE (CAST(date AS DATE) AS date) FROM read_parquet(['${overlayFile.replace(/'/g, "''")}'], union_by_name = true)`;
683
- if (lakeFiles.length === 0) return `CREATE OR REPLACE VIEW ${schema}.${table} AS ${overlay}`;
684
- return `CREATE OR REPLACE VIEW ${schema}.${table} AS WITH lake AS MATERIALIZED (${lakeSelect(lakeFiles)}), lake_dates AS (SELECT DISTINCT date FROM lake) SELECT * FROM lake UNION ALL BY NAME SELECT * FROM (${overlay}) AS overlay WHERE overlay.date NOT IN (SELECT date FROM lake_dates)`;
692
+ return `CREATE OR REPLACE VIEW ${schema}.${table} AS ${overlayViewBody({
693
+ lakeSelect: lakeFiles.length === 0 ? null : lakeSelect(lakeFiles),
694
+ overlaySelect: overlay,
695
+ materializeLake: true
696
+ })}`;
685
697
  }
686
698
  async function runWithConcurrency$1(items, concurrency, fn) {
687
699
  let next = 0;
@@ -1295,4 +1307,4 @@ function createBrowserAnalysisRuntime(boot, options = {}) {
1295
1307
  }
1296
1308
  };
1297
1309
  }
1298
- export { BrowserAttachBudgetExceededError, DuckDBWasmDatabase, OpfsQuotaExceededError, attachOpfsParquetTables, attachParquetTables, attachParquetUrlTables, attachParquetUrlTablesResult, bootDuckDBWasm, browserAttachErrors, clearOpfsSnapshotCache, compileArchetypeSql, countries, createBrowserAnalysisRuntime, createClient, createInsightRunner, dates, drizzle, estimateOpfsStorage, hourly_pages, isBrowserAttachError, mergeScope, page_queries, pages, queries, requestPersistentStorage, resolveWindow, schema, scopeFor, strikingMomentum, tableForArchetype };
1310
+ export { BrowserAttachBudgetExceededError, DuckDBWasmDatabase, OpfsQuotaExceededError, attachOpfsParquetTables, attachParquetTables, attachParquetUrlTables, attachParquetUrlTablesResult, bootDuckDBWasm, browserAttachErrors, clearOpfsSnapshotCache, compileArchetypeSql, countries, createBrowserAnalysisRuntime, createClient, createInsightRunner, dates, drizzle, estimateOpfsStorage, hourly_pages, isBrowserAttachError, mergeScope, overlayViewBody, page_queries, pages, queries, requestPersistentStorage, resolveWindow, schema, scopeFor, strikingMomentum, tableForArchetype };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gscdump/engine-duckdb-wasm",
3
3
  "type": "module",
4
- "version": "0.31.3",
4
+ "version": "0.31.4",
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
- "@gscdump/engine": "0.31.3",
49
- "@gscdump/contracts": "0.31.3",
50
- "gscdump": "0.31.3"
48
+ "@gscdump/contracts": "0.31.4",
49
+ "@gscdump/engine": "0.31.4",
50
+ "gscdump": "0.31.4"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@duckdb/duckdb-wasm": "^1.32.0",