import { DataSource } from "../storage.mjs"; import "../contracts.mjs"; import { RollupDef, RollupEngine } from "./core.mjs"; import { TenantCtx } from "@gscdump/contracts"; import { SearchType } from "gscdump/query"; declare const queryCanonicalVariantsRollup: RollupDef; /** * Canonical-grained fact aggregate (ADR-0018 Gap 2): pre-sums the raw * `(query × date)` query rows to `(query_canonical × date)`, so canonical- * primary top/gaining/losing reads a small pre-aggregated table instead of * re-collapsing variants on every request. Metrics are additive, so summing * these per-date sums over a window is exact — identical to aggregating the raw * rows. * * Null-free by construction: groups by the versioned query dimension when it * exists, with raw query as the fallback, so the rollup never carries a NULL/'' * canonical bucket and the read path can treat the rollup's `query_canonical` * column as already-derived. * * Date-grained full history (`windowDays: null`): one rollup serves every date * range (reads filter by `date`) and both windows of a comparison. Opt-in (not * in `DEFAULT_ROLLUPS`); the host points the main query's file set at it for * queries the rollup covers (see `canonicalRollupCovers` / * `RunOptimizedQueryOptions.canonicalSource`). */ declare const queryCanonicalDailyRollup: RollupDef; /** * Resumable, cross-invocation build of `query_canonical_daily` for a high- * cardinality site whose full windowed build exceeds one job reservation (300s). * * Each call builds from `(windowOffset, pageOffset)` until `deadlineMs`, writes * that batch's rows to a PART parquet, and returns `{ done:false, nextWindowOffset, * nextPageOffset }` for the caller to re-enqueue. When the last window is fully * paged it publishes a multi-file envelope listing every part (parts are disjoint * by `(query_canonical, date)`, so the read path just unions them — no merge), * returning `{ done:true }`. `builtAt` MUST be stable across the continuation chain * (it versions both the part keys and the final rollup key). * * INTRA-WINDOW resumability: the deadline is checked between raw-query hash shards, * not just between date windows. A single high-cardinality day can spend a full * reservation inside one grouped/sorted aggregate before the deadline check gets * control back. `pageOffset` is the next shard index for the current window, so a * continuation resumes the SAME day at the next shard. Parts are keyed by * `(windowOffset, pageOffset)`; multiple parts may contain the same canonical/date * from different raw-query shards, and rollup reads sum over the union. */ declare function rebuildCanonicalDailyResumable(opts: { engine: RollupEngine; ctx: TenantCtx; dataSource: DataSource; searchType?: SearchType; builtAt: number; windowOffset: number; /** Resume the `windowOffset` window at this shard offset (0 = window start). */ pageOffset?: number; /** Output rows per page (default `ROLLUP_PAGE_ROWS_DAILY`). Injectable for tests. */ pageRows?: number; /** Cap each input window's day span (default `DAILY_MAX_WINDOW_DAYS`). */ maxWindowDays?: number; /** Split each date window by raw-query hash before grouping (1 = no sharding). */ shardCount?: number; deadlineMs: number; }): Promise<{ done: boolean; nextWindowOffset: number; nextPageOffset: number; windowsTotal: number; windowsBuilt: number; rowsWritten: number; }>; export { queryCanonicalDailyRollup, queryCanonicalVariantsRollup, rebuildCanonicalDailyResumable };