@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,2524 +0,0 @@
|
|
|
1
|
-
import { BoundaryOrders, CompressionCodecs, ConvertedTypes, EdgeInterpolationAlgorithms, Encodings, FieldRepetitionTypes, PageTypes, ParquetTypes, getMaxDefinitionLevel, getSchemaPath, hashParquetValue, isListLike, isMapLike, toJson } from "./hyparquet.mjs";
|
|
2
|
-
function ByteWriter(initalSize = 1024) {
|
|
3
|
-
this.buffer = new ArrayBuffer(initalSize);
|
|
4
|
-
this.view = new DataView(this.buffer);
|
|
5
|
-
this.offset = 0;
|
|
6
|
-
this.index = 0;
|
|
7
|
-
return this;
|
|
8
|
-
}
|
|
9
|
-
ByteWriter.prototype.ensure = function(size) {
|
|
10
|
-
if (this.index + size > this.buffer.byteLength) {
|
|
11
|
-
const newSize = Math.max(this.buffer.byteLength * 2, this.index + size);
|
|
12
|
-
const newBuffer = new ArrayBuffer(newSize);
|
|
13
|
-
new Uint8Array(newBuffer).set(new Uint8Array(this.buffer));
|
|
14
|
-
this.buffer = newBuffer;
|
|
15
|
-
this.view = new DataView(this.buffer);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
ByteWriter.prototype.finish = function() {};
|
|
19
|
-
ByteWriter.prototype.getBuffer = function() {
|
|
20
|
-
return this.buffer.slice(0, this.index);
|
|
21
|
-
};
|
|
22
|
-
ByteWriter.prototype.getBytes = function() {
|
|
23
|
-
return new Uint8Array(this.buffer, 0, this.index);
|
|
24
|
-
};
|
|
25
|
-
ByteWriter.prototype.appendUint8 = function(value) {
|
|
26
|
-
this.ensure(this.index + 1);
|
|
27
|
-
this.view.setUint8(this.index, value);
|
|
28
|
-
this.offset++;
|
|
29
|
-
this.index++;
|
|
30
|
-
};
|
|
31
|
-
ByteWriter.prototype.appendUint32 = function(value) {
|
|
32
|
-
this.ensure(this.index + 4);
|
|
33
|
-
this.view.setUint32(this.index, value, true);
|
|
34
|
-
this.offset += 4;
|
|
35
|
-
this.index += 4;
|
|
36
|
-
};
|
|
37
|
-
ByteWriter.prototype.appendInt32 = function(value) {
|
|
38
|
-
this.ensure(this.index + 4);
|
|
39
|
-
this.view.setInt32(this.index, value, true);
|
|
40
|
-
this.offset += 4;
|
|
41
|
-
this.index += 4;
|
|
42
|
-
};
|
|
43
|
-
ByteWriter.prototype.appendInt64 = function(value) {
|
|
44
|
-
this.ensure(this.index + 8);
|
|
45
|
-
this.view.setBigInt64(this.index, BigInt(value), true);
|
|
46
|
-
this.offset += 8;
|
|
47
|
-
this.index += 8;
|
|
48
|
-
};
|
|
49
|
-
ByteWriter.prototype.appendFloat32 = function(value) {
|
|
50
|
-
this.ensure(this.index + 8);
|
|
51
|
-
this.view.setFloat32(this.index, value, true);
|
|
52
|
-
this.offset += 4;
|
|
53
|
-
this.index += 4;
|
|
54
|
-
};
|
|
55
|
-
ByteWriter.prototype.appendFloat64 = function(value) {
|
|
56
|
-
this.ensure(this.index + 8);
|
|
57
|
-
this.view.setFloat64(this.index, value, true);
|
|
58
|
-
this.offset += 8;
|
|
59
|
-
this.index += 8;
|
|
60
|
-
};
|
|
61
|
-
ByteWriter.prototype.appendBuffer = function(value) {
|
|
62
|
-
this.appendBytes(new Uint8Array(value));
|
|
63
|
-
};
|
|
64
|
-
ByteWriter.prototype.appendBytes = function(value) {
|
|
65
|
-
this.ensure(this.index + value.length);
|
|
66
|
-
new Uint8Array(this.buffer, this.index, value.length).set(value);
|
|
67
|
-
this.offset += value.length;
|
|
68
|
-
this.index += value.length;
|
|
69
|
-
};
|
|
70
|
-
ByteWriter.prototype.appendVarInt = function(value) {
|
|
71
|
-
while (true) if ((value & -128) === 0) {
|
|
72
|
-
this.appendUint8(value);
|
|
73
|
-
return;
|
|
74
|
-
} else {
|
|
75
|
-
this.appendUint8(value & 127 | 128);
|
|
76
|
-
value >>>= 7;
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
ByteWriter.prototype.appendVarBigInt = function(value) {
|
|
80
|
-
while (true) if ((value & -128n) === 0n) {
|
|
81
|
-
this.appendUint8(Number(value));
|
|
82
|
-
return;
|
|
83
|
-
} else {
|
|
84
|
-
this.appendUint8(Number(value & 127n | 128n));
|
|
85
|
-
value >>= 7n;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
ByteWriter.prototype.appendZigZag = function(value) {
|
|
89
|
-
if (typeof value === "number") this.appendVarInt(value << 1 ^ value >> 31);
|
|
90
|
-
else this.appendVarBigInt(value << 1n ^ value >> 63n);
|
|
91
|
-
};
|
|
92
|
-
const STOP = 0;
|
|
93
|
-
const TRUE = 1;
|
|
94
|
-
const FALSE = 2;
|
|
95
|
-
const BYTE = 3;
|
|
96
|
-
const I32 = 5;
|
|
97
|
-
const I64 = 6;
|
|
98
|
-
const DOUBLE = 7;
|
|
99
|
-
const BINARY = 8;
|
|
100
|
-
const LIST = 9;
|
|
101
|
-
const STRUCT = 12;
|
|
102
|
-
function serializeTCompactProtocol(writer, data) {
|
|
103
|
-
writeElement(writer, STRUCT, data);
|
|
104
|
-
}
|
|
105
|
-
function writeElement(writer, type, value) {
|
|
106
|
-
if (type === TRUE) return;
|
|
107
|
-
if (type === FALSE) return;
|
|
108
|
-
if (type === BYTE && typeof value === "number") writer.appendUint8(value);
|
|
109
|
-
else if (type === I32 && typeof value === "number") writer.appendZigZag(value);
|
|
110
|
-
else if (type === I64 && typeof value === "bigint") writer.appendZigZag(value);
|
|
111
|
-
else if (type === DOUBLE && typeof value === "number") writer.appendFloat64(value);
|
|
112
|
-
else if (type === BINARY && typeof value === "string") {
|
|
113
|
-
const bytes = new TextEncoder().encode(value);
|
|
114
|
-
writer.appendVarInt(bytes.length);
|
|
115
|
-
writer.appendBytes(bytes);
|
|
116
|
-
} else if (type === BINARY && value instanceof Uint8Array) {
|
|
117
|
-
writer.appendVarInt(value.byteLength);
|
|
118
|
-
writer.appendBytes(value);
|
|
119
|
-
} else if (type === LIST && Array.isArray(value)) {
|
|
120
|
-
const elemType = getCompactTypeForList(value);
|
|
121
|
-
if (value.length > 14) {
|
|
122
|
-
writer.appendUint8(240 | elemType);
|
|
123
|
-
writer.appendVarInt(value.length);
|
|
124
|
-
} else writer.appendUint8(value.length << 4 | elemType);
|
|
125
|
-
if (elemType === FALSE) for (const v of value) writer.appendUint8(v ? 1 : 0);
|
|
126
|
-
else for (const v of value) writeElement(writer, elemType, v);
|
|
127
|
-
} else if (type === STRUCT && typeof value === "object") {
|
|
128
|
-
let lastFid = 0;
|
|
129
|
-
for (const [k, v] of Object.entries(value)) {
|
|
130
|
-
if (v === void 0) continue;
|
|
131
|
-
const fid = parseInt(k.replace(/^field_/, ""), 10);
|
|
132
|
-
if (Number.isNaN(fid)) throw new Error(`thrift invalid field name: ${k}. Expected "field_###"`);
|
|
133
|
-
const t = getCompactTypeForValue(v);
|
|
134
|
-
const delta = fid - lastFid;
|
|
135
|
-
if (delta <= 0) throw new Error(`thrift non-monotonic field id: fid=${fid}, lastFid=${lastFid}`);
|
|
136
|
-
if (delta > 15) {
|
|
137
|
-
writer.appendUint8(t);
|
|
138
|
-
writer.appendZigZag(fid);
|
|
139
|
-
} else writer.appendUint8(delta << 4 | t);
|
|
140
|
-
writeElement(writer, t, v);
|
|
141
|
-
lastFid = fid;
|
|
142
|
-
}
|
|
143
|
-
writer.appendUint8(STOP);
|
|
144
|
-
} else throw new Error(`thrift invalid type ${type} for value ${value}`);
|
|
145
|
-
}
|
|
146
|
-
function getCompactTypeForValue(value) {
|
|
147
|
-
if (value === true) return TRUE;
|
|
148
|
-
if (value === false) return FALSE;
|
|
149
|
-
if (Number.isInteger(value)) return I32;
|
|
150
|
-
if (typeof value === "number") return DOUBLE;
|
|
151
|
-
if (typeof value === "bigint") return I64;
|
|
152
|
-
if (typeof value === "string") return BINARY;
|
|
153
|
-
if (value instanceof Uint8Array) return BINARY;
|
|
154
|
-
if (Array.isArray(value)) return LIST;
|
|
155
|
-
if (value && typeof value === "object") return STRUCT;
|
|
156
|
-
throw new Error(`Cannot determine thrift compact type for: ${value}`);
|
|
157
|
-
}
|
|
158
|
-
function getCompactTypeForList(value) {
|
|
159
|
-
let elemType = 0;
|
|
160
|
-
for (const v of value) {
|
|
161
|
-
let t = getCompactTypeForValue(v);
|
|
162
|
-
if (t === TRUE) t = FALSE;
|
|
163
|
-
if (!elemType) elemType = t;
|
|
164
|
-
if (elemType === DOUBLE && t === I32) t = DOUBLE;
|
|
165
|
-
if (elemType === I32 && t === DOUBLE) elemType = DOUBLE;
|
|
166
|
-
if (t !== elemType) throw new Error(`thrift invalid type for list element: ${v} (expected type ${elemType})`);
|
|
167
|
-
}
|
|
168
|
-
return elemType ?? BYTE;
|
|
169
|
-
}
|
|
170
|
-
const SALT = new Uint32Array([
|
|
171
|
-
1203114875,
|
|
172
|
-
1150766481,
|
|
173
|
-
2284105051,
|
|
174
|
-
2729912477,
|
|
175
|
-
1884591559,
|
|
176
|
-
770785867,
|
|
177
|
-
2667333959,
|
|
178
|
-
1550580529
|
|
179
|
-
]);
|
|
180
|
-
const BYTES_PER_BLOCK = 32;
|
|
181
|
-
const MIN_BYTES = 32;
|
|
182
|
-
const MAX_BYTES = 128 * 1024 * 1024;
|
|
183
|
-
function blockIndex(hash, numBlocks) {
|
|
184
|
-
return Number((hash >> 32n) * BigInt(numBlocks) >> 32n);
|
|
185
|
-
}
|
|
186
|
-
function blockMask(hash) {
|
|
187
|
-
const m = /* @__PURE__ */ new Uint32Array(8);
|
|
188
|
-
const low = Number(hash & 4294967295n) | 0;
|
|
189
|
-
for (let i = 0; i < 8; i++) m[i] = 1 << (Math.imul(low, SALT[i]) >>> 27);
|
|
190
|
-
return m;
|
|
191
|
-
}
|
|
192
|
-
function sbbfInsert(blocks, hash) {
|
|
193
|
-
const offset = blockIndex(hash, blocks.length >> 3) << 3;
|
|
194
|
-
const m = blockMask(hash);
|
|
195
|
-
for (let i = 0; i < 8; i++) blocks[offset + i] |= m[i];
|
|
196
|
-
}
|
|
197
|
-
function nextPowerOfTwo(n) {
|
|
198
|
-
let p = 1;
|
|
199
|
-
while (p < n) p <<= 1;
|
|
200
|
-
return p;
|
|
201
|
-
}
|
|
202
|
-
function optimalNumBytes(ndv, fpp) {
|
|
203
|
-
if (!(fpp > 0 && fpp < 1)) throw new Error(`bloom filter fpp must be in (0, 1), got ${fpp}`);
|
|
204
|
-
if (!(ndv >= 0)) throw new Error(`bloom filter ndv must be >= 0, got ${ndv}`);
|
|
205
|
-
const m = -8 * ndv / Math.log(1 - fpp ** (1 / 8));
|
|
206
|
-
let numBits = Math.ceil(m);
|
|
207
|
-
if (!isFinite(numBits) || numBits > MAX_BYTES << 3) numBits = MAX_BYTES << 3;
|
|
208
|
-
const blockBits = BYTES_PER_BLOCK << 3;
|
|
209
|
-
numBits = Math.ceil(numBits / blockBits) * blockBits;
|
|
210
|
-
let numBytes = numBits >> 3;
|
|
211
|
-
if (numBytes < MIN_BYTES) numBytes = MIN_BYTES;
|
|
212
|
-
if (numBytes < 1024) numBytes = nextPowerOfTwo(numBytes);
|
|
213
|
-
return numBytes;
|
|
214
|
-
}
|
|
215
|
-
var BloomBuilder = class {
|
|
216
|
-
constructor(element, { fpp = .01, maxBytes = 1024 * 1024 } = {}) {
|
|
217
|
-
this.element = element;
|
|
218
|
-
this.fpp = fpp;
|
|
219
|
-
this.maxBytes = maxBytes;
|
|
220
|
-
this.hashes = /* @__PURE__ */ new Set();
|
|
221
|
-
this.skipped = 0;
|
|
222
|
-
}
|
|
223
|
-
insert(value) {
|
|
224
|
-
if (value === null || value === void 0) return;
|
|
225
|
-
const h = hashParquetValue(value, this.element);
|
|
226
|
-
if (h === void 0) {
|
|
227
|
-
this.skipped++;
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
this.hashes.add(h);
|
|
231
|
-
}
|
|
232
|
-
finalize() {
|
|
233
|
-
if (this.skipped > 0 || this.hashes.size === 0) return void 0;
|
|
234
|
-
const numBytes = optimalNumBytes(this.hashes.size, this.fpp);
|
|
235
|
-
if (numBytes > this.maxBytes) return void 0;
|
|
236
|
-
const blocks = new Uint32Array(numBytes >> 2);
|
|
237
|
-
for (const h of this.hashes) sbbfInsert(blocks, h);
|
|
238
|
-
return blocks;
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
function writeBloomFilter(writer, blocks) {
|
|
242
|
-
if (blocks.length % 8 !== 0) throw new Error(`bloom filter block count must be a multiple of 8 uint32 words, got ${blocks.length}`);
|
|
243
|
-
serializeTCompactProtocol(writer, {
|
|
244
|
-
field_1: blocks.byteLength,
|
|
245
|
-
field_2: { field_1: {} },
|
|
246
|
-
field_3: { field_1: {} },
|
|
247
|
-
field_4: { field_1: {} }
|
|
248
|
-
});
|
|
249
|
-
for (let i = 0; i < blocks.length; i++) writer.appendUint32(blocks[i]);
|
|
250
|
-
}
|
|
251
|
-
function writeBlooms(writer, pageIndexes) {
|
|
252
|
-
for (const { chunk, bloomFilter } of pageIndexes) {
|
|
253
|
-
if (!bloomFilter || !chunk.meta_data) continue;
|
|
254
|
-
const offset = writer.offset;
|
|
255
|
-
writeBloomFilter(writer, bloomFilter);
|
|
256
|
-
chunk.meta_data.bloom_filter_offset = BigInt(offset);
|
|
257
|
-
chunk.meta_data.bloom_filter_length = writer.offset - offset;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
const BLOCK_SIZE$1 = 128;
|
|
261
|
-
const MINIBLOCKS_PER_BLOCK = 4;
|
|
262
|
-
const VALUES_PER_MINIBLOCK = BLOCK_SIZE$1 / MINIBLOCKS_PER_BLOCK;
|
|
263
|
-
function deltaBinaryPack(writer, values) {
|
|
264
|
-
const count = values.length;
|
|
265
|
-
if (count === 0) {
|
|
266
|
-
writer.appendVarInt(BLOCK_SIZE$1);
|
|
267
|
-
writer.appendVarInt(MINIBLOCKS_PER_BLOCK);
|
|
268
|
-
writer.appendVarInt(0);
|
|
269
|
-
writer.appendVarInt(0);
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
if (typeof values[0] !== "number" && typeof values[0] !== "bigint") throw new Error("deltaBinaryPack only supports number or bigint arrays");
|
|
273
|
-
writer.appendVarInt(BLOCK_SIZE$1);
|
|
274
|
-
writer.appendVarInt(MINIBLOCKS_PER_BLOCK);
|
|
275
|
-
writer.appendVarInt(count);
|
|
276
|
-
writer.appendZigZag(values[0]);
|
|
277
|
-
let index = 1;
|
|
278
|
-
while (index < count) {
|
|
279
|
-
const blockEnd = Math.min(index + BLOCK_SIZE$1, count);
|
|
280
|
-
const blockSize = blockEnd - index;
|
|
281
|
-
const blockDeltas = new BigInt64Array(blockSize);
|
|
282
|
-
let minDelta = BigInt(values[index]) - BigInt(values[index - 1]);
|
|
283
|
-
blockDeltas[0] = minDelta;
|
|
284
|
-
for (let i = 1; i < blockSize; i++) {
|
|
285
|
-
const delta = BigInt(values[index + i]) - BigInt(values[index + i - 1]);
|
|
286
|
-
blockDeltas[i] = delta;
|
|
287
|
-
if (delta < minDelta) minDelta = delta;
|
|
288
|
-
}
|
|
289
|
-
writer.appendZigZag(minDelta);
|
|
290
|
-
const bitWidths = new Uint8Array(MINIBLOCKS_PER_BLOCK);
|
|
291
|
-
for (let mb = 0; mb < MINIBLOCKS_PER_BLOCK; mb++) {
|
|
292
|
-
const mbStart = mb * VALUES_PER_MINIBLOCK;
|
|
293
|
-
const mbEnd = Math.min(mbStart + VALUES_PER_MINIBLOCK, blockSize);
|
|
294
|
-
let maxAdjusted = 0n;
|
|
295
|
-
for (let i = mbStart; i < mbEnd; i++) {
|
|
296
|
-
const adjusted = blockDeltas[i] - minDelta;
|
|
297
|
-
if (adjusted > maxAdjusted) maxAdjusted = adjusted;
|
|
298
|
-
}
|
|
299
|
-
bitWidths[mb] = bitWidth(maxAdjusted);
|
|
300
|
-
}
|
|
301
|
-
writer.appendBytes(bitWidths);
|
|
302
|
-
for (let mb = 0; mb < MINIBLOCKS_PER_BLOCK; mb++) {
|
|
303
|
-
const bitWidth = bitWidths[mb];
|
|
304
|
-
if (bitWidth === 0) continue;
|
|
305
|
-
const mbStart = mb * VALUES_PER_MINIBLOCK;
|
|
306
|
-
const mbEnd = Math.min(mbStart + VALUES_PER_MINIBLOCK, blockSize);
|
|
307
|
-
let buffer = 0n;
|
|
308
|
-
let bitsUsed = 0;
|
|
309
|
-
for (let i = 0; i < VALUES_PER_MINIBLOCK; i++) {
|
|
310
|
-
const adjusted = mbStart + i < mbEnd ? blockDeltas[mbStart + i] - minDelta : 0n;
|
|
311
|
-
buffer |= adjusted << BigInt(bitsUsed);
|
|
312
|
-
bitsUsed += bitWidth;
|
|
313
|
-
while (bitsUsed >= 8) {
|
|
314
|
-
writer.appendUint8(Number(buffer & 255n));
|
|
315
|
-
buffer >>= 8n;
|
|
316
|
-
bitsUsed -= 8;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
index = blockEnd;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
function deltaLengthByteArray(writer, values) {
|
|
324
|
-
const lengths = new Int32Array(values.length);
|
|
325
|
-
for (let i = 0; i < values.length; i++) {
|
|
326
|
-
const value = values[i];
|
|
327
|
-
if (!(value instanceof Uint8Array)) throw new Error("deltaLengthByteArray expects Uint8Array values");
|
|
328
|
-
lengths[i] = value.length;
|
|
329
|
-
}
|
|
330
|
-
deltaBinaryPack(writer, lengths);
|
|
331
|
-
for (const value of values) writer.appendBytes(value);
|
|
332
|
-
}
|
|
333
|
-
function deltaByteArray(writer, values) {
|
|
334
|
-
if (values.length === 0) {
|
|
335
|
-
deltaBinaryPack(writer, []);
|
|
336
|
-
deltaBinaryPack(writer, []);
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
const prefixLengths = new Int32Array(values.length);
|
|
340
|
-
const suffixLengths = new Int32Array(values.length);
|
|
341
|
-
const suffixes = new Array(values.length);
|
|
342
|
-
if (!(values[0] instanceof Uint8Array)) throw new Error("deltaByteArray expects Uint8Array values");
|
|
343
|
-
prefixLengths[0] = 0;
|
|
344
|
-
suffixLengths[0] = values[0].length;
|
|
345
|
-
suffixes[0] = values[0];
|
|
346
|
-
for (let i = 1; i < values.length; i++) {
|
|
347
|
-
const prev = values[i - 1];
|
|
348
|
-
const curr = values[i];
|
|
349
|
-
if (!(curr instanceof Uint8Array)) throw new Error("deltaByteArray expects Uint8Array values");
|
|
350
|
-
let prefixLen = 0;
|
|
351
|
-
const maxPrefix = Math.min(prev.length, curr.length);
|
|
352
|
-
while (prefixLen < maxPrefix && prev[prefixLen] === curr[prefixLen]) prefixLen++;
|
|
353
|
-
prefixLengths[i] = prefixLen;
|
|
354
|
-
suffixLengths[i] = curr.length - prefixLen;
|
|
355
|
-
suffixes[i] = curr.subarray(prefixLen);
|
|
356
|
-
}
|
|
357
|
-
deltaBinaryPack(writer, prefixLengths);
|
|
358
|
-
deltaBinaryPack(writer, suffixLengths);
|
|
359
|
-
for (const suffix of suffixes) writer.appendBytes(suffix);
|
|
360
|
-
}
|
|
361
|
-
function bitWidth(value) {
|
|
362
|
-
if (value === 0n) return 0;
|
|
363
|
-
let bits = 0;
|
|
364
|
-
while (value > 0n) {
|
|
365
|
-
bits++;
|
|
366
|
-
value >>= 1n;
|
|
367
|
-
}
|
|
368
|
-
return bits;
|
|
369
|
-
}
|
|
370
|
-
function writeRleBitPackedHybrid(writer, values, bitWidth) {
|
|
371
|
-
const offsetStart = writer.offset;
|
|
372
|
-
let pendingBitPackedGroups = 0;
|
|
373
|
-
let bitPackedStart = 0;
|
|
374
|
-
let i = 0;
|
|
375
|
-
while (i < values.length) {
|
|
376
|
-
let rleCount = 1;
|
|
377
|
-
const firstVal = values[i];
|
|
378
|
-
while (i + rleCount < values.length && values[i + rleCount] === firstVal) rleCount++;
|
|
379
|
-
if (rleCount >= 8) {
|
|
380
|
-
if (pendingBitPackedGroups) {
|
|
381
|
-
writeBitPackedGroups(writer, values, bitPackedStart, pendingBitPackedGroups, bitWidth);
|
|
382
|
-
pendingBitPackedGroups = 0;
|
|
383
|
-
}
|
|
384
|
-
writeRleRun(writer, firstVal, rleCount, bitWidth);
|
|
385
|
-
i += rleCount;
|
|
386
|
-
} else {
|
|
387
|
-
if (pendingBitPackedGroups === 0) bitPackedStart = i;
|
|
388
|
-
pendingBitPackedGroups++;
|
|
389
|
-
i += 8;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
if (pendingBitPackedGroups) writeBitPackedGroups(writer, values, bitPackedStart, pendingBitPackedGroups, bitWidth);
|
|
393
|
-
return writer.offset - offsetStart;
|
|
394
|
-
}
|
|
395
|
-
function writeRleRun(writer, value, count, bitWidth) {
|
|
396
|
-
writer.appendVarInt(count << 1);
|
|
397
|
-
const width = bitWidth + 7 >> 3;
|
|
398
|
-
for (let j = 0; j < width; j++) writer.appendUint8(value >> (j << 3) & 255);
|
|
399
|
-
}
|
|
400
|
-
function writeBitPackedGroups(writer, values, start, numGroups, bitWidth) {
|
|
401
|
-
writer.appendVarInt(numGroups << 1 | 1);
|
|
402
|
-
if (bitWidth === 0) return;
|
|
403
|
-
const mask = (1 << bitWidth) - 1;
|
|
404
|
-
let buffer = 0;
|
|
405
|
-
let bitsUsed = 0;
|
|
406
|
-
const totalValues = numGroups * 8;
|
|
407
|
-
for (let i = 0; i < totalValues; i++) {
|
|
408
|
-
const idx = start + i;
|
|
409
|
-
const v = idx < values.length ? values[idx] & mask : 0;
|
|
410
|
-
buffer |= v << bitsUsed;
|
|
411
|
-
bitsUsed += bitWidth;
|
|
412
|
-
while (bitsUsed >= 8) {
|
|
413
|
-
writer.appendUint8(buffer & 255);
|
|
414
|
-
buffer >>>= 8;
|
|
415
|
-
bitsUsed -= 8;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
if (bitsUsed > 0) writer.appendUint8(buffer & 255);
|
|
419
|
-
}
|
|
420
|
-
function writePlain(writer, values, type, fixedLength) {
|
|
421
|
-
if (type === "BOOLEAN") writePlainBoolean(writer, values);
|
|
422
|
-
else if (type === "INT32") writePlainInt32(writer, values);
|
|
423
|
-
else if (type === "INT64") writePlainInt64(writer, values);
|
|
424
|
-
else if (type === "FLOAT") writePlainFloat(writer, values);
|
|
425
|
-
else if (type === "DOUBLE") writePlainDouble(writer, values);
|
|
426
|
-
else if (type === "BYTE_ARRAY") writePlainByteArray(writer, values);
|
|
427
|
-
else if (type === "FIXED_LEN_BYTE_ARRAY") {
|
|
428
|
-
if (!fixedLength) throw new Error("parquet FIXED_LEN_BYTE_ARRAY expected type_length");
|
|
429
|
-
writePlainByteArrayFixed(writer, values, fixedLength);
|
|
430
|
-
} else throw new Error(`parquet unsupported type: ${type}`);
|
|
431
|
-
}
|
|
432
|
-
function writePlainBoolean(writer, values) {
|
|
433
|
-
let currentByte = 0;
|
|
434
|
-
for (let i = 0; i < values.length; i++) {
|
|
435
|
-
const value = values[i];
|
|
436
|
-
if (typeof value !== "boolean") throw new Error("parquet expected boolean value, got " + value);
|
|
437
|
-
const bitOffset = i % 8;
|
|
438
|
-
if (value) currentByte |= 1 << bitOffset;
|
|
439
|
-
if (bitOffset === 7) {
|
|
440
|
-
writer.appendUint8(currentByte);
|
|
441
|
-
currentByte = 0;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
if (values.length % 8) writer.appendUint8(currentByte);
|
|
445
|
-
}
|
|
446
|
-
function writePlainInt32(writer, values) {
|
|
447
|
-
for (const value of values) {
|
|
448
|
-
if (!Number.isSafeInteger(value)) throw new Error("parquet expected integer value, got " + value);
|
|
449
|
-
if (value < -2147483648 || value > 2147483647) throw new Error("parquet expected int32 value, got " + value);
|
|
450
|
-
writer.appendInt32(value);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
function writePlainInt64(writer, values) {
|
|
454
|
-
for (const value of values) {
|
|
455
|
-
if (typeof value !== "bigint") throw new Error("parquet expected bigint value, got " + value);
|
|
456
|
-
writer.appendInt64(value);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
function writePlainFloat(writer, values) {
|
|
460
|
-
for (const value of values) {
|
|
461
|
-
if (typeof value !== "number") throw new Error("parquet expected number value, got " + value);
|
|
462
|
-
writer.appendFloat32(value);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
function writePlainDouble(writer, values) {
|
|
466
|
-
for (const value of values) {
|
|
467
|
-
if (typeof value !== "number") throw new Error("parquet expected number value, got " + value);
|
|
468
|
-
writer.appendFloat64(value);
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
function writePlainByteArray(writer, values) {
|
|
472
|
-
for (const value of values) {
|
|
473
|
-
let bytes = value;
|
|
474
|
-
if (typeof bytes === "string") bytes = new TextEncoder().encode(value);
|
|
475
|
-
if (!(bytes instanceof Uint8Array)) throw new Error("parquet expected Uint8Array value, got " + typeof bytes);
|
|
476
|
-
writer.appendUint32(bytes.length);
|
|
477
|
-
writer.appendBytes(bytes);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
function writePlainByteArrayFixed(writer, values, fixedLength) {
|
|
481
|
-
for (const value of values) {
|
|
482
|
-
if (!(value instanceof Uint8Array)) throw new Error("parquet expected Uint8Array value, got " + typeof value);
|
|
483
|
-
if (value.length !== fixedLength) throw new Error(`parquet expected Uint8Array of length ${fixedLength}`);
|
|
484
|
-
writer.appendBytes(value);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
const encoder = new TextEncoder();
|
|
488
|
-
const INT64_MIN = -(2n ** 63n);
|
|
489
|
-
const INT64_MAX = 2n ** 63n - 1n;
|
|
490
|
-
const VARIANT_NULL = new Uint8Array([0]);
|
|
491
|
-
const RESERVED_SHREDDING_FIELDS = /* @__PURE__ */ new Set(["value", "typed_value"]);
|
|
492
|
-
const EMPTY_KEY_INDEX = /* @__PURE__ */ new Map();
|
|
493
|
-
const EMPTY_METADATA = writeVariantMetadata([]);
|
|
494
|
-
function encodeVariantColumn(values, shredding, column) {
|
|
495
|
-
if (column?.required) {
|
|
496
|
-
for (let i = 0; i < values.length; i++) if (values[i] === void 0) throw new Error(`required variant column ${column.name} has undefined value at index ${i}`);
|
|
497
|
-
}
|
|
498
|
-
const shreddingConfig = shredding && normalizeShreddingConfig(shredding);
|
|
499
|
-
if (shreddingConfig) {
|
|
500
|
-
const metadataCache = /* @__PURE__ */ new Map();
|
|
501
|
-
return values.map((value) => {
|
|
502
|
-
if (value === void 0) return null;
|
|
503
|
-
const keys = /* @__PURE__ */ new Set();
|
|
504
|
-
collectKeys(value, keys);
|
|
505
|
-
const { metadata, keyIndex } = getVariantRowMetadata(keys, metadataCache);
|
|
506
|
-
return {
|
|
507
|
-
metadata,
|
|
508
|
-
...encodeShredded(value, shreddingConfig, keyIndex, true)
|
|
509
|
-
};
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
const dictionary = buildVariantDictionary(values);
|
|
513
|
-
const metadata = writeVariantMetadata(dictionary);
|
|
514
|
-
const keyIndex = /* @__PURE__ */ new Map();
|
|
515
|
-
for (let i = 0; i < dictionary.length; i++) keyIndex.set(dictionary[i], i);
|
|
516
|
-
return values.map((value) => {
|
|
517
|
-
if (value === void 0) return null;
|
|
518
|
-
return {
|
|
519
|
-
metadata,
|
|
520
|
-
value: writeVariantValue(value, keyIndex)
|
|
521
|
-
};
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
function encodeShredded(value, shredType, keyIndex, allowPartialObjects) {
|
|
525
|
-
if (value === null || value === void 0) return {
|
|
526
|
-
value: VARIANT_NULL,
|
|
527
|
-
typed_value: null
|
|
528
|
-
};
|
|
529
|
-
if (Array.isArray(shredType)) {
|
|
530
|
-
if (!Array.isArray(value)) return {
|
|
531
|
-
value: writeVariantValue(value, keyIndex),
|
|
532
|
-
typed_value: null
|
|
533
|
-
};
|
|
534
|
-
const elemShred = shredType[0];
|
|
535
|
-
return {
|
|
536
|
-
value: null,
|
|
537
|
-
typed_value: value.map((el) => encodeShredded(el, elemShred, keyIndex, false))
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
if (typeof shredType === "object") {
|
|
541
|
-
if (typeof value !== "object" || Array.isArray(value) || value instanceof Date || value instanceof Uint8Array) return {
|
|
542
|
-
value: writeVariantValue(value, keyIndex),
|
|
543
|
-
typed_value: null
|
|
544
|
-
};
|
|
545
|
-
const remaining = {};
|
|
546
|
-
let hasRemaining = false;
|
|
547
|
-
for (const k of Object.keys(value)) {
|
|
548
|
-
if (k in shredType || value[k] === void 0) continue;
|
|
549
|
-
remaining[k] = value[k];
|
|
550
|
-
hasRemaining = true;
|
|
551
|
-
}
|
|
552
|
-
if (hasRemaining && !allowPartialObjects) return {
|
|
553
|
-
value: writeVariantValue(value, keyIndex),
|
|
554
|
-
typed_value: null
|
|
555
|
-
};
|
|
556
|
-
const fieldNames = Object.keys(shredType);
|
|
557
|
-
if (fieldNames.some((fieldName) => (!Object.prototype.hasOwnProperty.call(value, fieldName) || value[fieldName] === void 0) && keyIndex.has(fieldName))) return {
|
|
558
|
-
value: writeVariantValue(value, keyIndex),
|
|
559
|
-
typed_value: null
|
|
560
|
-
};
|
|
561
|
-
const typedValue = {};
|
|
562
|
-
for (const fieldName of fieldNames) {
|
|
563
|
-
if (!Object.prototype.hasOwnProperty.call(value, fieldName) || value[fieldName] === void 0) continue;
|
|
564
|
-
typedValue[fieldName] = encodeShredded(value[fieldName], shredType[fieldName], keyIndex, false);
|
|
565
|
-
}
|
|
566
|
-
return {
|
|
567
|
-
value: hasRemaining ? writeVariantValue(remaining, keyIndex) : null,
|
|
568
|
-
typed_value: typedValue
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
if (matchesType(value, shredType)) return {
|
|
572
|
-
value: null,
|
|
573
|
-
typed_value: value
|
|
574
|
-
};
|
|
575
|
-
return {
|
|
576
|
-
value: writeVariantValue(value, keyIndex),
|
|
577
|
-
typed_value: null
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
function getVariantRowMetadata(keys, metadataCache) {
|
|
581
|
-
if (keys.size === 0) return {
|
|
582
|
-
metadata: EMPTY_METADATA,
|
|
583
|
-
keyIndex: EMPTY_KEY_INDEX
|
|
584
|
-
};
|
|
585
|
-
const dictionary = [...keys].sort();
|
|
586
|
-
const cacheKey = dictionary.join("\0");
|
|
587
|
-
const cached = metadataCache.get(cacheKey);
|
|
588
|
-
if (cached) return cached;
|
|
589
|
-
const metadata = writeVariantMetadata(dictionary);
|
|
590
|
-
const keyIndex = /* @__PURE__ */ new Map();
|
|
591
|
-
for (let i = 0; i < dictionary.length; i++) keyIndex.set(dictionary[i], i);
|
|
592
|
-
const rowMetadata = {
|
|
593
|
-
metadata,
|
|
594
|
-
keyIndex
|
|
595
|
-
};
|
|
596
|
-
metadataCache.set(cacheKey, rowMetadata);
|
|
597
|
-
return rowMetadata;
|
|
598
|
-
}
|
|
599
|
-
function matchesType(value, type) {
|
|
600
|
-
if (value === null || value === void 0) return false;
|
|
601
|
-
switch (type) {
|
|
602
|
-
case "BOOLEAN": return typeof value === "boolean";
|
|
603
|
-
case "INT32": return typeof value === "number" && Number.isInteger(value) && value >= -2147483648 && value <= 2147483647;
|
|
604
|
-
case "INT64": return typeof value === "bigint" && value >= INT64_MIN && value <= INT64_MAX;
|
|
605
|
-
case "FLOAT": return typeof value === "number";
|
|
606
|
-
case "DOUBLE": return typeof value === "number";
|
|
607
|
-
case "STRING": return typeof value === "string";
|
|
608
|
-
case "TIMESTAMP": return value instanceof Date;
|
|
609
|
-
default: return false;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
function normalizeShreddingConfig(shredding) {
|
|
613
|
-
if (Array.isArray(shredding)) {
|
|
614
|
-
const elem = shredding.length ? normalizeShreddingConfig(shredding[0]) : void 0;
|
|
615
|
-
return elem === void 0 ? void 0 : [elem];
|
|
616
|
-
}
|
|
617
|
-
if (typeof shredding === "object") {
|
|
618
|
-
const normalized = {};
|
|
619
|
-
for (const [key, type] of Object.entries(shredding)) {
|
|
620
|
-
if (RESERVED_SHREDDING_FIELDS.has(key)) continue;
|
|
621
|
-
const norm = normalizeShreddingConfig(type);
|
|
622
|
-
if (norm !== void 0) normalized[key] = norm;
|
|
623
|
-
}
|
|
624
|
-
return Object.keys(normalized).length > 0 ? normalized : void 0;
|
|
625
|
-
}
|
|
626
|
-
return shredding;
|
|
627
|
-
}
|
|
628
|
-
function buildVariantDictionary(values) {
|
|
629
|
-
const keys = /* @__PURE__ */ new Set();
|
|
630
|
-
collectKeys(values, keys);
|
|
631
|
-
return [...keys].sort();
|
|
632
|
-
}
|
|
633
|
-
function collectKeys(value, keys) {
|
|
634
|
-
if (value === null || value === void 0) return;
|
|
635
|
-
if (Array.isArray(value)) {
|
|
636
|
-
for (const item of value) collectKeys(item, keys);
|
|
637
|
-
return;
|
|
638
|
-
}
|
|
639
|
-
if (value instanceof Date || value instanceof Uint8Array) return;
|
|
640
|
-
if (typeof value === "object") for (const key of Object.keys(value)) {
|
|
641
|
-
keys.add(key);
|
|
642
|
-
collectKeys(value[key], keys);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
function writeVariantMetadata(dictionary) {
|
|
646
|
-
const n = dictionary.length;
|
|
647
|
-
const encoded = new Array(n);
|
|
648
|
-
let totalStringBytes = 0;
|
|
649
|
-
for (let i = 0; i < n; i++) {
|
|
650
|
-
const e = encoder.encode(dictionary[i]);
|
|
651
|
-
encoded[i] = e;
|
|
652
|
-
totalStringBytes += e.length;
|
|
653
|
-
}
|
|
654
|
-
const offsetSize = byteWidth(totalStringBytes);
|
|
655
|
-
const header = 17 | offsetSize - 1 << 6;
|
|
656
|
-
const totalSize = 1 + offsetSize + (n + 1) * offsetSize + totalStringBytes;
|
|
657
|
-
const bytes = new Uint8Array(totalSize);
|
|
658
|
-
let offset = 0;
|
|
659
|
-
bytes[offset++] = header;
|
|
660
|
-
for (let j = 0; j < offsetSize; j++) bytes[offset++] = n >> j * 8 & 255;
|
|
661
|
-
let strOffset = 0;
|
|
662
|
-
for (let i = 0; i < n; i++) {
|
|
663
|
-
for (let j = 0; j < offsetSize; j++) bytes[offset++] = strOffset >> j * 8 & 255;
|
|
664
|
-
strOffset += encoded[i].length;
|
|
665
|
-
}
|
|
666
|
-
for (let j = 0; j < offsetSize; j++) bytes[offset++] = strOffset >> j * 8 & 255;
|
|
667
|
-
for (let i = 0; i < n; i++) {
|
|
668
|
-
bytes.set(encoded[i], offset);
|
|
669
|
-
offset += encoded[i].length;
|
|
670
|
-
}
|
|
671
|
-
return bytes;
|
|
672
|
-
}
|
|
673
|
-
function writeVariantValue(value, keyIndex) {
|
|
674
|
-
const writer = new ByteWriter(8);
|
|
675
|
-
writeValue(value, writer, keyIndex);
|
|
676
|
-
return writer.getBytes();
|
|
677
|
-
}
|
|
678
|
-
function writeValue(val, writer, keyIndex) {
|
|
679
|
-
if (val === null || val === void 0) {
|
|
680
|
-
writer.appendUint8(0);
|
|
681
|
-
return;
|
|
682
|
-
}
|
|
683
|
-
if (val === true) {
|
|
684
|
-
writer.appendUint8(4);
|
|
685
|
-
return;
|
|
686
|
-
}
|
|
687
|
-
if (val === false) {
|
|
688
|
-
writer.appendUint8(8);
|
|
689
|
-
return;
|
|
690
|
-
}
|
|
691
|
-
if (typeof val === "bigint") {
|
|
692
|
-
if (val < INT64_MIN || val > INT64_MAX) throw new RangeError(`variant bigint out of int64 range: ${val}`);
|
|
693
|
-
writer.appendUint8(24);
|
|
694
|
-
writer.appendInt64(val);
|
|
695
|
-
return;
|
|
696
|
-
}
|
|
697
|
-
if (typeof val === "number") {
|
|
698
|
-
if (Number.isInteger(val)) {
|
|
699
|
-
if (val >= -128 && val <= 127) {
|
|
700
|
-
writer.appendUint8(12);
|
|
701
|
-
writer.appendUint8(val & 255);
|
|
702
|
-
return;
|
|
703
|
-
}
|
|
704
|
-
if (val >= -32768 && val <= 32767) {
|
|
705
|
-
writer.appendUint8(16);
|
|
706
|
-
appendUnsignedLE(writer, val, 2);
|
|
707
|
-
return;
|
|
708
|
-
}
|
|
709
|
-
if (val >= -2147483648 && val <= 2147483647) {
|
|
710
|
-
writer.appendUint8(20);
|
|
711
|
-
writer.appendInt32(val);
|
|
712
|
-
return;
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
writer.appendUint8(28);
|
|
716
|
-
writer.appendFloat64(val);
|
|
717
|
-
return;
|
|
718
|
-
}
|
|
719
|
-
if (typeof val === "string") {
|
|
720
|
-
const strBytes = encoder.encode(val);
|
|
721
|
-
if (strBytes.length <= 63) {
|
|
722
|
-
writer.appendUint8(strBytes.length << 2 | 1);
|
|
723
|
-
writer.appendBytes(strBytes);
|
|
724
|
-
} else {
|
|
725
|
-
writer.appendUint8(64);
|
|
726
|
-
writer.appendUint32(strBytes.length);
|
|
727
|
-
writer.appendBytes(strBytes);
|
|
728
|
-
}
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
if (val instanceof Date) {
|
|
732
|
-
writer.appendUint8(52);
|
|
733
|
-
writer.appendInt64(BigInt(val.getTime()) * 1000n);
|
|
734
|
-
return;
|
|
735
|
-
}
|
|
736
|
-
if (val instanceof Uint8Array) {
|
|
737
|
-
writer.appendUint8(60);
|
|
738
|
-
writer.appendUint32(val.length);
|
|
739
|
-
writer.appendBytes(val);
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
if (Array.isArray(val)) {
|
|
743
|
-
writeVariantArray(val, writer, keyIndex);
|
|
744
|
-
return;
|
|
745
|
-
}
|
|
746
|
-
if (typeof val === "object") {
|
|
747
|
-
writeVariantObject(val, writer, keyIndex);
|
|
748
|
-
return;
|
|
749
|
-
}
|
|
750
|
-
throw new Error(`variant cannot encode value: ${val}`);
|
|
751
|
-
}
|
|
752
|
-
function writeVariantObject(obj, writer, keyIndex) {
|
|
753
|
-
const entries = Object.keys(obj).filter((key) => obj[key] !== void 0).map((key) => {
|
|
754
|
-
const id = keyIndex.get(key);
|
|
755
|
-
if (id === void 0) throw new Error(`variant key not in dictionary: ${key}`);
|
|
756
|
-
return {
|
|
757
|
-
id,
|
|
758
|
-
key
|
|
759
|
-
};
|
|
760
|
-
});
|
|
761
|
-
entries.sort((a, b) => a.id - b.id);
|
|
762
|
-
const numElements = entries.length;
|
|
763
|
-
const idWidth = byteWidth(numElements > 0 ? entries[numElements - 1].id : 0);
|
|
764
|
-
const scratch = new ByteWriter(8);
|
|
765
|
-
const offsets = new Array(numElements + 1);
|
|
766
|
-
offsets[0] = 0;
|
|
767
|
-
for (let i = 0; i < numElements; i++) {
|
|
768
|
-
writeValue(obj[entries[i].key], scratch, keyIndex);
|
|
769
|
-
offsets[i + 1] = scratch.index;
|
|
770
|
-
}
|
|
771
|
-
const offsetWidth = byteWidth(offsets[numElements]);
|
|
772
|
-
const isLarge = numElements > 255 ? 1 : 0;
|
|
773
|
-
writer.appendUint8((offsetWidth - 1 | idWidth - 1 << 2 | isLarge << 4) << 2 | 2);
|
|
774
|
-
if (isLarge) writer.appendUint32(numElements);
|
|
775
|
-
else writer.appendUint8(numElements);
|
|
776
|
-
for (const { id } of entries) appendUnsignedLE(writer, id, idWidth);
|
|
777
|
-
for (const off of offsets) appendUnsignedLE(writer, off, offsetWidth);
|
|
778
|
-
writer.appendBytes(scratch.getBytes());
|
|
779
|
-
}
|
|
780
|
-
function writeVariantArray(arr, writer, keyIndex) {
|
|
781
|
-
const numElements = arr.length;
|
|
782
|
-
const scratch = new ByteWriter(8);
|
|
783
|
-
const offsets = new Array(numElements + 1);
|
|
784
|
-
offsets[0] = 0;
|
|
785
|
-
for (let i = 0; i < numElements; i++) {
|
|
786
|
-
writeValue(arr[i], scratch, keyIndex);
|
|
787
|
-
offsets[i + 1] = scratch.index;
|
|
788
|
-
}
|
|
789
|
-
const offsetWidth = byteWidth(offsets[numElements]);
|
|
790
|
-
const isLarge = numElements > 255 ? 1 : 0;
|
|
791
|
-
writer.appendUint8((offsetWidth - 1 | isLarge << 2) << 2 | 3);
|
|
792
|
-
if (isLarge) writer.appendUint32(numElements);
|
|
793
|
-
else writer.appendUint8(numElements);
|
|
794
|
-
for (const off of offsets) appendUnsignedLE(writer, off, offsetWidth);
|
|
795
|
-
writer.appendBytes(scratch.getBytes());
|
|
796
|
-
}
|
|
797
|
-
function byteWidth(maxValue) {
|
|
798
|
-
if (maxValue <= 255) return 1;
|
|
799
|
-
if (maxValue <= 65535) return 2;
|
|
800
|
-
if (maxValue <= 16777215) return 3;
|
|
801
|
-
return 4;
|
|
802
|
-
}
|
|
803
|
-
function appendUnsignedLE(writer, value, width) {
|
|
804
|
-
for (let i = 0; i < width; i++) writer.appendUint8(value >> i * 8 & 255);
|
|
805
|
-
}
|
|
806
|
-
function schemaFromColumnData({ columnData, schemaOverrides }) {
|
|
807
|
-
const schema = [{
|
|
808
|
-
name: "root",
|
|
809
|
-
num_children: columnData.length
|
|
810
|
-
}];
|
|
811
|
-
for (const { name, data, type, nullable, shredding } of columnData) if (schemaOverrides?.[name]) {
|
|
812
|
-
const override = schemaOverrides[name];
|
|
813
|
-
if (type || nullable !== void 0) throw new Error(`cannot provide both type and schema override for column ${name}`);
|
|
814
|
-
if (override.name !== name) throw new Error(`schema override for column ${name} must have matching name, got ${override.name}`);
|
|
815
|
-
if (override.type === "FIXED_LEN_BYTE_ARRAY" && !override.type_length) throw new Error("schema override for FIXED_LEN_BYTE_ARRAY must include type_length");
|
|
816
|
-
if (override.num_children) throw new Error("schema override does not support nested types");
|
|
817
|
-
schema.push(override);
|
|
818
|
-
} else if (type === "VARIANT") {
|
|
819
|
-
const repetition_type = nullable === false ? "REQUIRED" : "OPTIONAL";
|
|
820
|
-
const shreddingConfig = shredding && shredding !== true ? normalizeShreddingConfig(shredding) : void 0;
|
|
821
|
-
if (shreddingConfig) schema.push({
|
|
822
|
-
name,
|
|
823
|
-
repetition_type,
|
|
824
|
-
num_children: 3,
|
|
825
|
-
logical_type: { type: "VARIANT" }
|
|
826
|
-
}, {
|
|
827
|
-
name: "metadata",
|
|
828
|
-
type: "BYTE_ARRAY",
|
|
829
|
-
repetition_type: "REQUIRED"
|
|
830
|
-
}, {
|
|
831
|
-
name: "value",
|
|
832
|
-
type: "BYTE_ARRAY",
|
|
833
|
-
repetition_type: "OPTIONAL"
|
|
834
|
-
}, ...buildVariantTypedValue(shreddingConfig));
|
|
835
|
-
else schema.push({
|
|
836
|
-
name,
|
|
837
|
-
repetition_type,
|
|
838
|
-
num_children: 2,
|
|
839
|
-
logical_type: { type: "VARIANT" }
|
|
840
|
-
}, {
|
|
841
|
-
name: "metadata",
|
|
842
|
-
type: "BYTE_ARRAY",
|
|
843
|
-
repetition_type: "REQUIRED"
|
|
844
|
-
}, {
|
|
845
|
-
name: "value",
|
|
846
|
-
type: "BYTE_ARRAY",
|
|
847
|
-
repetition_type: "OPTIONAL"
|
|
848
|
-
});
|
|
849
|
-
} else if (type) schema.push(basicTypeToSchemaElement(name, type, nullable));
|
|
850
|
-
else schema.push(autoSchemaElement(name, data.slice(0, 1e3)));
|
|
851
|
-
return schema;
|
|
852
|
-
}
|
|
853
|
-
function buildVariantTypedValue(shredType) {
|
|
854
|
-
if (Array.isArray(shredType)) return [
|
|
855
|
-
{
|
|
856
|
-
name: "typed_value",
|
|
857
|
-
repetition_type: "OPTIONAL",
|
|
858
|
-
converted_type: "LIST",
|
|
859
|
-
num_children: 1
|
|
860
|
-
},
|
|
861
|
-
{
|
|
862
|
-
name: "list",
|
|
863
|
-
repetition_type: "REPEATED",
|
|
864
|
-
num_children: 1
|
|
865
|
-
},
|
|
866
|
-
{
|
|
867
|
-
name: "element",
|
|
868
|
-
repetition_type: "REQUIRED",
|
|
869
|
-
num_children: 2
|
|
870
|
-
},
|
|
871
|
-
{
|
|
872
|
-
name: "value",
|
|
873
|
-
type: "BYTE_ARRAY",
|
|
874
|
-
repetition_type: "OPTIONAL"
|
|
875
|
-
},
|
|
876
|
-
...buildVariantTypedValue(shredType[0])
|
|
877
|
-
];
|
|
878
|
-
if (typeof shredType === "object") {
|
|
879
|
-
const fieldNames = Object.keys(shredType);
|
|
880
|
-
const elements = [{
|
|
881
|
-
name: "typed_value",
|
|
882
|
-
repetition_type: "OPTIONAL",
|
|
883
|
-
num_children: fieldNames.length
|
|
884
|
-
}];
|
|
885
|
-
for (const fieldName of fieldNames) elements.push({
|
|
886
|
-
name: fieldName,
|
|
887
|
-
repetition_type: "OPTIONAL",
|
|
888
|
-
num_children: 2
|
|
889
|
-
}, {
|
|
890
|
-
name: "value",
|
|
891
|
-
type: "BYTE_ARRAY",
|
|
892
|
-
repetition_type: "OPTIONAL"
|
|
893
|
-
}, ...buildVariantTypedValue(shredType[fieldName]));
|
|
894
|
-
return elements;
|
|
895
|
-
}
|
|
896
|
-
return [shreddedLeafElement(shredType)];
|
|
897
|
-
}
|
|
898
|
-
function shreddedLeafElement(type) {
|
|
899
|
-
switch (type) {
|
|
900
|
-
case "STRING": return {
|
|
901
|
-
name: "typed_value",
|
|
902
|
-
type: "BYTE_ARRAY",
|
|
903
|
-
converted_type: "UTF8",
|
|
904
|
-
repetition_type: "OPTIONAL"
|
|
905
|
-
};
|
|
906
|
-
case "INT32": return {
|
|
907
|
-
name: "typed_value",
|
|
908
|
-
type: "INT32",
|
|
909
|
-
repetition_type: "OPTIONAL"
|
|
910
|
-
};
|
|
911
|
-
case "INT64": return {
|
|
912
|
-
name: "typed_value",
|
|
913
|
-
type: "INT64",
|
|
914
|
-
repetition_type: "OPTIONAL"
|
|
915
|
-
};
|
|
916
|
-
case "DOUBLE": return {
|
|
917
|
-
name: "typed_value",
|
|
918
|
-
type: "DOUBLE",
|
|
919
|
-
repetition_type: "OPTIONAL"
|
|
920
|
-
};
|
|
921
|
-
case "FLOAT": return {
|
|
922
|
-
name: "typed_value",
|
|
923
|
-
type: "FLOAT",
|
|
924
|
-
repetition_type: "OPTIONAL"
|
|
925
|
-
};
|
|
926
|
-
case "BOOLEAN": return {
|
|
927
|
-
name: "typed_value",
|
|
928
|
-
type: "BOOLEAN",
|
|
929
|
-
repetition_type: "OPTIONAL"
|
|
930
|
-
};
|
|
931
|
-
case "TIMESTAMP": return {
|
|
932
|
-
name: "typed_value",
|
|
933
|
-
type: "INT64",
|
|
934
|
-
converted_type: "TIMESTAMP_MICROS",
|
|
935
|
-
repetition_type: "OPTIONAL"
|
|
936
|
-
};
|
|
937
|
-
default: throw new Error(`unsupported shredded field type: ${type}`);
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
function basicTypeToSchemaElement(name, type, nullable) {
|
|
941
|
-
const repetition_type = nullable === false ? "REQUIRED" : "OPTIONAL";
|
|
942
|
-
if (type === "STRING") return {
|
|
943
|
-
name,
|
|
944
|
-
type: "BYTE_ARRAY",
|
|
945
|
-
converted_type: "UTF8",
|
|
946
|
-
repetition_type
|
|
947
|
-
};
|
|
948
|
-
if (type === "JSON") return {
|
|
949
|
-
name,
|
|
950
|
-
type: "BYTE_ARRAY",
|
|
951
|
-
converted_type: "JSON",
|
|
952
|
-
repetition_type
|
|
953
|
-
};
|
|
954
|
-
if (type === "TIMESTAMP") return {
|
|
955
|
-
name,
|
|
956
|
-
type: "INT64",
|
|
957
|
-
converted_type: "TIMESTAMP_MILLIS",
|
|
958
|
-
repetition_type
|
|
959
|
-
};
|
|
960
|
-
if (type === "UUID") return {
|
|
961
|
-
name,
|
|
962
|
-
type: "FIXED_LEN_BYTE_ARRAY",
|
|
963
|
-
type_length: 16,
|
|
964
|
-
logical_type: { type: "UUID" },
|
|
965
|
-
repetition_type
|
|
966
|
-
};
|
|
967
|
-
if (type === "FLOAT16") return {
|
|
968
|
-
name,
|
|
969
|
-
type: "FIXED_LEN_BYTE_ARRAY",
|
|
970
|
-
type_length: 2,
|
|
971
|
-
logical_type: { type: "FLOAT16" },
|
|
972
|
-
repetition_type
|
|
973
|
-
};
|
|
974
|
-
if (type === "GEOMETRY") return {
|
|
975
|
-
name,
|
|
976
|
-
type: "BYTE_ARRAY",
|
|
977
|
-
logical_type: { type: "GEOMETRY" },
|
|
978
|
-
repetition_type
|
|
979
|
-
};
|
|
980
|
-
if (type === "GEOGRAPHY") return {
|
|
981
|
-
name,
|
|
982
|
-
type: "BYTE_ARRAY",
|
|
983
|
-
logical_type: { type: "GEOGRAPHY" },
|
|
984
|
-
repetition_type
|
|
985
|
-
};
|
|
986
|
-
return {
|
|
987
|
-
name,
|
|
988
|
-
type,
|
|
989
|
-
repetition_type
|
|
990
|
-
};
|
|
991
|
-
}
|
|
992
|
-
function autoSchemaElement(name, values) {
|
|
993
|
-
let type;
|
|
994
|
-
let repetition_type = "REQUIRED";
|
|
995
|
-
let converted_type;
|
|
996
|
-
if (values instanceof Int32Array) return {
|
|
997
|
-
name,
|
|
998
|
-
type: "INT32",
|
|
999
|
-
repetition_type
|
|
1000
|
-
};
|
|
1001
|
-
if (values instanceof BigInt64Array) return {
|
|
1002
|
-
name,
|
|
1003
|
-
type: "INT64",
|
|
1004
|
-
repetition_type
|
|
1005
|
-
};
|
|
1006
|
-
if (values instanceof Float32Array) return {
|
|
1007
|
-
name,
|
|
1008
|
-
type: "FLOAT",
|
|
1009
|
-
repetition_type
|
|
1010
|
-
};
|
|
1011
|
-
if (values instanceof Float64Array) return {
|
|
1012
|
-
name,
|
|
1013
|
-
type: "DOUBLE",
|
|
1014
|
-
repetition_type
|
|
1015
|
-
};
|
|
1016
|
-
for (const value of values) if (value === null || value === void 0) repetition_type = "OPTIONAL";
|
|
1017
|
-
else {
|
|
1018
|
-
let valueType;
|
|
1019
|
-
let valueConvertedType;
|
|
1020
|
-
if (typeof value === "boolean") valueType = "BOOLEAN";
|
|
1021
|
-
else if (typeof value === "bigint") valueType = "INT64";
|
|
1022
|
-
else if (Number.isInteger(value)) valueType = "INT32";
|
|
1023
|
-
else if (typeof value === "number") valueType = "DOUBLE";
|
|
1024
|
-
else if (value instanceof Uint8Array) valueType = "BYTE_ARRAY";
|
|
1025
|
-
else if (typeof value === "string") {
|
|
1026
|
-
valueType = "BYTE_ARRAY";
|
|
1027
|
-
valueConvertedType = "UTF8";
|
|
1028
|
-
} else if (value instanceof Date) {
|
|
1029
|
-
valueType = "INT64";
|
|
1030
|
-
valueConvertedType = "TIMESTAMP_MILLIS";
|
|
1031
|
-
} else if (typeof value === "object") {
|
|
1032
|
-
valueType = "BYTE_ARRAY";
|
|
1033
|
-
valueConvertedType = "JSON";
|
|
1034
|
-
} else throw new Error(`cannot determine parquet type for: ${value}`);
|
|
1035
|
-
if (type === void 0) {
|
|
1036
|
-
type = valueType;
|
|
1037
|
-
converted_type = valueConvertedType;
|
|
1038
|
-
} else if (type === "INT32" && valueType === "DOUBLE") type = "DOUBLE";
|
|
1039
|
-
else if (type === "DOUBLE" && valueType === "INT32") valueType = "DOUBLE";
|
|
1040
|
-
else if (type !== valueType || converted_type !== valueConvertedType) throw new Error(`parquet cannot write mixed types: ${converted_type ?? type} and ${valueConvertedType ?? valueType}`);
|
|
1041
|
-
}
|
|
1042
|
-
if (!type) {
|
|
1043
|
-
type = "BYTE_ARRAY";
|
|
1044
|
-
repetition_type = "OPTIONAL";
|
|
1045
|
-
}
|
|
1046
|
-
return {
|
|
1047
|
-
name,
|
|
1048
|
-
type,
|
|
1049
|
-
repetition_type,
|
|
1050
|
-
converted_type
|
|
1051
|
-
};
|
|
1052
|
-
}
|
|
1053
|
-
function getMaxRepetitionLevel(schemaPath) {
|
|
1054
|
-
let maxLevel = 0;
|
|
1055
|
-
for (const element of schemaPath) if (element.repetition_type === "REPEATED") maxLevel++;
|
|
1056
|
-
return maxLevel;
|
|
1057
|
-
}
|
|
1058
|
-
function writeByteStreamSplit(writer, values, type, typeLength) {
|
|
1059
|
-
const count = values.length;
|
|
1060
|
-
let bytes;
|
|
1061
|
-
let width;
|
|
1062
|
-
if (type === "FLOAT") {
|
|
1063
|
-
const typed = values instanceof Float32Array ? values : new Float32Array(numberArray(values));
|
|
1064
|
-
bytes = new Uint8Array(typed.buffer, typed.byteOffset, typed.byteLength);
|
|
1065
|
-
width = 4;
|
|
1066
|
-
} else if (type === "DOUBLE") {
|
|
1067
|
-
const typed = values instanceof Float64Array ? values : new Float64Array(numberArray(values));
|
|
1068
|
-
bytes = new Uint8Array(typed.buffer, typed.byteOffset, typed.byteLength);
|
|
1069
|
-
width = 8;
|
|
1070
|
-
} else if (type === "INT32") {
|
|
1071
|
-
const typed = values instanceof Int32Array ? values : new Int32Array(numberArray(values));
|
|
1072
|
-
bytes = new Uint8Array(typed.buffer, typed.byteOffset, typed.byteLength);
|
|
1073
|
-
width = 4;
|
|
1074
|
-
} else if (type === "INT64") {
|
|
1075
|
-
const typed = bigIntArray(values);
|
|
1076
|
-
bytes = new Uint8Array(typed.buffer, typed.byteOffset, typed.byteLength);
|
|
1077
|
-
width = 8;
|
|
1078
|
-
} else if (type === "FIXED_LEN_BYTE_ARRAY") {
|
|
1079
|
-
if (!typeLength) throw new Error("parquet byte_stream_split missing type_length");
|
|
1080
|
-
width = typeLength;
|
|
1081
|
-
bytes = new Uint8Array(count * width);
|
|
1082
|
-
for (let i = 0; i < count; i++) bytes.set(values[i], i * width);
|
|
1083
|
-
} else throw new Error(`parquet byte_stream_split unsupported type: ${type}`);
|
|
1084
|
-
for (let b = 0; b < width; b++) for (let i = 0; i < count; i++) writer.appendUint8(bytes[i * width + b]);
|
|
1085
|
-
}
|
|
1086
|
-
function numberArray(values) {
|
|
1087
|
-
if (Array.isArray(values) && values.every((v) => typeof v === "number")) return values;
|
|
1088
|
-
throw new Error("Expected number array for BYTE_STREAM_SPLIT encoding");
|
|
1089
|
-
}
|
|
1090
|
-
function bigIntArray(values) {
|
|
1091
|
-
if (values instanceof BigInt64Array) return values;
|
|
1092
|
-
if (Array.isArray(values) && values.every((v) => typeof v === "bigint")) return new BigInt64Array(values);
|
|
1093
|
-
throw new Error("Expected bigint array for BYTE_STREAM_SPLIT encoding");
|
|
1094
|
-
}
|
|
1095
|
-
function writeDataPageV2({ writer, column, encoding, pageData }) {
|
|
1096
|
-
const { columnName, element, codec, compressors } = column;
|
|
1097
|
-
const { type, type_length, repetition_type } = element;
|
|
1098
|
-
if (!type) throw new Error(`column ${columnName} cannot determine type`);
|
|
1099
|
-
if (repetition_type === "REPEATED") throw new Error(`column ${columnName} repeated types not supported`);
|
|
1100
|
-
const levelWriter = new ByteWriter();
|
|
1101
|
-
const { definition_levels_byte_length, repetition_levels_byte_length, num_nulls, num_values, num_rows } = writeLevels(levelWriter, column, pageData);
|
|
1102
|
-
const nonnull = num_nulls ? pageData.values.filter((v) => v !== null && v !== void 0) : pageData.values;
|
|
1103
|
-
const page = new ByteWriter();
|
|
1104
|
-
if (encoding === "PLAIN") writePlain(page, nonnull, type, type_length);
|
|
1105
|
-
else if (encoding === "RLE") {
|
|
1106
|
-
if (type !== "BOOLEAN") throw new Error("RLE encoding only supported for BOOLEAN type");
|
|
1107
|
-
const rleData = new ByteWriter();
|
|
1108
|
-
writeRleBitPackedHybrid(rleData, nonnull, 1);
|
|
1109
|
-
page.appendUint32(rleData.offset);
|
|
1110
|
-
page.appendBytes(rleData.getBytes());
|
|
1111
|
-
} else if (encoding === "PLAIN_DICTIONARY" || encoding === "RLE_DICTIONARY") {
|
|
1112
|
-
let maxValue = 0;
|
|
1113
|
-
for (const v of nonnull) if (v > maxValue) maxValue = v;
|
|
1114
|
-
const bitWidth = Math.ceil(Math.log2(maxValue + 1));
|
|
1115
|
-
page.appendUint8(bitWidth);
|
|
1116
|
-
writeRleBitPackedHybrid(page, nonnull, bitWidth);
|
|
1117
|
-
} else if (encoding === "DELTA_BINARY_PACKED") {
|
|
1118
|
-
if (type !== "INT32" && type !== "INT64") throw new Error("DELTA_BINARY_PACKED encoding only supported for INT32 and INT64 types");
|
|
1119
|
-
deltaBinaryPack(page, nonnull);
|
|
1120
|
-
} else if (encoding === "DELTA_LENGTH_BYTE_ARRAY") {
|
|
1121
|
-
if (type !== "BYTE_ARRAY") throw new Error("DELTA_LENGTH_BYTE_ARRAY encoding only supported for BYTE_ARRAY type");
|
|
1122
|
-
deltaLengthByteArray(page, nonnull);
|
|
1123
|
-
} else if (encoding === "DELTA_BYTE_ARRAY") {
|
|
1124
|
-
if (type !== "BYTE_ARRAY") throw new Error("DELTA_BYTE_ARRAY encoding only supported for BYTE_ARRAY type");
|
|
1125
|
-
deltaByteArray(page, nonnull);
|
|
1126
|
-
} else if (encoding === "BYTE_STREAM_SPLIT") writeByteStreamSplit(page, nonnull, type, type_length);
|
|
1127
|
-
else throw new Error(`parquet unsupported encoding: ${encoding}`);
|
|
1128
|
-
const pageBytes = page.getBytes();
|
|
1129
|
-
const compressedBytes = compressors[codec]?.(pageBytes) ?? pageBytes;
|
|
1130
|
-
writePageHeader(writer, {
|
|
1131
|
-
type: "DATA_PAGE_V2",
|
|
1132
|
-
uncompressed_page_size: levelWriter.offset + page.offset,
|
|
1133
|
-
compressed_page_size: levelWriter.offset + compressedBytes.length,
|
|
1134
|
-
data_page_header_v2: {
|
|
1135
|
-
num_values,
|
|
1136
|
-
num_nulls,
|
|
1137
|
-
num_rows,
|
|
1138
|
-
encoding,
|
|
1139
|
-
definition_levels_byte_length,
|
|
1140
|
-
repetition_levels_byte_length,
|
|
1141
|
-
is_compressed: !!codec
|
|
1142
|
-
}
|
|
1143
|
-
});
|
|
1144
|
-
writer.appendBytes(levelWriter.getBytes());
|
|
1145
|
-
writer.appendBytes(compressedBytes);
|
|
1146
|
-
}
|
|
1147
|
-
function writePageHeader(writer, header) {
|
|
1148
|
-
serializeTCompactProtocol(writer, {
|
|
1149
|
-
field_1: PageTypes.indexOf(header.type),
|
|
1150
|
-
field_2: header.uncompressed_page_size,
|
|
1151
|
-
field_3: header.compressed_page_size,
|
|
1152
|
-
field_4: header.crc,
|
|
1153
|
-
field_5: header.data_page_header && {
|
|
1154
|
-
field_1: header.data_page_header.num_values,
|
|
1155
|
-
field_2: Encodings.indexOf(header.data_page_header.encoding),
|
|
1156
|
-
field_3: Encodings.indexOf(header.data_page_header.definition_level_encoding),
|
|
1157
|
-
field_4: Encodings.indexOf(header.data_page_header.repetition_level_encoding)
|
|
1158
|
-
},
|
|
1159
|
-
field_7: header.dictionary_page_header && {
|
|
1160
|
-
field_1: header.dictionary_page_header.num_values,
|
|
1161
|
-
field_2: Encodings.indexOf(header.dictionary_page_header.encoding)
|
|
1162
|
-
},
|
|
1163
|
-
field_8: header.data_page_header_v2 && {
|
|
1164
|
-
field_1: header.data_page_header_v2.num_values,
|
|
1165
|
-
field_2: header.data_page_header_v2.num_nulls,
|
|
1166
|
-
field_3: header.data_page_header_v2.num_rows,
|
|
1167
|
-
field_4: Encodings.indexOf(header.data_page_header_v2.encoding),
|
|
1168
|
-
field_5: header.data_page_header_v2.definition_levels_byte_length,
|
|
1169
|
-
field_6: header.data_page_header_v2.repetition_levels_byte_length,
|
|
1170
|
-
field_7: header.data_page_header_v2.is_compressed ? void 0 : false
|
|
1171
|
-
}
|
|
1172
|
-
});
|
|
1173
|
-
}
|
|
1174
|
-
function writeLevels(writer, column, dataPage) {
|
|
1175
|
-
const { schemaPath } = column;
|
|
1176
|
-
const { values, definitionLevels, repetitionLevels, maxDefinitionLevel } = dataPage;
|
|
1177
|
-
const num_values = definitionLevels.length || values.length;
|
|
1178
|
-
let num_nulls = 0;
|
|
1179
|
-
let num_rows = 0;
|
|
1180
|
-
if (repetitionLevels.length) {
|
|
1181
|
-
for (let i = 0; i < repetitionLevels.length; i++) if (repetitionLevels[i] === 0) num_rows++;
|
|
1182
|
-
} else num_rows = values.length;
|
|
1183
|
-
if (definitionLevels.length) {
|
|
1184
|
-
for (let i = 0; i < definitionLevels.length; i++) if (definitionLevels[i] < maxDefinitionLevel) num_nulls++;
|
|
1185
|
-
}
|
|
1186
|
-
const maxRepetitionLevel = getMaxRepetitionLevel(schemaPath);
|
|
1187
|
-
let repetition_levels_byte_length = 0;
|
|
1188
|
-
if (maxRepetitionLevel) repetition_levels_byte_length = writeRleBitPackedHybrid(writer, repetitionLevels, Math.ceil(Math.log2(maxRepetitionLevel + 1)));
|
|
1189
|
-
let definition_levels_byte_length = 0;
|
|
1190
|
-
if (maxDefinitionLevel) definition_levels_byte_length = writeRleBitPackedHybrid(writer, definitionLevels, Math.ceil(Math.log2(maxDefinitionLevel + 1)));
|
|
1191
|
-
return {
|
|
1192
|
-
definition_levels_byte_length,
|
|
1193
|
-
repetition_levels_byte_length,
|
|
1194
|
-
num_values,
|
|
1195
|
-
num_nulls,
|
|
1196
|
-
num_rows
|
|
1197
|
-
};
|
|
1198
|
-
}
|
|
1199
|
-
function estimateValueSize(value, type, type_length) {
|
|
1200
|
-
if (value === null || value === void 0) return 0;
|
|
1201
|
-
if (type === "BOOLEAN") return .125;
|
|
1202
|
-
if (type === "INT32" || type === "FLOAT") return 4;
|
|
1203
|
-
if (type === "INT64" || type === "DOUBLE") return 8;
|
|
1204
|
-
if (type === "INT96") return 12;
|
|
1205
|
-
if (type === "FIXED_LEN_BYTE_ARRAY") return type_length ?? 0;
|
|
1206
|
-
if (type === "BYTE_ARRAY") {
|
|
1207
|
-
if (value instanceof Uint8Array) return value.byteLength;
|
|
1208
|
-
if (typeof value === "string") return value.length;
|
|
1209
|
-
}
|
|
1210
|
-
return 0;
|
|
1211
|
-
}
|
|
1212
|
-
function hashBytes(bytes) {
|
|
1213
|
-
let h = 2166136261;
|
|
1214
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
1215
|
-
h ^= bytes[i];
|
|
1216
|
-
h = Math.imul(h, 16777619);
|
|
1217
|
-
}
|
|
1218
|
-
return h >>> 0;
|
|
1219
|
-
}
|
|
1220
|
-
function bytesEqual(a, b) {
|
|
1221
|
-
if (a.length !== b.length) return false;
|
|
1222
|
-
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
|
|
1223
|
-
return true;
|
|
1224
|
-
}
|
|
1225
|
-
function useDictionary(values, type, type_length, encoding, pageSize) {
|
|
1226
|
-
if (encoding && encoding !== "RLE_DICTIONARY") return {};
|
|
1227
|
-
if (type === "BOOLEAN") return {};
|
|
1228
|
-
const sample = values.slice(0, 1e3);
|
|
1229
|
-
const sampleKeys = /* @__PURE__ */ new Set();
|
|
1230
|
-
for (const value of sample) sampleKeys.add(value instanceof Uint8Array ? hashBytes(value) : value);
|
|
1231
|
-
if (sampleKeys.size === 0 || sampleKeys.size / sample.length > .5) return {};
|
|
1232
|
-
const dictionary = [];
|
|
1233
|
-
const indexes = new Array(values.length);
|
|
1234
|
-
const valueIndex = /* @__PURE__ */ new Map();
|
|
1235
|
-
const hashBuckets = /* @__PURE__ */ new Map();
|
|
1236
|
-
let dictSize = 0;
|
|
1237
|
-
for (let i = 0; i < values.length; i++) {
|
|
1238
|
-
const value = values[i];
|
|
1239
|
-
if (value === null || value === void 0) continue;
|
|
1240
|
-
let index;
|
|
1241
|
-
if (value instanceof Uint8Array) {
|
|
1242
|
-
const hash = hashBytes(value);
|
|
1243
|
-
const bucket = hashBuckets.get(hash);
|
|
1244
|
-
if (bucket) {
|
|
1245
|
-
for (const j of bucket) if (bytesEqual(dictionary[j], value)) {
|
|
1246
|
-
index = j;
|
|
1247
|
-
break;
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
if (index === void 0) {
|
|
1251
|
-
dictSize += value.byteLength;
|
|
1252
|
-
if (pageSize && dictSize > pageSize) return {};
|
|
1253
|
-
index = dictionary.length;
|
|
1254
|
-
dictionary.push(value);
|
|
1255
|
-
if (bucket) bucket.push(index);
|
|
1256
|
-
else hashBuckets.set(hash, [index]);
|
|
1257
|
-
}
|
|
1258
|
-
} else {
|
|
1259
|
-
index = valueIndex.get(value);
|
|
1260
|
-
if (index === void 0) {
|
|
1261
|
-
dictSize += estimateValueSize(value, type, type_length);
|
|
1262
|
-
if (pageSize && dictSize > pageSize) return {};
|
|
1263
|
-
index = dictionary.length;
|
|
1264
|
-
dictionary.push(value);
|
|
1265
|
-
valueIndex.set(value, index);
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
indexes[i] = index;
|
|
1269
|
-
}
|
|
1270
|
-
return {
|
|
1271
|
-
dictionary,
|
|
1272
|
-
indexes
|
|
1273
|
-
};
|
|
1274
|
-
}
|
|
1275
|
-
function writeDictionaryPage(writer, column, dictionary) {
|
|
1276
|
-
const { element, codec, compressors } = column;
|
|
1277
|
-
const { type, type_length } = element;
|
|
1278
|
-
if (!type) throw new Error(`column ${column.columnName} cannot determine type`);
|
|
1279
|
-
const dictionaryPage = new ByteWriter();
|
|
1280
|
-
writePlain(dictionaryPage, dictionary, type, type_length);
|
|
1281
|
-
const dictionaryBytes = dictionaryPage.getBytes();
|
|
1282
|
-
const compressedBytes = compressors[codec]?.(dictionaryBytes) ?? dictionaryBytes;
|
|
1283
|
-
writePageHeader(writer, {
|
|
1284
|
-
type: "DICTIONARY_PAGE",
|
|
1285
|
-
uncompressed_page_size: dictionaryBytes.byteLength,
|
|
1286
|
-
compressed_page_size: compressedBytes.byteLength,
|
|
1287
|
-
dictionary_page_header: {
|
|
1288
|
-
num_values: dictionary.length,
|
|
1289
|
-
encoding: "PLAIN"
|
|
1290
|
-
}
|
|
1291
|
-
});
|
|
1292
|
-
writer.appendBytes(compressedBytes);
|
|
1293
|
-
}
|
|
1294
|
-
function geospatialStatistics(values) {
|
|
1295
|
-
const typeCodes = /* @__PURE__ */ new Set();
|
|
1296
|
-
let partial;
|
|
1297
|
-
for (const value of values) {
|
|
1298
|
-
if (value === null || value === void 0) continue;
|
|
1299
|
-
if (typeof value !== "object") throw new Error("geospatial column expects GeoJSON geometries");
|
|
1300
|
-
partial = extendBoundsFromGeometry(partial, value);
|
|
1301
|
-
typeCodes.add(geometryTypeCodeWithDimension(value));
|
|
1302
|
-
}
|
|
1303
|
-
let bbox;
|
|
1304
|
-
const { xmin, ymin, xmax, ymax } = partial ?? {};
|
|
1305
|
-
if (xmin !== void 0 && ymin !== void 0 && xmax !== void 0 && ymax !== void 0) bbox = {
|
|
1306
|
-
...partial,
|
|
1307
|
-
xmin,
|
|
1308
|
-
ymin,
|
|
1309
|
-
xmax,
|
|
1310
|
-
ymax
|
|
1311
|
-
};
|
|
1312
|
-
if (typeCodes.size || bbox) return {
|
|
1313
|
-
bbox,
|
|
1314
|
-
geospatial_types: typeCodes.size ? Array.from(typeCodes).sort((a, b) => a - b) : []
|
|
1315
|
-
};
|
|
1316
|
-
}
|
|
1317
|
-
function extendBoundsFromGeometry(bbox, geometry) {
|
|
1318
|
-
if (geometry.type === "GeometryCollection") {
|
|
1319
|
-
for (const child of geometry.geometries || []) bbox = extendBoundsFromGeometry(bbox, child);
|
|
1320
|
-
return bbox;
|
|
1321
|
-
}
|
|
1322
|
-
return extendBoundsFromCoordinates(bbox, geometry.coordinates);
|
|
1323
|
-
}
|
|
1324
|
-
function extendBoundsFromCoordinates(bbox, coordinates) {
|
|
1325
|
-
if (typeof coordinates[0] === "number") {
|
|
1326
|
-
bbox = updateAxis(bbox, "xmin", "xmax", coordinates[0]);
|
|
1327
|
-
bbox = updateAxis(bbox, "ymin", "ymax", coordinates[1]);
|
|
1328
|
-
if (coordinates.length > 2) bbox = updateAxis(bbox, "zmin", "zmax", coordinates[2]);
|
|
1329
|
-
if (coordinates.length > 3) bbox = updateAxis(bbox, "mmin", "mmax", coordinates[3]);
|
|
1330
|
-
return bbox;
|
|
1331
|
-
}
|
|
1332
|
-
for (const child of coordinates) bbox = extendBoundsFromCoordinates(bbox, child);
|
|
1333
|
-
return bbox;
|
|
1334
|
-
}
|
|
1335
|
-
function updateAxis(bbox, minKey, maxKey, value) {
|
|
1336
|
-
if (value === void 0 || !Number.isFinite(value)) return bbox;
|
|
1337
|
-
if (!bbox) bbox = {};
|
|
1338
|
-
const min = bbox[minKey];
|
|
1339
|
-
const max = bbox[maxKey];
|
|
1340
|
-
if (min === void 0 || value < min) bbox[minKey] = value;
|
|
1341
|
-
if (max === void 0 || value > max) bbox[maxKey] = value;
|
|
1342
|
-
return bbox;
|
|
1343
|
-
}
|
|
1344
|
-
function geometryTypeCodeWithDimension(geometry) {
|
|
1345
|
-
const base = geometryTypeCodes[geometry.type];
|
|
1346
|
-
if (base === void 0) throw new Error(`unknown geometry type: ${geometry.type}`);
|
|
1347
|
-
const dim = inferGeometryDimensions$1(geometry);
|
|
1348
|
-
if (dim === 2) return base;
|
|
1349
|
-
if (dim === 3) return base + 1e3;
|
|
1350
|
-
if (dim === 4) return base + 3e3;
|
|
1351
|
-
throw new Error(`unsupported geometry dimensions: ${dim}`);
|
|
1352
|
-
}
|
|
1353
|
-
const geometryTypeCodes = {
|
|
1354
|
-
Point: 1,
|
|
1355
|
-
LineString: 2,
|
|
1356
|
-
Polygon: 3,
|
|
1357
|
-
MultiPoint: 4,
|
|
1358
|
-
MultiLineString: 5,
|
|
1359
|
-
MultiPolygon: 6,
|
|
1360
|
-
GeometryCollection: 7
|
|
1361
|
-
};
|
|
1362
|
-
function inferGeometryDimensions$1(geometry) {
|
|
1363
|
-
if (geometry.type === "GeometryCollection") {
|
|
1364
|
-
let maxDim = 0;
|
|
1365
|
-
for (const child of geometry.geometries || []) maxDim = Math.max(maxDim, inferGeometryDimensions$1(child));
|
|
1366
|
-
return maxDim || 2;
|
|
1367
|
-
}
|
|
1368
|
-
return inferCoordinateDimensions$1(geometry.coordinates);
|
|
1369
|
-
}
|
|
1370
|
-
function inferCoordinateDimensions$1(value) {
|
|
1371
|
-
if (!value.length) return 2;
|
|
1372
|
-
if (typeof value[0] === "number") return value.length;
|
|
1373
|
-
let maxDim = 0;
|
|
1374
|
-
for (const item of value) maxDim = Math.max(maxDim, inferCoordinateDimensions$1(item));
|
|
1375
|
-
return maxDim || 2;
|
|
1376
|
-
}
|
|
1377
|
-
function geojsonToWkb(geometry) {
|
|
1378
|
-
const writer = new ByteWriter();
|
|
1379
|
-
writeGeometry(writer, geometry);
|
|
1380
|
-
return writer.getBytes();
|
|
1381
|
-
}
|
|
1382
|
-
function writeGeometry(writer, geometry) {
|
|
1383
|
-
if (typeof geometry !== "object") throw new Error("geometry values must be GeoJSON geometries");
|
|
1384
|
-
const typeCode = geometryTypeCode(geometry.type);
|
|
1385
|
-
const dim = inferGeometryDimensions(geometry);
|
|
1386
|
-
let flag = 0;
|
|
1387
|
-
if (dim === 3) flag = 1;
|
|
1388
|
-
else if (dim === 4) flag = 3;
|
|
1389
|
-
else if (dim > 4) throw new Error(`unsupported geometry dimensions: ${dim}`);
|
|
1390
|
-
writer.appendUint8(1);
|
|
1391
|
-
writer.appendUint32(typeCode + flag * 1e3);
|
|
1392
|
-
if (geometry.type === "Point") writePosition(writer, geometry.coordinates, dim);
|
|
1393
|
-
else if (geometry.type === "LineString") writeLine(writer, geometry.coordinates, dim);
|
|
1394
|
-
else if (geometry.type === "Polygon") {
|
|
1395
|
-
writer.appendUint32(geometry.coordinates.length);
|
|
1396
|
-
for (const ring of geometry.coordinates) writeLine(writer, ring, dim);
|
|
1397
|
-
} else if (geometry.type === "MultiPoint") {
|
|
1398
|
-
writer.appendUint32(geometry.coordinates.length);
|
|
1399
|
-
for (const coordinates of geometry.coordinates) writeGeometry(writer, {
|
|
1400
|
-
type: "Point",
|
|
1401
|
-
coordinates
|
|
1402
|
-
});
|
|
1403
|
-
} else if (geometry.type === "MultiLineString") {
|
|
1404
|
-
writer.appendUint32(geometry.coordinates.length);
|
|
1405
|
-
for (const coordinates of geometry.coordinates) writeGeometry(writer, {
|
|
1406
|
-
type: "LineString",
|
|
1407
|
-
coordinates
|
|
1408
|
-
});
|
|
1409
|
-
} else if (geometry.type === "MultiPolygon") {
|
|
1410
|
-
writer.appendUint32(geometry.coordinates.length);
|
|
1411
|
-
for (const coordinates of geometry.coordinates) writeGeometry(writer, {
|
|
1412
|
-
type: "Polygon",
|
|
1413
|
-
coordinates
|
|
1414
|
-
});
|
|
1415
|
-
} else if (geometry.type === "GeometryCollection") {
|
|
1416
|
-
writer.appendUint32(geometry.geometries.length);
|
|
1417
|
-
for (const child of geometry.geometries) writeGeometry(writer, child);
|
|
1418
|
-
} else throw new Error("unsupported geometry type");
|
|
1419
|
-
}
|
|
1420
|
-
function writePosition(writer, position, dim) {
|
|
1421
|
-
if (position.length < dim) throw new Error("geometry position dimensions mismatch");
|
|
1422
|
-
for (let i = 0; i < dim; i++) writer.appendFloat64(position[i]);
|
|
1423
|
-
}
|
|
1424
|
-
function writeLine(writer, coordinates, dim) {
|
|
1425
|
-
writer.appendUint32(coordinates.length);
|
|
1426
|
-
for (const position of coordinates) writePosition(writer, position, dim);
|
|
1427
|
-
}
|
|
1428
|
-
function geometryTypeCode(type) {
|
|
1429
|
-
if (type === "Point") return 1;
|
|
1430
|
-
if (type === "LineString") return 2;
|
|
1431
|
-
if (type === "Polygon") return 3;
|
|
1432
|
-
if (type === "MultiPoint") return 4;
|
|
1433
|
-
if (type === "MultiLineString") return 5;
|
|
1434
|
-
if (type === "MultiPolygon") return 6;
|
|
1435
|
-
if (type === "GeometryCollection") return 7;
|
|
1436
|
-
throw new Error(`unknown geometry type: ${type}`);
|
|
1437
|
-
}
|
|
1438
|
-
function inferGeometryDimensions(geometry) {
|
|
1439
|
-
if (geometry.type === "GeometryCollection") {
|
|
1440
|
-
let maxDim = 0;
|
|
1441
|
-
for (const child of geometry.geometries) maxDim = Math.max(maxDim, inferGeometryDimensions(child));
|
|
1442
|
-
return maxDim || 2;
|
|
1443
|
-
}
|
|
1444
|
-
return inferCoordinateDimensions(geometry.coordinates);
|
|
1445
|
-
}
|
|
1446
|
-
function inferCoordinateDimensions(value) {
|
|
1447
|
-
if (!Array.isArray(value)) return 2;
|
|
1448
|
-
if (!value.length) return 2;
|
|
1449
|
-
if (typeof value[0] === "number") return value.length;
|
|
1450
|
-
let maxDim = 0;
|
|
1451
|
-
for (const item of value) maxDim = Math.max(maxDim, inferCoordinateDimensions(item));
|
|
1452
|
-
return maxDim || 2;
|
|
1453
|
-
}
|
|
1454
|
-
const dayMillis = 864e5;
|
|
1455
|
-
function unconvert(element, values) {
|
|
1456
|
-
const { type, converted_type: ctype, logical_type: ltype } = element;
|
|
1457
|
-
if (ctype === "DECIMAL") {
|
|
1458
|
-
const factor = 10 ** (element.scale || 0);
|
|
1459
|
-
return values.map((v) => {
|
|
1460
|
-
if (v === null || v === void 0) return v;
|
|
1461
|
-
if (typeof v !== "number") throw new Error("DECIMAL must be a number");
|
|
1462
|
-
return unconvertDecimal(element, BigInt(Math.round(v * factor)));
|
|
1463
|
-
});
|
|
1464
|
-
}
|
|
1465
|
-
if (ctype === "DATE") return Array.from(values).map((v) => {
|
|
1466
|
-
if (v instanceof Date) return Math.floor(v.getTime() / dayMillis);
|
|
1467
|
-
return v;
|
|
1468
|
-
});
|
|
1469
|
-
if (ctype === "TIMESTAMP_MILLIS") return Array.from(values).map((v) => {
|
|
1470
|
-
if (v === null || v === void 0) return v;
|
|
1471
|
-
if (v instanceof Date) return BigInt(v.getTime());
|
|
1472
|
-
return BigInt(v);
|
|
1473
|
-
});
|
|
1474
|
-
if (ctype === "TIMESTAMP_MICROS") return Array.from(values).map((v) => {
|
|
1475
|
-
if (v === null || v === void 0) return v;
|
|
1476
|
-
if (v instanceof Date) return BigInt(v.getTime() * 1e3);
|
|
1477
|
-
return BigInt(v);
|
|
1478
|
-
});
|
|
1479
|
-
if (ctype === "JSON") {
|
|
1480
|
-
if (!Array.isArray(values)) throw new Error("JSON must be an array");
|
|
1481
|
-
const encoder = new TextEncoder();
|
|
1482
|
-
return values.map((v) => v === void 0 ? void 0 : encoder.encode(JSON.stringify(toJson(v))));
|
|
1483
|
-
}
|
|
1484
|
-
if (ctype === "UTF8") {
|
|
1485
|
-
if (!Array.isArray(values)) throw new Error("strings must be an array");
|
|
1486
|
-
const encoder = new TextEncoder();
|
|
1487
|
-
return values.map((v) => typeof v === "string" ? encoder.encode(v) : v);
|
|
1488
|
-
}
|
|
1489
|
-
if (ctype === "UINT_32" || ltype?.type === "INTEGER" && ltype.bitWidth === 32 && !ltype.isSigned) {
|
|
1490
|
-
if (values instanceof Uint32Array) return values;
|
|
1491
|
-
if (values instanceof Int32Array) return new Uint32Array(values.buffer, values.byteOffset, values.length);
|
|
1492
|
-
return Array.from(values).map((v) => {
|
|
1493
|
-
if (v === null || v === void 0) return v;
|
|
1494
|
-
if (!Number.isSafeInteger(v)) throw new Error("expected integer value, got " + v);
|
|
1495
|
-
if (v < 0 || v > 4294967295) throw new Error("expected uint32 value, got " + v);
|
|
1496
|
-
if (v > 2147483647) return v - 4294967296;
|
|
1497
|
-
return v;
|
|
1498
|
-
});
|
|
1499
|
-
}
|
|
1500
|
-
if (ltype?.type === "FLOAT16") {
|
|
1501
|
-
if (type !== "FIXED_LEN_BYTE_ARRAY") throw new Error("FLOAT16 must be FIXED_LEN_BYTE_ARRAY type");
|
|
1502
|
-
if (element.type_length !== 2) throw new Error("FLOAT16 expected type_length to be 2 bytes");
|
|
1503
|
-
return Array.from(values).map(unconvertFloat16);
|
|
1504
|
-
}
|
|
1505
|
-
if (ltype?.type === "UUID") {
|
|
1506
|
-
if (!Array.isArray(values)) throw new Error("UUID must be an array");
|
|
1507
|
-
if (type !== "FIXED_LEN_BYTE_ARRAY") throw new Error("UUID must be FIXED_LEN_BYTE_ARRAY type");
|
|
1508
|
-
if (element.type_length !== 16) throw new Error("UUID expected type_length to be 16 bytes");
|
|
1509
|
-
return values.map(unconvertUuid);
|
|
1510
|
-
}
|
|
1511
|
-
if (ltype?.type === "TIMESTAMP") return Array.from(values).map((v) => {
|
|
1512
|
-
if (v === null || v === void 0) return v;
|
|
1513
|
-
if (v instanceof Date) {
|
|
1514
|
-
const millis = BigInt(v.getTime());
|
|
1515
|
-
if (ltype.unit === "NANOS") return millis * 1000000n;
|
|
1516
|
-
if (ltype.unit === "MICROS") return millis * 1000n;
|
|
1517
|
-
return millis;
|
|
1518
|
-
}
|
|
1519
|
-
return BigInt(v);
|
|
1520
|
-
});
|
|
1521
|
-
if (ltype?.type === "GEOMETRY" || ltype?.type === "GEOGRAPHY") {
|
|
1522
|
-
if (!Array.isArray(values)) throw new Error("geometry must be an array");
|
|
1523
|
-
return values.map((v) => {
|
|
1524
|
-
if (v === null || v === void 0) return v;
|
|
1525
|
-
return geojsonToWkb(v);
|
|
1526
|
-
});
|
|
1527
|
-
}
|
|
1528
|
-
return values;
|
|
1529
|
-
}
|
|
1530
|
-
function unconvertUuid(value) {
|
|
1531
|
-
if (value === void 0 || value === null) return;
|
|
1532
|
-
if (value instanceof Uint8Array) return value;
|
|
1533
|
-
if (typeof value === "string") {
|
|
1534
|
-
if (!/^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$/i.test(value)) throw new Error("UUID must be a valid UUID string");
|
|
1535
|
-
value = value.replace(/-/g, "").toLowerCase();
|
|
1536
|
-
const bytes = /* @__PURE__ */ new Uint8Array(16);
|
|
1537
|
-
for (let i = 0; i < 16; i++) bytes[i] = parseInt(value.slice(i * 2, i * 2 + 2), 16);
|
|
1538
|
-
return bytes;
|
|
1539
|
-
}
|
|
1540
|
-
throw new Error("UUID must be a string or Uint8Array");
|
|
1541
|
-
}
|
|
1542
|
-
const STATS_TRUNCATE_LENGTH = 16;
|
|
1543
|
-
function truncateStatistic(bytes, isMax) {
|
|
1544
|
-
if (bytes.length <= STATS_TRUNCATE_LENGTH) return bytes;
|
|
1545
|
-
let cut = STATS_TRUNCATE_LENGTH;
|
|
1546
|
-
while (cut > 0 && (bytes[cut] & 192) === 128) cut--;
|
|
1547
|
-
const prefix = bytes.slice(0, cut);
|
|
1548
|
-
if (!isMax) return prefix;
|
|
1549
|
-
const out = new Uint8Array(prefix.length + 4);
|
|
1550
|
-
out.set(prefix, 0);
|
|
1551
|
-
out.set([
|
|
1552
|
-
244,
|
|
1553
|
-
143,
|
|
1554
|
-
191,
|
|
1555
|
-
191
|
|
1556
|
-
], prefix.length);
|
|
1557
|
-
return out;
|
|
1558
|
-
}
|
|
1559
|
-
function minMaxIsExact(value, element) {
|
|
1560
|
-
if (value === void 0 || value === null) return void 0;
|
|
1561
|
-
const { type } = element;
|
|
1562
|
-
if (type !== "BYTE_ARRAY" && type !== "FIXED_LEN_BYTE_ARRAY") return void 0;
|
|
1563
|
-
if (element.logical_type?.type === "UUID") return void 0;
|
|
1564
|
-
return (value instanceof Uint8Array ? value : new TextEncoder().encode(value.toString())).length > STATS_TRUNCATE_LENGTH ? false : void 0;
|
|
1565
|
-
}
|
|
1566
|
-
function unconvertMinMax(value, element, isMax) {
|
|
1567
|
-
if (value === void 0 || value === null) return void 0;
|
|
1568
|
-
const { type, converted_type } = element;
|
|
1569
|
-
if (type === "BOOLEAN") return new Uint8Array([value ? 1 : 0]);
|
|
1570
|
-
if (element.logical_type?.type === "UUID" && (typeof value === "string" || value instanceof Uint8Array)) return unconvertUuid(value);
|
|
1571
|
-
if (converted_type === "DECIMAL") {
|
|
1572
|
-
if (typeof value !== "number") throw new Error("DECIMAL must be a number");
|
|
1573
|
-
const factor = 10 ** (element.scale || 0);
|
|
1574
|
-
const out = unconvertDecimal(element, BigInt(Math.round(value * factor)));
|
|
1575
|
-
if (out instanceof Uint8Array) return out;
|
|
1576
|
-
if (typeof out === "number") {
|
|
1577
|
-
const buffer = /* @__PURE__ */ new ArrayBuffer(4);
|
|
1578
|
-
new DataView(buffer).setFloat32(0, out, true);
|
|
1579
|
-
return new Uint8Array(buffer);
|
|
1580
|
-
}
|
|
1581
|
-
if (typeof out === "bigint") {
|
|
1582
|
-
const buffer = /* @__PURE__ */ new ArrayBuffer(8);
|
|
1583
|
-
new DataView(buffer).setBigInt64(0, out, true);
|
|
1584
|
-
return new Uint8Array(buffer);
|
|
1585
|
-
}
|
|
1586
|
-
}
|
|
1587
|
-
if (type === "BYTE_ARRAY" || type === "FIXED_LEN_BYTE_ARRAY") return truncateStatistic(value instanceof Uint8Array ? value : new TextEncoder().encode(value.toString()), isMax);
|
|
1588
|
-
if (type === "FLOAT" && typeof value === "number") {
|
|
1589
|
-
const buffer = /* @__PURE__ */ new ArrayBuffer(4);
|
|
1590
|
-
new DataView(buffer).setFloat32(0, value, true);
|
|
1591
|
-
return new Uint8Array(buffer);
|
|
1592
|
-
}
|
|
1593
|
-
if (type === "DOUBLE" && typeof value === "number") {
|
|
1594
|
-
const buffer = /* @__PURE__ */ new ArrayBuffer(8);
|
|
1595
|
-
new DataView(buffer).setFloat64(0, value, true);
|
|
1596
|
-
return new Uint8Array(buffer);
|
|
1597
|
-
}
|
|
1598
|
-
if (type === "INT32" && typeof value === "number") {
|
|
1599
|
-
const buffer = /* @__PURE__ */ new ArrayBuffer(4);
|
|
1600
|
-
new DataView(buffer).setInt32(0, value, true);
|
|
1601
|
-
return new Uint8Array(buffer);
|
|
1602
|
-
}
|
|
1603
|
-
if (type === "INT64" && typeof value === "bigint") {
|
|
1604
|
-
const buffer = /* @__PURE__ */ new ArrayBuffer(8);
|
|
1605
|
-
new DataView(buffer).setBigInt64(0, value, true);
|
|
1606
|
-
return new Uint8Array(buffer);
|
|
1607
|
-
}
|
|
1608
|
-
if (type === "INT32" && converted_type === "DATE" && value instanceof Date) {
|
|
1609
|
-
const buffer = /* @__PURE__ */ new ArrayBuffer(4);
|
|
1610
|
-
new DataView(buffer).setInt32(0, Math.floor(value.getTime() / dayMillis), true);
|
|
1611
|
-
return new Uint8Array(buffer);
|
|
1612
|
-
}
|
|
1613
|
-
if (type === "INT64" && converted_type === "TIMESTAMP_MILLIS" && value instanceof Date) {
|
|
1614
|
-
const buffer = /* @__PURE__ */ new ArrayBuffer(8);
|
|
1615
|
-
new DataView(buffer).setBigInt64(0, BigInt(value.getTime()), true);
|
|
1616
|
-
return new Uint8Array(buffer);
|
|
1617
|
-
}
|
|
1618
|
-
if (type === "INT64" && converted_type === "TIMESTAMP_MICROS" && value instanceof Date) {
|
|
1619
|
-
const buffer = /* @__PURE__ */ new ArrayBuffer(8);
|
|
1620
|
-
new DataView(buffer).setBigInt64(0, BigInt(value.getTime() * 1e3), true);
|
|
1621
|
-
return new Uint8Array(buffer);
|
|
1622
|
-
}
|
|
1623
|
-
if (type === "INT64" && element.logical_type?.type === "TIMESTAMP" && value instanceof Date) {
|
|
1624
|
-
const millis = BigInt(value.getTime());
|
|
1625
|
-
const { unit } = element.logical_type;
|
|
1626
|
-
let bigintValue = millis;
|
|
1627
|
-
if (unit === "NANOS") bigintValue = millis * 1000000n;
|
|
1628
|
-
else if (unit === "MICROS") bigintValue = millis * 1000n;
|
|
1629
|
-
const buffer = /* @__PURE__ */ new ArrayBuffer(8);
|
|
1630
|
-
new DataView(buffer).setBigInt64(0, bigintValue, true);
|
|
1631
|
-
return new Uint8Array(buffer);
|
|
1632
|
-
}
|
|
1633
|
-
throw new Error(`unsupported type for statistics: ${type} with value ${value}`);
|
|
1634
|
-
}
|
|
1635
|
-
function unconvertStatistics(stats, element) {
|
|
1636
|
-
return {
|
|
1637
|
-
field_1: unconvertMinMax(stats.max, element, true),
|
|
1638
|
-
field_2: unconvertMinMax(stats.min, element, false),
|
|
1639
|
-
field_3: stats.null_count,
|
|
1640
|
-
field_4: stats.distinct_count,
|
|
1641
|
-
field_5: unconvertMinMax(stats.max_value, element, true),
|
|
1642
|
-
field_6: unconvertMinMax(stats.min_value, element, false),
|
|
1643
|
-
field_7: stats.is_max_value_exact ?? minMaxIsExact(stats.max_value ?? stats.max, element),
|
|
1644
|
-
field_8: stats.is_min_value_exact ?? minMaxIsExact(stats.min_value ?? stats.min, element)
|
|
1645
|
-
};
|
|
1646
|
-
}
|
|
1647
|
-
function unconvertDecimal({ type, type_length }, value) {
|
|
1648
|
-
if (type === "INT32") return Number(value);
|
|
1649
|
-
if (type === "INT64") return value;
|
|
1650
|
-
if (type === "FIXED_LEN_BYTE_ARRAY" && !type_length) throw new Error("fixed length byte array type_length is required");
|
|
1651
|
-
if (!type_length && !value) return /* @__PURE__ */ new Uint8Array();
|
|
1652
|
-
const bytes = [];
|
|
1653
|
-
while (true) {
|
|
1654
|
-
const byte = Number(value & 255n);
|
|
1655
|
-
bytes.unshift(byte);
|
|
1656
|
-
value >>= 8n;
|
|
1657
|
-
if (type_length) {
|
|
1658
|
-
if (bytes.length >= type_length) break;
|
|
1659
|
-
} else {
|
|
1660
|
-
const sign = byte & 128;
|
|
1661
|
-
if (!sign && value === 0n || sign && value === -1n) break;
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
return new Uint8Array(bytes);
|
|
1665
|
-
}
|
|
1666
|
-
function unconvertFloat16(value) {
|
|
1667
|
-
if (value === void 0 || value === null) return;
|
|
1668
|
-
if (typeof value !== "number") throw new Error("parquet float16 expected number value");
|
|
1669
|
-
if (Number.isNaN(value)) return new Uint8Array([0, 126]);
|
|
1670
|
-
const sign = value < 0 || Object.is(value, -0) ? 1 : 0;
|
|
1671
|
-
const abs = Math.abs(value);
|
|
1672
|
-
if (!isFinite(abs)) return new Uint8Array([0, sign << 7 | 124]);
|
|
1673
|
-
if (abs === 0) return new Uint8Array([0, sign << 7]);
|
|
1674
|
-
const buf = /* @__PURE__ */ new ArrayBuffer(4);
|
|
1675
|
-
new Float32Array(buf)[0] = abs;
|
|
1676
|
-
const bits32 = new Uint32Array(buf)[0];
|
|
1677
|
-
let exp32 = bits32 >>> 23 & 255;
|
|
1678
|
-
let mant32 = bits32 & 8388607;
|
|
1679
|
-
exp32 -= 127;
|
|
1680
|
-
if (exp32 < -14) {
|
|
1681
|
-
const shift = -14 - exp32;
|
|
1682
|
-
mant32 = (mant32 | 8388608) >> shift + 13;
|
|
1683
|
-
if (mant32 & 1) mant32 += 1;
|
|
1684
|
-
const bits16 = sign << 15 | mant32;
|
|
1685
|
-
return new Uint8Array([bits16 & 255, bits16 >> 8]);
|
|
1686
|
-
}
|
|
1687
|
-
if (exp32 > 15) return new Uint8Array([0, sign << 7 | 124]);
|
|
1688
|
-
let exp16 = exp32 + 15;
|
|
1689
|
-
mant32 = mant32 + 4096;
|
|
1690
|
-
if (mant32 & 8388608) {
|
|
1691
|
-
mant32 = 0;
|
|
1692
|
-
if (++exp16 === 31) return new Uint8Array([0, sign << 7 | 124]);
|
|
1693
|
-
}
|
|
1694
|
-
const bits16 = sign << 15 | exp16 << 10 | mant32 >> 13;
|
|
1695
|
-
return new Uint8Array([bits16 & 255, bits16 >> 8]);
|
|
1696
|
-
}
|
|
1697
|
-
function writeColumn({ writer, column, pageData }) {
|
|
1698
|
-
const { columnName, element, schemaPath, stats, pageSize, encoding: userEncoding } = column;
|
|
1699
|
-
const { type, type_length } = element;
|
|
1700
|
-
if (!type) throw new Error(`column ${columnName} cannot determine type`);
|
|
1701
|
-
const { values, definitionLevels, repetitionLevels, maxDefinitionLevel } = pageData;
|
|
1702
|
-
const offsetStart = writer.offset;
|
|
1703
|
-
const encodings = [];
|
|
1704
|
-
const isGeospatial = element?.logical_type?.type === "GEOMETRY" || element?.logical_type?.type === "GEOGRAPHY";
|
|
1705
|
-
const statistics = stats ? getStatistics(values) : void 0;
|
|
1706
|
-
const geospatial_statistics = stats && isGeospatial ? geospatialStatistics(values) : void 0;
|
|
1707
|
-
let bloomFilter;
|
|
1708
|
-
if (column.bloomFilter) {
|
|
1709
|
-
const builder = new BloomBuilder(element, typeof column.bloomFilter === "object" ? column.bloomFilter : void 0);
|
|
1710
|
-
for (const v of values) builder.insert(v);
|
|
1711
|
-
bloomFilter = builder.finalize();
|
|
1712
|
-
}
|
|
1713
|
-
let dictionary_page_offset;
|
|
1714
|
-
const { dictionary, indexes } = useDictionary(values, type, type_length, userEncoding, pageSize);
|
|
1715
|
-
let encoding;
|
|
1716
|
-
let writeValues;
|
|
1717
|
-
let writeType = type;
|
|
1718
|
-
if (dictionary && indexes) {
|
|
1719
|
-
writeValues = indexes;
|
|
1720
|
-
writeType = "INT32";
|
|
1721
|
-
encoding = "RLE_DICTIONARY";
|
|
1722
|
-
dictionary_page_offset = BigInt(writer.offset);
|
|
1723
|
-
writeDictionaryPage(writer, column, unconvert(element, dictionary));
|
|
1724
|
-
} else {
|
|
1725
|
-
writeValues = unconvert(element, values);
|
|
1726
|
-
encoding = userEncoding ?? (type === "BOOLEAN" && values.length > 16 ? "RLE" : "PLAIN");
|
|
1727
|
-
}
|
|
1728
|
-
encodings.push(encoding);
|
|
1729
|
-
const pageBoundaries = getPageBoundaries(writeValues, writeType, type_length, pageSize);
|
|
1730
|
-
const columnIndex = column.columnIndex && pageBoundaries.length > 1 ? {
|
|
1731
|
-
null_pages: [],
|
|
1732
|
-
min_values: [],
|
|
1733
|
-
max_values: [],
|
|
1734
|
-
boundary_order: "UNORDERED",
|
|
1735
|
-
null_counts: []
|
|
1736
|
-
} : void 0;
|
|
1737
|
-
const offsetIndex = column.offsetIndex && pageBoundaries.length > 1 ? { page_locations: [] } : void 0;
|
|
1738
|
-
const data_page_offset = BigInt(writer.offset);
|
|
1739
|
-
let first_row_index = 0n;
|
|
1740
|
-
let prevStart = 0;
|
|
1741
|
-
let prevMinValue;
|
|
1742
|
-
let prevMaxValue;
|
|
1743
|
-
let ascending = true;
|
|
1744
|
-
let descending = true;
|
|
1745
|
-
for (const { start, end } of pageBoundaries) {
|
|
1746
|
-
const pageOffset = writer.offset;
|
|
1747
|
-
const pageChunk = {
|
|
1748
|
-
values: writeValues.slice(start, end),
|
|
1749
|
-
definitionLevels: definitionLevels.slice(start, end),
|
|
1750
|
-
repetitionLevels: repetitionLevels.slice(start, end),
|
|
1751
|
-
maxDefinitionLevel
|
|
1752
|
-
};
|
|
1753
|
-
writeDataPageV2({
|
|
1754
|
-
writer,
|
|
1755
|
-
column,
|
|
1756
|
-
encoding,
|
|
1757
|
-
pageData: pageChunk
|
|
1758
|
-
});
|
|
1759
|
-
if (columnIndex) {
|
|
1760
|
-
const { min_value, max_value, null_count = 0n } = getStatistics(values.slice(start, end));
|
|
1761
|
-
columnIndex.null_pages.push(null_count === BigInt(end - start));
|
|
1762
|
-
columnIndex.min_values.push(unconvertMinMax(min_value, element, false) ?? /* @__PURE__ */ new Uint8Array());
|
|
1763
|
-
columnIndex.max_values.push(unconvertMinMax(max_value, element, true) ?? /* @__PURE__ */ new Uint8Array());
|
|
1764
|
-
columnIndex.null_counts?.push(null_count);
|
|
1765
|
-
if (prevMinValue !== void 0 && min_value !== void 0) {
|
|
1766
|
-
if (prevMinValue > min_value) ascending = false;
|
|
1767
|
-
if (prevMinValue < min_value) descending = false;
|
|
1768
|
-
}
|
|
1769
|
-
if (prevMaxValue !== void 0 && max_value !== void 0) {
|
|
1770
|
-
if (prevMaxValue > max_value) ascending = false;
|
|
1771
|
-
if (prevMaxValue < max_value) descending = false;
|
|
1772
|
-
}
|
|
1773
|
-
prevMinValue = min_value;
|
|
1774
|
-
prevMaxValue = max_value;
|
|
1775
|
-
}
|
|
1776
|
-
if (offsetIndex) {
|
|
1777
|
-
if (repetitionLevels.length) {
|
|
1778
|
-
for (let i = prevStart + 1; i <= start; i++) if (repetitionLevels[i] === 0) first_row_index++;
|
|
1779
|
-
} else first_row_index = BigInt(start);
|
|
1780
|
-
offsetIndex.page_locations.push({
|
|
1781
|
-
offset: BigInt(pageOffset),
|
|
1782
|
-
compressed_page_size: writer.offset - pageOffset,
|
|
1783
|
-
first_row_index
|
|
1784
|
-
});
|
|
1785
|
-
}
|
|
1786
|
-
prevStart = start;
|
|
1787
|
-
}
|
|
1788
|
-
if (columnIndex) {
|
|
1789
|
-
if (ascending) columnIndex.boundary_order = "ASCENDING";
|
|
1790
|
-
else if (descending) columnIndex.boundary_order = "DESCENDING";
|
|
1791
|
-
}
|
|
1792
|
-
let encoding_stats;
|
|
1793
|
-
if (stats) {
|
|
1794
|
-
encoding_stats = [];
|
|
1795
|
-
if (dictionary_page_offset !== void 0) encoding_stats.push({
|
|
1796
|
-
page_type: "DICTIONARY_PAGE",
|
|
1797
|
-
encoding: "PLAIN",
|
|
1798
|
-
count: 1
|
|
1799
|
-
});
|
|
1800
|
-
encoding_stats.push({
|
|
1801
|
-
page_type: "DATA_PAGE_V2",
|
|
1802
|
-
encoding,
|
|
1803
|
-
count: pageBoundaries.length
|
|
1804
|
-
});
|
|
1805
|
-
}
|
|
1806
|
-
return {
|
|
1807
|
-
chunk: {
|
|
1808
|
-
meta_data: {
|
|
1809
|
-
type,
|
|
1810
|
-
encodings,
|
|
1811
|
-
path_in_schema: schemaPath.slice(1).map((s) => s.name),
|
|
1812
|
-
codec: column.codec ?? "UNCOMPRESSED",
|
|
1813
|
-
num_values: BigInt(values.length),
|
|
1814
|
-
total_compressed_size: BigInt(writer.offset - offsetStart),
|
|
1815
|
-
total_uncompressed_size: BigInt(writer.offset - offsetStart),
|
|
1816
|
-
data_page_offset,
|
|
1817
|
-
dictionary_page_offset,
|
|
1818
|
-
statistics,
|
|
1819
|
-
encoding_stats,
|
|
1820
|
-
geospatial_statistics
|
|
1821
|
-
},
|
|
1822
|
-
file_offset: BigInt(offsetStart)
|
|
1823
|
-
},
|
|
1824
|
-
columnIndex,
|
|
1825
|
-
offsetIndex,
|
|
1826
|
-
bloomFilter
|
|
1827
|
-
};
|
|
1828
|
-
}
|
|
1829
|
-
function getPageBoundaries(values, type, type_length, pageSize) {
|
|
1830
|
-
if (!pageSize) return [{
|
|
1831
|
-
start: 0,
|
|
1832
|
-
end: values.length
|
|
1833
|
-
}];
|
|
1834
|
-
const boundaries = [];
|
|
1835
|
-
let start = 0;
|
|
1836
|
-
let accumulatedBytes = 0;
|
|
1837
|
-
for (let i = 0; i < values.length; i++) {
|
|
1838
|
-
const valueSize = estimateValueSize(values[i], type, type_length);
|
|
1839
|
-
accumulatedBytes += valueSize;
|
|
1840
|
-
if (accumulatedBytes >= pageSize && i > start) {
|
|
1841
|
-
boundaries.push({
|
|
1842
|
-
start,
|
|
1843
|
-
end: i
|
|
1844
|
-
});
|
|
1845
|
-
start = i;
|
|
1846
|
-
accumulatedBytes = valueSize;
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
if (start < values.length) boundaries.push({
|
|
1850
|
-
start,
|
|
1851
|
-
end: values.length
|
|
1852
|
-
});
|
|
1853
|
-
return boundaries;
|
|
1854
|
-
}
|
|
1855
|
-
function getStatistics(values) {
|
|
1856
|
-
let min_value = void 0;
|
|
1857
|
-
let max_value = void 0;
|
|
1858
|
-
let null_count = 0n;
|
|
1859
|
-
for (const value of values) {
|
|
1860
|
-
if (value === null || value === void 0) {
|
|
1861
|
-
null_count++;
|
|
1862
|
-
continue;
|
|
1863
|
-
}
|
|
1864
|
-
if (typeof value === "object") continue;
|
|
1865
|
-
if (typeof value === "number" && Number.isNaN(value)) continue;
|
|
1866
|
-
if (min_value === void 0 || value < min_value) min_value = value;
|
|
1867
|
-
if (max_value === void 0 || value > max_value) max_value = value;
|
|
1868
|
-
}
|
|
1869
|
-
if (min_value === 0) min_value = -0;
|
|
1870
|
-
if (max_value === 0) max_value = 0;
|
|
1871
|
-
return {
|
|
1872
|
-
min_value,
|
|
1873
|
-
max_value,
|
|
1874
|
-
null_count
|
|
1875
|
-
};
|
|
1876
|
-
}
|
|
1877
|
-
function encodeNestedValues(treePath, rows) {
|
|
1878
|
-
const schemaPath = treePath.map((n) => n.element);
|
|
1879
|
-
if (treePath.length < 2) throw new Error("parquet schema path must include column");
|
|
1880
|
-
const definitionLevels = [];
|
|
1881
|
-
const repetitionLevels = [];
|
|
1882
|
-
const maxDefinitionLevel = getMaxDefinitionLevel(treePath);
|
|
1883
|
-
if (treePath.length === 2 && maxDefinitionLevel === 0) return {
|
|
1884
|
-
values: rows,
|
|
1885
|
-
definitionLevels,
|
|
1886
|
-
repetitionLevels,
|
|
1887
|
-
maxDefinitionLevel
|
|
1888
|
-
};
|
|
1889
|
-
if (treePath.length === 2 && maxDefinitionLevel === 1) {
|
|
1890
|
-
const definitionLevels = new Array(rows.length);
|
|
1891
|
-
for (let i = 0; i < rows.length; i++) definitionLevels[i] = rows[i] === null || rows[i] === void 0 ? 0 : 1;
|
|
1892
|
-
return {
|
|
1893
|
-
values: rows,
|
|
1894
|
-
definitionLevels,
|
|
1895
|
-
repetitionLevels,
|
|
1896
|
-
maxDefinitionLevel
|
|
1897
|
-
};
|
|
1898
|
-
}
|
|
1899
|
-
const repLevelPrior = new Array(treePath.length);
|
|
1900
|
-
let repeatedCount = 0;
|
|
1901
|
-
for (let i = 0; i < treePath.length; i++) {
|
|
1902
|
-
repLevelPrior[i] = repeatedCount;
|
|
1903
|
-
if (schemaPath[i].repetition_type === "REPEATED") repeatedCount++;
|
|
1904
|
-
}
|
|
1905
|
-
const values = [];
|
|
1906
|
-
for (const row of rows) visit(1, row, 0, 0, false);
|
|
1907
|
-
return {
|
|
1908
|
-
values,
|
|
1909
|
-
definitionLevels,
|
|
1910
|
-
repetitionLevels,
|
|
1911
|
-
maxDefinitionLevel
|
|
1912
|
-
};
|
|
1913
|
-
function visit(depth, value, defLevel, repLevel, allowNull) {
|
|
1914
|
-
const element = schemaPath[depth];
|
|
1915
|
-
const repetition = element.repetition_type || "REQUIRED";
|
|
1916
|
-
if (depth === treePath.length - 1) {
|
|
1917
|
-
if (value === null || value === void 0) {
|
|
1918
|
-
if (repetition === "REQUIRED" && !allowNull) throw new Error("parquet required value is undefined");
|
|
1919
|
-
definitionLevels.push(defLevel);
|
|
1920
|
-
} else definitionLevels.push(repetition === "REQUIRED" ? defLevel : defLevel + 1);
|
|
1921
|
-
repetitionLevels.push(repLevel);
|
|
1922
|
-
values.push(value);
|
|
1923
|
-
return;
|
|
1924
|
-
}
|
|
1925
|
-
if (repetition === "REPEATED") {
|
|
1926
|
-
if (value === null || value === void 0) {
|
|
1927
|
-
if (!allowNull) throw new Error("parquet required value is undefined");
|
|
1928
|
-
visit(depth + 1, void 0, defLevel, repLevel, true);
|
|
1929
|
-
return;
|
|
1930
|
-
}
|
|
1931
|
-
if (!Array.isArray(value)) throw new Error(`parquet repeated field ${element.name} must be an array`);
|
|
1932
|
-
if (!value.length) {
|
|
1933
|
-
visit(depth + 1, void 0, defLevel, repLevel, true);
|
|
1934
|
-
return;
|
|
1935
|
-
}
|
|
1936
|
-
const isMapEntry = isMapLike(treePath[depth - 1]);
|
|
1937
|
-
const childElement = schemaPath[depth + 1];
|
|
1938
|
-
for (let i = 0; i < value.length; i++) {
|
|
1939
|
-
let childValue = value[i];
|
|
1940
|
-
if (isMapEntry && childValue && typeof childValue === "object" && childElement) childValue = childValue[childElement.name];
|
|
1941
|
-
const childRep = i === 0 ? repLevel : repLevelPrior[depth] + 1;
|
|
1942
|
-
visit(depth + 1, childValue, defLevel + 1, childRep, false);
|
|
1943
|
-
}
|
|
1944
|
-
return;
|
|
1945
|
-
}
|
|
1946
|
-
if (repetition === "OPTIONAL") {
|
|
1947
|
-
if (value === null || value === void 0) visit(depth + 1, void 0, defLevel, repLevel, true);
|
|
1948
|
-
else {
|
|
1949
|
-
const childValue = getChildValue(depth, value);
|
|
1950
|
-
const childIsNull = childValue === null || childValue === void 0;
|
|
1951
|
-
const isLogicalContainer = isListLike(treePath[depth]) || isMapLike(treePath[depth]);
|
|
1952
|
-
const nextDef = element.num_children && !element.type && !isLogicalContainer || !childIsNull ? defLevel + 1 : defLevel;
|
|
1953
|
-
visit(depth + 1, childValue, nextDef, repLevel, childIsNull);
|
|
1954
|
-
}
|
|
1955
|
-
return;
|
|
1956
|
-
}
|
|
1957
|
-
if (value === null || value === void 0) {
|
|
1958
|
-
if (!allowNull) throw new Error("parquet required value is undefined");
|
|
1959
|
-
visit(depth + 1, void 0, defLevel, repLevel, true);
|
|
1960
|
-
} else visit(depth + 1, getChildValue(depth, value), defLevel, repLevel, false);
|
|
1961
|
-
}
|
|
1962
|
-
function getChildValue(depth, currentValue) {
|
|
1963
|
-
if (currentValue === null || currentValue === void 0) return void 0;
|
|
1964
|
-
const child = schemaPath[depth + 1];
|
|
1965
|
-
if (!child) return void 0;
|
|
1966
|
-
if (isListLike(treePath[depth])) return currentValue;
|
|
1967
|
-
if (isMapLike(treePath[depth])) return normalizeMap(currentValue, schemaPath[depth]);
|
|
1968
|
-
if (typeof currentValue === "object" && !Array.isArray(currentValue)) return currentValue[child.name];
|
|
1969
|
-
throw new Error(`parquet expected struct, got ${currentValue}`);
|
|
1970
|
-
}
|
|
1971
|
-
}
|
|
1972
|
-
function normalizeMap(value, element) {
|
|
1973
|
-
if (value instanceof Map) return Array.from(value.entries(), ([k, v]) => ({
|
|
1974
|
-
key: k,
|
|
1975
|
-
value: v
|
|
1976
|
-
}));
|
|
1977
|
-
if (Array.isArray(value)) return value.map((entry) => {
|
|
1978
|
-
if (entry && typeof entry === "object" && "key" in entry && "value" in entry) return entry;
|
|
1979
|
-
if (Array.isArray(entry) && entry.length === 2) return {
|
|
1980
|
-
key: entry[0],
|
|
1981
|
-
value: entry[1]
|
|
1982
|
-
};
|
|
1983
|
-
throw new Error("parquet map entry must provide key and value");
|
|
1984
|
-
});
|
|
1985
|
-
if (typeof value === "object") return Object.entries(value).map(([k, v]) => ({
|
|
1986
|
-
key: k,
|
|
1987
|
-
value: v
|
|
1988
|
-
}));
|
|
1989
|
-
throw new Error(`parquet map field ${element.name} must be Map, array, or object`);
|
|
1990
|
-
}
|
|
1991
|
-
function writeIndexes(writer, pageIndexes) {
|
|
1992
|
-
for (const { chunk, columnIndex } of pageIndexes) writeColumnIndex(writer, chunk, columnIndex);
|
|
1993
|
-
for (const { chunk, offsetIndex } of pageIndexes) writeOffsetIndex(writer, chunk, offsetIndex);
|
|
1994
|
-
}
|
|
1995
|
-
function writeColumnIndex(writer, columnChunk, columnIndex) {
|
|
1996
|
-
if (!columnIndex || columnIndex.min_values.length <= 1) return;
|
|
1997
|
-
const columnIndexOffset = writer.offset;
|
|
1998
|
-
serializeTCompactProtocol(writer, {
|
|
1999
|
-
field_1: columnIndex.null_pages,
|
|
2000
|
-
field_2: columnIndex.min_values,
|
|
2001
|
-
field_3: columnIndex.max_values,
|
|
2002
|
-
field_4: BoundaryOrders.indexOf(columnIndex.boundary_order),
|
|
2003
|
-
field_5: columnIndex.null_counts
|
|
2004
|
-
});
|
|
2005
|
-
columnChunk.column_index_offset = BigInt(columnIndexOffset);
|
|
2006
|
-
columnChunk.column_index_length = writer.offset - columnIndexOffset;
|
|
2007
|
-
}
|
|
2008
|
-
function writeOffsetIndex(writer, columnChunk, offsetIndex) {
|
|
2009
|
-
if (!offsetIndex || offsetIndex.page_locations.length <= 1) return;
|
|
2010
|
-
const offsetIndexOffset = writer.offset;
|
|
2011
|
-
serializeTCompactProtocol(writer, { field_1: offsetIndex.page_locations.map((p) => ({
|
|
2012
|
-
field_1: p.offset,
|
|
2013
|
-
field_2: p.compressed_page_size,
|
|
2014
|
-
field_3: p.first_row_index
|
|
2015
|
-
})) });
|
|
2016
|
-
columnChunk.offset_index_offset = BigInt(offsetIndexOffset);
|
|
2017
|
-
columnChunk.offset_index_length = writer.offset - offsetIndexOffset;
|
|
2018
|
-
}
|
|
2019
|
-
function writeMetadata(writer, metadata) {
|
|
2020
|
-
const compact = {
|
|
2021
|
-
field_1: metadata.version,
|
|
2022
|
-
field_2: metadata.schema.map((element) => ({
|
|
2023
|
-
field_1: element.type && ParquetTypes.indexOf(element.type),
|
|
2024
|
-
field_2: element.type_length,
|
|
2025
|
-
field_3: element.repetition_type && FieldRepetitionTypes.indexOf(element.repetition_type),
|
|
2026
|
-
field_4: element.name,
|
|
2027
|
-
field_5: element.num_children,
|
|
2028
|
-
field_6: element.converted_type && ConvertedTypes.indexOf(element.converted_type),
|
|
2029
|
-
field_7: element.scale,
|
|
2030
|
-
field_8: element.precision,
|
|
2031
|
-
field_9: element.field_id,
|
|
2032
|
-
field_10: logicalType(element.logical_type)
|
|
2033
|
-
})),
|
|
2034
|
-
field_3: metadata.num_rows,
|
|
2035
|
-
field_4: metadata.row_groups.map((rg) => ({
|
|
2036
|
-
field_1: rg.columns.map((c) => ({
|
|
2037
|
-
field_1: c.file_path,
|
|
2038
|
-
field_2: c.file_offset,
|
|
2039
|
-
field_3: c.meta_data && {
|
|
2040
|
-
field_1: ParquetTypes.indexOf(c.meta_data.type),
|
|
2041
|
-
field_2: c.meta_data.encodings.map((e) => Encodings.indexOf(e)),
|
|
2042
|
-
field_3: c.meta_data.path_in_schema,
|
|
2043
|
-
field_4: CompressionCodecs.indexOf(c.meta_data.codec),
|
|
2044
|
-
field_5: c.meta_data.num_values,
|
|
2045
|
-
field_6: c.meta_data.total_uncompressed_size,
|
|
2046
|
-
field_7: c.meta_data.total_compressed_size,
|
|
2047
|
-
field_8: c.meta_data.key_value_metadata && c.meta_data.key_value_metadata.map((kv) => ({
|
|
2048
|
-
field_1: kv.key,
|
|
2049
|
-
field_2: kv.value
|
|
2050
|
-
})),
|
|
2051
|
-
field_9: c.meta_data.data_page_offset,
|
|
2052
|
-
field_10: c.meta_data.index_page_offset,
|
|
2053
|
-
field_11: c.meta_data.dictionary_page_offset,
|
|
2054
|
-
field_12: c.meta_data.statistics && unconvertStatistics(c.meta_data.statistics, schemaElement(metadata.schema, c.meta_data.path_in_schema)),
|
|
2055
|
-
field_13: c.meta_data.encoding_stats && c.meta_data.encoding_stats.map((es) => ({
|
|
2056
|
-
field_1: PageTypes.indexOf(es.page_type),
|
|
2057
|
-
field_2: Encodings.indexOf(es.encoding),
|
|
2058
|
-
field_3: es.count
|
|
2059
|
-
})),
|
|
2060
|
-
field_14: c.meta_data.bloom_filter_offset,
|
|
2061
|
-
field_15: c.meta_data.bloom_filter_length,
|
|
2062
|
-
field_16: c.meta_data.size_statistics && {
|
|
2063
|
-
field_1: c.meta_data.size_statistics.unencoded_byte_array_data_bytes,
|
|
2064
|
-
field_2: c.meta_data.size_statistics.repetition_level_histogram,
|
|
2065
|
-
field_3: c.meta_data.size_statistics.definition_level_histogram
|
|
2066
|
-
},
|
|
2067
|
-
field_17: c.meta_data.geospatial_statistics && {
|
|
2068
|
-
field_1: c.meta_data.geospatial_statistics.bbox && {
|
|
2069
|
-
field_1: c.meta_data.geospatial_statistics.bbox.xmin,
|
|
2070
|
-
field_2: c.meta_data.geospatial_statistics.bbox.xmax,
|
|
2071
|
-
field_3: c.meta_data.geospatial_statistics.bbox.ymin,
|
|
2072
|
-
field_4: c.meta_data.geospatial_statistics.bbox.ymax,
|
|
2073
|
-
field_5: c.meta_data.geospatial_statistics.bbox.zmin,
|
|
2074
|
-
field_6: c.meta_data.geospatial_statistics.bbox.zmax,
|
|
2075
|
-
field_7: c.meta_data.geospatial_statistics.bbox.mmin,
|
|
2076
|
-
field_8: c.meta_data.geospatial_statistics.bbox.mmax
|
|
2077
|
-
},
|
|
2078
|
-
field_2: c.meta_data.geospatial_statistics.geospatial_types
|
|
2079
|
-
}
|
|
2080
|
-
},
|
|
2081
|
-
field_4: c.offset_index_offset,
|
|
2082
|
-
field_5: c.offset_index_length,
|
|
2083
|
-
field_6: c.column_index_offset,
|
|
2084
|
-
field_7: c.column_index_length,
|
|
2085
|
-
field_9: c.encrypted_column_metadata
|
|
2086
|
-
})),
|
|
2087
|
-
field_2: rg.total_byte_size,
|
|
2088
|
-
field_3: rg.num_rows,
|
|
2089
|
-
field_4: rg.sorting_columns && rg.sorting_columns.map((sc) => ({
|
|
2090
|
-
field_1: sc.column_idx,
|
|
2091
|
-
field_2: sc.descending,
|
|
2092
|
-
field_3: sc.nulls_first
|
|
2093
|
-
})),
|
|
2094
|
-
field_5: rg.file_offset,
|
|
2095
|
-
field_6: rg.total_compressed_size
|
|
2096
|
-
})),
|
|
2097
|
-
field_5: metadata.key_value_metadata && metadata.key_value_metadata.map((kv) => ({
|
|
2098
|
-
field_1: kv.key,
|
|
2099
|
-
field_2: kv.value
|
|
2100
|
-
})),
|
|
2101
|
-
field_6: metadata.created_by
|
|
2102
|
-
};
|
|
2103
|
-
const metadataStart = writer.offset;
|
|
2104
|
-
serializeTCompactProtocol(writer, compact);
|
|
2105
|
-
const metadataLength = writer.offset - metadataStart;
|
|
2106
|
-
writer.appendUint32(metadataLength);
|
|
2107
|
-
}
|
|
2108
|
-
function schemaElement(schema, path) {
|
|
2109
|
-
const tree = getSchemaPath(schema, path);
|
|
2110
|
-
return tree[tree.length - 1].element;
|
|
2111
|
-
}
|
|
2112
|
-
function logicalType(type) {
|
|
2113
|
-
if (!type) return;
|
|
2114
|
-
if (type.type === "STRING") return { field_1: {} };
|
|
2115
|
-
if (type.type === "MAP") return { field_2: {} };
|
|
2116
|
-
if (type.type === "LIST") return { field_3: {} };
|
|
2117
|
-
if (type.type === "ENUM") return { field_4: {} };
|
|
2118
|
-
if (type.type === "DECIMAL") return { field_5: {
|
|
2119
|
-
field_1: type.scale,
|
|
2120
|
-
field_2: type.precision
|
|
2121
|
-
} };
|
|
2122
|
-
if (type.type === "DATE") return { field_6: {} };
|
|
2123
|
-
if (type.type === "TIME") return { field_7: {
|
|
2124
|
-
field_1: type.isAdjustedToUTC,
|
|
2125
|
-
field_2: timeUnit(type.unit)
|
|
2126
|
-
} };
|
|
2127
|
-
if (type.type === "TIMESTAMP") return { field_8: {
|
|
2128
|
-
field_1: type.isAdjustedToUTC,
|
|
2129
|
-
field_2: timeUnit(type.unit)
|
|
2130
|
-
} };
|
|
2131
|
-
if (type.type === "INTEGER") return { field_10: {
|
|
2132
|
-
field_1: type.bitWidth,
|
|
2133
|
-
field_2: type.isSigned
|
|
2134
|
-
} };
|
|
2135
|
-
if (type.type === "NULL") return { field_11: {} };
|
|
2136
|
-
if (type.type === "JSON") return { field_12: {} };
|
|
2137
|
-
if (type.type === "BSON") return { field_13: {} };
|
|
2138
|
-
if (type.type === "UUID") return { field_14: {} };
|
|
2139
|
-
if (type.type === "FLOAT16") return { field_15: {} };
|
|
2140
|
-
if (type.type === "VARIANT") return { field_16: {} };
|
|
2141
|
-
if (type.type === "GEOMETRY") return { field_17: { field_1: type.crs } };
|
|
2142
|
-
if (type.type === "GEOGRAPHY") return { field_18: {
|
|
2143
|
-
field_1: type.crs,
|
|
2144
|
-
field_2: type.algorithm && EdgeInterpolationAlgorithms.indexOf(type.algorithm)
|
|
2145
|
-
} };
|
|
2146
|
-
}
|
|
2147
|
-
function timeUnit(unit) {
|
|
2148
|
-
if (unit === "NANOS") return { field_3: {} };
|
|
2149
|
-
if (unit === "MICROS") return { field_2: {} };
|
|
2150
|
-
return { field_1: {} };
|
|
2151
|
-
}
|
|
2152
|
-
const BLOCK_SIZE = 65536;
|
|
2153
|
-
const MAX_HASH_TABLE_BITS = 14;
|
|
2154
|
-
const globalHashTables = new Array(15);
|
|
2155
|
-
function snappyCompress(input) {
|
|
2156
|
-
const writer = new ByteWriter();
|
|
2157
|
-
writer.appendVarInt(input.length);
|
|
2158
|
-
let pos = 0;
|
|
2159
|
-
while (pos < input.length) {
|
|
2160
|
-
const fragmentSize = Math.min(input.length - pos, BLOCK_SIZE);
|
|
2161
|
-
compressFragment(writer, input, pos, fragmentSize);
|
|
2162
|
-
pos += fragmentSize;
|
|
2163
|
-
}
|
|
2164
|
-
return writer.getBytes();
|
|
2165
|
-
}
|
|
2166
|
-
function hashFunc(key, hashFuncShift) {
|
|
2167
|
-
return key * 506832829 >>> hashFuncShift;
|
|
2168
|
-
}
|
|
2169
|
-
function load32(array, pos) {
|
|
2170
|
-
return array[pos] + (array[pos + 1] << 8) + (array[pos + 2] << 16) + (array[pos + 3] << 24);
|
|
2171
|
-
}
|
|
2172
|
-
function equals32(array, pos1, pos2) {
|
|
2173
|
-
return array[pos1] === array[pos2] && array[pos1 + 1] === array[pos2 + 1] && array[pos1 + 2] === array[pos2 + 2] && array[pos1 + 3] === array[pos2 + 3];
|
|
2174
|
-
}
|
|
2175
|
-
function emitLiteral(writer, input, ip, len) {
|
|
2176
|
-
if (len <= 60) writer.appendUint8(len - 1 << 2);
|
|
2177
|
-
else if (len < 256) {
|
|
2178
|
-
writer.appendUint8(240);
|
|
2179
|
-
writer.appendUint8(len - 1);
|
|
2180
|
-
} else {
|
|
2181
|
-
writer.appendUint8(244);
|
|
2182
|
-
writer.appendUint8(len - 1 & 255);
|
|
2183
|
-
writer.appendUint8(len - 1 >>> 8);
|
|
2184
|
-
}
|
|
2185
|
-
writer.appendBytes(input.subarray(ip, ip + len));
|
|
2186
|
-
}
|
|
2187
|
-
function emitCopyLessThan64(writer, offset, len) {
|
|
2188
|
-
if (len < 12 && offset < 2048) {
|
|
2189
|
-
writer.appendUint8(1 + (len - 4 << 2) + (offset >>> 8 << 5));
|
|
2190
|
-
writer.appendUint8(offset & 255);
|
|
2191
|
-
} else {
|
|
2192
|
-
writer.appendUint8(2 + (len - 1 << 2));
|
|
2193
|
-
writer.appendUint8(offset & 255);
|
|
2194
|
-
writer.appendUint8(offset >>> 8);
|
|
2195
|
-
}
|
|
2196
|
-
}
|
|
2197
|
-
function emitCopy(writer, offset, len) {
|
|
2198
|
-
while (len >= 68) {
|
|
2199
|
-
emitCopyLessThan64(writer, offset, 64);
|
|
2200
|
-
len -= 64;
|
|
2201
|
-
}
|
|
2202
|
-
if (len > 64) {
|
|
2203
|
-
emitCopyLessThan64(writer, offset, 60);
|
|
2204
|
-
len -= 60;
|
|
2205
|
-
}
|
|
2206
|
-
emitCopyLessThan64(writer, offset, len);
|
|
2207
|
-
}
|
|
2208
|
-
function compressFragment(writer, input, ip, inputSize) {
|
|
2209
|
-
let hashTableBits = 1;
|
|
2210
|
-
while (1 << hashTableBits <= inputSize && hashTableBits <= MAX_HASH_TABLE_BITS) hashTableBits++;
|
|
2211
|
-
hashTableBits--;
|
|
2212
|
-
const hashFuncShift = 32 - hashTableBits;
|
|
2213
|
-
globalHashTables[hashTableBits] ??= new Uint16Array(1 << hashTableBits);
|
|
2214
|
-
const hashTable = globalHashTables[hashTableBits];
|
|
2215
|
-
hashTable.fill(0);
|
|
2216
|
-
const ipEnd = ip + inputSize;
|
|
2217
|
-
let ipLimit;
|
|
2218
|
-
const baseIp = ip;
|
|
2219
|
-
let nextEmit = ip;
|
|
2220
|
-
let hash, nextHash;
|
|
2221
|
-
let nextIp, candidate, skip;
|
|
2222
|
-
let bytesBetweenHashLookups;
|
|
2223
|
-
let base, matched, offset;
|
|
2224
|
-
let prevHash, curHash;
|
|
2225
|
-
let flag = true;
|
|
2226
|
-
const INPUT_MARGIN = 15;
|
|
2227
|
-
if (inputSize >= INPUT_MARGIN) {
|
|
2228
|
-
ipLimit = ipEnd - INPUT_MARGIN;
|
|
2229
|
-
ip++;
|
|
2230
|
-
nextHash = hashFunc(load32(input, ip), hashFuncShift);
|
|
2231
|
-
while (flag) {
|
|
2232
|
-
skip = 32;
|
|
2233
|
-
nextIp = ip;
|
|
2234
|
-
do {
|
|
2235
|
-
ip = nextIp;
|
|
2236
|
-
hash = nextHash;
|
|
2237
|
-
bytesBetweenHashLookups = skip >>> 5;
|
|
2238
|
-
skip++;
|
|
2239
|
-
nextIp = ip + bytesBetweenHashLookups;
|
|
2240
|
-
if (ip > ipLimit) {
|
|
2241
|
-
flag = false;
|
|
2242
|
-
break;
|
|
2243
|
-
}
|
|
2244
|
-
nextHash = hashFunc(load32(input, nextIp), hashFuncShift);
|
|
2245
|
-
candidate = baseIp + hashTable[hash];
|
|
2246
|
-
hashTable[hash] = ip - baseIp;
|
|
2247
|
-
} while (!equals32(input, ip, candidate));
|
|
2248
|
-
if (!flag) break;
|
|
2249
|
-
emitLiteral(writer, input, nextEmit, ip - nextEmit);
|
|
2250
|
-
do {
|
|
2251
|
-
base = ip;
|
|
2252
|
-
matched = 4;
|
|
2253
|
-
while (ip + matched < ipEnd && input[ip + matched] === input[candidate + matched]) matched++;
|
|
2254
|
-
ip += matched;
|
|
2255
|
-
offset = base - candidate;
|
|
2256
|
-
emitCopy(writer, offset, matched);
|
|
2257
|
-
nextEmit = ip;
|
|
2258
|
-
if (ip >= ipLimit) {
|
|
2259
|
-
flag = false;
|
|
2260
|
-
break;
|
|
2261
|
-
}
|
|
2262
|
-
prevHash = hashFunc(load32(input, ip - 1), hashFuncShift);
|
|
2263
|
-
hashTable[prevHash] = ip - 1 - baseIp;
|
|
2264
|
-
curHash = hashFunc(load32(input, ip), hashFuncShift);
|
|
2265
|
-
candidate = baseIp + hashTable[curHash];
|
|
2266
|
-
hashTable[curHash] = ip - baseIp;
|
|
2267
|
-
} while (equals32(input, ip, candidate));
|
|
2268
|
-
if (!flag) break;
|
|
2269
|
-
ip++;
|
|
2270
|
-
nextHash = hashFunc(load32(input, ip), hashFuncShift);
|
|
2271
|
-
}
|
|
2272
|
-
}
|
|
2273
|
-
if (nextEmit < ipEnd) emitLiteral(writer, input, nextEmit, ipEnd - nextEmit);
|
|
2274
|
-
}
|
|
2275
|
-
function ParquetWriter({ writer, schema, codec = "SNAPPY", compressors, statistics = true, kvMetadata }) {
|
|
2276
|
-
this.writer = writer;
|
|
2277
|
-
this.schema = schema;
|
|
2278
|
-
this.codec = codec;
|
|
2279
|
-
this.compressors = {
|
|
2280
|
-
SNAPPY: snappyCompress,
|
|
2281
|
-
...compressors
|
|
2282
|
-
};
|
|
2283
|
-
this.statistics = statistics;
|
|
2284
|
-
this.kvMetadata = kvMetadata;
|
|
2285
|
-
this.row_groups = [];
|
|
2286
|
-
this.num_rows = 0n;
|
|
2287
|
-
this.pendingIndexes = [];
|
|
2288
|
-
this.writer.appendUint32(827474256);
|
|
2289
|
-
}
|
|
2290
|
-
ParquetWriter.prototype.write = function({ columnData, rowGroupSize = [1e3, 1e5], pageSize = 1048576 }) {
|
|
2291
|
-
const columnDataRows = columnData[0]?.data?.length || 0;
|
|
2292
|
-
let pending;
|
|
2293
|
-
for (const { groupStartIndex, groupSize } of groupIterator({
|
|
2294
|
-
columnDataRows,
|
|
2295
|
-
rowGroupSize
|
|
2296
|
-
})) {
|
|
2297
|
-
const writeGroup = () => {
|
|
2298
|
-
const groupStartOffset = this.writer.offset;
|
|
2299
|
-
const columns = [];
|
|
2300
|
-
for (let j = 0; j < columnData.length; j++) {
|
|
2301
|
-
const { name, data, encoding, codec = this.codec, columnIndex = false, offsetIndex = true, shredding, bloomFilter } = columnData[j];
|
|
2302
|
-
if (columnIndex && !offsetIndex) throw new Error("parquet ColumnIndex cannot be present without OffsetIndex");
|
|
2303
|
-
if (data.length !== columnDataRows) throw new Error("parquet columns must have the same length");
|
|
2304
|
-
const groupData = data.slice(groupStartIndex, groupStartIndex + groupSize);
|
|
2305
|
-
const columnPath = getSchemaPath(this.schema, [name]);
|
|
2306
|
-
const leafPaths = getLeafSchemaPaths(columnPath);
|
|
2307
|
-
const columnElement = columnPath.at(-1)?.element;
|
|
2308
|
-
const shreddingConfig = shredding && shredding !== true ? shredding : void 0;
|
|
2309
|
-
const isVariant = columnElement?.logical_type?.type === "VARIANT";
|
|
2310
|
-
const isRequired = columnElement?.repetition_type === "REQUIRED";
|
|
2311
|
-
const rows = isVariant ? encodeVariantColumn(Array.from(groupData), shreddingConfig, {
|
|
2312
|
-
name,
|
|
2313
|
-
required: isRequired
|
|
2314
|
-
}) : groupData;
|
|
2315
|
-
for (const leafPath of leafPaths) {
|
|
2316
|
-
const schemaPath = leafPath.map((node) => node.element);
|
|
2317
|
-
const column = {
|
|
2318
|
-
columnName: schemaPath.slice(1).map((s) => s.name).join("."),
|
|
2319
|
-
element: schemaPath[schemaPath.length - 1],
|
|
2320
|
-
schemaPath,
|
|
2321
|
-
codec,
|
|
2322
|
-
compressors: this.compressors,
|
|
2323
|
-
stats: this.statistics,
|
|
2324
|
-
pageSize,
|
|
2325
|
-
columnIndex,
|
|
2326
|
-
offsetIndex,
|
|
2327
|
-
encoding,
|
|
2328
|
-
bloomFilter
|
|
2329
|
-
};
|
|
2330
|
-
const pageData = encodeNestedValues(leafPath, rows);
|
|
2331
|
-
const result = writeColumn({
|
|
2332
|
-
writer: this.writer,
|
|
2333
|
-
column,
|
|
2334
|
-
pageData
|
|
2335
|
-
});
|
|
2336
|
-
columns.push(result.chunk);
|
|
2337
|
-
this.pendingIndexes.push(result);
|
|
2338
|
-
}
|
|
2339
|
-
}
|
|
2340
|
-
this.num_rows += BigInt(groupSize);
|
|
2341
|
-
this.row_groups.push({
|
|
2342
|
-
columns,
|
|
2343
|
-
total_byte_size: BigInt(this.writer.offset - groupStartOffset),
|
|
2344
|
-
num_rows: BigInt(groupSize)
|
|
2345
|
-
});
|
|
2346
|
-
return this.writer.flush?.();
|
|
2347
|
-
};
|
|
2348
|
-
if (pending) pending = pending.then(writeGroup);
|
|
2349
|
-
else {
|
|
2350
|
-
const r = writeGroup();
|
|
2351
|
-
if (r) pending = Promise.resolve(r);
|
|
2352
|
-
}
|
|
2353
|
-
}
|
|
2354
|
-
return pending;
|
|
2355
|
-
};
|
|
2356
|
-
ParquetWriter.prototype.finish = function() {
|
|
2357
|
-
writeIndexes(this.writer, this.pendingIndexes);
|
|
2358
|
-
writeBlooms(this.writer, this.pendingIndexes);
|
|
2359
|
-
const metadata = {
|
|
2360
|
-
version: 2,
|
|
2361
|
-
created_by: "hyparquet",
|
|
2362
|
-
schema: this.schema,
|
|
2363
|
-
num_rows: this.num_rows,
|
|
2364
|
-
row_groups: this.row_groups,
|
|
2365
|
-
metadata_length: 0,
|
|
2366
|
-
key_value_metadata: this.kvMetadata
|
|
2367
|
-
};
|
|
2368
|
-
delete metadata.metadata_length;
|
|
2369
|
-
writeMetadata(this.writer, metadata);
|
|
2370
|
-
this.writer.appendUint32(827474256);
|
|
2371
|
-
return this.writer.finish();
|
|
2372
|
-
};
|
|
2373
|
-
function groupSize(rowGroupSize, i) {
|
|
2374
|
-
return Array.isArray(rowGroupSize) ? rowGroupSize[Math.min(i, rowGroupSize.length - 1)] : rowGroupSize;
|
|
2375
|
-
}
|
|
2376
|
-
function groupIterator({ columnDataRows, rowGroupSize }) {
|
|
2377
|
-
if (Array.isArray(rowGroupSize) && !rowGroupSize.length) throw new Error("rowGroupSize array cannot be empty");
|
|
2378
|
-
const groups = [];
|
|
2379
|
-
let groupIndex = 0;
|
|
2380
|
-
let groupStartIndex = 0;
|
|
2381
|
-
while (groupStartIndex < columnDataRows) {
|
|
2382
|
-
const size = groupSize(rowGroupSize, groupIndex);
|
|
2383
|
-
groups.push({
|
|
2384
|
-
groupStartIndex,
|
|
2385
|
-
groupSize: Math.min(size, columnDataRows - groupStartIndex)
|
|
2386
|
-
});
|
|
2387
|
-
groupStartIndex += size;
|
|
2388
|
-
groupIndex++;
|
|
2389
|
-
}
|
|
2390
|
-
return groups;
|
|
2391
|
-
}
|
|
2392
|
-
function getLeafSchemaPaths(schemaPath) {
|
|
2393
|
-
const leaves = [];
|
|
2394
|
-
dfs(schemaPath);
|
|
2395
|
-
return leaves;
|
|
2396
|
-
function dfs(path) {
|
|
2397
|
-
const node = path[path.length - 1];
|
|
2398
|
-
if (!node.children.length) {
|
|
2399
|
-
leaves.push(path);
|
|
2400
|
-
return;
|
|
2401
|
-
}
|
|
2402
|
-
for (const child of node.children) dfs([...path, child]);
|
|
2403
|
-
}
|
|
2404
|
-
}
|
|
2405
|
-
function parquetWriteRows({ writer, rows, columns, schema, rowGroupSize = [1e3, 1e5], pageSize, ...options }) {
|
|
2406
|
-
if (!Array.isArray(columns) || columns.length === 0) throw new Error("parquetWriteRows requires a non-empty columns array");
|
|
2407
|
-
const isArray = Array.isArray(rows);
|
|
2408
|
-
const source = rows;
|
|
2409
|
-
const isAsync = !isArray && source && typeof source[Symbol.asyncIterator] === "function";
|
|
2410
|
-
const isSync = !isArray && source && typeof source[Symbol.iterator] === "function";
|
|
2411
|
-
if (!isArray && !isAsync && !isSync) throw new Error("parquetWriteRows expects a rows array, iterable, or async iterable");
|
|
2412
|
-
if (Array.isArray(rowGroupSize) && !rowGroupSize.length) throw new Error("rowGroupSize array cannot be empty");
|
|
2413
|
-
const fields = columns.map((s) => s.name);
|
|
2414
|
-
let pq;
|
|
2415
|
-
function* windows() {
|
|
2416
|
-
if (isArray) {
|
|
2417
|
-
let i = 0;
|
|
2418
|
-
let g = 0;
|
|
2419
|
-
while (i < rows.length) {
|
|
2420
|
-
const size = Math.min(groupSize(rowGroupSize, g++), rows.length - i);
|
|
2421
|
-
yield {
|
|
2422
|
-
src: rows,
|
|
2423
|
-
start: i,
|
|
2424
|
-
size
|
|
2425
|
-
};
|
|
2426
|
-
i += size;
|
|
2427
|
-
}
|
|
2428
|
-
} else {
|
|
2429
|
-
let batch = [];
|
|
2430
|
-
let g = 0;
|
|
2431
|
-
let target = groupSize(rowGroupSize, 0);
|
|
2432
|
-
for (const row of source) {
|
|
2433
|
-
batch.push(row);
|
|
2434
|
-
if (batch.length >= target) {
|
|
2435
|
-
yield {
|
|
2436
|
-
src: batch,
|
|
2437
|
-
start: 0,
|
|
2438
|
-
size: batch.length
|
|
2439
|
-
};
|
|
2440
|
-
batch = [];
|
|
2441
|
-
target = groupSize(rowGroupSize, ++g);
|
|
2442
|
-
}
|
|
2443
|
-
}
|
|
2444
|
-
if (batch.length) yield {
|
|
2445
|
-
src: batch,
|
|
2446
|
-
start: 0,
|
|
2447
|
-
size: batch.length
|
|
2448
|
-
};
|
|
2449
|
-
}
|
|
2450
|
-
}
|
|
2451
|
-
function writeWindow(src, start, size) {
|
|
2452
|
-
const cols = transposeWindow(src, fields, start, size);
|
|
2453
|
-
const columnData = columns.map((spec, c) => ({
|
|
2454
|
-
...spec,
|
|
2455
|
-
data: cols[c]
|
|
2456
|
-
}));
|
|
2457
|
-
if (!pq) pq = new ParquetWriter({
|
|
2458
|
-
writer,
|
|
2459
|
-
schema: schema ?? schemaFromColumnData({ columnData }),
|
|
2460
|
-
...options
|
|
2461
|
-
});
|
|
2462
|
-
return pq.write({
|
|
2463
|
-
columnData,
|
|
2464
|
-
rowGroupSize: size,
|
|
2465
|
-
pageSize
|
|
2466
|
-
});
|
|
2467
|
-
}
|
|
2468
|
-
const it = windows();
|
|
2469
|
-
function drain() {
|
|
2470
|
-
for (let next = it.next(); !next.done; next = it.next()) {
|
|
2471
|
-
const { src, start, size } = next.value;
|
|
2472
|
-
const r = writeWindow(src, start, size);
|
|
2473
|
-
if (r) return r.then(drain);
|
|
2474
|
-
}
|
|
2475
|
-
}
|
|
2476
|
-
async function drainAsync() {
|
|
2477
|
-
let batch = [];
|
|
2478
|
-
let g = 0;
|
|
2479
|
-
let target = groupSize(rowGroupSize, 0);
|
|
2480
|
-
for await (const row of source) {
|
|
2481
|
-
batch.push(row);
|
|
2482
|
-
if (batch.length >= target) {
|
|
2483
|
-
await writeWindow(batch, 0, batch.length);
|
|
2484
|
-
batch = [];
|
|
2485
|
-
target = groupSize(rowGroupSize, ++g);
|
|
2486
|
-
}
|
|
2487
|
-
}
|
|
2488
|
-
if (batch.length) await writeWindow(batch, 0, batch.length);
|
|
2489
|
-
}
|
|
2490
|
-
function finish() {
|
|
2491
|
-
if (!pq) {
|
|
2492
|
-
const columnData = columns.map((spec) => ({
|
|
2493
|
-
...spec,
|
|
2494
|
-
data: []
|
|
2495
|
-
}));
|
|
2496
|
-
pq = new ParquetWriter({
|
|
2497
|
-
writer,
|
|
2498
|
-
schema: schema ?? schemaFromColumnData({ columnData }),
|
|
2499
|
-
...options
|
|
2500
|
-
});
|
|
2501
|
-
const w = pq.write({
|
|
2502
|
-
columnData,
|
|
2503
|
-
rowGroupSize,
|
|
2504
|
-
pageSize
|
|
2505
|
-
});
|
|
2506
|
-
if (w) return w.then(() => pq?.finish());
|
|
2507
|
-
}
|
|
2508
|
-
return pq?.finish();
|
|
2509
|
-
}
|
|
2510
|
-
if (isAsync) return drainAsync().then(finish);
|
|
2511
|
-
const drained = drain();
|
|
2512
|
-
return drained ? drained.then(finish) : finish();
|
|
2513
|
-
}
|
|
2514
|
-
function transposeWindow(rows, fields, start, size) {
|
|
2515
|
-
const width = fields.length;
|
|
2516
|
-
const cols = new Array(width);
|
|
2517
|
-
for (let c = 0; c < width; c++) cols[c] = new Array(size);
|
|
2518
|
-
for (let k = 0; k < size; k++) {
|
|
2519
|
-
const row = rows[start + k];
|
|
2520
|
-
for (let c = 0; c < width; c++) cols[c][k] = row[fields[c]];
|
|
2521
|
-
}
|
|
2522
|
-
return cols;
|
|
2523
|
-
}
|
|
2524
|
-
export { ByteWriter, parquetWriteRows };
|