import { FileSetRef, Row as Row$1, TableName as TableName$1 } from "../storage.mjs"; import "../contracts.mjs"; import { RollupEngine } from "./core.mjs"; import { TenantCtx } from "@gscdump/contracts"; import { SearchType } from "gscdump/query"; /** * Per-window budget, measured in *parquet* bytes (manifest `bytes`), used by * `planRollupWindows` to chunk a full-history scan. * * The executor decodes a window's parquet and ships it as an Arrow IPC stream * over the service binding; that IPC is hard-guarded at 28MiB * (`IPC_PLACEHOLDER_BUDGET` in @gscdump/cloudflare). Parquet is compressed and * the IPC stream is not, so a window inflates on the wire — keep this * conservatively below the guard. Re-measure the parquet→IPC ratio against * production and raise if headroom allows. */ declare const WINDOW_BYTE_BUDGET: number; /** * Per-page OUTPUT row cap for key-paginated rollups (`runWindowed({ paginate })` * and `runPagedQuery`). `planRollupWindows` bounds the *input* parquet bytes a * window scans, which is a fine proxy for output size on fact aggregations whose * grain matches the input (one output row per input date). It is NOT a proxy for * aggregations that COLLAPSE to a smaller-cardinality grain whose row count is * driven by a high-cardinality GROUP key — `(query_canonical × date)` and * `(query_canonical)` — where output rows scale with distinct canonicals, not * input bytes. For those, each `runSQL` result (shipped as an Arrow IPC stream * over the Workers service-binding RPC; 28MiB guard in `@gscdump/cloudflare`, * duckdb-worker `assertResultBudget` at 24MiB / 100k rows) must be bounded by * paging the OUTPUT, independent of how the input is windowed. * * Narrow rows — `(canonical, date, 3 metrics)` — page at 50k (≈16MiB at the * worker's `cols×64` heuristic, well under both guards). WIDE rows carry a * `GROUP_CONCAT` variants string (up to ~10 variants × ~60 chars) the heuristic * under-counts, so they page smaller to keep the real IPC payload bounded. */ declare const ROLLUP_PAGE_ROWS = 50000; declare const ROLLUP_PAGE_ROWS_WIDE = 20000; declare const ROLLUP_PAGE_ROWS_DAILY = 70000; /** * Plan byte-bounded windows over a partition set. Each window names the * partitions whose span intersects it; a coarse tier file can land in two * windows, so every windowed SQL MUST also date-filter to the window bounds. */ declare function planRollupWindows(parts: Array<{ partition: string; bytes: number; }>, clampRange?: { start: string; end: string; }, maxWindowDays?: number): Array<{ start: string; end: string; partitions: string[]; }>; /** * Run a full-history aggregation in byte-bounded windows and concat the rows. * Each window's SQL MUST date-filter to `[w.start, w.end]` (see `sqlFor`) so a * tier file spanning a window boundary doesn't double-count calendar dates. * * `paginate` additionally pages each window's OUTPUT (see `runPagedQuery`) so a * window whose GROUP cardinality is high — `(query_canonical × date)` on a large * site — can't ship an oversized result even though its input bytes fit a window. * Date-windowing bounds the per-query scan; output paging bounds the IPC payload. * The two are orthogonal and compose. When `paginate` is set, `sqlFor` MUST emit * no trailing `ORDER BY`/`LIMIT` and `paginate.orderBy` MUST be a total order. */ declare function runWindowed(opts: { engine: RollupEngine; ctx: TenantCtx; table: TableName$1; searchType?: SearchType; sqlFor: (w: { start: string; end: string; }) => string; /** * Extra named file sets merged into every window's `runSQL` (alongside the * windowed `FILES`). Use to JOIN a non-windowed sidecar (e.g. the query * dimension parquet via `{ QUERY_DIM: { keys: [...] } }`) inside `sqlFor`. */ extraFileSets?: Record; /** Page each window's output by a total-order key. See `runPagedQuery`. */ paginate?: { orderBy: string; pageRows: number; }; /** Cap each window's day span (output-cardinality bound). See `planRollupWindows`. */ maxWindowDays?: number; }): Promise; export { ROLLUP_PAGE_ROWS, ROLLUP_PAGE_ROWS_DAILY, ROLLUP_PAGE_ROWS_WIDE, WINDOW_BYTE_BUDGET, planRollupWindows, runWindowed };