@gscdump/engine 1.4.0 → 1.4.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.
- package/dist/adapters/duckdb-node.d.mts +7 -0
- package/dist/adapters/duckdb-node.mjs +94 -0
- package/dist/adapters/filesystem.d.mts +1 -1
- package/dist/adapters/filesystem.mjs +1 -1
- package/dist/adapters/hyparquet.d.mts +4 -3
- package/dist/adapters/hyparquet.mjs +7 -3
- package/dist/adapters/node-harness.d.mts +38 -0
- package/dist/adapters/node-harness.mjs +47 -0
- package/dist/adapters/node.d.mts +4 -100
- package/dist/adapters/node.mjs +4 -240
- package/dist/adapters/parquet-attach.d.mts +23 -0
- package/dist/adapters/parquet-attach.mjs +21 -0
- package/dist/adapters/r2-manifest.d.mts +82 -0
- package/dist/adapters/r2-manifest.mjs +364 -0
- package/dist/adapters/r2.d.mts +1 -1
- package/dist/adapters/read-optional.mjs +15 -0
- package/dist/adapters/snapshot-attach.d.mts +38 -0
- package/dist/adapters/snapshot-attach.mjs +85 -0
- package/dist/analysis-types.d.mts +56 -1
- package/dist/analyzer/define.d.mts +48 -0
- package/dist/analyzer/define.mjs +60 -0
- package/dist/analyzer/dispatch.d.mts +17 -0
- package/dist/analyzer/index.d.mts +4 -14
- package/dist/analyzer/index.mjs +4 -112
- package/dist/analyzer/registry.d.mts +33 -0
- package/dist/analyzer/registry.mjs +49 -0
- package/dist/analyzer/types.d.mts +95 -0
- package/dist/analyzer/types.mjs +5 -0
- package/dist/coerce.d.mts +4 -0
- package/dist/compaction.d.mts +14 -0
- package/dist/{_chunks/parquet-plan.mjs → compaction.mjs} +2 -138
- package/dist/contracts.d.mts +1 -2
- package/dist/{_chunks/schema.d.mts → drizzle-schema.d.mts} +2 -34
- package/dist/{_chunks/schema.mjs → drizzle-schema.mjs} +2 -78
- package/dist/{_chunks/snapshot.d.mts → duckdb.d.mts} +1 -14
- package/dist/duckdb.mjs +207 -0
- package/dist/engine.d.mts +4 -0
- package/dist/engine.mjs +385 -0
- package/dist/entities.d.mts +3 -52
- package/dist/entities.mjs +867 -2
- package/dist/errors.d.mts +114 -1
- package/dist/gc.mjs +92 -0
- package/dist/iceberg/append-sink.d.mts +14 -0
- package/dist/iceberg/append-sink.mjs +142 -0
- package/dist/iceberg/catalog.d.mts +71 -0
- package/dist/iceberg/catalog.mjs +109 -0
- package/dist/iceberg/index.d.mts +4 -13
- package/dist/iceberg/index.mjs +3 -244
- package/dist/iceberg/overwrite-writer.d.mts +161 -0
- package/dist/iceberg/overwrite-writer.mjs +102 -0
- package/dist/iceberg/pyiceberg-runtime.mjs +34 -0
- package/dist/iceberg/schema.d.mts +69 -0
- package/dist/{_chunks/schema2.mjs → iceberg/schema.mjs} +3 -2
- package/dist/index.d.mts +14 -190
- package/dist/index.mjs +10 -645
- package/dist/ingest-accumulator.d.mts +1 -1
- package/dist/ingest.d.mts +1 -1
- package/dist/layout.d.mts +31 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/brotli.bitreader.mjs +88 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/brotli.blocks.mjs +120 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/brotli.context.mjs +1805 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/brotli.contextmap.mjs +49 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/brotli.dictionary.mjs +984 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/brotli.huffman.mjs +266 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/brotli.mjs +340 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/brotli.prefix.mjs +109 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/brotli.streams.mjs +21 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/brotli.transform.mjs +190 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/compressors.mjs +7 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/gzip.huffman.mjs +121 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/gzip.mjs +176 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/index.mjs +7 -0
- package/dist/node_modules/.pnpm/hyparquet-compressors@1.1.1/node_modules/hyparquet-compressors/src/lz4.mjs +52 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/bloom.mjs +93 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/bytewriter.mjs +91 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/column.mjs +186 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/datapage.mjs +113 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/delta.mjs +111 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/dictionary.mjs +99 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/dremel.mjs +116 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/encoding.mjs +51 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/geospatial.mjs +84 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/index.mjs +7 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/indexes.mjs +31 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/metadata.mjs +138 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/node.mjs +8 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/parquet-writer.mjs +139 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/plain.mjs +68 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/schema.mjs +254 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/snappy.mjs +125 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/splitstream.mjs +38 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/thrift.mjs +79 -0
- package/dist/{_chunks/libs/hyparquet-writer.d.mts → node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/types.d.mts} +2 -2
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/unconvert.mjs +247 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/variant.mjs +321 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/wkb.mjs +79 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/write-rows.mjs +122 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/src/write.mjs +5 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/types/bytewriter.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/types/index.d.mts +10 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/types/node.d.mts +3 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/types/parquet-writer.d.mts +2 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/types/schema.d.mts +2 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/types/wkb.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/types/write-rows.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet-writer@0.16.1_patch_hash_7a5e451ac7634d7546ac56bcc5eadacf7715a6241640c2b5a5bc0cfc9763b8ec/node_modules/hyparquet-writer/types/write.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/assemble.mjs +3 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/bloom.mjs +69 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/column.mjs +8 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/constants.mjs +80 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/convert.mjs +3 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/datapage.mjs +6 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/delta.mjs +2 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/encoding.mjs +2 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/filter.mjs +3 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/geoparquet.mjs +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/index.mjs +7 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/indexes.mjs +5 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/metadata.mjs +7 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/node.mjs +3 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/plain.mjs +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/plan.mjs +5 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/query.mjs +3 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/read.mjs +6 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/rowgroup.mjs +7 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/schema.mjs +54 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/snappy.mjs +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/thrift.mjs +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/types.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/utils.mjs +19 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/variant.mjs +3 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/wkb.mjs +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/src/xxhash.mjs +68 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/types/index.d.mts +7 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/types/indexes.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/types/metadata.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/types/node.d.mts +2 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/types/query.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/types/read.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/types/snappy.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.1/node_modules/hyparquet/types/utils.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/assemble.mjs +144 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/bloom.mjs +124 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/column.mjs +127 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/constants.mjs +75 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/convert.mjs +118 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/datapage.mjs +144 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/delta.mjs +65 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/encoding.mjs +76 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/filter.mjs +98 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/geoparquet.mjs +24 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/index.mjs +7 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/indexes.mjs +16 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/metadata.mjs +235 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/node.mjs +7 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/plain.mjs +78 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/plan.mjs +147 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/query.mjs +3 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/read.mjs +106 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/rowgroup.mjs +154 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/schema.mjs +75 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/snappy.mjs +70 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/thrift.mjs +86 -0
- package/dist/{_chunks/libs/hyparquet.d.mts → node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/types.d.mts} +6 -8
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/utils.mjs +31 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/variant.mjs +225 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/wkb.mjs +94 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/src/xxhash.mjs +68 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/types/index.d.mts +10 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/types/indexes.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/types/metadata.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/types/node.d.mts +3 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/types/query.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/types/read.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/types/snappy.d.mts +1 -0
- package/dist/node_modules/.pnpm/hyparquet@1.26.2/node_modules/hyparquet/types/utils.d.mts +1 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/avro/avro.metadata.mjs +1 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/avro/avro.read.mjs +4 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/avro/avro.write.mjs +2 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/catalog/file.mjs +1 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/catalog/loadTable.mjs +3 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/catalog/rest.mjs +73 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/create.mjs +67 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/delete.mjs +2 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/fetch.mjs +8 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/index.mjs +13 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/json.mjs +147 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/manifest.mjs +2 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/metadata.mjs +3 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/prune.mjs +4 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/puffin/deletion-vector.mjs +2 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/puffin/puffin.mjs +2 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/puffin/roaring.mjs +1 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/read.mjs +9 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/s3.mjs +3 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/schema.mjs +76 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/sigv4.mjs +2 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/sql/icebergDataSource.mjs +8 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/sql/icebergQuery.mjs +5 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/sql/whereFilter.mjs +1 -0
- package/dist/{_chunks/libs/icebird.d.mts → node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/types.d.mts} +5 -33
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/utils.mjs +8 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/commit.mjs +5 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/conversions.mjs +19 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/delete-file.mjs +3 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/geospatial.mjs +1 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/manifest-list.mjs +2 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/manifest.mjs +3 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/parquet.mjs +5 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/partition.mjs +75 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/rewrite.mjs +10 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/serde.mjs +2 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/snapshot.mjs +5 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/sort.mjs +3 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/stage-deletion-vector.mjs +11 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/stage-position-delete.mjs +8 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/stage.mjs +10 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/stats.mjs +4 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/transform.mjs +60 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/src/write/write.mjs +45 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/types/catalog/file.d.mts +1 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/types/catalog/rest.d.mts +1 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/types/create.d.mts +1 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/types/fetch.d.mts +1 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/types/index.d.mts +13 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/types/manifest.d.mts +1 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/types/metadata.d.mts +1 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/types/read.d.mts +2 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/types/s3.d.mts +1 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/types/sql/icebergDataSource.d.mts +2 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/types/sql/icebergQuery.d.mts +2 -0
- package/dist/node_modules/.pnpm/icebird@0.8.15_patch_hash_d1902372376af18885e7c7dce807f1ecab86c2f86a9d1ff65d51e3b63b64b057/node_modules/icebird/types/write/write.d.mts +32 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/ast.d.mts +1 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/backend/dataSource.mjs +1 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/execute/accumulator.mjs +2 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/execute/aggregates.mjs +10 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/execute/execute.mjs +15 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/execute/join.mjs +5 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/execute/scanColumn.mjs +1 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/execute/sort.mjs +5 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/execute/streamingAggregate.mjs +9 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/execute/utils.mjs +1 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/execute/window.mjs +5 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/execute/yield.mjs +17 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/expression/alias.mjs +1 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/expression/binary.mjs +1 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/expression/date.mjs +1 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/expression/evaluate.mjs +15 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/expression/math.mjs +1 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/expression/regexp.mjs +2 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/expression/strings.mjs +3 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/index.d.mts +1 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/index.mjs +9 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/parse/expression.mjs +6 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/parse/extractTables.mjs +1 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/parse/functions.mjs +5 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/parse/joins.mjs +7 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/parse/parse.mjs +10 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/parse/primary.mjs +8 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/parse/state.mjs +2 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/parse/tokenize.mjs +3 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/parse/types.d.mts +1 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/plan/columns.mjs +3 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/plan/plan.mjs +7 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/plan/types.d.mts +1 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/spatial/bbox.mjs +2 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/spatial/equality.mjs +2 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/spatial/operations.mjs +5 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/spatial/pointRelations.mjs +2 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/spatial/primitives.mjs +2 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/spatial/segments.mjs +2 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/spatial/spatial.mjs +6 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/spatial/wkt.mjs +1 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/types.d.mts +3 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/validation/aggregates.mjs +3 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/validation/executionErrors.mjs +2 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/validation/functions.mjs +2 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/validation/keywords.mjs +1 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/validation/parseErrors.mjs +2 -0
- package/dist/node_modules/.pnpm/squirreling@0.15.0/node_modules/squirreling/src/validation/tables.mjs +2 -0
- package/dist/parquet-plan.d.mts +15 -0
- package/dist/parquet-plan.mjs +139 -0
- package/dist/parquet-pushdown.mjs +58 -0
- package/dist/period/index.d.mts +52 -1
- package/dist/planner.d.mts +2 -14
- package/dist/planner.mjs +2 -1
- package/dist/profile.d.mts +21 -0
- package/dist/profile.mjs +27 -0
- package/dist/query-dim.d.mts +54 -0
- package/dist/query-dim.mjs +91 -0
- package/dist/report/define.d.mts +8 -0
- package/dist/report/define.mjs +15 -0
- package/dist/report/hash.d.mts +13 -0
- package/dist/report/hash.mjs +29 -0
- package/dist/report/index.d.mts +4 -170
- package/dist/report/index.mjs +3 -55
- package/dist/report/registry.d.mts +18 -0
- package/dist/report/registry.mjs +14 -0
- package/dist/report/types.d.mts +139 -0
- package/dist/resolver/adapter.d.mts +13 -0
- package/dist/resolver/adapter.mjs +27 -0
- package/dist/resolver/canonical-source.d.mts +5 -0
- package/dist/resolver/canonical-source.mjs +14 -0
- package/dist/resolver/compile.d.mts +15 -0
- package/dist/resolver/compile.mjs +396 -0
- package/dist/resolver/datasets.d.mts +16 -0
- package/dist/resolver/datasets.mjs +159 -0
- package/dist/resolver/extras-overlay.d.mts +37 -0
- package/dist/resolver/extras-overlay.mjs +17 -0
- package/dist/resolver/filter-utils.d.mts +10 -0
- package/dist/resolver/filter-utils.mjs +59 -0
- package/dist/resolver/fragments.d.mts +60 -0
- package/dist/resolver/fragments.mjs +206 -0
- package/dist/resolver/index.d.mts +11 -371
- package/dist/resolver/index.mjs +10 -1
- package/dist/resolver/pg-adapter.d.mts +56 -0
- package/dist/resolver/pg-adapter.mjs +110 -0
- package/dist/resolver/run-query.d.mts +172 -0
- package/dist/resolver/run-query.mjs +241 -0
- package/dist/resolver/schema-drift.d.mts +15 -0
- package/dist/resolver/schema-drift.mjs +12 -0
- package/dist/rollups.d.mts +4 -4
- package/dist/rollups.mjs +3 -2
- package/dist/schedule.mjs +100 -0
- package/dist/schema.d.mts +34 -1
- package/dist/schema.mjs +78 -1
- package/dist/sink-node.d.mts +1 -159
- package/dist/sink-node.mjs +1 -133
- package/dist/sink.d.mts +125 -0
- package/dist/sinks/in-memory-sink.d.mts +25 -0
- package/dist/sinks/in-memory-sink.mjs +61 -0
- package/dist/sinks/index.d.mts +2 -0
- package/dist/sinks/index.mjs +2 -0
- package/dist/snapshot.d.mts +14 -0
- package/dist/source/attached-table.d.mts +45 -0
- package/dist/source/attached-table.mjs +55 -0
- package/dist/source/create-sql-query-source.d.mts +24 -0
- package/dist/source/create-sql-query-source.mjs +28 -0
- package/dist/source/index.d.mts +6 -66
- package/dist/source/index.mjs +9 -82
- package/dist/source/source-types.d.mts +49 -0
- package/dist/{_chunks/storage.d.mts → storage.d.mts} +4 -14
- package/dist/sync-config.d.mts +36 -0
- package/dist/sync-config.mjs +98 -0
- package/dist/vendor/hysnappy-purejs.mjs +12 -1
- package/package.json +4 -4
- package/dist/_chunks/analysis-types.d.mts +0 -57
- package/dist/_chunks/contracts.d.mts +0 -1
- package/dist/_chunks/engine.mjs +0 -731
- package/dist/_chunks/entities.mjs +0 -967
- package/dist/_chunks/errors.d.mts +0 -115
- package/dist/_chunks/index.d.mts +0 -53
- package/dist/_chunks/libs/hyparquet-compressors.mjs +0 -2796
- package/dist/_chunks/libs/hyparquet-writer.mjs +0 -2524
- package/dist/_chunks/libs/hyparquet.mjs +0 -2596
- package/dist/_chunks/libs/icebird.mjs +0 -564
- package/dist/_chunks/registry.d.mts +0 -213
- package/dist/_chunks/resolver.mjs +0 -1220
- package/dist/_chunks/sink.d.mts +0 -257
- /package/dist/{_chunks → analyzer}/dispatch.mjs +0 -0
- /package/dist/{_chunks/coerce.mjs → coerce.mjs} +0 -0
- /package/dist/{_chunks/layout.mjs → layout.mjs} +0 -0
- /package/dist/{_chunks/manifest-store-utils.mjs → manifest-store-utils.mjs} +0 -0
- /package/dist/{_chunks/libs/fzstd.mjs → node_modules/.pnpm/fzstd@0.1.1/node_modules/fzstd/esm/index.mjs} +0 -0
- /package/dist/{_chunks → resolver}/types.d.mts +0 -0
- /package/dist/{_chunks/schedule.d.mts → schedule.d.mts} +0 -0
|
@@ -1,1220 +0,0 @@
|
|
|
1
|
-
import { SCHEMAS, drizzleSchema } from "./schema.mjs";
|
|
2
|
-
import { enumeratePartitions } from "./parquet-plan.mjs";
|
|
3
|
-
import { escapeLike } from "../sql-fragments.mjs";
|
|
4
|
-
import "../planner.mjs";
|
|
5
|
-
import { UnresolvableDatasetError, buildLogicalComparisonPlan, buildLogicalPlan, inferDataset as inferLogicalDataset, isDatasetResolvable } from "gscdump/query/plan";
|
|
6
|
-
import { PgDialect, pgTable, varchar } from "drizzle-orm/pg-core";
|
|
7
|
-
import { normalizeUrl } from "gscdump/normalize";
|
|
8
|
-
import { DEFAULT_PARTITION_KEY_ENCODING } from "@gscdump/lakehouse/schema";
|
|
9
|
-
import { sql } from "drizzle-orm";
|
|
10
|
-
import { and as and$1, gte as gte$1, impressions } from "gscdump/query";
|
|
11
|
-
const DIMENSION_SURFACES = {
|
|
12
|
-
page: ["api", "stored"],
|
|
13
|
-
query: ["api", "stored"],
|
|
14
|
-
queryCanonical: ["derived"],
|
|
15
|
-
country: ["api", "stored"],
|
|
16
|
-
device: ["api", "stored"],
|
|
17
|
-
searchAppearance: ["api", "stored"],
|
|
18
|
-
date: ["api", "stored"],
|
|
19
|
-
hour: ["api", "stored"]
|
|
20
|
-
};
|
|
21
|
-
const LOGICAL_DATASETS = {
|
|
22
|
-
pages: { dimensions: {
|
|
23
|
-
page: {
|
|
24
|
-
column: "url",
|
|
25
|
-
surfaces: ["api", "stored"]
|
|
26
|
-
},
|
|
27
|
-
date: {
|
|
28
|
-
column: "date",
|
|
29
|
-
surfaces: ["api", "stored"]
|
|
30
|
-
}
|
|
31
|
-
} },
|
|
32
|
-
queries: { dimensions: {
|
|
33
|
-
query: {
|
|
34
|
-
column: "query",
|
|
35
|
-
surfaces: ["api", "stored"]
|
|
36
|
-
},
|
|
37
|
-
queryCanonical: {
|
|
38
|
-
column: "query_canonical",
|
|
39
|
-
surfaces: ["derived"]
|
|
40
|
-
},
|
|
41
|
-
date: {
|
|
42
|
-
column: "date",
|
|
43
|
-
surfaces: ["api", "stored"]
|
|
44
|
-
}
|
|
45
|
-
} },
|
|
46
|
-
page_queries: { dimensions: {
|
|
47
|
-
page: {
|
|
48
|
-
column: "url",
|
|
49
|
-
surfaces: ["api", "stored"]
|
|
50
|
-
},
|
|
51
|
-
query: {
|
|
52
|
-
column: "query",
|
|
53
|
-
surfaces: ["api", "stored"]
|
|
54
|
-
},
|
|
55
|
-
queryCanonical: {
|
|
56
|
-
column: "query_canonical",
|
|
57
|
-
surfaces: ["derived"]
|
|
58
|
-
},
|
|
59
|
-
date: {
|
|
60
|
-
column: "date",
|
|
61
|
-
surfaces: ["api", "stored"]
|
|
62
|
-
}
|
|
63
|
-
} },
|
|
64
|
-
countries: { dimensions: {
|
|
65
|
-
country: {
|
|
66
|
-
column: "country",
|
|
67
|
-
surfaces: ["api", "stored"]
|
|
68
|
-
},
|
|
69
|
-
date: {
|
|
70
|
-
column: "date",
|
|
71
|
-
surfaces: ["api", "stored"]
|
|
72
|
-
}
|
|
73
|
-
} },
|
|
74
|
-
dates: { dimensions: { date: {
|
|
75
|
-
column: "date",
|
|
76
|
-
surfaces: ["api", "stored"]
|
|
77
|
-
} } },
|
|
78
|
-
search_appearance: { dimensions: {
|
|
79
|
-
searchAppearance: {
|
|
80
|
-
column: "searchAppearance",
|
|
81
|
-
surfaces: ["api", "stored"]
|
|
82
|
-
},
|
|
83
|
-
date: {
|
|
84
|
-
column: "date",
|
|
85
|
-
surfaces: ["api", "stored"]
|
|
86
|
-
}
|
|
87
|
-
} },
|
|
88
|
-
search_appearance_pages: { dimensions: {
|
|
89
|
-
searchAppearance: {
|
|
90
|
-
column: "searchAppearance",
|
|
91
|
-
surfaces: ["stored"]
|
|
92
|
-
},
|
|
93
|
-
page: {
|
|
94
|
-
column: "url",
|
|
95
|
-
surfaces: ["stored"]
|
|
96
|
-
},
|
|
97
|
-
date: {
|
|
98
|
-
column: "date",
|
|
99
|
-
surfaces: ["stored"]
|
|
100
|
-
}
|
|
101
|
-
} },
|
|
102
|
-
search_appearance_queries: { dimensions: {
|
|
103
|
-
searchAppearance: {
|
|
104
|
-
column: "searchAppearance",
|
|
105
|
-
surfaces: ["stored"]
|
|
106
|
-
},
|
|
107
|
-
query: {
|
|
108
|
-
column: "query",
|
|
109
|
-
surfaces: ["stored"]
|
|
110
|
-
},
|
|
111
|
-
queryCanonical: {
|
|
112
|
-
column: "query_canonical",
|
|
113
|
-
surfaces: ["derived"]
|
|
114
|
-
},
|
|
115
|
-
date: {
|
|
116
|
-
column: "date",
|
|
117
|
-
surfaces: ["stored"]
|
|
118
|
-
}
|
|
119
|
-
} },
|
|
120
|
-
search_appearance_page_queries: { dimensions: {
|
|
121
|
-
searchAppearance: {
|
|
122
|
-
column: "searchAppearance",
|
|
123
|
-
surfaces: ["stored"]
|
|
124
|
-
},
|
|
125
|
-
page: {
|
|
126
|
-
column: "url",
|
|
127
|
-
surfaces: ["stored"]
|
|
128
|
-
},
|
|
129
|
-
query: {
|
|
130
|
-
column: "query",
|
|
131
|
-
surfaces: ["stored"]
|
|
132
|
-
},
|
|
133
|
-
queryCanonical: {
|
|
134
|
-
column: "query_canonical",
|
|
135
|
-
surfaces: ["derived"]
|
|
136
|
-
},
|
|
137
|
-
date: {
|
|
138
|
-
column: "date",
|
|
139
|
-
surfaces: ["stored"]
|
|
140
|
-
}
|
|
141
|
-
} },
|
|
142
|
-
hourly_pages: { dimensions: {
|
|
143
|
-
page: {
|
|
144
|
-
column: "url",
|
|
145
|
-
surfaces: ["api", "stored"]
|
|
146
|
-
},
|
|
147
|
-
date: {
|
|
148
|
-
column: "date",
|
|
149
|
-
surfaces: ["api", "stored"]
|
|
150
|
-
},
|
|
151
|
-
hour: {
|
|
152
|
-
column: "hour",
|
|
153
|
-
surfaces: ["api", "stored"]
|
|
154
|
-
}
|
|
155
|
-
} }
|
|
156
|
-
};
|
|
157
|
-
function dimensionColumn(dim, dataset) {
|
|
158
|
-
return LOGICAL_DATASETS[dataset].dimensions[dim]?.column ?? dim;
|
|
159
|
-
}
|
|
160
|
-
function supportsDimensionOnSurface(dim, surface) {
|
|
161
|
-
return DIMENSION_SURFACES[dim].includes(surface);
|
|
162
|
-
}
|
|
163
|
-
function assertDimensionsSupported(dimensions, surface, context) {
|
|
164
|
-
const unsupported = dimensions.filter((dim) => !supportsDimensionOnSurface(dim, surface));
|
|
165
|
-
if (unsupported.length === 0) return;
|
|
166
|
-
throw new Error(`${context}: unsupported dimensions for ${surface}: ${unsupported.join(", ")}`);
|
|
167
|
-
}
|
|
168
|
-
const METRIC_NAMES = [
|
|
169
|
-
"clicks",
|
|
170
|
-
"impressions",
|
|
171
|
-
"ctr",
|
|
172
|
-
"position"
|
|
173
|
-
];
|
|
174
|
-
const QUERY_DIM_ALIAS = "query_dim";
|
|
175
|
-
function quoteIdent(id) {
|
|
176
|
-
return `"${id.replace(/"/g, "\"\"")}"`;
|
|
177
|
-
}
|
|
178
|
-
function qualifiedRaw(alias, column) {
|
|
179
|
-
return sql.raw(`${quoteIdent(alias)}.${quoteIdent(column)}`);
|
|
180
|
-
}
|
|
181
|
-
function defaultSqliteUrlToPathExpr(col) {
|
|
182
|
-
return `CASE WHEN ${col} LIKE 'http%' THEN CASE WHEN INSTR(SUBSTR(${col}, INSTR(${col}, '://') + 3), '/') > 0 THEN SUBSTR(${col}, INSTR(${col}, '://') + 2 + INSTR(SUBSTR(${col}, INSTR(${col}, '://') + 3), '/')) ELSE '/' END ELSE ${col} END`;
|
|
183
|
-
}
|
|
184
|
-
function buildDimensionColumnMap(datasetToTableKey) {
|
|
185
|
-
const entries = Object.entries(datasetToTableKey).map(([dataset, tableKey]) => {
|
|
186
|
-
const dims = LOGICAL_DATASETS[dataset].dimensions;
|
|
187
|
-
return [tableKey, Object.fromEntries(Object.entries(dims).map(([dim, binding]) => [dim, binding?.column ?? dim]))];
|
|
188
|
-
});
|
|
189
|
-
return Object.fromEntries(entries);
|
|
190
|
-
}
|
|
191
|
-
function createSqlFragments(config) {
|
|
192
|
-
const { schema, datasetToTableKey, metricCast, regexPredicate, tableLabel, includeSiteId, includeSearchType, urlToPathExpr: urlToPathExprOverride, tableRef: tableRefOverride, queryCanonicalSource = "queryDim", queryDimTableRef, queryDimSiteScoped = false } = config;
|
|
193
|
-
const DIM_COLUMN_MAP = buildDimensionColumnMap(datasetToTableKey);
|
|
194
|
-
function isMetricDimension(dim) {
|
|
195
|
-
return METRIC_NAMES.includes(dim);
|
|
196
|
-
}
|
|
197
|
-
function dimColumn(dim, table) {
|
|
198
|
-
return DIM_COLUMN_MAP[table]?.[dim] ?? dim;
|
|
199
|
-
}
|
|
200
|
-
function tableKeyForDataset(dataset) {
|
|
201
|
-
return datasetToTableKey[dataset];
|
|
202
|
-
}
|
|
203
|
-
function inferTable(dimensions, filterDims = []) {
|
|
204
|
-
if (!isDatasetResolvable(dimensions, filterDims)) throw new UnresolvableDatasetError(dimensions, filterDims);
|
|
205
|
-
return tableKeyForDataset(inferLogicalDataset(dimensions, filterDims));
|
|
206
|
-
}
|
|
207
|
-
const urlToPathExpr = urlToPathExprOverride ?? defaultSqliteUrlToPathExpr;
|
|
208
|
-
function colRef(tableKey, colName) {
|
|
209
|
-
const c = schema[tableKey][colName];
|
|
210
|
-
if (!c) throw new Error(`${tableLabel}: unknown column '${colName}' on ${tableKey}`);
|
|
211
|
-
return sql`${c}`;
|
|
212
|
-
}
|
|
213
|
-
function tableRef(tableKey) {
|
|
214
|
-
if (tableRefOverride) return tableRefOverride(tableKey);
|
|
215
|
-
return sql`${schema[tableKey]}`;
|
|
216
|
-
}
|
|
217
|
-
function fromSql(tableKey, options = {}) {
|
|
218
|
-
const base = tableRef(tableKey);
|
|
219
|
-
if (!options.queryCanonical || queryCanonicalSource !== "queryDim") return base;
|
|
220
|
-
return sql`${base} LEFT JOIN ${queryDimTableRef?.() ?? sql.raw(`${quoteIdent(QUERY_DIM_ALIAS)}`)} ON ${queryDimSiteScoped ? sql`${colRef(tableKey, "query")} = ${qualifiedRaw(QUERY_DIM_ALIAS, "query")} AND ${colRef(tableKey, "site_id")} = ${qualifiedRaw(QUERY_DIM_ALIAS, "site_id")}` : sql`${colRef(tableKey, "query")} = ${qualifiedRaw(QUERY_DIM_ALIAS, "query")}`}`;
|
|
221
|
-
}
|
|
222
|
-
function dateColRef(tableKey) {
|
|
223
|
-
return colRef(tableKey, "date");
|
|
224
|
-
}
|
|
225
|
-
function siteIdColRef(tableKey) {
|
|
226
|
-
return colRef(tableKey, "site_id");
|
|
227
|
-
}
|
|
228
|
-
function searchTypeColRef(tableKey) {
|
|
229
|
-
return colRef(tableKey, "search_type");
|
|
230
|
-
}
|
|
231
|
-
function dimExprSql(dim, tableKey) {
|
|
232
|
-
const colName = dimColumn(dim, tableKey);
|
|
233
|
-
if (dim === "page") return sql.raw(urlToPathExpr(colName));
|
|
234
|
-
if (dim === "queryCanonical") {
|
|
235
|
-
if (queryCanonicalSource === "queryDim") return sql`COALESCE(${qualifiedRaw(QUERY_DIM_ALIAS, "query_canonical")}, ${colRef(tableKey, "query")})`;
|
|
236
|
-
return qualifiedRaw(String(tableKey), "query_canonical");
|
|
237
|
-
}
|
|
238
|
-
return colRef(tableKey, colName);
|
|
239
|
-
}
|
|
240
|
-
function metricSql(metric, tableKey) {
|
|
241
|
-
const t = schema[tableKey];
|
|
242
|
-
switch (metric) {
|
|
243
|
-
case "clicks": return sql`CAST(SUM(${t.clicks}) AS ${sql.raw(metricCast)})`;
|
|
244
|
-
case "impressions": return sql`CAST(SUM(${t.impressions}) AS ${sql.raw(metricCast)})`;
|
|
245
|
-
case "ctr": return sql`CAST(SUM(${t.clicks}) AS ${sql.raw(metricCast)}) / NULLIF(SUM(${t.impressions}), 0)`;
|
|
246
|
-
case "position": return sql`SUM(${t.sum_position}) / NULLIF(SUM(${t.impressions}), 0) + 1`;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
function havingPredicates(filters, tableKey) {
|
|
250
|
-
const preds = [];
|
|
251
|
-
for (const f of filters) {
|
|
252
|
-
const metric = f.dimension;
|
|
253
|
-
if (!isMetricDimension(metric)) continue;
|
|
254
|
-
const expr = metricSql(metric, tableKey);
|
|
255
|
-
const v = Number(f.expression);
|
|
256
|
-
switch (f.operator) {
|
|
257
|
-
case "metricGte":
|
|
258
|
-
preds.push(sql`${expr} >= ${v}`);
|
|
259
|
-
break;
|
|
260
|
-
case "metricGt":
|
|
261
|
-
preds.push(sql`${expr} > ${v}`);
|
|
262
|
-
break;
|
|
263
|
-
case "metricLte":
|
|
264
|
-
preds.push(sql`${expr} <= ${v}`);
|
|
265
|
-
break;
|
|
266
|
-
case "metricLt":
|
|
267
|
-
preds.push(sql`${expr} < ${v}`);
|
|
268
|
-
break;
|
|
269
|
-
case "metricBetween": {
|
|
270
|
-
const v2 = Number(f.expression2);
|
|
271
|
-
preds.push(sql`${expr} >= ${v} AND ${expr} <= ${v2}`);
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
return preds;
|
|
277
|
-
}
|
|
278
|
-
function prefilterPredicates(filters, tableKey) {
|
|
279
|
-
const t = schema[tableKey];
|
|
280
|
-
const preds = [];
|
|
281
|
-
for (const f of filters) {
|
|
282
|
-
const metric = f.dimension;
|
|
283
|
-
let col;
|
|
284
|
-
if (metric === "clicks") col = t.clicks;
|
|
285
|
-
else if (metric === "impressions") col = t.impressions;
|
|
286
|
-
if (!col) continue;
|
|
287
|
-
const v = Number(f.expression);
|
|
288
|
-
switch (f.operator) {
|
|
289
|
-
case "metricGte":
|
|
290
|
-
preds.push(sql`${col} >= ${v}`);
|
|
291
|
-
break;
|
|
292
|
-
case "metricGt":
|
|
293
|
-
preds.push(sql`${col} > ${v}`);
|
|
294
|
-
break;
|
|
295
|
-
case "metricLte":
|
|
296
|
-
preds.push(sql`${col} <= ${v}`);
|
|
297
|
-
break;
|
|
298
|
-
case "metricLt":
|
|
299
|
-
preds.push(sql`${col} < ${v}`);
|
|
300
|
-
break;
|
|
301
|
-
case "metricBetween": {
|
|
302
|
-
const v2 = Number(f.expression2);
|
|
303
|
-
preds.push(sql`${col} >= ${v} AND ${col} <= ${v2}`);
|
|
304
|
-
break;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
return preds;
|
|
309
|
-
}
|
|
310
|
-
function dimensionPredicates(filters, tableKey) {
|
|
311
|
-
const preds = [];
|
|
312
|
-
for (const f of filters) {
|
|
313
|
-
if (isMetricDimension(f.dimension)) continue;
|
|
314
|
-
if (f.dimension === "date") continue;
|
|
315
|
-
if (f.operator === "topLevel") continue;
|
|
316
|
-
const dim = f.dimension;
|
|
317
|
-
const cRef = dim === "queryCanonical" ? void 0 : colRef(tableKey, dimColumn(dim, tableKey));
|
|
318
|
-
const matchExpr = dim === "page" || dim === "queryCanonical" ? dimExprSql(dim, tableKey) : cRef;
|
|
319
|
-
const patternExpr = dim === "queryCanonical" ? matchExpr : cRef;
|
|
320
|
-
switch (f.operator) {
|
|
321
|
-
case "equals":
|
|
322
|
-
preds.push(sql`${matchExpr} = ${f.expression}`);
|
|
323
|
-
break;
|
|
324
|
-
case "notEquals":
|
|
325
|
-
preds.push(sql`${matchExpr} != ${f.expression}`);
|
|
326
|
-
break;
|
|
327
|
-
case "contains":
|
|
328
|
-
preds.push(sql`${patternExpr} LIKE ${`%${escapeLike(f.expression)}%`} ESCAPE '\\'`);
|
|
329
|
-
break;
|
|
330
|
-
case "notContains":
|
|
331
|
-
preds.push(sql`${patternExpr} NOT LIKE ${`%${escapeLike(f.expression)}%`} ESCAPE '\\'`);
|
|
332
|
-
break;
|
|
333
|
-
case "includingRegex":
|
|
334
|
-
preds.push(regexPredicate(patternExpr, f.expression, false));
|
|
335
|
-
break;
|
|
336
|
-
case "excludingRegex":
|
|
337
|
-
preds.push(regexPredicate(patternExpr, f.expression, true));
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return preds;
|
|
342
|
-
}
|
|
343
|
-
function topLevelPredicate(filters, tableKey) {
|
|
344
|
-
if (!filters.some((f) => f.operator === "topLevel")) return void 0;
|
|
345
|
-
const pathExpr = dimExprSql("page", tableKey);
|
|
346
|
-
return sql`LENGTH(${pathExpr}) - LENGTH(REPLACE(${pathExpr}, '/', '')) <= 1`;
|
|
347
|
-
}
|
|
348
|
-
return {
|
|
349
|
-
METRIC_NAMES,
|
|
350
|
-
DIM_COLUMN_MAP,
|
|
351
|
-
isMetricDimension,
|
|
352
|
-
tableKeyForDataset,
|
|
353
|
-
dimColumn,
|
|
354
|
-
inferTable,
|
|
355
|
-
urlToPathExpr,
|
|
356
|
-
colRef,
|
|
357
|
-
tableRef,
|
|
358
|
-
fromSql,
|
|
359
|
-
dateColRef,
|
|
360
|
-
siteIdColRef: includeSiteId ? siteIdColRef : void 0,
|
|
361
|
-
searchTypeColRef: includeSearchType ? searchTypeColRef : void 0,
|
|
362
|
-
dimExprSql,
|
|
363
|
-
metricSql,
|
|
364
|
-
havingPredicates,
|
|
365
|
-
prefilterPredicates,
|
|
366
|
-
dimensionPredicates,
|
|
367
|
-
topLevelPredicate
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
function createResolverAdapter(config) {
|
|
371
|
-
const runtime = createSqlFragments(config);
|
|
372
|
-
return {
|
|
373
|
-
METRIC_NAMES: runtime.METRIC_NAMES,
|
|
374
|
-
capabilities: config.capabilities,
|
|
375
|
-
schema: config.schema,
|
|
376
|
-
tableKeyForDataset: runtime.tableKeyForDataset,
|
|
377
|
-
inferTable: runtime.inferTable,
|
|
378
|
-
dimColumn: runtime.dimColumn,
|
|
379
|
-
isMetricDimension: runtime.isMetricDimension,
|
|
380
|
-
tableRef: runtime.tableRef,
|
|
381
|
-
fromSql: runtime.fromSql,
|
|
382
|
-
dateColRef: runtime.dateColRef,
|
|
383
|
-
urlToPathExpr: runtime.urlToPathExpr,
|
|
384
|
-
siteIdColRef: runtime.siteIdColRef,
|
|
385
|
-
searchTypeColRef: runtime.searchTypeColRef,
|
|
386
|
-
dimExprSql: runtime.dimExprSql,
|
|
387
|
-
metricSql: runtime.metricSql,
|
|
388
|
-
dimensionPredicates: runtime.dimensionPredicates,
|
|
389
|
-
havingPredicates: runtime.havingPredicates,
|
|
390
|
-
prefilterPredicates: runtime.prefilterPredicates,
|
|
391
|
-
topLevelPredicate: runtime.topLevelPredicate,
|
|
392
|
-
compile: config.compile
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
const ALLOWED_FILTER_DIMS = /* @__PURE__ */ new Set(["date", "queryCanonical"]);
|
|
396
|
-
function planCoveredByCanonicalRollup(plan) {
|
|
397
|
-
if (plan.dataset !== "queries") return false;
|
|
398
|
-
if (plan.groupByDimensions.length !== 1 || plan.groupByDimensions[0] !== "queryCanonical") return false;
|
|
399
|
-
if (!plan.dimensionFilters.every((f) => ALLOWED_FILTER_DIMS.has(f.dimension))) return false;
|
|
400
|
-
if (plan.prefilters.length > 0) return false;
|
|
401
|
-
if (plan.specialFilters.topLevel) return false;
|
|
402
|
-
return true;
|
|
403
|
-
}
|
|
404
|
-
function canonicalRollupCovers(state, capabilities) {
|
|
405
|
-
return planCoveredByCanonicalRollup(buildLogicalPlan(state, capabilities));
|
|
406
|
-
}
|
|
407
|
-
const COMPARISON_FILTER_SQL = {
|
|
408
|
-
new: sql`AND COALESCE(p.impressions, 0) = 0 AND COALESCE(c.impressions, 0) > 0`,
|
|
409
|
-
lost: sql`AND COALESCE(p.impressions, 0) > 0 AND COALESCE(c.impressions, 0) = 0`,
|
|
410
|
-
improving: sql`AND COALESCE(c.clicks, 0) > COALESCE(p.clicks, 0)`,
|
|
411
|
-
declining: sql`AND COALESCE(c.clicks, 0) < COALESCE(p.clicks, 0) AND COALESCE(p.clicks, 0) > 0`
|
|
412
|
-
};
|
|
413
|
-
function collapseWs(s) {
|
|
414
|
-
return s.replace(/\s+/g, " ").trim();
|
|
415
|
-
}
|
|
416
|
-
function joinAnd(parts) {
|
|
417
|
-
return sql.join(parts, sql` AND `);
|
|
418
|
-
}
|
|
419
|
-
function joinComma(parts) {
|
|
420
|
-
return sql.join(parts, sql`, `);
|
|
421
|
-
}
|
|
422
|
-
const ORDER_BY_HELPER_PREFIX = "__order_";
|
|
423
|
-
function withMinimumImpressions(state, options) {
|
|
424
|
-
if (options.minimumImpressions === void 0) return state;
|
|
425
|
-
const minimum = Number(options.minimumImpressions);
|
|
426
|
-
if (!Number.isFinite(minimum) || minimum < 0) throw new RangeError("minimumImpressions must be a finite non-negative number");
|
|
427
|
-
const guard = gte$1(impressions, minimum);
|
|
428
|
-
return {
|
|
429
|
-
...state,
|
|
430
|
-
prefilter: state.prefilter ? and$1(state.prefilter, guard) : guard
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
function orderByClause(state, prefix = "", columnOverride) {
|
|
434
|
-
if (state.orderBy) {
|
|
435
|
-
const safeCol = (columnOverride ?? state.orderBy.column).replace(/\W/g, "");
|
|
436
|
-
const safeDir = state.orderBy.dir.toUpperCase() === "ASC" ? "ASC" : "DESC";
|
|
437
|
-
return sql.raw(`ORDER BY ${prefix}${safeCol} ${safeDir}`);
|
|
438
|
-
}
|
|
439
|
-
return sql.raw(`ORDER BY ${prefix}clicks DESC`);
|
|
440
|
-
}
|
|
441
|
-
function limitOffsetClause(state) {
|
|
442
|
-
const rowLimit = Math.max(0, Math.floor(Number(state.rowLimit ?? 100)));
|
|
443
|
-
const offset = state.startRow ? Math.max(0, Math.floor(Number(state.startRow))) : 0;
|
|
444
|
-
return sql.raw(offset > 0 ? `LIMIT ${rowLimit} OFFSET ${offset}` : `LIMIT ${rowLimit}`);
|
|
445
|
-
}
|
|
446
|
-
function aliasRaw(name) {
|
|
447
|
-
const safe = name.replace(/\W/g, "");
|
|
448
|
-
return sql.raw(`"${safe}"`);
|
|
449
|
-
}
|
|
450
|
-
function toInternalDimensionFilters(filters) {
|
|
451
|
-
return filters.map((filter) => ({
|
|
452
|
-
dimension: filter.dimension,
|
|
453
|
-
operator: filter.operator,
|
|
454
|
-
expression: filter.expression,
|
|
455
|
-
expression2: filter.expression2
|
|
456
|
-
}));
|
|
457
|
-
}
|
|
458
|
-
function toInternalMetricFilters(filters) {
|
|
459
|
-
return filters.map((filter) => ({
|
|
460
|
-
dimension: filter.metric,
|
|
461
|
-
operator: filter.operator,
|
|
462
|
-
expression: String(filter.expression),
|
|
463
|
-
expression2: filter.expression2 == null ? void 0 : String(filter.expression2)
|
|
464
|
-
}));
|
|
465
|
-
}
|
|
466
|
-
function topLevelFilters(plan) {
|
|
467
|
-
if (!plan.specialFilters.topLevel) return [];
|
|
468
|
-
return [{
|
|
469
|
-
dimension: "page",
|
|
470
|
-
operator: "topLevel",
|
|
471
|
-
expression: ""
|
|
472
|
-
}];
|
|
473
|
-
}
|
|
474
|
-
function logicalFilterToInternal(filter) {
|
|
475
|
-
return {
|
|
476
|
-
dimension: filter.dimension,
|
|
477
|
-
operator: filter.operator,
|
|
478
|
-
expression: filter.expression,
|
|
479
|
-
expression2: filter.expression2
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
function compileFilterTree(node, adapter, tableKey) {
|
|
483
|
-
if (!node) return void 0;
|
|
484
|
-
if (node.kind === "leaf") return adapter.dimensionPredicates([logicalFilterToInternal(node.filter)], tableKey)[0];
|
|
485
|
-
const childSqls = node.children.map((child) => compileFilterTree(child, adapter, tableKey)).filter((s) => s !== void 0);
|
|
486
|
-
if (childSqls.length === 0) return void 0;
|
|
487
|
-
if (childSqls.length === 1) return childSqls[0];
|
|
488
|
-
const sep = node.groupType === "or" ? sql` OR ` : sql` AND `;
|
|
489
|
-
return sql`(${sql.join(childSqls, sep)})`;
|
|
490
|
-
}
|
|
491
|
-
function buildScope(state, options) {
|
|
492
|
-
const { adapter, siteId, searchType } = options;
|
|
493
|
-
const plan = buildLogicalPlan(state, adapter.capabilities);
|
|
494
|
-
const tableKey = adapter.tableKeyForDataset(plan.dataset);
|
|
495
|
-
const dimFilters = toInternalDimensionFilters(plan.dimensionFilters);
|
|
496
|
-
const metricFilters = toInternalMetricFilters(plan.metricFilters);
|
|
497
|
-
const prefilters = toInternalMetricFilters(plan.prefilters);
|
|
498
|
-
const groupByDims = plan.groupByDimensions;
|
|
499
|
-
const hasDate = plan.hasDate;
|
|
500
|
-
const metrics = plan.metrics;
|
|
501
|
-
const queryCanonicalUsed = groupByDims.includes("queryCanonical") || plan.dimensionFilters.some((filter) => filter.dimension === "queryCanonical");
|
|
502
|
-
const wherePredicates = [];
|
|
503
|
-
if (adapter.siteIdColRef && siteId != null) wherePredicates.push(sql`${adapter.siteIdColRef(tableKey)} = ${siteId}`);
|
|
504
|
-
if (adapter.searchTypeColRef && searchType != null) wherePredicates.push(sql`${adapter.searchTypeColRef(tableKey)} = ${searchType}`);
|
|
505
|
-
wherePredicates.push(sql`${adapter.dateColRef(tableKey)} >= ${plan.dateRange.startDate}`);
|
|
506
|
-
wherePredicates.push(sql`${adapter.dateColRef(tableKey)} <= ${plan.dateRange.endDate}`);
|
|
507
|
-
wherePredicates.push(...adapter.prefilterPredicates(prefilters, tableKey));
|
|
508
|
-
const dimSql = plan.dimensionFilterTree ? compileFilterTree(plan.dimensionFilterTree, adapter, tableKey) : void 0;
|
|
509
|
-
if (dimSql) wherePredicates.push(dimSql);
|
|
510
|
-
else if (!plan.dimensionFilterTree) wherePredicates.push(...adapter.dimensionPredicates(dimFilters, tableKey));
|
|
511
|
-
const tl = adapter.topLevelPredicate(topLevelFilters(plan), tableKey);
|
|
512
|
-
if (tl) wherePredicates.push(tl);
|
|
513
|
-
return {
|
|
514
|
-
plan,
|
|
515
|
-
tableKey,
|
|
516
|
-
groupByDims,
|
|
517
|
-
hasDate,
|
|
518
|
-
metrics,
|
|
519
|
-
wherePredicates,
|
|
520
|
-
having: adapter.havingPredicates(metricFilters, tableKey),
|
|
521
|
-
dimFilters,
|
|
522
|
-
startDate: plan.dateRange.startDate,
|
|
523
|
-
endDate: plan.dateRange.endDate,
|
|
524
|
-
queryCanonicalUsed
|
|
525
|
-
};
|
|
526
|
-
}
|
|
527
|
-
function buildComparisonPlan(current, previous, capabilities) {
|
|
528
|
-
return buildLogicalComparisonPlan(current, previous, capabilities);
|
|
529
|
-
}
|
|
530
|
-
function compileCollapsed(adapter, q) {
|
|
531
|
-
const c = adapter.compile(q);
|
|
532
|
-
return {
|
|
533
|
-
sql: collapseWs(c.sql),
|
|
534
|
-
params: c.params
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
function resolveToSQLOptimized(state, options) {
|
|
538
|
-
state = withMinimumImpressions(state, options);
|
|
539
|
-
const { adapter } = options;
|
|
540
|
-
const { tableKey, groupByDims, hasDate, metrics, wherePredicates, having, queryCanonicalUsed } = buildScope(state, options);
|
|
541
|
-
const table = adapter.fromSql(tableKey, { queryCanonical: queryCanonicalUsed });
|
|
542
|
-
const schema = adapter.schema;
|
|
543
|
-
const cteSelect = [];
|
|
544
|
-
for (const d of groupByDims) {
|
|
545
|
-
const expr = adapter.dimExprSql(d, tableKey);
|
|
546
|
-
const colName = adapter.dimColumn(d, tableKey);
|
|
547
|
-
if (d === "page" || colName !== d) cteSelect.push(sql`${expr} as ${aliasRaw(d)}`);
|
|
548
|
-
else cteSelect.push(expr);
|
|
549
|
-
}
|
|
550
|
-
if (hasDate) cteSelect.push(adapter.dateColRef(tableKey));
|
|
551
|
-
const t = schema[tableKey];
|
|
552
|
-
cteSelect.push(sql`CAST(SUM(${t.clicks}) AS DOUBLE) as clicks`);
|
|
553
|
-
cteSelect.push(sql`CAST(SUM(${t.impressions}) AS DOUBLE) as impressions`);
|
|
554
|
-
cteSelect.push(sql`CAST(SUM(${t.sum_position}) AS DOUBLE) as sum_position`);
|
|
555
|
-
const groupByExprs = groupByDims.map((d) => adapter.dimExprSql(d, tableKey));
|
|
556
|
-
if (hasDate) groupByExprs.push(adapter.dateColRef(tableKey));
|
|
557
|
-
const outerSelect = [];
|
|
558
|
-
for (const d of groupByDims) outerSelect.push(aliasRaw(d));
|
|
559
|
-
if (hasDate) outerSelect.push(sql.raw("date"));
|
|
560
|
-
const outerTotals = [];
|
|
561
|
-
for (const m of metrics) switch (m) {
|
|
562
|
-
case "clicks":
|
|
563
|
-
outerSelect.push(sql.raw("clicks"));
|
|
564
|
-
outerTotals.push(sql.raw("CAST(SUM(clicks) OVER() AS DOUBLE) as totalClicks"));
|
|
565
|
-
break;
|
|
566
|
-
case "impressions":
|
|
567
|
-
outerSelect.push(sql.raw("impressions"));
|
|
568
|
-
outerTotals.push(sql.raw("CAST(SUM(impressions) OVER() AS DOUBLE) as totalImpressions"));
|
|
569
|
-
break;
|
|
570
|
-
case "ctr":
|
|
571
|
-
outerSelect.push(sql.raw("CAST(clicks AS REAL) / NULLIF(impressions, 0) as ctr"));
|
|
572
|
-
outerTotals.push(sql.raw("CAST(SUM(clicks) OVER() AS REAL) / NULLIF(SUM(impressions) OVER(), 0) as totalCtr"));
|
|
573
|
-
break;
|
|
574
|
-
case "position":
|
|
575
|
-
outerSelect.push(sql.raw("sum_position / NULLIF(impressions, 0) + 1 as position"));
|
|
576
|
-
outerTotals.push(sql.raw("SUM(sum_position) OVER() / NULLIF(SUM(impressions) OVER(), 0) + 1 as totalPosition"));
|
|
577
|
-
break;
|
|
578
|
-
}
|
|
579
|
-
let orderByColumnOverride;
|
|
580
|
-
const orderColumn = state.orderBy?.column;
|
|
581
|
-
if (orderColumn && orderColumn !== "date" && !metrics.includes(orderColumn)) {
|
|
582
|
-
orderByColumnOverride = `${ORDER_BY_HELPER_PREFIX}${orderColumn}`;
|
|
583
|
-
switch (orderColumn) {
|
|
584
|
-
case "clicks":
|
|
585
|
-
outerSelect.push(sql.raw(`clicks as "${orderByColumnOverride}"`));
|
|
586
|
-
break;
|
|
587
|
-
case "impressions":
|
|
588
|
-
outerSelect.push(sql.raw(`impressions as "${orderByColumnOverride}"`));
|
|
589
|
-
break;
|
|
590
|
-
case "ctr":
|
|
591
|
-
outerSelect.push(sql.raw(`CAST(clicks AS REAL) / NULLIF(impressions, 0) as "${orderByColumnOverride}"`));
|
|
592
|
-
break;
|
|
593
|
-
case "position":
|
|
594
|
-
outerSelect.push(sql.raw(`sum_position / NULLIF(impressions, 0) + 1 as "${orderByColumnOverride}"`));
|
|
595
|
-
break;
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
outerSelect.push(sql.raw("COUNT(*) OVER() as totalCount"));
|
|
599
|
-
for (const totalExpr of outerTotals) outerSelect.push(totalExpr);
|
|
600
|
-
let cte = wherePredicates.length > 0 ? sql`SELECT ${joinComma(cteSelect)} FROM ${table} WHERE ${joinAnd(wherePredicates)}` : sql`SELECT ${joinComma(cteSelect)} FROM ${table}`;
|
|
601
|
-
if (groupByExprs.length > 0) cte = sql`${cte} GROUP BY ${joinComma(groupByExprs)}`;
|
|
602
|
-
if (having.length > 0) cte = sql`${cte} HAVING ${joinAnd(having)}`;
|
|
603
|
-
return compileCollapsed(adapter, sql`WITH aggregated AS (${cte}) SELECT ${joinComma(outerSelect)} FROM aggregated ${orderByClause(state, "", orderByColumnOverride)} ${limitOffsetClause(state)}`);
|
|
604
|
-
}
|
|
605
|
-
function resolveToSQL(state, options) {
|
|
606
|
-
state = withMinimumImpressions(state, options);
|
|
607
|
-
const { adapter } = options;
|
|
608
|
-
const { tableKey, groupByDims, hasDate, metrics, wherePredicates, having, queryCanonicalUsed } = buildScope(state, options);
|
|
609
|
-
const table = adapter.fromSql(tableKey, { queryCanonical: queryCanonicalUsed });
|
|
610
|
-
const selectExprs = [];
|
|
611
|
-
for (const d of groupByDims) {
|
|
612
|
-
const expr = adapter.dimExprSql(d, tableKey);
|
|
613
|
-
const colName = adapter.dimColumn(d, tableKey);
|
|
614
|
-
if (d === "page" || colName !== d) selectExprs.push(sql`${expr} as ${aliasRaw(d)}`);
|
|
615
|
-
else selectExprs.push(expr);
|
|
616
|
-
}
|
|
617
|
-
if (hasDate) selectExprs.push(adapter.dateColRef(tableKey));
|
|
618
|
-
for (const m of metrics) selectExprs.push(sql`${adapter.metricSql(m, tableKey)} as ${aliasRaw(m)}`);
|
|
619
|
-
const groupByExprs = groupByDims.map((d) => adapter.dimExprSql(d, tableKey));
|
|
620
|
-
if (hasDate) groupByExprs.push(adapter.dateColRef(tableKey));
|
|
621
|
-
let body = wherePredicates.length > 0 ? sql`SELECT ${joinComma(selectExprs)} FROM ${table} WHERE ${joinAnd(wherePredicates)}` : sql`SELECT ${joinComma(selectExprs)} FROM ${table}`;
|
|
622
|
-
if (groupByExprs.length > 0) body = sql`${body} GROUP BY ${joinComma(groupByExprs)}`;
|
|
623
|
-
if (having.length > 0) body = sql`${body} HAVING ${joinAnd(having)}`;
|
|
624
|
-
const mainQuery = sql`${body} ${orderByClause(state)} ${limitOffsetClause(state)}`;
|
|
625
|
-
let countQuery;
|
|
626
|
-
if (groupByExprs.length > 0) {
|
|
627
|
-
let inner = wherePredicates.length > 0 ? sql`SELECT ${joinComma(groupByExprs)} FROM ${table} WHERE ${joinAnd(wherePredicates)} GROUP BY ${joinComma(groupByExprs)}` : sql`SELECT ${joinComma(groupByExprs)} FROM ${table} GROUP BY ${joinComma(groupByExprs)}`;
|
|
628
|
-
if (having.length > 0) inner = sql`${inner} HAVING ${joinAnd(having)}`;
|
|
629
|
-
countQuery = sql`SELECT COUNT(*) as total FROM (${inner})`;
|
|
630
|
-
} else countQuery = wherePredicates.length > 0 ? sql`SELECT COUNT(*) as total FROM ${table} WHERE ${joinAnd(wherePredicates)}` : sql`SELECT COUNT(*) as total FROM ${table}`;
|
|
631
|
-
const main = compileCollapsed(adapter, mainQuery);
|
|
632
|
-
const count = compileCollapsed(adapter, countQuery);
|
|
633
|
-
return {
|
|
634
|
-
sql: main.sql,
|
|
635
|
-
params: main.params,
|
|
636
|
-
countSql: count.sql,
|
|
637
|
-
countParams: count.params
|
|
638
|
-
};
|
|
639
|
-
}
|
|
640
|
-
function buildTotalsSql(state, options) {
|
|
641
|
-
state = withMinimumImpressions(state, options);
|
|
642
|
-
const { adapter } = options;
|
|
643
|
-
const { tableKey, metrics, wherePredicates, queryCanonicalUsed } = buildScope(state, options);
|
|
644
|
-
const table = adapter.fromSql(tableKey, { queryCanonical: queryCanonicalUsed });
|
|
645
|
-
const selectExprs = metrics.map((m) => sql`${adapter.metricSql(m, tableKey)} as ${aliasRaw(m)}`);
|
|
646
|
-
return compileCollapsed(adapter, wherePredicates.length > 0 ? sql`SELECT ${joinComma(selectExprs)} FROM ${table} WHERE ${joinAnd(wherePredicates)}` : sql`SELECT ${joinComma(selectExprs)} FROM ${table}`);
|
|
647
|
-
}
|
|
648
|
-
function resolveComparisonSQL(current, previous, options, comparisonFilter) {
|
|
649
|
-
const { adapter, siteId, searchType } = options;
|
|
650
|
-
const comparisonPlan = buildComparisonPlan(current, previous, adapter.capabilities);
|
|
651
|
-
const currentScope = buildScope(current, options);
|
|
652
|
-
const previousScope = buildScope(previous, options);
|
|
653
|
-
const { tableKey, groupByDims, metrics, wherePredicates: currentWhere, having } = currentScope;
|
|
654
|
-
const table = adapter.fromSql(tableKey, { queryCanonical: currentScope.queryCanonicalUsed || previousScope.queryCanonicalUsed });
|
|
655
|
-
const dimSelectExprs = [];
|
|
656
|
-
for (const d of groupByDims) {
|
|
657
|
-
const expr = adapter.dimExprSql(d, tableKey);
|
|
658
|
-
const colName = adapter.dimColumn(d, tableKey);
|
|
659
|
-
if (d === "page" || colName !== d) dimSelectExprs.push(sql`${expr} as ${aliasRaw(d)}`);
|
|
660
|
-
else dimSelectExprs.push(expr);
|
|
661
|
-
}
|
|
662
|
-
const currentSelect = [...dimSelectExprs, ...metrics.map((m) => sql`${adapter.metricSql(m, tableKey)} as ${aliasRaw(m)}`)];
|
|
663
|
-
const prevSelect = [...dimSelectExprs, ...adapter.METRIC_NAMES.map((m) => sql`${adapter.metricSql(m, tableKey)} as ${aliasRaw(m)}`)];
|
|
664
|
-
const groupByExprs = groupByDims.map((d) => adapter.dimExprSql(d, tableKey));
|
|
665
|
-
const prevWhere = [];
|
|
666
|
-
if (adapter.siteIdColRef && siteId != null) prevWhere.push(sql`${adapter.siteIdColRef(tableKey)} = ${siteId}`);
|
|
667
|
-
if (adapter.searchTypeColRef && searchType != null) prevWhere.push(sql`${adapter.searchTypeColRef(tableKey)} = ${searchType}`);
|
|
668
|
-
if (previousScope.startDate) prevWhere.push(sql`${adapter.dateColRef(tableKey)} >= ${previousScope.startDate}`);
|
|
669
|
-
if (previousScope.endDate) prevWhere.push(sql`${adapter.dateColRef(tableKey)} <= ${previousScope.endDate}`);
|
|
670
|
-
const prevDimSql = comparisonPlan.current.dimensionFilterTree ? compileFilterTree(comparisonPlan.current.dimensionFilterTree, adapter, tableKey) : void 0;
|
|
671
|
-
if (prevDimSql) prevWhere.push(prevDimSql);
|
|
672
|
-
else if (!comparisonPlan.current.dimensionFilterTree) prevWhere.push(...adapter.dimensionPredicates(toInternalDimensionFilters(comparisonPlan.current.dimensionFilters), tableKey));
|
|
673
|
-
let currentCte = currentWhere.length > 0 ? sql`SELECT ${joinComma(currentSelect)} FROM ${table} WHERE ${joinAnd(currentWhere)}` : sql`SELECT ${joinComma(currentSelect)} FROM ${table}`;
|
|
674
|
-
if (groupByExprs.length > 0) currentCte = sql`${currentCte} GROUP BY ${joinComma(groupByExprs)}`;
|
|
675
|
-
if (having.length > 0) currentCte = sql`${currentCte} HAVING ${joinAnd(having)}`;
|
|
676
|
-
let previousCte = prevWhere.length > 0 ? sql`SELECT ${joinComma(prevSelect)} FROM ${table} WHERE ${joinAnd(prevWhere)}` : sql`SELECT ${joinComma(prevSelect)} FROM ${table}`;
|
|
677
|
-
if (groupByExprs.length > 0) previousCte = sql`${previousCte} GROUP BY ${joinComma(groupByExprs)}`;
|
|
678
|
-
const joinOn = groupByDims.length > 0 ? sql.raw(groupByDims.map((d) => `c.${d.replace(/\W/g, "")} = p.${d.replace(/\W/g, "")}`).join(" AND ")) : sql.raw("1=1");
|
|
679
|
-
const filterClause = comparisonFilter ? COMPARISON_FILTER_SQL[comparisonFilter] : sql.raw("");
|
|
680
|
-
const orderSql = orderByClause(current, "");
|
|
681
|
-
const limitSql = limitOffsetClause(current);
|
|
682
|
-
const outerCurrentCols = [];
|
|
683
|
-
for (const d of groupByDims) {
|
|
684
|
-
const colName = d.replace(/\W/g, "");
|
|
685
|
-
outerCurrentCols.push(sql.raw(`COALESCE(c.${colName}, p.${colName}) as "${colName}"`));
|
|
686
|
-
}
|
|
687
|
-
outerCurrentCols.push(sql.raw("CAST(COALESCE(c.clicks, 0) AS DOUBLE) as \"clicks\""));
|
|
688
|
-
outerCurrentCols.push(sql.raw("CAST(COALESCE(c.impressions, 0) AS DOUBLE) as \"impressions\""));
|
|
689
|
-
outerCurrentCols.push(sql.raw("COALESCE(c.ctr, 0) as \"ctr\""));
|
|
690
|
-
outerCurrentCols.push(sql.raw("COALESCE(c.position, 0) as \"position\""));
|
|
691
|
-
const mainQuery = sql`WITH current AS (${currentCte}), previous AS (${previousCte}) SELECT ${joinComma(outerCurrentCols)}, COALESCE(CAST(p.clicks AS DOUBLE), 0) as "prevClicks", COALESCE(CAST(p.impressions AS DOUBLE), 0) as "prevImpressions", COALESCE(p.ctr, 0) as "prevCtr", COALESCE(p.position, 0) as "prevPosition" FROM current c FULL OUTER JOIN previous p ON ${joinOn} WHERE 1=1 ${filterClause} ${orderSql} ${limitSql}`;
|
|
692
|
-
const firstGroupBy = groupByDims[0] ? groupByDims[0].replace(/\W/g, "") : "clicks";
|
|
693
|
-
const countInnerSelect = groupByDims[0] ? sql.raw(`COALESCE(c.${firstGroupBy}, p.${firstGroupBy})`) : sql.raw(`c.${firstGroupBy}`);
|
|
694
|
-
const countQuery = sql`WITH current AS (${currentCte}), previous AS (${previousCte}) SELECT COUNT(*) as total FROM (SELECT ${countInnerSelect} FROM current c FULL OUTER JOIN previous p ON ${joinOn} WHERE 1=1 ${filterClause})`;
|
|
695
|
-
const main = compileCollapsed(adapter, mainQuery);
|
|
696
|
-
const count = compileCollapsed(adapter, countQuery);
|
|
697
|
-
return {
|
|
698
|
-
sql: main.sql,
|
|
699
|
-
params: main.params,
|
|
700
|
-
countSql: count.sql,
|
|
701
|
-
countParams: count.params
|
|
702
|
-
};
|
|
703
|
-
}
|
|
704
|
-
function buildExtrasQueries(state, options) {
|
|
705
|
-
const { adapter, siteId, searchType } = options;
|
|
706
|
-
const plan = buildLogicalPlan(state, adapter.capabilities);
|
|
707
|
-
const dims = plan.groupByDimensions;
|
|
708
|
-
const extras = [];
|
|
709
|
-
if (!dims.includes("queryCanonical")) return extras;
|
|
710
|
-
const queriesKey = adapter.tableKeyForDataset("queries");
|
|
711
|
-
const t = adapter.schema[queriesKey];
|
|
712
|
-
const table = adapter.fromSql(queriesKey, { queryCanonical: true });
|
|
713
|
-
const whereParts = [];
|
|
714
|
-
if (adapter.siteIdColRef && siteId != null) whereParts.push(sql`${adapter.siteIdColRef(queriesKey)} = ${siteId}`);
|
|
715
|
-
if (adapter.searchTypeColRef && searchType != null) whereParts.push(sql`${adapter.searchTypeColRef(queriesKey)} = ${searchType}`);
|
|
716
|
-
whereParts.push(sql`${adapter.dateColRef(queriesKey)} >= ${plan.dateRange.startDate}`);
|
|
717
|
-
whereParts.push(sql`${adapter.dateColRef(queriesKey)} <= ${plan.dateRange.endDate}`);
|
|
718
|
-
const whereExpr = whereParts.length > 0 ? sql`WHERE ${joinAnd(whereParts)}` : sql``;
|
|
719
|
-
const outerQueryCol = sql.raw("query");
|
|
720
|
-
const canonKey = adapter.dimExprSql("queryCanonical", queriesKey);
|
|
721
|
-
const compiled = compileCollapsed(adapter, sql`WITH per_variant AS (SELECT ${canonKey} as joinKey, ${t.query} as query, SUM(${t.clicks}) as clicks, SUM(${t.impressions}) as impressions, SUM(${t.sum_position}) as sum_pos, ROW_NUMBER() OVER (PARTITION BY ${canonKey} ORDER BY SUM(${t.clicks}) DESC) as rn, COUNT(*) OVER (PARTITION BY ${canonKey}) as variantCount FROM ${table} ${whereExpr} GROUP BY ${canonKey}, ${t.query}) SELECT joinKey, MAX(variantCount) as variantCount, MAX(CASE WHEN rn = 1 THEN ${outerQueryCol} END) as canonicalName, GROUP_CONCAT(CASE WHEN rn <= 10 THEN ${outerQueryCol} || ':::' || clicks || ':::' || impressions || ':::' || CAST(ROUND(CAST(sum_pos AS REAL) / NULLIF(impressions, 0) + 1, 1) AS TEXT) END, '||') as variants FROM per_variant GROUP BY joinKey`);
|
|
722
|
-
extras.push({
|
|
723
|
-
key: "canonicalExtras",
|
|
724
|
-
sql: compiled.sql,
|
|
725
|
-
params: compiled.params
|
|
726
|
-
});
|
|
727
|
-
return extras;
|
|
728
|
-
}
|
|
729
|
-
function mergeExtras(rows, extrasResults) {
|
|
730
|
-
if (extrasResults.length === 0) return rows;
|
|
731
|
-
const lookups = [];
|
|
732
|
-
const parseVariants = (raw) => {
|
|
733
|
-
if (raw.length === 0) return [];
|
|
734
|
-
const encoded = raw.split("||");
|
|
735
|
-
const variants = [];
|
|
736
|
-
for (const value of encoded) {
|
|
737
|
-
if (value.length === 0) continue;
|
|
738
|
-
const parts = value.split(":::");
|
|
739
|
-
variants.push({
|
|
740
|
-
query: parts[0],
|
|
741
|
-
clicks: Number(parts[1] || 0),
|
|
742
|
-
impressions: Number(parts[2] || 0),
|
|
743
|
-
position: Number(parts[3] || 0)
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
return variants;
|
|
747
|
-
};
|
|
748
|
-
for (const { key, results } of extrasResults) {
|
|
749
|
-
if (key === "canonicalExtras") {
|
|
750
|
-
const map = /* @__PURE__ */ new Map();
|
|
751
|
-
for (const r of results) {
|
|
752
|
-
const jk = String(r.joinKey);
|
|
753
|
-
const raw = r.variants;
|
|
754
|
-
map.set(jk, {
|
|
755
|
-
variantCount: r.variantCount,
|
|
756
|
-
variants: typeof raw === "string" ? parseVariants(raw) : [],
|
|
757
|
-
canonicalName: r.canonicalName
|
|
758
|
-
});
|
|
759
|
-
}
|
|
760
|
-
lookups.push({
|
|
761
|
-
kind: "canonical",
|
|
762
|
-
map
|
|
763
|
-
});
|
|
764
|
-
continue;
|
|
765
|
-
}
|
|
766
|
-
const map = /* @__PURE__ */ new Map();
|
|
767
|
-
for (const r of results) {
|
|
768
|
-
if (r.rn !== void 0 && r.rn !== 1) continue;
|
|
769
|
-
let val = r[key];
|
|
770
|
-
if (key === "variants" && typeof val === "string") val = parseVariants(val);
|
|
771
|
-
map.set(String(r.joinKey), val);
|
|
772
|
-
}
|
|
773
|
-
lookups.push({
|
|
774
|
-
kind: "generic",
|
|
775
|
-
key,
|
|
776
|
-
map
|
|
777
|
-
});
|
|
778
|
-
}
|
|
779
|
-
return rows.map((row) => {
|
|
780
|
-
const enriched = { ...row };
|
|
781
|
-
for (const lookup of lookups) {
|
|
782
|
-
if (lookup.kind === "canonical") {
|
|
783
|
-
const joinValue = String(row.queryCanonical ?? row.query_canonical ?? "");
|
|
784
|
-
const extra = joinValue ? lookup.map.get(joinValue) : void 0;
|
|
785
|
-
enriched.variantCount = extra?.variantCount ?? null;
|
|
786
|
-
enriched.variants = extra?.variants ?? [];
|
|
787
|
-
enriched.canonicalName = extra?.canonicalName ?? null;
|
|
788
|
-
if (enriched.canonicalName) enriched.queryCanonical = enriched.canonicalName;
|
|
789
|
-
continue;
|
|
790
|
-
}
|
|
791
|
-
const { key, map } = lookup;
|
|
792
|
-
const joinValue = key === "variantCount" || key === "variants" || key === "canonicalName" ? String(row.queryCanonical ?? row.query_canonical ?? "") : void 0;
|
|
793
|
-
enriched[key] = (joinValue && map.get(joinValue)) ?? (key === "variants" ? [] : null);
|
|
794
|
-
if (key === "canonicalName" && enriched[key]) enriched.queryCanonical = enriched[key];
|
|
795
|
-
}
|
|
796
|
-
return enriched;
|
|
797
|
-
});
|
|
798
|
-
}
|
|
799
|
-
const EXTRA_ROLLUP_IDS = { canonicalExtras: "query_canonical_variants" };
|
|
800
|
-
function createRollupExtrasOverlay(readRollupRows) {
|
|
801
|
-
return async ({ key, ctx, dateRange }) => {
|
|
802
|
-
const id = EXTRA_ROLLUP_IDS[key];
|
|
803
|
-
if (id === void 0) return null;
|
|
804
|
-
return readRollupRows({
|
|
805
|
-
id,
|
|
806
|
-
ctx: {
|
|
807
|
-
userId: ctx.userId,
|
|
808
|
-
siteId: ctx.siteId
|
|
809
|
-
},
|
|
810
|
-
dateRange,
|
|
811
|
-
...ctx.searchType !== void 0 ? { searchType: ctx.searchType } : {}
|
|
812
|
-
});
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
function collectInternalFilters(filter) {
|
|
816
|
-
if (!filter || !("_filters" in filter)) return [];
|
|
817
|
-
const flat = filter._filters;
|
|
818
|
-
const nested = filter._nestedGroups?.flatMap((group) => collectInternalFilters(group)) ?? [];
|
|
819
|
-
return [...flat, ...nested];
|
|
820
|
-
}
|
|
821
|
-
function getInternalFilters(filter) {
|
|
822
|
-
return collectInternalFilters(filter);
|
|
823
|
-
}
|
|
824
|
-
function getDimensionFilters(filter, isMetricDimension) {
|
|
825
|
-
return collectInternalFilters(filter).filter((f) => f.dimension !== "date" && !isMetricDimension(f.dimension) && f.operator !== "topLevel" && !f.operator.startsWith("metric"));
|
|
826
|
-
}
|
|
827
|
-
function getFilterDimensions(filter, isMetricDimension) {
|
|
828
|
-
return getDimensionFilters(filter, isMetricDimension).map((f) => f.dimension);
|
|
829
|
-
}
|
|
830
|
-
function metricValue(row, metric) {
|
|
831
|
-
const value = row[metric];
|
|
832
|
-
if (typeof value === "number") return value;
|
|
833
|
-
if (typeof value === "bigint") return Number(value);
|
|
834
|
-
if (value == null) return 0;
|
|
835
|
-
return Number(value);
|
|
836
|
-
}
|
|
837
|
-
function dimensionValue(row, dimension) {
|
|
838
|
-
const value = row[dimension];
|
|
839
|
-
return value == null ? "" : String(value);
|
|
840
|
-
}
|
|
841
|
-
function matchesDimensionFilter(row, filter) {
|
|
842
|
-
const raw = dimensionValue(row, filter.dimension);
|
|
843
|
-
const value = filter.dimension === "page" ? normalizeUrl(raw) : raw;
|
|
844
|
-
switch (filter.operator) {
|
|
845
|
-
case "equals": return value === filter.expression;
|
|
846
|
-
case "notEquals": return value !== filter.expression;
|
|
847
|
-
case "contains": return raw.includes(filter.expression);
|
|
848
|
-
case "notContains": return !raw.includes(filter.expression);
|
|
849
|
-
case "includingRegex": return new RegExp(filter.expression).test(raw);
|
|
850
|
-
case "excludingRegex": return !new RegExp(filter.expression).test(raw);
|
|
851
|
-
default: return true;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
function matchesMetricFilter(row, filter) {
|
|
855
|
-
const value = metricValue(row, filter.dimension);
|
|
856
|
-
const target = Number(filter.expression);
|
|
857
|
-
switch (filter.operator) {
|
|
858
|
-
case "metricGte": return value >= target;
|
|
859
|
-
case "metricGt": return value > target;
|
|
860
|
-
case "metricLte": return value <= target;
|
|
861
|
-
case "metricLt": return value < target;
|
|
862
|
-
case "metricBetween": return value >= target && value <= Number(filter.expression2);
|
|
863
|
-
default: return true;
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
function matchesTopLevelPage(row) {
|
|
867
|
-
const path = normalizeUrl(dimensionValue(row, "page"));
|
|
868
|
-
let slashes = 0;
|
|
869
|
-
for (let index = 0; index < path.length; index++) if (path.charCodeAt(index) === 47 && ++slashes > 1) return false;
|
|
870
|
-
return true;
|
|
871
|
-
}
|
|
872
|
-
const pgDialect = new PgDialect();
|
|
873
|
-
function withTenantCols(tableName, baseTable) {
|
|
874
|
-
const t = pgTable(tableName, {
|
|
875
|
-
site_id: varchar("site_id").notNull(),
|
|
876
|
-
search_type: varchar("search_type").notNull()
|
|
877
|
-
});
|
|
878
|
-
return {
|
|
879
|
-
...baseTable,
|
|
880
|
-
site_id: t.site_id,
|
|
881
|
-
search_type: t.search_type
|
|
882
|
-
};
|
|
883
|
-
}
|
|
884
|
-
const icebergSchema = {
|
|
885
|
-
pages: withTenantCols("pages", drizzleSchema.pages),
|
|
886
|
-
queries: withTenantCols("queries", drizzleSchema.queries),
|
|
887
|
-
countries: withTenantCols("countries", drizzleSchema.countries),
|
|
888
|
-
page_queries: withTenantCols("page_queries", drizzleSchema.page_queries),
|
|
889
|
-
dates: withTenantCols("dates", drizzleSchema.dates),
|
|
890
|
-
search_appearance: withTenantCols("search_appearance", drizzleSchema.search_appearance),
|
|
891
|
-
search_appearance_pages: withTenantCols("search_appearance_pages", drizzleSchema.search_appearance_pages),
|
|
892
|
-
search_appearance_queries: withTenantCols("search_appearance_queries", drizzleSchema.search_appearance_queries),
|
|
893
|
-
search_appearance_page_queries: withTenantCols("search_appearance_page_queries", drizzleSchema.search_appearance_page_queries),
|
|
894
|
-
hourly_pages: withTenantCols("hourly_pages", drizzleSchema.hourly_pages)
|
|
895
|
-
};
|
|
896
|
-
function compilePg(query) {
|
|
897
|
-
const compiled = pgDialect.sqlToQuery(query);
|
|
898
|
-
return {
|
|
899
|
-
sql: compiled.sql,
|
|
900
|
-
params: compiled.params
|
|
901
|
-
};
|
|
902
|
-
}
|
|
903
|
-
const PG_BASE_CONFIG = {
|
|
904
|
-
schema: drizzleSchema,
|
|
905
|
-
datasetToTableKey: {
|
|
906
|
-
pages: "pages",
|
|
907
|
-
queries: "queries",
|
|
908
|
-
page_queries: "page_queries",
|
|
909
|
-
countries: "countries",
|
|
910
|
-
dates: "dates",
|
|
911
|
-
search_appearance: "search_appearance",
|
|
912
|
-
search_appearance_pages: "search_appearance_pages",
|
|
913
|
-
search_appearance_queries: "search_appearance_queries",
|
|
914
|
-
search_appearance_page_queries: "search_appearance_page_queries",
|
|
915
|
-
hourly_pages: "hourly_pages"
|
|
916
|
-
},
|
|
917
|
-
metricCast: "DOUBLE",
|
|
918
|
-
regexPredicate: (expr, pattern, negate) => negate ? sql`NOT regexp_matches(${expr}, ${pattern})` : sql`regexp_matches(${expr}, ${pattern})`,
|
|
919
|
-
urlToPathExpr: (col) => `CASE WHEN ${col} LIKE 'http%' THEN COALESCE(NULLIF(regexp_replace(${col}, '^https?://[^/]+', ''), ''), '/') ELSE ${col} END`,
|
|
920
|
-
includeSiteId: false,
|
|
921
|
-
compile: compilePg,
|
|
922
|
-
capabilities: {
|
|
923
|
-
regex: true,
|
|
924
|
-
comparisonJoin: true,
|
|
925
|
-
windowTotals: true
|
|
926
|
-
}
|
|
927
|
-
};
|
|
928
|
-
const pgResolverAdapter = createResolverAdapter({
|
|
929
|
-
...PG_BASE_CONFIG,
|
|
930
|
-
tableLabel: "pg-resolver-adapter"
|
|
931
|
-
});
|
|
932
|
-
function createParquetResolverAdapter(options = {}) {
|
|
933
|
-
return createResolverAdapter({
|
|
934
|
-
...PG_BASE_CONFIG,
|
|
935
|
-
tableLabel: "parquet-resolver-adapter",
|
|
936
|
-
queryCanonicalSource: options.queryCanonicalSource ?? "queryDim",
|
|
937
|
-
tableRef: (tk) => sql.raw(`read_parquet({{FILES}}, union_by_name = true) AS "${tk}"`),
|
|
938
|
-
queryDimTableRef: () => sql.raw("read_parquet({{QUERY_DIM}}, union_by_name = true) AS \"query_dim\"")
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
function createIcebergResolverAdapter(options = {}) {
|
|
942
|
-
return createResolverAdapter({
|
|
943
|
-
...PG_BASE_CONFIG,
|
|
944
|
-
schema: icebergSchema,
|
|
945
|
-
includeSiteId: true,
|
|
946
|
-
includeSearchType: true,
|
|
947
|
-
tableLabel: "iceberg-resolver-adapter",
|
|
948
|
-
queryCanonicalSource: options.queryCanonicalSource ?? "queryDim",
|
|
949
|
-
tableRef: (tk) => sql.raw(`"${tk}"`),
|
|
950
|
-
queryDimTableRef: () => sql.raw("\"query_dim\"")
|
|
951
|
-
});
|
|
952
|
-
}
|
|
953
|
-
function createR2SqlResolverAdapter(options = {}) {
|
|
954
|
-
const adapter = createResolverAdapter({
|
|
955
|
-
...PG_BASE_CONFIG,
|
|
956
|
-
schema: icebergSchema,
|
|
957
|
-
includeSiteId: true,
|
|
958
|
-
includeSearchType: true,
|
|
959
|
-
tableLabel: "r2-sql-resolver-adapter",
|
|
960
|
-
queryCanonicalSource: options.queryCanonicalSource ?? "queryDim",
|
|
961
|
-
capabilities: {
|
|
962
|
-
regex: false,
|
|
963
|
-
comparisonJoin: false,
|
|
964
|
-
windowTotals: false
|
|
965
|
-
},
|
|
966
|
-
tableRef: (tk) => sql.raw(`"${tk}"`),
|
|
967
|
-
queryDimTableRef: () => sql.raw("\"query_dim\"")
|
|
968
|
-
});
|
|
969
|
-
if ((options.partitionKeyEncoding ?? DEFAULT_PARTITION_KEY_ENCODING) === "int") return adapter;
|
|
970
|
-
return {
|
|
971
|
-
...adapter,
|
|
972
|
-
siteIdColRef: (tk) => sql`CONCAT(${adapter.siteIdColRef(tk)}, '')`,
|
|
973
|
-
searchTypeColRef: (tk) => sql`CONCAT(${adapter.searchTypeColRef(tk)}, '')`
|
|
974
|
-
};
|
|
975
|
-
}
|
|
976
|
-
var QuerySourceCoverageError = class extends Error {
|
|
977
|
-
fallback;
|
|
978
|
-
name = "QuerySourceCoverageError";
|
|
979
|
-
constructor(fallback) {
|
|
980
|
-
super(fallback.message);
|
|
981
|
-
this.fallback = fallback;
|
|
982
|
-
}
|
|
983
|
-
};
|
|
984
|
-
function canonicalSourceWithinCoverage(source, windowEnd) {
|
|
985
|
-
return source.coversThrough === void 0 || windowEnd <= source.coversThrough;
|
|
986
|
-
}
|
|
987
|
-
function querySourceDecision(kind, fallbacks = []) {
|
|
988
|
-
const first = fallbacks[0];
|
|
989
|
-
return {
|
|
990
|
-
kind,
|
|
991
|
-
...first ? {
|
|
992
|
-
fallback: first,
|
|
993
|
-
fallbacks
|
|
994
|
-
} : {}
|
|
995
|
-
};
|
|
996
|
-
}
|
|
997
|
-
function canonicalFeatureRequested(state, capabilities) {
|
|
998
|
-
const plan = buildLogicalPlan(state, capabilities);
|
|
999
|
-
return plan.groupByDimensions.includes("queryCanonical") || plan.dimensionFilters.some((f) => f.dimension === "queryCanonical");
|
|
1000
|
-
}
|
|
1001
|
-
function fallback(kind, message) {
|
|
1002
|
-
return {
|
|
1003
|
-
kind,
|
|
1004
|
-
message
|
|
1005
|
-
};
|
|
1006
|
-
}
|
|
1007
|
-
function staleQueryDim(source, requirements) {
|
|
1008
|
-
if (requirements?.normalizerVersion !== void 0 && source.normalizerVersion !== requirements.normalizerVersion) return fallback("query-dim-stale-version", `canonical query dimension normalizer v${source.normalizerVersion} does not match required v${requirements.normalizerVersion}`);
|
|
1009
|
-
if (requirements?.intentVersion !== void 0 && source.intentVersion !== requirements.intentVersion) return fallback("query-dim-stale-version", `canonical query dimension intent v${source.intentVersion ?? "missing"} does not match required v${requirements.intentVersion}`);
|
|
1010
|
-
}
|
|
1011
|
-
function canonicalQueryDim(options) {
|
|
1012
|
-
return options.queryDim ?? options.canonicalSource?.queryDim;
|
|
1013
|
-
}
|
|
1014
|
-
function queryDimMiss(source, requirements) {
|
|
1015
|
-
if (!source) return fallback("query-dim-missing", "canonical query requires queryDim; fact tables do not carry query_canonical");
|
|
1016
|
-
if (source.keys.length === 0) return fallback("query-dim-empty", "queryDim has no parquet keys; refusing to run canonical query from an empty dimension");
|
|
1017
|
-
return staleQueryDim(source, requirements);
|
|
1018
|
-
}
|
|
1019
|
-
function decideCanonicalSource(state, capabilities, options, windowEnd) {
|
|
1020
|
-
if (!canonicalFeatureRequested(state, capabilities)) return querySourceDecision("raw-partitions");
|
|
1021
|
-
const dimMiss = queryDimMiss(canonicalQueryDim(options), options.canonicalRequirements);
|
|
1022
|
-
if (dimMiss) throw new QuerySourceCoverageError(dimMiss);
|
|
1023
|
-
const source = options.canonicalSource;
|
|
1024
|
-
const miss = (() => {
|
|
1025
|
-
if (!source) return fallback("canonical-source-missing", "canonical rollup source missing; falling back to primary facts joined through query_dim");
|
|
1026
|
-
if (source.keys.length === 0) return fallback("canonical-source-empty", "canonicalSource has no parquet keys; falling back to primary facts joined through query_dim");
|
|
1027
|
-
if (!canonicalSourceWithinCoverage(source, windowEnd)) return fallback("canonical-source-stale-coverage", `canonicalSource covers through ${source.coversThrough}, but query needs ${windowEnd}`);
|
|
1028
|
-
if (!canonicalRollupCovers(state, capabilities)) return fallback("canonical-source-not-coverable", "canonicalSource only covers queryCanonical/date reads without raw-grain filters");
|
|
1029
|
-
})();
|
|
1030
|
-
if (!miss) return querySourceDecision("canonical-rollup");
|
|
1031
|
-
return querySourceDecision("raw-partitions", [miss]);
|
|
1032
|
-
}
|
|
1033
|
-
function primarySourceMiss(source, dateRange) {
|
|
1034
|
-
if (!source) return fallback("primary-source-missing", "primary columnar source is required; pass primarySourceFallback: \"raw\" to use raw daily partitions explicitly");
|
|
1035
|
-
if (source.keys.length === 0) return fallback("primary-source-empty", "primarySource has no parquet keys; refusing to return partial or empty data implicitly");
|
|
1036
|
-
if (source.coversFrom !== void 0 && dateRange.startDate < source.coversFrom) return fallback("primary-source-missing-coverage", `primarySource covers from ${source.coversFrom}, but query starts ${dateRange.startDate}`);
|
|
1037
|
-
if (source.coversThrough !== void 0 && dateRange.endDate > source.coversThrough) return fallback("primary-source-stale-coverage", `primarySource covers through ${source.coversThrough}, but query needs ${dateRange.endDate}`);
|
|
1038
|
-
}
|
|
1039
|
-
function decidePrimarySource(options, dateRange, priorFallbacks = []) {
|
|
1040
|
-
const miss = primarySourceMiss(options.primarySource, dateRange);
|
|
1041
|
-
if (!miss) return querySourceDecision("primary-columnar", priorFallbacks);
|
|
1042
|
-
const fallbacks = [...priorFallbacks, miss];
|
|
1043
|
-
if (options.primarySourceFallback === "raw") return querySourceDecision("raw-partitions", fallbacks);
|
|
1044
|
-
throw new QuerySourceCoverageError(miss);
|
|
1045
|
-
}
|
|
1046
|
-
function sourceFallbacks(source) {
|
|
1047
|
-
if (source.fallbacks) return source.fallbacks;
|
|
1048
|
-
return source.fallback ? [source.fallback] : [];
|
|
1049
|
-
}
|
|
1050
|
-
function runArgs(ctx, partitions) {
|
|
1051
|
-
return {
|
|
1052
|
-
ctx: {
|
|
1053
|
-
userId: ctx.userId,
|
|
1054
|
-
siteId: ctx.siteId
|
|
1055
|
-
},
|
|
1056
|
-
table: ctx.table,
|
|
1057
|
-
fileSets: { FILES: {
|
|
1058
|
-
table: ctx.table,
|
|
1059
|
-
partitions
|
|
1060
|
-
} },
|
|
1061
|
-
...ctx.searchType !== void 0 ? { searchType: ctx.searchType } : {}
|
|
1062
|
-
};
|
|
1063
|
-
}
|
|
1064
|
-
function primaryRunArgs(ctx, keys) {
|
|
1065
|
-
return {
|
|
1066
|
-
ctx: {
|
|
1067
|
-
userId: ctx.userId,
|
|
1068
|
-
siteId: ctx.siteId
|
|
1069
|
-
},
|
|
1070
|
-
table: ctx.table,
|
|
1071
|
-
fileSets: { FILES: {
|
|
1072
|
-
table: ctx.table,
|
|
1073
|
-
keys
|
|
1074
|
-
} },
|
|
1075
|
-
...ctx.searchType !== void 0 ? { searchType: ctx.searchType } : {}
|
|
1076
|
-
};
|
|
1077
|
-
}
|
|
1078
|
-
function withQueryDimFileSet(args, queryDim, enabled) {
|
|
1079
|
-
if (!enabled || !queryDim) return args;
|
|
1080
|
-
return {
|
|
1081
|
-
...args,
|
|
1082
|
-
fileSets: {
|
|
1083
|
-
...args.fileSets,
|
|
1084
|
-
QUERY_DIM: {
|
|
1085
|
-
table: "queries",
|
|
1086
|
-
keys: queryDim.keys
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
};
|
|
1090
|
-
}
|
|
1091
|
-
async function runOptimizedQuery(runSQL, ctx, state, dateRange, options = {}) {
|
|
1092
|
-
const base = runArgs(ctx, enumeratePartitions(dateRange.startDate, dateRange.endDate));
|
|
1093
|
-
const probe = createParquetResolverAdapter();
|
|
1094
|
-
const canonicalRequested = canonicalFeatureRequested(state, probe.capabilities);
|
|
1095
|
-
const canonicalDecision = decideCanonicalSource(state, probe.capabilities, options, dateRange.endDate);
|
|
1096
|
-
const useCanonicalSource = canonicalDecision.kind === "canonical-rollup";
|
|
1097
|
-
const source = useCanonicalSource ? canonicalDecision : decidePrimarySource(options, dateRange, sourceFallbacks(canonicalDecision));
|
|
1098
|
-
const optimized = resolveToSQLOptimized(state, {
|
|
1099
|
-
adapter: useCanonicalSource ? createParquetResolverAdapter({ queryCanonicalSource: "column" }) : probe,
|
|
1100
|
-
siteId: void 0
|
|
1101
|
-
});
|
|
1102
|
-
const extras = buildExtrasQueries(state, {
|
|
1103
|
-
adapter: probe,
|
|
1104
|
-
siteId: void 0
|
|
1105
|
-
});
|
|
1106
|
-
const extraSource = extras.length > 0 ? useCanonicalSource ? decidePrimarySource(options, dateRange) : source : void 0;
|
|
1107
|
-
const queryDim = canonicalQueryDim(options);
|
|
1108
|
-
const mainArgs = withQueryDimFileSet(useCanonicalSource ? {
|
|
1109
|
-
...base,
|
|
1110
|
-
fileSets: { FILES: {
|
|
1111
|
-
table: ctx.table,
|
|
1112
|
-
keys: options.canonicalSource.keys
|
|
1113
|
-
} }
|
|
1114
|
-
} : source.kind === "primary-columnar" ? primaryRunArgs(ctx, options.primarySource.keys) : base, queryDim, canonicalRequested && !useCanonicalSource);
|
|
1115
|
-
const extraArgs = withQueryDimFileSet(extraSource?.kind === "primary-columnar" ? primaryRunArgs(ctx, options.primarySource.keys) : base, queryDim, extras.length > 0);
|
|
1116
|
-
const resolveExtra = options.resolveExtra;
|
|
1117
|
-
const [optRes, ...extrasRows] = await Promise.all([runSQL({
|
|
1118
|
-
...mainArgs,
|
|
1119
|
-
sql: optimized.sql,
|
|
1120
|
-
params: optimized.params
|
|
1121
|
-
}), ...extras.map(async (e) => {
|
|
1122
|
-
const overlaid = resolveExtra ? await resolveExtra({
|
|
1123
|
-
key: e.key,
|
|
1124
|
-
state,
|
|
1125
|
-
ctx,
|
|
1126
|
-
dateRange
|
|
1127
|
-
}) : null;
|
|
1128
|
-
return overlaid !== null ? { rows: overlaid } : runSQL({
|
|
1129
|
-
...extraArgs,
|
|
1130
|
-
sql: e.sql,
|
|
1131
|
-
params: e.params
|
|
1132
|
-
});
|
|
1133
|
-
})]);
|
|
1134
|
-
const firstRow = optRes.rows[0];
|
|
1135
|
-
const totalCount = Number(firstRow?.totalCount ?? 0);
|
|
1136
|
-
const totals = {
|
|
1137
|
-
clicks: Number(firstRow?.totalClicks ?? 0),
|
|
1138
|
-
impressions: Number(firstRow?.totalImpressions ?? 0),
|
|
1139
|
-
ctr: Number(firstRow?.totalCtr ?? 0),
|
|
1140
|
-
position: Number(firstRow?.totalPosition ?? 0)
|
|
1141
|
-
};
|
|
1142
|
-
return {
|
|
1143
|
-
rows: optRes.rows.map((r) => {
|
|
1144
|
-
const { totalCount: _tc, totalClicks: _tcl, totalImpressions: _ti, totalCtr: _tr, totalPosition: _tp, ...rest } = r;
|
|
1145
|
-
for (const key of Object.keys(rest)) if (key.startsWith("__order_")) delete rest[key];
|
|
1146
|
-
return rest;
|
|
1147
|
-
}),
|
|
1148
|
-
totalCount,
|
|
1149
|
-
totals,
|
|
1150
|
-
extras: extras.map((e, i) => ({
|
|
1151
|
-
key: e.key,
|
|
1152
|
-
rows: extrasRows[i].rows
|
|
1153
|
-
})),
|
|
1154
|
-
source,
|
|
1155
|
-
...extraSource ? { extraSource } : {}
|
|
1156
|
-
};
|
|
1157
|
-
}
|
|
1158
|
-
async function runComparisonQuery(runSQL, ctx, current, previous, windows, filter, options = {}) {
|
|
1159
|
-
const probe = createParquetResolverAdapter();
|
|
1160
|
-
const maxWindowEnd = windows.current.endDate > windows.previous.endDate ? windows.current.endDate : windows.previous.endDate;
|
|
1161
|
-
const currentSource = decideCanonicalSource(current, probe.capabilities, options, maxWindowEnd);
|
|
1162
|
-
const previousSource = decideCanonicalSource(previous, probe.capabilities, options, maxWindowEnd);
|
|
1163
|
-
const startDate = windows.current.startDate < windows.previous.startDate ? windows.current.startDate : windows.previous.startDate;
|
|
1164
|
-
const endDate = windows.current.endDate > windows.previous.endDate ? windows.current.endDate : windows.previous.endDate;
|
|
1165
|
-
const comparisonRange = {
|
|
1166
|
-
startDate,
|
|
1167
|
-
endDate
|
|
1168
|
-
};
|
|
1169
|
-
const source = currentSource.kind === "canonical-rollup" && previousSource.kind === "canonical-rollup" ? querySourceDecision("canonical-rollup") : decidePrimarySource(options, comparisonRange, [...sourceFallbacks(currentSource), ...sourceFallbacks(previousSource)]);
|
|
1170
|
-
const useCanonicalSource = source.kind === "canonical-rollup";
|
|
1171
|
-
const adapter = useCanonicalSource ? createParquetResolverAdapter({ queryCanonicalSource: "column" }) : probe;
|
|
1172
|
-
const comparison = resolveComparisonSQL(current, previous, {
|
|
1173
|
-
adapter,
|
|
1174
|
-
siteId: void 0
|
|
1175
|
-
}, filter);
|
|
1176
|
-
const totals = buildTotalsSql(current, {
|
|
1177
|
-
adapter,
|
|
1178
|
-
siteId: void 0
|
|
1179
|
-
});
|
|
1180
|
-
const partitions = enumeratePartitions(startDate, endDate);
|
|
1181
|
-
const base = withQueryDimFileSet(useCanonicalSource ? {
|
|
1182
|
-
...runArgs(ctx, partitions),
|
|
1183
|
-
fileSets: { FILES: {
|
|
1184
|
-
table: ctx.table,
|
|
1185
|
-
keys: options.canonicalSource.keys
|
|
1186
|
-
} }
|
|
1187
|
-
} : source.kind === "primary-columnar" ? primaryRunArgs(ctx, options.primarySource.keys) : runArgs(ctx, partitions), canonicalQueryDim(options), !useCanonicalSource && (canonicalFeatureRequested(current, probe.capabilities) || canonicalFeatureRequested(previous, probe.capabilities)));
|
|
1188
|
-
const main = await runSQL({
|
|
1189
|
-
...base,
|
|
1190
|
-
sql: comparison.sql,
|
|
1191
|
-
params: comparison.params
|
|
1192
|
-
});
|
|
1193
|
-
const count = await runSQL({
|
|
1194
|
-
...base,
|
|
1195
|
-
sql: comparison.countSql,
|
|
1196
|
-
params: comparison.countParams
|
|
1197
|
-
});
|
|
1198
|
-
const totalsRow = await runSQL({
|
|
1199
|
-
...base,
|
|
1200
|
-
sql: totals.sql,
|
|
1201
|
-
params: totals.params
|
|
1202
|
-
});
|
|
1203
|
-
return {
|
|
1204
|
-
rows: main.rows,
|
|
1205
|
-
totalCount: Number(count.rows[0]?.total ?? 0),
|
|
1206
|
-
totals: totalsRow.rows[0] ?? {},
|
|
1207
|
-
source
|
|
1208
|
-
};
|
|
1209
|
-
}
|
|
1210
|
-
function assertSchemaInSync(options) {
|
|
1211
|
-
const { label, schema, tableKeyToName, mode } = options;
|
|
1212
|
-
for (const [key, table] of Object.entries(schema)) {
|
|
1213
|
-
const sourceCols = SCHEMAS[tableKeyToName(key)].columns.map((c) => c.name).sort();
|
|
1214
|
-
const drizzleCols = Object.keys(table[Symbol.for("drizzle:Columns")] ?? {}).sort();
|
|
1215
|
-
const missing = sourceCols.filter((c) => !drizzleCols.includes(c));
|
|
1216
|
-
const extra = mode === "exact" ? drizzleCols.filter((c) => !sourceCols.includes(c)) : [];
|
|
1217
|
-
if (missing.length > 0 || extra.length > 0) throw new Error(`${label} drizzle schema for '${key}' drifted from SCHEMAS. Missing: [${missing.join(", ")}]. Extra: [${extra.join(", ")}].`);
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
export { DIMENSION_SURFACES, LOGICAL_DATASETS, QuerySourceCoverageError, UnresolvableDatasetError, assertDimensionsSupported, assertSchemaInSync, buildExtrasQueries, buildTotalsSql, canonicalRollupCovers, createIcebergResolverAdapter, createParquetResolverAdapter, createR2SqlResolverAdapter, createResolverAdapter, createRollupExtrasOverlay, createSqlFragments, dimensionColumn, dimensionValue, getDimensionFilters, getFilterDimensions, getInternalFilters, inferLogicalDataset, isDatasetResolvable, matchesDimensionFilter, matchesMetricFilter, matchesTopLevelPage, mergeExtras, metricValue, pgResolverAdapter, resolveComparisonSQL, resolveToSQL, resolveToSQLOptimized, runComparisonQuery, runOptimizedQuery, supportsDimensionOnSurface };
|