@loaders.gl/parquet 5.0.0-alpha.1 → 5.0.0-alpha.2
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/LICENSE +14 -3
- package/dist/bundled.d.ts +6 -3
- package/dist/bundled.d.ts.map +1 -1
- package/dist/bundled.js +5 -2
- package/dist/bundled.js.map +1 -1
- package/dist/geoparquet-loader-with-parser.d.ts +0 -1
- package/dist/geoparquet-loader-with-parser.d.ts.map +1 -1
- package/dist/geoparquet-loader-with-parser.js +1 -1
- package/dist/geoparquet-loader-with-parser.js.map +1 -1
- package/dist/geoparquet-loader.d.ts +0 -2
- package/dist/geoparquet-loader.d.ts.map +1 -1
- package/dist/geoparquet-loader.js +1 -1
- package/dist/index.cjs +27979 -7118
- package/dist/index.cjs.map +3 -4
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/arrow/convert-columns-to-row-group.js +3 -0
- package/dist/lib/arrow/convert-columns-to-row-group.js.map +1 -1
- package/dist/lib/arrow/convert-schema-from-parquet.d.ts.map +1 -1
- package/dist/lib/arrow/convert-schema-from-parquet.js +86 -26
- package/dist/lib/arrow/convert-schema-from-parquet.js.map +1 -1
- package/dist/lib/arrow/convert-schema-to-parquet.d.ts.map +1 -1
- package/dist/lib/arrow/convert-schema-to-parquet.js +16 -7
- package/dist/lib/arrow/convert-schema-to-parquet.js.map +1 -1
- package/dist/lib/arrow/create-nested-arrow-vector.d.ts +8 -0
- package/dist/lib/arrow/create-nested-arrow-vector.d.ts.map +1 -0
- package/dist/lib/arrow/create-nested-arrow-vector.js +396 -0
- package/dist/lib/arrow/create-nested-arrow-vector.js.map +1 -0
- package/dist/lib/constants.d.ts +0 -1
- package/dist/lib/constants.d.ts.map +1 -1
- package/dist/lib/constants.js +1 -2
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/encoders/encode-arrow-to-parquet.js.map +1 -1
- package/dist/lib/encoders/encode-table-to-parquet-js.js +59 -9
- package/dist/lib/encoders/encode-table-to-parquet-js.js.map +1 -1
- package/dist/lib/geo/geospatial-metadata.d.ts.map +1 -1
- package/dist/lib/geo/geospatial-metadata.js +7 -26
- package/dist/lib/geo/geospatial-metadata.js.map +1 -1
- package/dist/lib/parquet-page-index.d.ts +62 -0
- package/dist/lib/parquet-page-index.d.ts.map +1 -0
- package/dist/lib/parquet-page-index.js +377 -0
- package/dist/lib/parquet-page-index.js.map +1 -0
- package/dist/lib/parquet-predicate.d.ts +17 -0
- package/dist/lib/parquet-predicate.d.ts.map +1 -0
- package/dist/lib/parquet-predicate.js +300 -0
- package/dist/lib/parquet-predicate.js.map +1 -0
- package/dist/lib/parquet-source-worker-client.d.ts +6 -0
- package/dist/lib/parquet-source-worker-client.d.ts.map +1 -0
- package/dist/lib/parquet-source-worker-client.js +22 -0
- package/dist/lib/parquet-source-worker-client.js.map +1 -0
- package/dist/lib/parquet-source-worker-decoder.d.ts +4 -0
- package/dist/lib/parquet-source-worker-decoder.d.ts.map +1 -0
- package/dist/lib/parquet-source-worker-decoder.js +115 -0
- package/dist/lib/parquet-source-worker-decoder.js.map +1 -0
- package/dist/lib/parquet-source-worker-file.d.ts +24 -0
- package/dist/lib/parquet-source-worker-file.d.ts.map +1 -0
- package/dist/lib/parquet-source-worker-file.js +40 -0
- package/dist/lib/parquet-source-worker-file.js.map +1 -0
- package/dist/lib/parquet-source-worker-types.d.ts +97 -0
- package/dist/lib/parquet-source-worker-types.d.ts.map +1 -0
- package/dist/lib/parquet-source-worker-types.js +5 -0
- package/dist/lib/parquet-source-worker-types.js.map +1 -0
- package/dist/lib/parquet-worker-transport.d.ts +8 -0
- package/dist/lib/parquet-worker-transport.d.ts.map +1 -0
- package/dist/lib/parquet-worker-transport.js +40 -0
- package/dist/lib/parquet-worker-transport.js.map +1 -0
- package/dist/lib/parsers/convert-parquet-tables.d.ts +16 -0
- package/dist/lib/parsers/convert-parquet-tables.d.ts.map +1 -0
- package/dist/lib/parsers/convert-parquet-tables.js +30 -0
- package/dist/lib/parsers/convert-parquet-tables.js.map +1 -0
- package/dist/lib/parsers/parse-parquet-tables.d.ts +1 -14
- package/dist/lib/parsers/parse-parquet-tables.d.ts.map +1 -1
- package/dist/lib/parsers/parse-parquet-tables.js +4 -55
- package/dist/lib/parsers/parse-parquet-tables.js.map +1 -1
- package/dist/lib/parsers/parse-parquet-to-arrow-js.d.ts +16 -3
- package/dist/lib/parsers/parse-parquet-to-arrow-js.d.ts.map +1 -1
- package/dist/lib/parsers/parse-parquet-to-arrow-js.js +599 -14
- package/dist/lib/parsers/parse-parquet-to-arrow-js.js.map +1 -1
- package/dist/lib/parsers/parse-parquet-to-json.d.ts +3 -3
- package/dist/lib/parsers/parse-parquet-to-json.d.ts.map +1 -1
- package/dist/lib/parsers/parse-parquet-to-json.js.map +1 -1
- package/dist/lib/sources/parquet-range-file.d.ts +80 -0
- package/dist/lib/sources/parquet-range-file.d.ts.map +1 -0
- package/dist/lib/sources/parquet-range-file.js +261 -0
- package/dist/lib/sources/parquet-range-file.js.map +1 -0
- package/dist/lib/sources/single-batch-queue.d.ts +24 -0
- package/dist/lib/sources/single-batch-queue.d.ts.map +1 -0
- package/dist/lib/sources/single-batch-queue.js +91 -0
- package/dist/lib/sources/single-batch-queue.js.map +1 -0
- package/dist/lib/utils/load-wasm-node.d.ts +3 -0
- package/dist/lib/utils/load-wasm-node.d.ts.map +1 -0
- package/dist/lib/utils/load-wasm-node.js +23 -0
- package/dist/lib/utils/load-wasm-node.js.map +1 -0
- package/dist/lib/utils/load-wasm.d.ts.map +1 -1
- package/dist/lib/utils/load-wasm.js +23 -7
- package/dist/lib/utils/load-wasm.js.map +1 -1
- package/dist/lib/utils/make-stream-iterator.d.ts +2 -0
- package/dist/lib/utils/make-stream-iterator.d.ts.map +1 -1
- package/dist/lib/utils/make-stream-iterator.js +124 -15
- package/dist/lib/utils/make-stream-iterator.js.map +1 -1
- package/dist/parquet-dataset-source.cjs +26413 -0
- package/dist/parquet-dataset-source.cjs.map +6 -0
- package/dist/parquet-dataset-source.d.ts +54 -0
- package/dist/parquet-dataset-source.d.ts.map +1 -0
- package/dist/parquet-dataset-source.js +380 -0
- package/dist/parquet-dataset-source.js.map +1 -0
- package/dist/parquet-js-loader-types.d.ts +57 -0
- package/dist/parquet-js-loader-types.d.ts.map +1 -0
- package/dist/parquet-js-loader-types.js +33 -0
- package/dist/parquet-js-loader-types.js.map +1 -0
- package/dist/parquet-js-loader.d.ts +12 -37
- package/dist/parquet-js-loader.d.ts.map +1 -1
- package/dist/parquet-js-loader.js +46 -21
- package/dist/parquet-js-loader.js.map +1 -1
- package/dist/parquet-js-writer.d.ts +10 -0
- package/dist/parquet-js-writer.d.ts.map +1 -1
- package/dist/parquet-js-writer.js +1 -1
- package/dist/parquet-js-writer.js.map +1 -1
- package/dist/parquet-loader-base.d.ts +25 -0
- package/dist/parquet-loader-base.d.ts.map +1 -0
- package/dist/parquet-loader-base.js +23 -0
- package/dist/parquet-loader-base.js.map +1 -0
- package/dist/parquet-loader-options.d.ts +6 -18
- package/dist/parquet-loader-options.d.ts.map +1 -1
- package/dist/parquet-loader-options.js +0 -1
- package/dist/parquet-loader-options.js.map +1 -1
- package/dist/parquet-loader-types.d.ts +61 -0
- package/dist/parquet-loader-types.d.ts.map +1 -0
- package/dist/parquet-loader-types.js +17 -0
- package/dist/parquet-loader-types.js.map +1 -0
- package/dist/parquet-loader.d.ts +17 -37
- package/dist/parquet-loader.d.ts.map +1 -1
- package/dist/parquet-loader.js +59 -44
- package/dist/parquet-loader.js.map +1 -1
- package/dist/parquet-source-capabilities.d.ts +36 -0
- package/dist/parquet-source-capabilities.d.ts.map +1 -0
- package/dist/parquet-source-capabilities.js +22 -0
- package/dist/parquet-source-capabilities.js.map +1 -0
- package/dist/parquet-source-loader-types.d.ts +72 -0
- package/dist/parquet-source-loader-types.d.ts.map +1 -0
- package/dist/parquet-source-loader-types.js +74 -0
- package/dist/parquet-source-loader-types.js.map +1 -0
- package/dist/parquet-source-loader.cjs +25975 -0
- package/dist/parquet-source-loader.cjs.map +6 -0
- package/dist/parquet-source-loader.d.ts +120 -0
- package/dist/parquet-source-loader.d.ts.map +1 -0
- package/dist/parquet-source-loader.js +812 -0
- package/dist/parquet-source-loader.js.map +1 -0
- package/dist/parquet-source-types.d.ts +384 -0
- package/dist/parquet-source-types.d.ts.map +1 -0
- package/dist/parquet-source-types.js +5 -0
- package/dist/parquet-source-types.js.map +1 -0
- package/dist/parquet-source-worker-url.d.ts +3 -0
- package/dist/parquet-source-worker-url.d.ts.map +1 -0
- package/dist/parquet-source-worker-url.js +22 -0
- package/dist/parquet-source-worker-url.js.map +1 -0
- package/dist/parquet-source-worker.js +38491 -0
- package/dist/parquet-source-worker.js.map +7 -0
- package/dist/parquet-worker-node.cjs +54779 -0
- package/dist/parquet-worker-node.cjs.map +7 -0
- package/dist/parquet-worker-url.d.ts +3 -0
- package/dist/parquet-worker-url.d.ts.map +1 -0
- package/dist/parquet-worker-url.js +15 -0
- package/dist/parquet-worker-url.js.map +1 -0
- package/dist/parquet-worker.js +19920 -0
- package/dist/parquet-worker.js.map +7 -0
- package/dist/parquet-writer.d.ts.map +1 -1
- package/dist/parquet-writer.js +2 -4
- package/dist/parquet-writer.js.map +1 -1
- package/dist/parquet_wasm_bg.wasm +0 -0
- package/dist/parquetjs/codecs/byte-stream-split.d.ts +9 -0
- package/dist/parquetjs/codecs/byte-stream-split.d.ts.map +1 -0
- package/dist/parquetjs/codecs/byte-stream-split.js +159 -0
- package/dist/parquetjs/codecs/byte-stream-split.js.map +1 -0
- package/dist/parquetjs/codecs/declare.d.ts +18 -1
- package/dist/parquetjs/codecs/declare.d.ts.map +1 -1
- package/dist/parquetjs/codecs/declare.js +7 -1
- package/dist/parquetjs/codecs/declare.js.map +1 -1
- package/dist/parquetjs/codecs/delta.d.ts +17 -0
- package/dist/parquetjs/codecs/delta.d.ts.map +1 -0
- package/dist/parquetjs/codecs/delta.js +439 -0
- package/dist/parquetjs/codecs/delta.js.map +1 -0
- package/dist/parquetjs/codecs/dictionary.d.ts +5 -2
- package/dist/parquetjs/codecs/dictionary.d.ts.map +1 -1
- package/dist/parquetjs/codecs/dictionary.js +16 -4
- package/dist/parquetjs/codecs/dictionary.js.map +1 -1
- package/dist/parquetjs/codecs/index.d.ts.map +1 -1
- package/dist/parquetjs/codecs/index.js +18 -0
- package/dist/parquetjs/codecs/index.js.map +1 -1
- package/dist/parquetjs/codecs/plain.d.ts +2 -2
- package/dist/parquetjs/codecs/plain.d.ts.map +1 -1
- package/dist/parquetjs/codecs/plain.js +62 -45
- package/dist/parquetjs/codecs/plain.js.map +1 -1
- package/dist/parquetjs/codecs/rle.d.ts +2 -2
- package/dist/parquetjs/codecs/rle.d.ts.map +1 -1
- package/dist/parquetjs/codecs/rle.js +184 -51
- package/dist/parquetjs/codecs/rle.js.map +1 -1
- package/dist/parquetjs/compression.d.ts +5 -5
- package/dist/parquetjs/compression.d.ts.map +1 -1
- package/dist/parquetjs/compression.js +97 -42
- package/dist/parquetjs/compression.js.map +1 -1
- package/dist/parquetjs/encoder/dictionary-planner.d.ts +17 -0
- package/dist/parquetjs/encoder/dictionary-planner.d.ts.map +1 -0
- package/dist/parquetjs/encoder/dictionary-planner.js +64 -0
- package/dist/parquetjs/encoder/dictionary-planner.js.map +1 -0
- package/dist/parquetjs/encoder/page-planner.d.ts +11 -0
- package/dist/parquetjs/encoder/page-planner.d.ts.map +1 -0
- package/dist/parquetjs/encoder/page-planner.js +60 -0
- package/dist/parquetjs/encoder/page-planner.js.map +1 -0
- package/dist/parquetjs/encoder/parquet-encoder.d.ts +7 -0
- package/dist/parquetjs/encoder/parquet-encoder.d.ts.map +1 -1
- package/dist/parquetjs/encoder/parquet-encoder.js +225 -23
- package/dist/parquetjs/encoder/parquet-encoder.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/BsonType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/BsonType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/BsonType.js +1 -1
- package/dist/parquetjs/parquet-thrift/BsonType.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnChunk.d.ts +2 -2
- package/dist/parquetjs/parquet-thrift/ColumnChunk.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnChunk.js +2 -2
- package/dist/parquetjs/parquet-thrift/ColumnChunk.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnIndex.d.ts +6 -6
- package/dist/parquetjs/parquet-thrift/ColumnIndex.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnIndex.js +2 -2
- package/dist/parquetjs/parquet-thrift/ColumnIndex.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnMetaData.d.ts +2 -2
- package/dist/parquetjs/parquet-thrift/ColumnMetaData.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnMetaData.js +2 -2
- package/dist/parquetjs/parquet-thrift/ColumnMetaData.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnOrder.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnOrder.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnOrder.js +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnOrder.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/DataPageHeader.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/DataPageHeader.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/DataPageHeader.js +1 -1
- package/dist/parquetjs/parquet-thrift/DataPageHeader.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.js +1 -1
- package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/DateType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/DateType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/DateType.js +1 -1
- package/dist/parquetjs/parquet-thrift/DateType.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/DecimalType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/DecimalType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/DecimalType.js +1 -1
- package/dist/parquetjs/parquet-thrift/DecimalType.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.js +1 -1
- package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/EdgeInterpolationAlgorithm.d.ts +8 -0
- package/dist/parquetjs/parquet-thrift/EdgeInterpolationAlgorithm.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/EdgeInterpolationAlgorithm.js +14 -0
- package/dist/parquetjs/parquet-thrift/EdgeInterpolationAlgorithm.js.map +1 -0
- package/dist/parquetjs/parquet-thrift/Encoding.d.ts +2 -1
- package/dist/parquetjs/parquet-thrift/Encoding.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/Encoding.js +1 -0
- package/dist/parquetjs/parquet-thrift/Encoding.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/EnumType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/EnumType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/EnumType.js +1 -1
- package/dist/parquetjs/parquet-thrift/EnumType.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/FileMetaData.d.ts +2 -2
- package/dist/parquetjs/parquet-thrift/FileMetaData.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/FileMetaData.js +2 -2
- package/dist/parquetjs/parquet-thrift/FileMetaData.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/Float16Type.d.ts +9 -0
- package/dist/parquetjs/parquet-thrift/Float16Type.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/Float16Type.js +27 -0
- package/dist/parquetjs/parquet-thrift/Float16Type.js.map +1 -0
- package/dist/parquetjs/parquet-thrift/GeographyType.d.ts +14 -0
- package/dist/parquetjs/parquet-thrift/GeographyType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/GeographyType.js +51 -0
- package/dist/parquetjs/parquet-thrift/GeographyType.js.map +1 -0
- package/dist/parquetjs/parquet-thrift/GeometryType.d.ts +11 -0
- package/dist/parquetjs/parquet-thrift/GeometryType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/GeometryType.js +41 -0
- package/dist/parquetjs/parquet-thrift/GeometryType.js.map +1 -0
- package/dist/parquetjs/parquet-thrift/IndexPageHeader.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/IndexPageHeader.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/IndexPageHeader.js +1 -1
- package/dist/parquetjs/parquet-thrift/IndexPageHeader.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/IntType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/IntType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/IntType.js +1 -1
- package/dist/parquetjs/parquet-thrift/IntType.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/JsonType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/JsonType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/JsonType.js +1 -1
- package/dist/parquetjs/parquet-thrift/JsonType.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/KeyValue.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/KeyValue.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/KeyValue.js +1 -1
- package/dist/parquetjs/parquet-thrift/KeyValue.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/ListType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/ListType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/ListType.js +1 -1
- package/dist/parquetjs/parquet-thrift/ListType.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/LogicalType.d.ts +17 -1
- package/dist/parquetjs/parquet-thrift/LogicalType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/LogicalType.js +97 -1
- package/dist/parquetjs/parquet-thrift/LogicalType.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/MapType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/MapType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/MapType.js +1 -1
- package/dist/parquetjs/parquet-thrift/MapType.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/MicroSeconds.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/MicroSeconds.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/MicroSeconds.js +1 -1
- package/dist/parquetjs/parquet-thrift/MicroSeconds.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/MilliSeconds.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/MilliSeconds.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/MilliSeconds.js +1 -1
- package/dist/parquetjs/parquet-thrift/MilliSeconds.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/NanoSeconds.d.ts +9 -0
- package/dist/parquetjs/parquet-thrift/NanoSeconds.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/NanoSeconds.js +27 -0
- package/dist/parquetjs/parquet-thrift/NanoSeconds.js.map +1 -0
- package/dist/parquetjs/parquet-thrift/NullType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/NullType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/NullType.js +1 -1
- package/dist/parquetjs/parquet-thrift/NullType.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/OffsetIndex.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/OffsetIndex.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/OffsetIndex.js +1 -1
- package/dist/parquetjs/parquet-thrift/OffsetIndex.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/PageEncodingStats.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/PageEncodingStats.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/PageEncodingStats.js +1 -1
- package/dist/parquetjs/parquet-thrift/PageEncodingStats.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/PageHeader.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/PageHeader.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/PageHeader.js +1 -1
- package/dist/parquetjs/parquet-thrift/PageHeader.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/PageLocation.d.ts +2 -2
- package/dist/parquetjs/parquet-thrift/PageLocation.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/PageLocation.js +2 -2
- package/dist/parquetjs/parquet-thrift/PageLocation.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/RowGroup.d.ts +2 -2
- package/dist/parquetjs/parquet-thrift/RowGroup.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/RowGroup.js +2 -2
- package/dist/parquetjs/parquet-thrift/RowGroup.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/SchemaElement.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/SchemaElement.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/SchemaElement.js +1 -1
- package/dist/parquetjs/parquet-thrift/SchemaElement.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/SortingColumn.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/SortingColumn.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/SortingColumn.js +1 -1
- package/dist/parquetjs/parquet-thrift/SortingColumn.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/Statistics.d.ts +14 -10
- package/dist/parquetjs/parquet-thrift/Statistics.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/Statistics.js +38 -2
- package/dist/parquetjs/parquet-thrift/Statistics.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/StringType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/StringType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/StringType.js +1 -1
- package/dist/parquetjs/parquet-thrift/StringType.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/TimeType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/TimeType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/TimeType.js +1 -1
- package/dist/parquetjs/parquet-thrift/TimeType.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/TimeUnit.d.ts +5 -1
- package/dist/parquetjs/parquet-thrift/TimeUnit.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/TimeUnit.js +25 -1
- package/dist/parquetjs/parquet-thrift/TimeUnit.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/TimestampType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/TimestampType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/TimestampType.js +1 -1
- package/dist/parquetjs/parquet-thrift/TimestampType.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/TypeDefinedOrder.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/TypeDefinedOrder.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/TypeDefinedOrder.js +1 -1
- package/dist/parquetjs/parquet-thrift/TypeDefinedOrder.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/UUIDType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/UUIDType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/UUIDType.js +1 -1
- package/dist/parquetjs/parquet-thrift/UUIDType.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/VariantType.d.ts +11 -0
- package/dist/parquetjs/parquet-thrift/VariantType.d.ts.map +1 -0
- package/dist/parquetjs/parquet-thrift/VariantType.js +41 -0
- package/dist/parquetjs/parquet-thrift/VariantType.js.map +1 -0
- package/dist/parquetjs/parquet-thrift/index.d.ts +6 -1
- package/dist/parquetjs/parquet-thrift/index.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/index.js +6 -1
- package/dist/parquetjs/parquet-thrift/index.js.map +1 -1
- package/dist/parquetjs/parser/decoders.d.ts +13 -2
- package/dist/parquetjs/parser/decoders.d.ts.map +1 -1
- package/dist/parquetjs/parser/decoders.js +379 -97
- package/dist/parquetjs/parser/decoders.js.map +1 -1
- package/dist/parquetjs/parser/parquet-reader.d.ts +35 -10
- package/dist/parquetjs/parser/parquet-reader.d.ts.map +1 -1
- package/dist/parquetjs/parser/parquet-reader.js +171 -51
- package/dist/parquetjs/parser/parquet-reader.js.map +1 -1
- package/dist/parquetjs/schema/declare.d.ts +61 -7
- package/dist/parquetjs/schema/declare.d.ts.map +1 -1
- package/dist/parquetjs/schema/declare.js.map +1 -1
- package/dist/parquetjs/schema/schema.d.ts +3 -0
- package/dist/parquetjs/schema/schema.d.ts.map +1 -1
- package/dist/parquetjs/schema/schema.js +21 -3
- package/dist/parquetjs/schema/schema.js.map +1 -1
- package/dist/parquetjs/schema/shred.d.ts +2 -0
- package/dist/parquetjs/schema/shred.d.ts.map +1 -1
- package/dist/parquetjs/schema/shred.js +71 -23
- package/dist/parquetjs/schema/shred.js.map +1 -1
- package/dist/parquetjs/schema/types.d.ts.map +1 -1
- package/dist/parquetjs/schema/types.js +245 -25
- package/dist/parquetjs/schema/types.js.map +1 -1
- package/dist/parquetjs/utils/binary-utils.d.ts +4 -2
- package/dist/parquetjs/utils/binary-utils.d.ts.map +1 -1
- package/dist/parquetjs/utils/binary-utils.js +6 -2
- package/dist/parquetjs/utils/binary-utils.js.map +1 -1
- package/dist/parquetjs/utils/read-utils.d.ts +10 -2
- package/dist/parquetjs/utils/read-utils.d.ts.map +1 -1
- package/dist/parquetjs/utils/read-utils.js +34 -22
- package/dist/parquetjs/utils/read-utils.js.map +1 -1
- package/dist/parquetjs/utils/thrift-runtime.d.ts +106 -0
- package/dist/parquetjs/utils/thrift-runtime.d.ts.map +1 -0
- package/dist/parquetjs/utils/thrift-runtime.js +50 -0
- package/dist/parquetjs/utils/thrift-runtime.js.map +1 -0
- package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.d.ts +1 -1
- package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.d.ts.map +1 -1
- package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.js +1 -1
- package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.js.map +1 -1
- package/dist/parquetjs/utils/uint8-array-compact-protocol.d.ts +4 -2
- package/dist/parquetjs/utils/uint8-array-compact-protocol.d.ts.map +1 -1
- package/dist/parquetjs/utils/uint8-array-compact-protocol.js +2 -2
- package/dist/parquetjs/utils/uint8-array-compact-protocol.js.map +1 -1
- package/dist/polyfills/process.d.ts +12 -0
- package/dist/polyfills/process.d.ts.map +1 -0
- package/dist/polyfills/process.js +17 -0
- package/dist/polyfills/process.js.map +1 -0
- package/dist/unbundled.d.ts +6 -3
- package/dist/unbundled.d.ts.map +1 -1
- package/dist/unbundled.js +5 -2
- package/dist/unbundled.js.map +1 -1
- package/dist/wasm.d.ts +3 -0
- package/dist/wasm.d.ts.map +1 -0
- package/dist/wasm.js +6 -0
- package/dist/wasm.js.map +1 -0
- package/dist/workers/parquet-source-worker.d.ts +2 -0
- package/dist/workers/parquet-source-worker.d.ts.map +1 -0
- package/dist/workers/parquet-source-worker.js +17 -0
- package/dist/workers/parquet-source-worker.js.map +1 -0
- package/dist/workers/parquet-worker-node.d.ts +2 -0
- package/dist/workers/parquet-worker-node.d.ts.map +1 -0
- package/dist/workers/parquet-worker-node.js +5 -0
- package/dist/workers/parquet-worker-node.js.map +1 -0
- package/dist/workers/parquet-worker.d.ts +2 -0
- package/dist/workers/parquet-worker.d.ts.map +1 -0
- package/dist/workers/parquet-worker.js +27 -0
- package/dist/workers/parquet-worker.js.map +1 -0
- package/package.json +57 -23
- package/src/bundled.ts +27 -3
- package/src/geoparquet-loader-with-parser.ts +1 -1
- package/src/index.ts +47 -3
- package/src/lib/arrow/convert-columns-to-row-group.ts +3 -0
- package/src/lib/arrow/convert-schema-from-parquet.ts +97 -30
- package/src/lib/arrow/convert-schema-to-parquet.ts +16 -7
- package/src/lib/arrow/create-nested-arrow-vector.ts +589 -0
- package/src/lib/constants.ts +0 -2
- package/src/lib/encoders/encode-arrow-to-parquet.ts +1 -1
- package/src/lib/encoders/encode-table-to-parquet-js.ts +71 -9
- package/src/lib/geo/geospatial-metadata.ts +15 -65
- package/src/lib/parquet-page-index.ts +581 -0
- package/src/lib/parquet-predicate.ts +374 -0
- package/src/lib/parquet-source-worker-client.ts +39 -0
- package/src/lib/parquet-source-worker-decoder.ts +156 -0
- package/src/lib/parquet-source-worker-file.ts +56 -0
- package/src/lib/parquet-source-worker-types.ts +107 -0
- package/src/lib/parquet-worker-transport.ts +57 -0
- package/src/lib/parsers/convert-parquet-tables.ts +39 -0
- package/src/lib/parsers/parse-parquet-tables.ts +10 -65
- package/src/lib/parsers/parse-parquet-to-arrow-js.ts +811 -18
- package/src/lib/parsers/parse-parquet-to-json.ts +4 -4
- package/src/lib/sources/parquet-range-file.ts +359 -0
- package/src/lib/sources/single-batch-queue.ts +95 -0
- package/src/lib/utils/load-wasm-node.ts +25 -0
- package/src/lib/utils/load-wasm.ts +25 -9
- package/src/lib/utils/make-stream-iterator.ts +127 -15
- package/src/parquet-dataset-source.ts +488 -0
- package/src/parquet-js-loader-types.ts +52 -0
- package/src/parquet-js-loader.ts +68 -28
- package/src/parquet-js-writer.ts +16 -0
- package/src/parquet-loader-base.ts +34 -0
- package/src/parquet-loader-options.ts +8 -20
- package/src/parquet-loader-types.ts +35 -0
- package/src/parquet-loader.ts +91 -55
- package/src/parquet-source-capabilities.ts +56 -0
- package/src/parquet-source-loader-types.ts +87 -0
- package/src/parquet-source-loader.ts +1265 -0
- package/src/parquet-source-types.ts +458 -0
- package/src/parquet-source-worker-url.ts +23 -0
- package/src/parquet-worker-url.ts +18 -0
- package/src/parquet-writer.ts +2 -4
- package/src/parquetjs/LICENSE +23 -1
- package/src/parquetjs/codecs/byte-stream-split.ts +221 -0
- package/src/parquetjs/codecs/declare.ts +33 -1
- package/src/parquetjs/codecs/delta.ts +587 -0
- package/src/parquetjs/codecs/dictionary.ts +22 -4
- package/src/parquetjs/codecs/index.ts +18 -0
- package/src/parquetjs/codecs/plain.ts +103 -55
- package/src/parquetjs/codecs/rle.ts +252 -60
- package/src/parquetjs/compression.ts +114 -52
- package/src/parquetjs/encoder/dictionary-planner.ts +99 -0
- package/src/parquetjs/encoder/page-planner.ts +83 -0
- package/src/parquetjs/encoder/parquet-encoder.ts +334 -39
- package/src/parquetjs/parquet-thrift/BsonType.ts +1 -1
- package/src/parquetjs/parquet-thrift/ColumnChunk.ts +2 -2
- package/src/parquetjs/parquet-thrift/ColumnIndex.ts +12 -12
- package/src/parquetjs/parquet-thrift/ColumnMetaData.ts +2 -2
- package/src/parquetjs/parquet-thrift/ColumnOrder.ts +1 -1
- package/src/parquetjs/parquet-thrift/DataPageHeader.ts +1 -1
- package/src/parquetjs/parquet-thrift/DataPageHeaderV2.ts +1 -1
- package/src/parquetjs/parquet-thrift/DateType.ts +1 -1
- package/src/parquetjs/parquet-thrift/DecimalType.ts +1 -1
- package/src/parquetjs/parquet-thrift/DictionaryPageHeader.ts +1 -1
- package/src/parquetjs/parquet-thrift/EdgeInterpolationAlgorithm.ts +13 -0
- package/src/parquetjs/parquet-thrift/Encoding.ts +2 -1
- package/src/parquetjs/parquet-thrift/EnumType.ts +1 -1
- package/src/parquetjs/parquet-thrift/FileMetaData.ts +2 -2
- package/src/parquetjs/parquet-thrift/Float16Type.ts +28 -0
- package/src/parquetjs/parquet-thrift/GeographyType.ts +54 -0
- package/src/parquetjs/parquet-thrift/GeometryType.ts +43 -0
- package/src/parquetjs/parquet-thrift/IndexPageHeader.ts +1 -1
- package/src/parquetjs/parquet-thrift/IntType.ts +1 -1
- package/src/parquetjs/parquet-thrift/JsonType.ts +1 -1
- package/src/parquetjs/parquet-thrift/KeyValue.ts +1 -1
- package/src/parquetjs/parquet-thrift/ListType.ts +1 -1
- package/src/parquetjs/parquet-thrift/LogicalType.ts +97 -1
- package/src/parquetjs/parquet-thrift/MapType.ts +1 -1
- package/src/parquetjs/parquet-thrift/MicroSeconds.ts +1 -1
- package/src/parquetjs/parquet-thrift/MilliSeconds.ts +1 -1
- package/src/parquetjs/parquet-thrift/NanoSeconds.ts +28 -0
- package/src/parquetjs/parquet-thrift/NullType.ts +1 -1
- package/src/parquetjs/parquet-thrift/OffsetIndex.ts +1 -1
- package/src/parquetjs/parquet-thrift/PageEncodingStats.ts +1 -1
- package/src/parquetjs/parquet-thrift/PageHeader.ts +1 -1
- package/src/parquetjs/parquet-thrift/PageLocation.ts +2 -2
- package/src/parquetjs/parquet-thrift/RowGroup.ts +2 -2
- package/src/parquetjs/parquet-thrift/SchemaElement.ts +1 -1
- package/src/parquetjs/parquet-thrift/SortingColumn.ts +1 -1
- package/src/parquetjs/parquet-thrift/Statistics.ts +50 -14
- package/src/parquetjs/parquet-thrift/StringType.ts +1 -1
- package/src/parquetjs/parquet-thrift/TimeType.ts +1 -1
- package/src/parquetjs/parquet-thrift/TimeUnit.ts +25 -1
- package/src/parquetjs/parquet-thrift/TimestampType.ts +1 -1
- package/src/parquetjs/parquet-thrift/TypeDefinedOrder.ts +1 -1
- package/src/parquetjs/parquet-thrift/UUIDType.ts +1 -1
- package/src/parquetjs/parquet-thrift/VariantType.ts +43 -0
- package/src/parquetjs/parquet-thrift/index.ts +6 -2
- package/src/parquetjs/parser/decoders.ts +485 -113
- package/src/parquetjs/parser/parquet-reader.ts +288 -60
- package/src/parquetjs/schema/declare.ts +98 -6
- package/src/parquetjs/schema/schema.ts +23 -3
- package/src/parquetjs/schema/shred.ts +112 -35
- package/src/parquetjs/schema/types.ts +256 -31
- package/src/parquetjs/utils/binary-utils.ts +8 -3
- package/src/parquetjs/utils/read-utils.ts +37 -21
- package/src/parquetjs/utils/thrift-runtime.ts +109 -0
- package/src/parquetjs/utils/uint8-array-compact-protocol-writer.ts +1 -1
- package/src/parquetjs/utils/uint8-array-compact-protocol.ts +3 -3
- package/src/polyfills/process.ts +17 -0
- package/src/unbundled.ts +27 -3
- package/src/wasm.ts +6 -0
- package/src/workers/parquet-source-worker.ts +21 -0
- package/src/workers/parquet-worker-node.ts +5 -0
- package/src/workers/parquet-worker.ts +31 -0
- package/dist/parquet-loader-with-parser.d.ts +0 -33
- package/dist/parquet-loader-with-parser.d.ts.map +0 -1
- package/dist/parquet-loader-with-parser.js +0 -40
- package/dist/parquet-loader-with-parser.js.map +0 -1
- package/dist/parquet-wasm-loader-with-parser.d.ts +0 -40
- package/dist/parquet-wasm-loader-with-parser.d.ts.map +0 -1
- package/dist/parquet-wasm-loader-with-parser.js +0 -68
- package/dist/parquet-wasm-loader-with-parser.js.map +0 -1
- package/src/parquet-loader-with-parser.ts +0 -68
- package/src/parquet-wasm-loader-with-parser.ts +0 -115
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
// Forked from https://github.com/kbajalc/parquets under MIT license
|
|
6
6
|
|
|
7
7
|
import {PARQUET_CODECS} from '../codecs/index';
|
|
8
|
+
import {isByteStreamSplitType} from '../codecs/byte-stream-split';
|
|
9
|
+
import {isDeltaEncodingType} from '../codecs/delta';
|
|
8
10
|
import {PARQUET_COMPRESSION_METHODS} from '../compression';
|
|
9
11
|
import {
|
|
10
12
|
FieldDefinition,
|
|
@@ -15,7 +17,8 @@ import {
|
|
|
15
17
|
RepetitionType,
|
|
16
18
|
SchemaDefinition
|
|
17
19
|
} from './declare';
|
|
18
|
-
import {
|
|
20
|
+
import type {ArrayType} from '@loaders.gl/schema';
|
|
21
|
+
import {materializeColumns, materializeRows, shredBuffer, shredRecord} from './shred';
|
|
19
22
|
import {PARQUET_LOGICAL_TYPES} from './types';
|
|
20
23
|
|
|
21
24
|
/**
|
|
@@ -82,6 +85,11 @@ export class ParquetSchema {
|
|
|
82
85
|
return materializeRows(this, rowGroup);
|
|
83
86
|
}
|
|
84
87
|
|
|
88
|
+
/** Materializes one decoded row group as top-level column arrays. */
|
|
89
|
+
materializeColumns(rowGroup: ParquetRowGroup): Record<string, ArrayType> {
|
|
90
|
+
return materializeColumns(this, rowGroup);
|
|
91
|
+
}
|
|
92
|
+
|
|
85
93
|
compress(type: ParquetCompression): this {
|
|
86
94
|
setCompress(this.schema, type);
|
|
87
95
|
setCompress(this.fields, type);
|
|
@@ -140,6 +148,8 @@ function buildFields(
|
|
|
140
148
|
name,
|
|
141
149
|
path: cpath,
|
|
142
150
|
key: cpath.join(),
|
|
151
|
+
logicalType: opts.logicalType,
|
|
152
|
+
fieldId: opts.fieldId,
|
|
143
153
|
repetitionType,
|
|
144
154
|
rLevelMax,
|
|
145
155
|
dLevelMax,
|
|
@@ -159,6 +169,13 @@ function buildFields(
|
|
|
159
169
|
if (!(opts.encoding in PARQUET_CODECS)) {
|
|
160
170
|
throw new Error(`unsupported parquet encoding: ${opts.encoding}`);
|
|
161
171
|
}
|
|
172
|
+
const primitiveType = opts.physicalType || typeDef.primitiveType;
|
|
173
|
+
if (opts.encoding === 'BYTE_STREAM_SPLIT' && !isByteStreamSplitType(primitiveType)) {
|
|
174
|
+
throw new Error(`BYTE_STREAM_SPLIT does not support ${primitiveType}`);
|
|
175
|
+
}
|
|
176
|
+
if (opts.encoding.startsWith('DELTA_') && !isDeltaEncodingType(opts.encoding, primitiveType)) {
|
|
177
|
+
throw new Error(`${opts.encoding} does not support ${primitiveType}`);
|
|
178
|
+
}
|
|
162
179
|
|
|
163
180
|
opts.compression = opts.compression || 'UNCOMPRESSED';
|
|
164
181
|
if (!(opts.compression in PARQUET_COMPRESSION_METHODS)) {
|
|
@@ -169,15 +186,18 @@ function buildFields(
|
|
|
169
186
|
const cpath = path.concat([name]);
|
|
170
187
|
fieldList[name] = {
|
|
171
188
|
name,
|
|
172
|
-
primitiveType
|
|
189
|
+
primitiveType,
|
|
173
190
|
originalType: typeDef.originalType,
|
|
191
|
+
logicalType: opts.logicalType,
|
|
192
|
+
fieldId: opts.fieldId,
|
|
174
193
|
path: cpath,
|
|
175
194
|
key: cpath.join(),
|
|
176
195
|
repetitionType,
|
|
177
196
|
encoding: opts.encoding,
|
|
178
197
|
compression: opts.compression,
|
|
179
198
|
typeLength: opts.typeLength || typeDef.typeLength,
|
|
180
|
-
presision: opts.presision,
|
|
199
|
+
presision: opts.precision ?? opts.presision,
|
|
200
|
+
precision: opts.precision ?? opts.presision,
|
|
181
201
|
scale: opts.scale,
|
|
182
202
|
rLevelMax,
|
|
183
203
|
dLevelMax
|
|
@@ -65,9 +65,18 @@ export function shredRecord(
|
|
|
65
65
|
}
|
|
66
66
|
rowGroup.rowCount += 1;
|
|
67
67
|
for (const field of schema.fieldList) {
|
|
68
|
-
Array.prototype.push.apply(
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
Array.prototype.push.apply(
|
|
69
|
+
rowGroup.columnData[field.key].rlevels as number[],
|
|
70
|
+
data[field.key].rlevels as number[]
|
|
71
|
+
);
|
|
72
|
+
Array.prototype.push.apply(
|
|
73
|
+
rowGroup.columnData[field.key].dlevels as number[],
|
|
74
|
+
data[field.key].dlevels as number[]
|
|
75
|
+
);
|
|
76
|
+
Array.prototype.push.apply(
|
|
77
|
+
rowGroup.columnData[field.key].values as unknown[],
|
|
78
|
+
data[field.key].values as unknown as unknown[]
|
|
79
|
+
);
|
|
71
80
|
rowGroup.columnData[field.key].count += data[field.key].count;
|
|
72
81
|
}
|
|
73
82
|
}
|
|
@@ -111,8 +120,8 @@ function shredRecordFields(
|
|
|
111
120
|
shredRecordFields(field.fields!, null!, data, rLevel, dLevel);
|
|
112
121
|
} else {
|
|
113
122
|
data[field.key].count += 1;
|
|
114
|
-
data[field.key].rlevels.push(rLevel);
|
|
115
|
-
data[field.key].dlevels.push(dLevel);
|
|
123
|
+
(data[field.key].rlevels as number[]).push(rLevel);
|
|
124
|
+
(data[field.key].dlevels as number[]).push(dLevel);
|
|
116
125
|
}
|
|
117
126
|
continue; // eslint-disable-line no-continue
|
|
118
127
|
}
|
|
@@ -124,10 +133,10 @@ function shredRecordFields(
|
|
|
124
133
|
shredRecordFields(field.fields!, values[i], data, rlvl, field.dLevelMax);
|
|
125
134
|
} else {
|
|
126
135
|
data[field.key].count += 1;
|
|
127
|
-
data[field.key].rlevels.push(rlvl);
|
|
128
|
-
data[field.key].dlevels.push(field.dLevelMax);
|
|
129
|
-
data[field.key].values.push(
|
|
130
|
-
Types.toPrimitive((field.originalType || field.primitiveType)!, values[i])
|
|
136
|
+
(data[field.key].rlevels as number[]).push(rlvl);
|
|
137
|
+
(data[field.key].dlevels as number[]).push(field.dLevelMax);
|
|
138
|
+
(data[field.key].values as unknown[]).push(
|
|
139
|
+
Types.toPrimitive((field.originalType || field.primitiveType)!, values[i], field)
|
|
131
140
|
);
|
|
132
141
|
}
|
|
133
142
|
}
|
|
@@ -154,10 +163,9 @@ function shredRecordFields(
|
|
|
154
163
|
* }
|
|
155
164
|
*/
|
|
156
165
|
export function materializeRows(schema: ParquetSchema, rowGroup: ParquetRowGroup): ParquetRow[] {
|
|
157
|
-
const rows
|
|
158
|
-
// rows = new Array(rowGroup.rowCount).fill({})'
|
|
166
|
+
const rows = new Array<ParquetRow>(rowGroup.rowCount);
|
|
159
167
|
for (let i = 0; i < rowGroup.rowCount; i++) {
|
|
160
|
-
rows
|
|
168
|
+
rows[i] = {};
|
|
161
169
|
}
|
|
162
170
|
for (const key in rowGroup.columnData) {
|
|
163
171
|
const columnData = rowGroup.columnData[key];
|
|
@@ -179,6 +187,14 @@ function materializeColumnAsRows(
|
|
|
179
187
|
const field = schema.findField(key);
|
|
180
188
|
const branch = schema.findFieldBranch(key);
|
|
181
189
|
|
|
190
|
+
if (branch.length === 1 && field.repetitionType !== 'REPEATED') {
|
|
191
|
+
materializeFlatColumnAsRows(field, columnData, rows);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const logicalType = field.originalType || field.primitiveType!;
|
|
196
|
+
const fromPrimitive = Types.PARQUET_LOGICAL_TYPES[logicalType].fromPrimitive;
|
|
197
|
+
|
|
182
198
|
// tslint:disable-next-line:prefer-array-literal
|
|
183
199
|
const rLevels: number[] = new Array(field.rLevelMax + 1).fill(0);
|
|
184
200
|
let vIndex = 0;
|
|
@@ -219,12 +235,8 @@ function materializeColumnAsRows(
|
|
|
219
235
|
|
|
220
236
|
// Leaf node - Add the value
|
|
221
237
|
if (dLevel === field.dLevelMax) {
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
field.originalType || field.primitiveType,
|
|
225
|
-
columnData.values[vIndex],
|
|
226
|
-
field
|
|
227
|
-
);
|
|
238
|
+
const primitiveValue = columnData.values[vIndex];
|
|
239
|
+
const value = fromPrimitive ? fromPrimitive(primitiveValue, field) : primitiveValue;
|
|
228
240
|
vIndex++;
|
|
229
241
|
|
|
230
242
|
switch (field.repetitionType) {
|
|
@@ -248,6 +260,35 @@ function materializeColumnAsRows(
|
|
|
248
260
|
}
|
|
249
261
|
}
|
|
250
262
|
|
|
263
|
+
/** Materializes a top-level required or optional primitive directly into row objects. */
|
|
264
|
+
function materializeFlatColumnAsRows(
|
|
265
|
+
field: ParquetField,
|
|
266
|
+
columnData: ParquetColumnChunk,
|
|
267
|
+
rows: ParquetRow[]
|
|
268
|
+
): void {
|
|
269
|
+
const logicalType = field.originalType || field.primitiveType!;
|
|
270
|
+
const fromPrimitive = Types.PARQUET_LOGICAL_TYPES[logicalType].fromPrimitive;
|
|
271
|
+
const count = Math.min(columnData.count, rows.length);
|
|
272
|
+
let valueIndex = 0;
|
|
273
|
+
|
|
274
|
+
if (field.repetitionType === 'REQUIRED' && !fromPrimitive) {
|
|
275
|
+
for (let rowIndex = 0; rowIndex < count; rowIndex++) {
|
|
276
|
+
rows[rowIndex][field.name] = columnData.values[rowIndex];
|
|
277
|
+
}
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
for (let rowIndex = 0; rowIndex < count; rowIndex++) {
|
|
282
|
+
if (columnData.dlevels[rowIndex] === field.dLevelMax) {
|
|
283
|
+
const primitiveValue = columnData.values[valueIndex];
|
|
284
|
+
rows[rowIndex][field.name] = fromPrimitive
|
|
285
|
+
? fromPrimitive(primitiveValue, field)
|
|
286
|
+
: primitiveValue;
|
|
287
|
+
valueIndex++;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
251
292
|
// Columnar export
|
|
252
293
|
|
|
253
294
|
/**
|
|
@@ -275,14 +316,30 @@ export function materializeColumns(
|
|
|
275
316
|
): Record<string, ArrayType> {
|
|
276
317
|
const columns: Record<string, ArrayType> = {};
|
|
277
318
|
for (const key in rowGroup.columnData) {
|
|
278
|
-
const
|
|
279
|
-
if (
|
|
280
|
-
|
|
319
|
+
const column = materializeColumn(schema, rowGroup, key);
|
|
320
|
+
if (column) {
|
|
321
|
+
columns[schema.findFieldBranch(key)[0].name] = column;
|
|
281
322
|
}
|
|
282
323
|
}
|
|
283
324
|
return columns;
|
|
284
325
|
}
|
|
285
326
|
|
|
327
|
+
/** Materializes one decoded Parquet column into its top-level columnar representation. */
|
|
328
|
+
export function materializeColumn(
|
|
329
|
+
schema: ParquetSchema,
|
|
330
|
+
rowGroup: ParquetRowGroup,
|
|
331
|
+
key: string
|
|
332
|
+
): ArrayType | undefined {
|
|
333
|
+
const columnData = rowGroup.columnData[key];
|
|
334
|
+
if (!columnData?.count) {
|
|
335
|
+
return undefined;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const columns: Record<string, ArrayType> = {};
|
|
339
|
+
materializeColumnAsColumnarArray(schema, columnData, rowGroup.rowCount, key, columns);
|
|
340
|
+
return columns[schema.findFieldBranch(key)[0].name];
|
|
341
|
+
}
|
|
342
|
+
|
|
286
343
|
// eslint-disable-next-line max-statements, complexity
|
|
287
344
|
function materializeColumnAsColumnarArray(
|
|
288
345
|
schema: ParquetSchema,
|
|
@@ -300,23 +357,12 @@ function materializeColumnAsColumnarArray(
|
|
|
300
357
|
|
|
301
358
|
const columnName = branch[0].name;
|
|
302
359
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
if (values.length === rowCount && branch[0].primitiveType) {
|
|
306
|
-
// if (branch[0].repetitionType === `REQUIRED`) {
|
|
307
|
-
// switch (branch[0].primitiveType) {
|
|
308
|
-
// case 'INT32': return values instanceof Int32Array ? values : new Int32Array(values);
|
|
309
|
-
// }
|
|
310
|
-
// }
|
|
311
|
-
column = values;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (column) {
|
|
315
|
-
columns[columnName] = column;
|
|
360
|
+
if (branch.length === 1 && field.repetitionType !== 'REPEATED') {
|
|
361
|
+
columns[columnName] = materializeFlatColumn(field, columnData, rowCount);
|
|
316
362
|
return;
|
|
317
363
|
}
|
|
318
364
|
|
|
319
|
-
column = new Array(rowCount);
|
|
365
|
+
const column: ArrayType = new Array(rowCount);
|
|
320
366
|
for (let i = 0; i < rowCount; i++) {
|
|
321
367
|
column[i] = {};
|
|
322
368
|
}
|
|
@@ -397,3 +443,34 @@ function materializeColumnAsColumnarArray(
|
|
|
397
443
|
}
|
|
398
444
|
}
|
|
399
445
|
}
|
|
446
|
+
|
|
447
|
+
/** Materializes a required or optional top-level primitive column with logical type conversion. */
|
|
448
|
+
function materializeFlatColumn(
|
|
449
|
+
field: ParquetField,
|
|
450
|
+
columnData: ParquetColumnChunk,
|
|
451
|
+
rowCount: number
|
|
452
|
+
): ArrayType {
|
|
453
|
+
const logicalType = field.originalType || field.primitiveType!;
|
|
454
|
+
const fromPrimitive = Types.PARQUET_LOGICAL_TYPES[logicalType].fromPrimitive;
|
|
455
|
+
const count = Math.min(columnData.count, rowCount);
|
|
456
|
+
|
|
457
|
+
if (
|
|
458
|
+
field.repetitionType === 'REQUIRED' &&
|
|
459
|
+
!fromPrimitive &&
|
|
460
|
+
count === rowCount &&
|
|
461
|
+
columnData.values.length === rowCount
|
|
462
|
+
) {
|
|
463
|
+
return columnData.values;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const column = new Array(rowCount).fill(null);
|
|
467
|
+
let valueIndex = 0;
|
|
468
|
+
for (let rowIndex = 0; rowIndex < count; rowIndex++) {
|
|
469
|
+
if (columnData.dlevels[rowIndex] === field.dLevelMax) {
|
|
470
|
+
const primitiveValue = columnData.values[valueIndex];
|
|
471
|
+
column[rowIndex] = fromPrimitive ? fromPrimitive(primitiveValue, field) : primitiveValue;
|
|
472
|
+
valueIndex++;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return column;
|
|
476
|
+
}
|
|
@@ -64,6 +64,12 @@ export const PARQUET_LOGICAL_TYPES: Record<ParquetType, ParquetTypeKit> = {
|
|
|
64
64
|
toPrimitive: toPrimitive_UTF8,
|
|
65
65
|
fromPrimitive: fromPrimitive_UTF8
|
|
66
66
|
},
|
|
67
|
+
ENUM: {
|
|
68
|
+
primitiveType: 'BYTE_ARRAY',
|
|
69
|
+
originalType: 'ENUM',
|
|
70
|
+
toPrimitive: toPrimitive_UTF8,
|
|
71
|
+
fromPrimitive: fromPrimitive_UTF8
|
|
72
|
+
},
|
|
67
73
|
TIME_MILLIS: {
|
|
68
74
|
primitiveType: 'INT32',
|
|
69
75
|
originalType: 'TIME_MILLIS',
|
|
@@ -74,6 +80,11 @@ export const PARQUET_LOGICAL_TYPES: Record<ParquetType, ParquetTypeKit> = {
|
|
|
74
80
|
originalType: 'TIME_MICROS',
|
|
75
81
|
toPrimitive: toPrimitive_TIME_MICROS
|
|
76
82
|
},
|
|
83
|
+
TIME_NANOS: {
|
|
84
|
+
primitiveType: 'INT64',
|
|
85
|
+
originalType: 'TIME_NANOS',
|
|
86
|
+
toPrimitive: toPrimitive_TIME_NANOS
|
|
87
|
+
},
|
|
77
88
|
DATE: {
|
|
78
89
|
primitiveType: 'INT32',
|
|
79
90
|
originalType: 'DATE',
|
|
@@ -92,6 +103,11 @@ export const PARQUET_LOGICAL_TYPES: Record<ParquetType, ParquetTypeKit> = {
|
|
|
92
103
|
toPrimitive: toPrimitive_TIMESTAMP_MICROS,
|
|
93
104
|
fromPrimitive: fromPrimitive_TIMESTAMP_MICROS
|
|
94
105
|
},
|
|
106
|
+
TIMESTAMP_NANOS: {
|
|
107
|
+
primitiveType: 'INT64',
|
|
108
|
+
originalType: 'TIMESTAMP_NANOS',
|
|
109
|
+
toPrimitive: toPrimitive_TIMESTAMP_NANOS
|
|
110
|
+
},
|
|
95
111
|
UINT_8: {
|
|
96
112
|
primitiveType: 'INT32',
|
|
97
113
|
originalType: 'UINT_8',
|
|
@@ -144,6 +160,39 @@ export const PARQUET_LOGICAL_TYPES: Record<ParquetType, ParquetTypeKit> = {
|
|
|
144
160
|
toPrimitive: toPrimitive_BSON,
|
|
145
161
|
fromPrimitive: fromPrimitive_BSON
|
|
146
162
|
},
|
|
163
|
+
UUID: {
|
|
164
|
+
primitiveType: 'FIXED_LEN_BYTE_ARRAY',
|
|
165
|
+
originalType: 'UUID',
|
|
166
|
+
typeLength: 16,
|
|
167
|
+
toPrimitive: toPrimitive_BYTE_ARRAY
|
|
168
|
+
},
|
|
169
|
+
FLOAT16: {
|
|
170
|
+
primitiveType: 'FIXED_LEN_BYTE_ARRAY',
|
|
171
|
+
originalType: 'FLOAT16',
|
|
172
|
+
typeLength: 2,
|
|
173
|
+
toPrimitive: toPrimitive_FLOAT16,
|
|
174
|
+
fromPrimitive: fromPrimitive_FLOAT16
|
|
175
|
+
},
|
|
176
|
+
UNKNOWN: {
|
|
177
|
+
primitiveType: 'BYTE_ARRAY',
|
|
178
|
+
originalType: 'UNKNOWN',
|
|
179
|
+
toPrimitive: toPrimitive_BYTE_ARRAY
|
|
180
|
+
},
|
|
181
|
+
VARIANT: {
|
|
182
|
+
primitiveType: 'BYTE_ARRAY',
|
|
183
|
+
originalType: 'VARIANT',
|
|
184
|
+
toPrimitive: toPrimitive_BYTE_ARRAY
|
|
185
|
+
},
|
|
186
|
+
GEOMETRY: {
|
|
187
|
+
primitiveType: 'BYTE_ARRAY',
|
|
188
|
+
originalType: 'GEOMETRY',
|
|
189
|
+
toPrimitive: toPrimitive_BYTE_ARRAY
|
|
190
|
+
},
|
|
191
|
+
GEOGRAPHY: {
|
|
192
|
+
primitiveType: 'BYTE_ARRAY',
|
|
193
|
+
originalType: 'GEOGRAPHY',
|
|
194
|
+
toPrimitive: toPrimitive_BYTE_ARRAY
|
|
195
|
+
},
|
|
147
196
|
INTERVAL: {
|
|
148
197
|
primitiveType: 'FIXED_LEN_BYTE_ARRAY',
|
|
149
198
|
originalType: 'INTERVAL',
|
|
@@ -221,6 +270,73 @@ function toPrimitive_FLOAT(value: any): number {
|
|
|
221
270
|
return v;
|
|
222
271
|
}
|
|
223
272
|
|
|
273
|
+
/** Converts a JavaScript number to the two-byte IEEE 754 binary16 representation. */
|
|
274
|
+
function toPrimitive_FLOAT16(value: unknown): Uint8Array {
|
|
275
|
+
const numberValue = Number(value);
|
|
276
|
+
if (Number.isNaN(numberValue) && !Number.isNaN(value)) {
|
|
277
|
+
throw new Error(`invalid value for FLOAT16: ${value}`);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const float32 = new Float32Array([numberValue]);
|
|
281
|
+
const bits = new Uint32Array(float32.buffer)[0];
|
|
282
|
+
const sign = (bits >>> 16) & 0x8000;
|
|
283
|
+
const exponent = (bits >>> 23) & 0xff;
|
|
284
|
+
const mantissa = bits & 0x7fffff;
|
|
285
|
+
let half: number;
|
|
286
|
+
if (exponent === 0xff) {
|
|
287
|
+
half = sign | 0x7c00 | (mantissa ? 0x0200 : 0);
|
|
288
|
+
} else {
|
|
289
|
+
const halfExponent = exponent - 127 + 15;
|
|
290
|
+
if (halfExponent >= 0x1f) {
|
|
291
|
+
half = sign | 0x7c00;
|
|
292
|
+
} else if (halfExponent <= 0) {
|
|
293
|
+
if (halfExponent < -10) {
|
|
294
|
+
half = sign;
|
|
295
|
+
} else {
|
|
296
|
+
const normalizedMantissa = mantissa | 0x800000;
|
|
297
|
+
half = sign | roundRightShiftToNearestEven(normalizedMantissa, 14 - halfExponent);
|
|
298
|
+
}
|
|
299
|
+
} else {
|
|
300
|
+
const halfMantissa = roundRightShiftToNearestEven(mantissa, 13);
|
|
301
|
+
if (halfMantissa === 0x400) {
|
|
302
|
+
const roundedExponent = halfExponent + 1;
|
|
303
|
+
half = roundedExponent >= 0x1f ? sign | 0x7c00 : sign | (roundedExponent << 10);
|
|
304
|
+
} else {
|
|
305
|
+
half = sign | (halfExponent << 10) | halfMantissa;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return new Uint8Array([half & 0xff, half >>> 8]);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** Rounds a non-negative integer right shift using IEEE round-to-nearest, ties-to-even. */
|
|
313
|
+
function roundRightShiftToNearestEven(value: number, shift: number): number {
|
|
314
|
+
const divisor = 2 ** shift;
|
|
315
|
+
const quotient = Math.floor(value / divisor);
|
|
316
|
+
const remainder = value - quotient * divisor;
|
|
317
|
+
const halfway = divisor / 2;
|
|
318
|
+
return quotient + (remainder > halfway || (remainder === halfway && quotient % 2 === 1) ? 1 : 0);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** Converts little-endian IEEE 754 binary16 bytes to a JavaScript number. */
|
|
322
|
+
function fromPrimitive_FLOAT16(value: unknown): number {
|
|
323
|
+
const bytes = toUint8Array(value as ArrayBuffer | ArrayBufferView);
|
|
324
|
+
if (bytes.byteLength !== 2) {
|
|
325
|
+
throw new Error(`invalid FLOAT16 byte length: ${bytes.byteLength}`);
|
|
326
|
+
}
|
|
327
|
+
const half = bytes[0] | (bytes[1] << 8);
|
|
328
|
+
const sign = half & 0x8000 ? -1 : 1;
|
|
329
|
+
const exponent = (half >>> 10) & 0x1f;
|
|
330
|
+
const mantissa = half & 0x03ff;
|
|
331
|
+
if (exponent === 0x1f) {
|
|
332
|
+
return mantissa ? Number.NaN : sign * Number.POSITIVE_INFINITY;
|
|
333
|
+
}
|
|
334
|
+
if (exponent === 0) {
|
|
335
|
+
return sign * 2 ** -14 * (mantissa / 1024);
|
|
336
|
+
}
|
|
337
|
+
return sign * 2 ** (exponent - 15) * (1 + mantissa / 1024);
|
|
338
|
+
}
|
|
339
|
+
|
|
224
340
|
function toPrimitive_DOUBLE(value: any): number {
|
|
225
341
|
const v = parseFloat(value);
|
|
226
342
|
if (Number.isNaN(v)) {
|
|
@@ -285,18 +401,30 @@ function decimalToPrimitive_INT32(value: number, field: ParquetField): number {
|
|
|
285
401
|
|
|
286
402
|
function toPrimitive_UINT32(value: any): number {
|
|
287
403
|
const v = parseInt(value, 10);
|
|
288
|
-
if (v < 0 || v >
|
|
404
|
+
if (v < 0 || v > 0xffffffff || Number.isNaN(v)) {
|
|
289
405
|
throw new Error(`invalid value for UINT32: ${value}`);
|
|
290
406
|
}
|
|
291
407
|
return v;
|
|
292
408
|
}
|
|
293
409
|
|
|
294
|
-
function toPrimitive_INT64(value:
|
|
295
|
-
|
|
296
|
-
|
|
410
|
+
function toPrimitive_INT64(value: unknown): number | bigint {
|
|
411
|
+
if (typeof value === 'number') {
|
|
412
|
+
if (!Number.isSafeInteger(value)) {
|
|
413
|
+
throw new Error(`invalid value for INT64: ${value}`);
|
|
414
|
+
}
|
|
415
|
+
return value;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
let primitiveValue: bigint;
|
|
419
|
+
try {
|
|
420
|
+
primitiveValue = BigInt(value as bigint | boolean | string);
|
|
421
|
+
} catch {
|
|
297
422
|
throw new Error(`invalid value for INT64: ${value}`);
|
|
298
423
|
}
|
|
299
|
-
|
|
424
|
+
if (primitiveValue < -(2n ** 63n) || primitiveValue > 2n ** 63n - 1n) {
|
|
425
|
+
throw new Error(`invalid value for INT64: ${value}`);
|
|
426
|
+
}
|
|
427
|
+
return primitiveValue;
|
|
300
428
|
}
|
|
301
429
|
|
|
302
430
|
function decimalToPrimitive_INT64(value: number, field: ParquetField) {
|
|
@@ -309,13 +437,12 @@ function decimalToPrimitive_INT64(value: number, field: ParquetField) {
|
|
|
309
437
|
return v;
|
|
310
438
|
}
|
|
311
439
|
|
|
312
|
-
function toPrimitive_UINT64(value:
|
|
313
|
-
const
|
|
314
|
-
if (
|
|
440
|
+
function toPrimitive_UINT64(value: unknown): bigint {
|
|
441
|
+
const primitiveValue = BigInt(value as bigint | boolean | number | string);
|
|
442
|
+
if (primitiveValue < 0n || primitiveValue > 2n ** 64n - 1n) {
|
|
315
443
|
throw new Error(`invalid value for UINT64: ${value}`);
|
|
316
444
|
}
|
|
317
|
-
|
|
318
|
-
return v;
|
|
445
|
+
return BigInt.asIntN(64, primitiveValue);
|
|
319
446
|
}
|
|
320
447
|
|
|
321
448
|
function toPrimitive_INT96(value: any) {
|
|
@@ -331,9 +458,90 @@ function toPrimitive_BYTE_ARRAY(value: any): Uint8Array {
|
|
|
331
458
|
return typeof value === 'string' ? encodeUtf8(value) : toUint8Array(value);
|
|
332
459
|
}
|
|
333
460
|
|
|
334
|
-
function decimalToPrimitive_BYTE_ARRAY(value:
|
|
335
|
-
|
|
336
|
-
|
|
461
|
+
function decimalToPrimitive_BYTE_ARRAY(value: unknown, field: ParquetField): Uint8Array {
|
|
462
|
+
if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
|
|
463
|
+
const bytes = toUint8Array(value);
|
|
464
|
+
if (field.typeLength !== undefined && bytes.byteLength !== field.typeLength) {
|
|
465
|
+
throw new Error(
|
|
466
|
+
`invalid DECIMAL byte width: expected ${field.typeLength}, received ${bytes.byteLength}`
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
return bytes;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const unscaledValue = getUnscaledDecimalInteger(value, field.scale || 0);
|
|
473
|
+
const precision = field.precision ?? field.presision;
|
|
474
|
+
if (precision !== undefined && getDecimalDigitCount(unscaledValue) > precision) {
|
|
475
|
+
throw new Error(`DECIMAL value ${value} exceeds precision ${precision}`);
|
|
476
|
+
}
|
|
477
|
+
const byteWidth = field.typeLength ?? getSignedBigIntByteWidth(unscaledValue);
|
|
478
|
+
const bitWidth = BigInt(byteWidth * 8);
|
|
479
|
+
const minimum = -(1n << (bitWidth - 1n));
|
|
480
|
+
const maximum = (1n << (bitWidth - 1n)) - 1n;
|
|
481
|
+
if (unscaledValue < minimum || unscaledValue > maximum) {
|
|
482
|
+
throw new Error(`DECIMAL value ${value} does not fit in ${byteWidth} bytes`);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const bytes = new Uint8Array(byteWidth);
|
|
486
|
+
let unsignedValue = BigInt.asUintN(byteWidth * 8, unscaledValue);
|
|
487
|
+
for (let byteIndex = byteWidth - 1; byteIndex >= 0; byteIndex--) {
|
|
488
|
+
bytes[byteIndex] = Number(unsignedValue & 0xffn);
|
|
489
|
+
unsignedValue >>= 8n;
|
|
490
|
+
}
|
|
491
|
+
return bytes;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/** Converts a logical decimal value to its exact scaled integer. */
|
|
495
|
+
function getUnscaledDecimalInteger(value: unknown, scale: number): bigint {
|
|
496
|
+
if (!Number.isInteger(scale) || scale < 0) {
|
|
497
|
+
throw new Error(`invalid DECIMAL scale: ${scale}`);
|
|
498
|
+
}
|
|
499
|
+
if (typeof value === 'bigint') {
|
|
500
|
+
return value * 10n ** BigInt(scale);
|
|
501
|
+
}
|
|
502
|
+
if (typeof value === 'number') {
|
|
503
|
+
const scaledValue = Math.round(value * 10 ** scale);
|
|
504
|
+
if (!Number.isFinite(value) || !Number.isSafeInteger(scaledValue)) {
|
|
505
|
+
throw new Error(`DECIMAL number ${value} cannot be represented exactly; use a string`);
|
|
506
|
+
}
|
|
507
|
+
return BigInt(scaledValue);
|
|
508
|
+
}
|
|
509
|
+
if (typeof value !== 'string') {
|
|
510
|
+
throw new Error(`invalid value for DECIMAL: ${value}`);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
const match = /^([+-]?)(\d+)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/.exec(value.trim());
|
|
514
|
+
if (!match) {
|
|
515
|
+
throw new Error(`invalid value for DECIMAL: ${value}`);
|
|
516
|
+
}
|
|
517
|
+
const sign = match[1] === '-' ? -1n : 1n;
|
|
518
|
+
const fraction = match[3] || '';
|
|
519
|
+
let unscaledValue = BigInt(`${match[2]}${fraction}` || '0');
|
|
520
|
+
const decimalShift = scale + Number(match[4] || 0) - fraction.length;
|
|
521
|
+
if (decimalShift >= 0) {
|
|
522
|
+
unscaledValue *= 10n ** BigInt(decimalShift);
|
|
523
|
+
} else {
|
|
524
|
+
const divisor = 10n ** BigInt(-decimalShift);
|
|
525
|
+
if (unscaledValue % divisor !== 0n) {
|
|
526
|
+
throw new Error(`DECIMAL value ${value} has more fractional digits than scale ${scale}`);
|
|
527
|
+
}
|
|
528
|
+
unscaledValue /= divisor;
|
|
529
|
+
}
|
|
530
|
+
return sign * unscaledValue;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/** Returns the number of base-10 digits in a signed integer, treating zero as one digit. */
|
|
534
|
+
function getDecimalDigitCount(value: bigint): number {
|
|
535
|
+
return (value < 0n ? -value : value).toString().length;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/** Returns the smallest two's-complement byte width that can contain a signed integer. */
|
|
539
|
+
function getSignedBigIntByteWidth(value: bigint): number {
|
|
540
|
+
let byteWidth = 1;
|
|
541
|
+
while (value < -(1n << BigInt(byteWidth * 8 - 1)) || value >= 1n << BigInt(byteWidth * 8 - 1)) {
|
|
542
|
+
byteWidth++;
|
|
543
|
+
}
|
|
544
|
+
return byteWidth;
|
|
337
545
|
}
|
|
338
546
|
|
|
339
547
|
function toPrimitive_UTF8(value: any): Uint8Array {
|
|
@@ -364,20 +572,27 @@ function fromPrimitive_BSON(value: any) {
|
|
|
364
572
|
|
|
365
573
|
function toPrimitive_TIME_MILLIS(value: any) {
|
|
366
574
|
const v = parseInt(value, 10);
|
|
367
|
-
|
|
368
|
-
if (v < 0 || v > 0xffffffffffffffff || Number.isNaN(v)) {
|
|
575
|
+
if (v < 0 || v >= kMillisPerDay || Number.isNaN(v)) {
|
|
369
576
|
throw new Error(`invalid value for TIME_MILLIS: ${value}`);
|
|
370
577
|
}
|
|
371
578
|
|
|
372
579
|
return v;
|
|
373
580
|
}
|
|
374
581
|
|
|
375
|
-
function toPrimitive_TIME_MICROS(value:
|
|
376
|
-
const
|
|
377
|
-
if (
|
|
582
|
+
function toPrimitive_TIME_MICROS(value: unknown): bigint {
|
|
583
|
+
const primitiveValue = BigInt(value as bigint | boolean | number | string);
|
|
584
|
+
if (primitiveValue < 0n || primitiveValue >= 86_400_000_000n) {
|
|
378
585
|
throw new Error(`invalid value for TIME_MICROS: ${value}`);
|
|
379
586
|
}
|
|
380
|
-
return
|
|
587
|
+
return primitiveValue;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function toPrimitive_TIME_NANOS(value: unknown): bigint {
|
|
591
|
+
const primitiveValue = BigInt(value as bigint | boolean | number | string);
|
|
592
|
+
if (primitiveValue < 0n || primitiveValue >= 86_400_000_000_000n) {
|
|
593
|
+
throw new Error(`invalid value for TIME_NANOS: ${value}`);
|
|
594
|
+
}
|
|
595
|
+
return primitiveValue;
|
|
381
596
|
}
|
|
382
597
|
|
|
383
598
|
const kMillisPerDay = 86400000;
|
|
@@ -391,7 +606,7 @@ function toPrimitive_DATE(value: any): number {
|
|
|
391
606
|
/* convert from integer */
|
|
392
607
|
{
|
|
393
608
|
const v = parseInt(value, 10);
|
|
394
|
-
if (v <
|
|
609
|
+
if (v < -0x80000000 || v > 0x7fffffff || Number.isNaN(v)) {
|
|
395
610
|
throw new Error(`invalid value for DATE: ${value}`);
|
|
396
611
|
}
|
|
397
612
|
|
|
@@ -412,7 +627,7 @@ function toPrimitive_TIMESTAMP_MILLIS(value: any): number {
|
|
|
412
627
|
/* convert from integer */
|
|
413
628
|
{
|
|
414
629
|
const v = parseInt(value, 10);
|
|
415
|
-
if (
|
|
630
|
+
if (!Number.isSafeInteger(v)) {
|
|
416
631
|
throw new Error(`invalid value for TIMESTAMP_MILLIS: ${value}`);
|
|
417
632
|
}
|
|
418
633
|
|
|
@@ -421,28 +636,36 @@ function toPrimitive_TIMESTAMP_MILLIS(value: any): number {
|
|
|
421
636
|
}
|
|
422
637
|
|
|
423
638
|
function fromPrimitive_TIMESTAMP_MILLIS(value: any): Date {
|
|
424
|
-
return new Date(value);
|
|
639
|
+
return new Date(Number(value));
|
|
425
640
|
}
|
|
426
641
|
|
|
427
|
-
function toPrimitive_TIMESTAMP_MICROS(value:
|
|
642
|
+
function toPrimitive_TIMESTAMP_MICROS(value: unknown): bigint {
|
|
428
643
|
/* convert from date */
|
|
429
644
|
if (value instanceof Date) {
|
|
430
|
-
return value.getTime() *
|
|
645
|
+
return BigInt(value.getTime()) * 1000n;
|
|
431
646
|
}
|
|
432
647
|
|
|
433
648
|
/* convert from integer */
|
|
434
649
|
{
|
|
435
|
-
|
|
436
|
-
|
|
650
|
+
let primitiveValue: bigint;
|
|
651
|
+
try {
|
|
652
|
+
primitiveValue = BigInt(value as bigint | boolean | number | string);
|
|
653
|
+
} catch {
|
|
437
654
|
throw new Error(`invalid value for TIMESTAMP_MICROS: ${value}`);
|
|
438
655
|
}
|
|
439
|
-
|
|
440
|
-
return v;
|
|
656
|
+
return primitiveValue;
|
|
441
657
|
}
|
|
442
658
|
}
|
|
443
659
|
|
|
444
660
|
function fromPrimitive_TIMESTAMP_MICROS(value: any) {
|
|
445
|
-
return new Date(value / 1000);
|
|
661
|
+
return new Date(Number(value) / 1000);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
function toPrimitive_TIMESTAMP_NANOS(value: unknown): bigint {
|
|
665
|
+
if (value instanceof Date) {
|
|
666
|
+
return BigInt(value.getTime()) * 1_000_000n;
|
|
667
|
+
}
|
|
668
|
+
return BigInt(value as bigint | boolean | number | string);
|
|
446
669
|
}
|
|
447
670
|
|
|
448
671
|
function toPrimitive_INTERVAL(value: any) {
|
|
@@ -470,8 +693,10 @@ function fromPrimitive_INTERVAL(value: any) {
|
|
|
470
693
|
}
|
|
471
694
|
|
|
472
695
|
function decimalFromPrimitive_INT(value: any, field: ParquetField) {
|
|
473
|
-
const
|
|
474
|
-
|
|
696
|
+
const numberValue = Number(value);
|
|
697
|
+
const precision = field.precision ?? field.presision!;
|
|
698
|
+
const precisionInt = Math.round(((numberValue * 10 ** -precision) % 1) * 10 ** precision);
|
|
699
|
+
return precisionInt * 10 ** -(field.scale || 0);
|
|
475
700
|
}
|
|
476
701
|
|
|
477
702
|
function decimalFromPrimitive_BYTE_ARRAY(value: any, field: ParquetField) {
|