@loaders.gl/parquet 4.4.2 → 5.0.0-alpha.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/bundled.d.ts +6 -0
- package/dist/bundled.d.ts.map +1 -0
- package/dist/bundled.js +7 -0
- package/dist/bundled.js.map +1 -0
- package/dist/geoparquet-loader-with-parser.d.ts +34 -0
- package/dist/geoparquet-loader-with-parser.d.ts.map +1 -0
- package/dist/geoparquet-loader-with-parser.js +52 -0
- package/dist/geoparquet-loader-with-parser.js.map +1 -0
- package/dist/geoparquet-loader.d.ts +61 -0
- package/dist/geoparquet-loader.d.ts.map +1 -0
- package/dist/geoparquet-loader.js +30 -0
- package/dist/geoparquet-loader.js.map +1 -0
- package/dist/index.cjs +5879 -5643
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -11
- package/dist/index.js.map +1 -1
- package/dist/lib/constants.d.ts +1 -1
- package/dist/lib/constants.js +2 -2
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/encoders/encode-arrow-to-parquet.d.ts +2 -2
- package/dist/lib/encoders/encode-arrow-to-parquet.d.ts.map +1 -1
- package/dist/lib/encoders/encode-arrow-to-parquet.js +3 -10
- package/dist/lib/encoders/encode-arrow-to-parquet.js.map +1 -1
- package/dist/lib/encoders/encode-table-to-parquet-js.d.ts +5 -0
- package/dist/lib/encoders/encode-table-to-parquet-js.d.ts.map +1 -0
- package/dist/lib/encoders/encode-table-to-parquet-js.js +149 -0
- package/dist/lib/encoders/encode-table-to-parquet-js.js.map +1 -0
- package/dist/lib/geo/geospatial-metadata.d.ts +67 -0
- package/dist/lib/geo/geospatial-metadata.d.ts.map +1 -0
- package/dist/lib/geo/geospatial-metadata.js +357 -0
- package/dist/lib/geo/geospatial-metadata.js.map +1 -0
- package/dist/lib/parsers/get-parquet-schema.d.ts.map +1 -1
- package/dist/lib/parsers/get-parquet-schema.js +3 -1
- package/dist/lib/parsers/get-parquet-schema.js.map +1 -1
- package/dist/lib/parsers/parse-geoparquet-to-geojson.d.ts +4 -4
- package/dist/lib/parsers/parse-geoparquet-to-geojson.d.ts.map +1 -1
- package/dist/lib/parsers/parse-geoparquet-to-geojson.js +19 -6
- package/dist/lib/parsers/parse-geoparquet-to-geojson.js.map +1 -1
- package/dist/lib/parsers/parse-parquet-tables.d.ts +50 -0
- package/dist/lib/parsers/parse-parquet-tables.d.ts.map +1 -0
- package/dist/lib/parsers/parse-parquet-tables.js +101 -0
- package/dist/lib/parsers/parse-parquet-tables.js.map +1 -0
- package/dist/lib/parsers/parse-parquet-to-arrow-js.d.ts +6 -0
- package/dist/lib/parsers/parse-parquet-to-arrow-js.d.ts.map +1 -0
- package/dist/lib/parsers/parse-parquet-to-arrow-js.js +23 -0
- package/dist/lib/parsers/parse-parquet-to-arrow-js.js.map +1 -0
- package/dist/lib/parsers/parse-parquet-to-arrow.d.ts +7 -7
- package/dist/lib/parsers/parse-parquet-to-arrow.d.ts.map +1 -1
- package/dist/lib/parsers/parse-parquet-to-arrow.js +45 -32
- package/dist/lib/parsers/parse-parquet-to-arrow.js.map +1 -1
- package/dist/lib/parsers/parse-parquet-to-columns.d.ts +3 -3
- package/dist/lib/parsers/parse-parquet-to-columns.d.ts.map +1 -1
- package/dist/lib/parsers/parse-parquet-to-columns.js +1 -4
- package/dist/lib/parsers/parse-parquet-to-columns.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 +77 -26
- package/dist/lib/parsers/parse-parquet-to-json.js.map +1 -1
- package/dist/lib/utils/load-wasm.d.ts +2 -2
- package/dist/lib/utils/load-wasm.d.ts.map +1 -1
- package/dist/lib/utils/load-wasm.js +7 -7
- package/dist/lib/utils/load-wasm.js.map +1 -1
- package/dist/lib/utils/make-stream-iterator.js +1 -1
- package/dist/lib/utils/make-stream-iterator.js.map +1 -1
- package/dist/lib/utils/normalize-parquet-options.d.ts +5 -0
- package/dist/lib/utils/normalize-parquet-options.d.ts.map +1 -0
- package/dist/lib/utils/normalize-parquet-options.js +11 -0
- package/dist/lib/utils/normalize-parquet-options.js.map +1 -0
- package/dist/parquet-format.d.ts +2 -0
- package/dist/parquet-format.d.ts.map +1 -1
- package/dist/parquet-format.js +2 -0
- package/dist/parquet-format.js.map +1 -1
- package/dist/parquet-js-loader.d.ts +57 -0
- package/dist/parquet-js-loader.d.ts.map +1 -0
- package/dist/parquet-js-loader.js +33 -0
- package/dist/parquet-js-loader.js.map +1 -0
- package/dist/parquet-js-writer.d.ts +34 -0
- package/dist/parquet-js-writer.d.ts.map +1 -0
- package/dist/parquet-js-writer.js +28 -0
- package/dist/parquet-js-writer.js.map +1 -0
- package/dist/parquet-loader-options.d.ts +56 -0
- package/dist/parquet-loader-options.d.ts.map +1 -0
- package/dist/parquet-loader-options.js +11 -0
- package/dist/parquet-loader-options.js.map +1 -0
- package/dist/parquet-loader-with-parser.d.ts +33 -0
- package/dist/parquet-loader-with-parser.d.ts.map +1 -0
- package/dist/parquet-loader-with-parser.js +40 -0
- package/dist/parquet-loader-with-parser.js.map +1 -0
- package/dist/parquet-loader.d.ts +62 -0
- package/dist/parquet-loader.d.ts.map +1 -0
- package/dist/parquet-loader.js +53 -0
- package/dist/parquet-loader.js.map +1 -0
- package/dist/parquet-wasm-loader-with-parser.d.ts +40 -0
- package/dist/parquet-wasm-loader-with-parser.d.ts.map +1 -0
- package/dist/parquet-wasm-loader-with-parser.js +68 -0
- package/dist/parquet-wasm-loader-with-parser.js.map +1 -0
- package/dist/parquet-writer.d.ts +10 -0
- package/dist/parquet-writer.d.ts.map +1 -0
- package/dist/parquet-writer.js +29 -0
- package/dist/parquet-writer.js.map +1 -0
- package/dist/parquet_wasm_bg.wasm +0 -0
- package/dist/parquetjs/codecs/declare.d.ts +2 -2
- package/dist/parquetjs/codecs/declare.d.ts.map +1 -1
- package/dist/parquetjs/codecs/dictionary.js +1 -1
- package/dist/parquetjs/codecs/dictionary.js.map +1 -1
- package/dist/parquetjs/codecs/plain.d.ts +1 -1
- package/dist/parquetjs/codecs/plain.d.ts.map +1 -1
- package/dist/parquetjs/codecs/plain.js +36 -41
- package/dist/parquetjs/codecs/plain.js.map +1 -1
- package/dist/parquetjs/codecs/rle.d.ts +1 -1
- package/dist/parquetjs/codecs/rle.d.ts.map +1 -1
- package/dist/parquetjs/codecs/rle.js +16 -21
- package/dist/parquetjs/codecs/rle.js.map +1 -1
- package/dist/parquetjs/compression.d.ts +2 -3
- package/dist/parquetjs/compression.d.ts.map +1 -1
- package/dist/parquetjs/compression.js +4 -105
- package/dist/parquetjs/compression.js.map +1 -1
- package/dist/parquetjs/encoder/parquet-encoder.d.ts +4 -4
- package/dist/parquetjs/encoder/parquet-encoder.d.ts.map +1 -1
- package/dist/parquetjs/encoder/parquet-encoder.js +38 -33
- package/dist/parquetjs/encoder/parquet-encoder.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnIndex.js +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnIndex.js.map +1 -1
- package/dist/parquetjs/parquet-thrift/index.d.ts +0 -1
- package/dist/parquetjs/parquet-thrift/index.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/index.js +0 -1
- package/dist/parquetjs/parquet-thrift/index.js.map +1 -1
- package/dist/parquetjs/parser/decoders.d.ts +1 -1
- package/dist/parquetjs/parser/decoders.d.ts.map +1 -1
- package/dist/parquetjs/parser/decoders.js +4 -22
- package/dist/parquetjs/parser/decoders.js.map +1 -1
- package/dist/parquetjs/parser/parquet-reader.d.ts +1 -1
- package/dist/parquetjs/parser/parquet-reader.d.ts.map +1 -1
- package/dist/parquetjs/parser/parquet-reader.js +9 -9
- package/dist/parquetjs/parser/parquet-reader.js.map +1 -1
- package/dist/parquetjs/schema/declare.d.ts +1 -1
- package/dist/parquetjs/schema/declare.d.ts.map +1 -1
- package/dist/parquetjs/schema/types.d.ts.map +1 -1
- package/dist/parquetjs/schema/types.js +36 -35
- package/dist/parquetjs/schema/types.js.map +1 -1
- package/dist/parquetjs/utils/binary-utils.d.ts +39 -0
- package/dist/parquetjs/utils/binary-utils.d.ts.map +1 -0
- package/dist/parquetjs/utils/binary-utils.js +102 -0
- package/dist/parquetjs/utils/binary-utils.js.map +1 -0
- package/dist/parquetjs/utils/file-utils.d.ts +1 -1
- package/dist/parquetjs/utils/file-utils.d.ts.map +1 -1
- package/dist/parquetjs/utils/file-utils.js +3 -3
- package/dist/parquetjs/utils/file-utils.js.map +1 -1
- package/dist/parquetjs/utils/read-utils.d.ts +4 -4
- package/dist/parquetjs/utils/read-utils.d.ts.map +1 -1
- package/dist/parquetjs/utils/read-utils.js +12 -17
- package/dist/parquetjs/utils/read-utils.js.map +1 -1
- package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.d.ts +78 -0
- package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.d.ts.map +1 -0
- package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.js +213 -0
- package/dist/parquetjs/utils/uint8-array-compact-protocol-writer.js.map +1 -0
- package/dist/parquetjs/utils/uint8-array-compact-protocol.d.ts +78 -0
- package/dist/parquetjs/utils/uint8-array-compact-protocol.d.ts.map +1 -0
- package/dist/parquetjs/utils/uint8-array-compact-protocol.js +276 -0
- package/dist/parquetjs/utils/uint8-array-compact-protocol.js.map +1 -0
- package/dist/parquetjs/utils/uint8-array-transport.d.ts +25 -0
- package/dist/parquetjs/utils/uint8-array-transport.d.ts.map +1 -0
- package/dist/parquetjs/utils/uint8-array-transport.js +62 -0
- package/dist/parquetjs/utils/uint8-array-transport.js.map +1 -0
- package/dist/unbundled.d.ts +6 -0
- package/dist/unbundled.d.ts.map +1 -0
- package/dist/unbundled.js +7 -0
- package/dist/unbundled.js.map +1 -0
- package/package.json +21 -25
- package/src/bundled.ts +9 -0
- package/src/geoparquet-loader-with-parser.ts +95 -0
- package/src/geoparquet-loader.ts +54 -0
- package/src/index.ts +7 -25
- package/src/lib/constants.ts +1 -1
- package/src/lib/encoders/encode-arrow-to-parquet.ts +9 -15
- package/src/lib/encoders/encode-table-to-parquet-js.ts +199 -0
- package/src/lib/geo/geospatial-metadata.ts +507 -0
- package/src/lib/parsers/get-parquet-schema.ts +3 -1
- package/src/lib/parsers/parse-geoparquet-to-geojson.ts +27 -14
- package/src/lib/parsers/parse-parquet-tables.ts +137 -0
- package/src/lib/parsers/parse-parquet-to-arrow-js.ts +36 -0
- package/src/lib/parsers/parse-parquet-to-arrow.ts +63 -36
- package/src/lib/parsers/parse-parquet-to-columns.ts +6 -7
- package/src/lib/parsers/parse-parquet-to-json.ts +101 -33
- package/src/lib/utils/load-wasm.ts +16 -9
- package/src/lib/utils/make-stream-iterator.ts +1 -1
- package/src/lib/utils/normalize-parquet-options.ts +14 -0
- package/src/parquet-format.ts +2 -0
- package/src/parquet-js-loader.ts +43 -0
- package/src/parquet-js-writer.ts +52 -0
- package/src/parquet-loader-options.ts +63 -0
- package/src/parquet-loader-with-parser.ts +68 -0
- package/src/parquet-loader.ts +79 -0
- package/src/parquet-wasm-loader-with-parser.ts +115 -0
- package/src/parquet-writer.ts +44 -0
- package/src/parquetjs/codecs/declare.ts +2 -2
- package/src/parquetjs/codecs/dictionary.ts +1 -1
- package/src/parquetjs/codecs/plain.ts +67 -53
- package/src/parquetjs/codecs/rle.ts +20 -26
- package/src/parquetjs/compression.ts +7 -114
- package/src/parquetjs/encoder/parquet-encoder.ts +49 -43
- package/src/parquetjs/parquet-thrift/ColumnIndex.ts +1 -1
- package/src/parquetjs/parquet-thrift/index.ts +0 -2
- package/src/parquetjs/parser/decoders.ts +5 -23
- package/src/parquetjs/parser/parquet-reader.ts +10 -12
- package/src/parquetjs/schema/declare.ts +1 -1
- package/src/parquetjs/schema/types.ts +48 -40
- package/src/parquetjs/utils/binary-utils.ts +127 -0
- package/src/parquetjs/utils/file-utils.ts +4 -4
- package/src/parquetjs/utils/read-utils.ts +19 -34
- package/src/parquetjs/utils/uint8-array-compact-protocol-writer.ts +254 -0
- package/src/parquetjs/utils/uint8-array-compact-protocol.ts +322 -0
- package/src/parquetjs/utils/uint8-array-transport.ts +79 -0
- package/src/unbundled.ts +9 -0
- package/dist/parquet-arrow-loader.d.ts +0 -43
- package/dist/parquet-arrow-loader.d.ts.map +0 -1
- package/dist/parquet-arrow-loader.js +0 -49
- package/dist/parquet-arrow-loader.js.map +0 -1
- package/dist/parquet-arrow-writer.d.ts +0 -9
- package/dist/parquet-arrow-writer.d.ts.map +0 -1
- package/dist/parquet-arrow-writer.js +0 -23
- package/dist/parquet-arrow-writer.js.map +0 -1
- package/dist/parquet-json-loader.d.ts +0 -148
- package/dist/parquet-json-loader.d.ts.map +0 -1
- package/dist/parquet-json-loader.js +0 -106
- package/dist/parquet-json-loader.js.map +0 -1
- package/dist/parquet-json-writer.d.ts +0 -19
- package/dist/parquet-json-writer.d.ts.map +0 -1
- package/dist/parquet-json-writer.js +0 -20
- package/dist/parquet-json-writer.js.map +0 -1
- package/dist/polyfills/buffer/buffer-polyfill.browser.d.ts +0 -3
- package/dist/polyfills/buffer/buffer-polyfill.browser.d.ts.map +0 -1
- package/dist/polyfills/buffer/buffer-polyfill.browser.js +0 -12
- package/dist/polyfills/buffer/buffer-polyfill.browser.js.map +0 -1
- package/dist/polyfills/buffer/buffer-polyfill.node.d.ts +0 -3
- package/dist/polyfills/buffer/buffer-polyfill.node.d.ts.map +0 -1
- package/dist/polyfills/buffer/buffer-polyfill.node.js +0 -17
- package/dist/polyfills/buffer/buffer-polyfill.node.js.map +0 -1
- package/dist/polyfills/buffer/buffer.d.ts +0 -222
- package/dist/polyfills/buffer/buffer.d.ts.map +0 -1
- package/dist/polyfills/buffer/buffer.js +0 -1868
- package/dist/polyfills/buffer/buffer.js.map +0 -1
- package/dist/polyfills/buffer/index.d.ts +0 -4
- package/dist/polyfills/buffer/index.d.ts.map +0 -1
- package/dist/polyfills/buffer/index.js +0 -9
- package/dist/polyfills/buffer/index.js.map +0 -1
- package/dist/polyfills/buffer/install-buffer-polyfill.d.ts +0 -2
- package/dist/polyfills/buffer/install-buffer-polyfill.d.ts.map +0 -1
- package/dist/polyfills/buffer/install-buffer-polyfill.js +0 -10
- package/dist/polyfills/buffer/install-buffer-polyfill.js.map +0 -1
- package/dist/workers/parquet-json-worker.d.ts +0 -2
- package/dist/workers/parquet-json-worker.d.ts.map +0 -1
- package/dist/workers/parquet-json-worker.js +0 -7
- package/dist/workers/parquet-json-worker.js.map +0 -1
- package/src/parquet-arrow-loader.ts +0 -74
- package/src/parquet-arrow-writer.ts +0 -33
- package/src/parquet-json-loader.ts +0 -160
- package/src/parquet-json-writer.ts +0 -27
- package/src/parquetjs/modules.d.ts +0 -25
- package/src/polyfills/buffer/buffer-polyfill.browser.ts +0 -14
- package/src/polyfills/buffer/buffer-polyfill.node.ts +0 -19
- package/src/polyfills/buffer/buffer.ts +0 -2205
- package/src/polyfills/buffer/index.ts +0 -11
- package/src/polyfills/buffer/install-buffer-polyfill.ts +0 -12
- package/src/workers/parquet-json-worker.ts +0 -8
|
@@ -5,8 +5,16 @@
|
|
|
5
5
|
// Forked from https://github.com/kbajalc/parquets under MIT license
|
|
6
6
|
|
|
7
7
|
/* eslint-disable camelcase */
|
|
8
|
-
import {
|
|
8
|
+
import {BSONWriter, parseBSONSync} from '@loaders.gl/bson';
|
|
9
9
|
import {OriginalType, ParquetField, ParquetType, PrimitiveType} from './declare';
|
|
10
|
+
import {
|
|
11
|
+
decodeUtf8,
|
|
12
|
+
encodeUtf8,
|
|
13
|
+
readUInt32LE,
|
|
14
|
+
toArrayBuffer,
|
|
15
|
+
toUint8Array,
|
|
16
|
+
writeUInt32LE
|
|
17
|
+
} from '../utils/binary-utils';
|
|
10
18
|
|
|
11
19
|
export interface ParquetTypeKit {
|
|
12
20
|
primitiveType: PrimitiveType;
|
|
@@ -207,7 +215,7 @@ function fromPrimitive_BOOLEAN(value: any): boolean {
|
|
|
207
215
|
|
|
208
216
|
function toPrimitive_FLOAT(value: any): number {
|
|
209
217
|
const v = parseFloat(value);
|
|
210
|
-
if (isNaN(v)) {
|
|
218
|
+
if (Number.isNaN(v)) {
|
|
211
219
|
throw new Error(`invalid value for FLOAT: ${value}`);
|
|
212
220
|
}
|
|
213
221
|
return v;
|
|
@@ -215,7 +223,7 @@ function toPrimitive_FLOAT(value: any): number {
|
|
|
215
223
|
|
|
216
224
|
function toPrimitive_DOUBLE(value: any): number {
|
|
217
225
|
const v = parseFloat(value);
|
|
218
|
-
if (isNaN(v)) {
|
|
226
|
+
if (Number.isNaN(v)) {
|
|
219
227
|
throw new Error(`invalid value for DOUBLE: ${value}`);
|
|
220
228
|
}
|
|
221
229
|
return v;
|
|
@@ -223,7 +231,7 @@ function toPrimitive_DOUBLE(value: any): number {
|
|
|
223
231
|
|
|
224
232
|
function toPrimitive_INT8(value: any) {
|
|
225
233
|
const v = parseInt(value, 10);
|
|
226
|
-
if (v < -0x80 || v > 0x7f || isNaN(v)) {
|
|
234
|
+
if (v < -0x80 || v > 0x7f || Number.isNaN(v)) {
|
|
227
235
|
throw new Error(`invalid value for INT8: ${value}`);
|
|
228
236
|
}
|
|
229
237
|
|
|
@@ -232,7 +240,7 @@ function toPrimitive_INT8(value: any) {
|
|
|
232
240
|
|
|
233
241
|
function toPrimitive_UINT8(value: any) {
|
|
234
242
|
const v = parseInt(value, 10);
|
|
235
|
-
if (v < 0 || v > 0xff || isNaN(v)) {
|
|
243
|
+
if (v < 0 || v > 0xff || Number.isNaN(v)) {
|
|
236
244
|
throw new Error(`invalid value for UINT8: ${value}`);
|
|
237
245
|
}
|
|
238
246
|
|
|
@@ -241,7 +249,7 @@ function toPrimitive_UINT8(value: any) {
|
|
|
241
249
|
|
|
242
250
|
function toPrimitive_INT16(value: any) {
|
|
243
251
|
const v = parseInt(value, 10);
|
|
244
|
-
if (v < -0x8000 || v > 0x7fff || isNaN(v)) {
|
|
252
|
+
if (v < -0x8000 || v > 0x7fff || Number.isNaN(v)) {
|
|
245
253
|
throw new Error(`invalid value for INT16: ${value}`);
|
|
246
254
|
}
|
|
247
255
|
|
|
@@ -250,7 +258,7 @@ function toPrimitive_INT16(value: any) {
|
|
|
250
258
|
|
|
251
259
|
function toPrimitive_UINT16(value: any) {
|
|
252
260
|
const v = parseInt(value, 10);
|
|
253
|
-
if (v < 0 || v > 0xffff || isNaN(v)) {
|
|
261
|
+
if (v < 0 || v > 0xffff || Number.isNaN(v)) {
|
|
254
262
|
throw new Error(`invalid value for UINT16: ${value}`);
|
|
255
263
|
}
|
|
256
264
|
|
|
@@ -259,7 +267,7 @@ function toPrimitive_UINT16(value: any) {
|
|
|
259
267
|
|
|
260
268
|
function toPrimitive_INT32(value: any) {
|
|
261
269
|
const v = parseInt(value, 10);
|
|
262
|
-
if (v < -0x80000000 || v > 0x7fffffff || isNaN(v)) {
|
|
270
|
+
if (v < -0x80000000 || v > 0x7fffffff || Number.isNaN(v)) {
|
|
263
271
|
throw new Error(`invalid value for INT32: ${value}`);
|
|
264
272
|
}
|
|
265
273
|
|
|
@@ -269,7 +277,7 @@ function toPrimitive_INT32(value: any) {
|
|
|
269
277
|
function decimalToPrimitive_INT32(value: number, field: ParquetField): number {
|
|
270
278
|
const primitiveValue = value * 10 ** (field.scale || 0);
|
|
271
279
|
const v = Math.round(((primitiveValue * 10 ** -field.presision!) % 1) * 10 ** field.presision!);
|
|
272
|
-
if (v < -0x80000000 || v > 0x7fffffff || isNaN(v)) {
|
|
280
|
+
if (v < -0x80000000 || v > 0x7fffffff || Number.isNaN(v)) {
|
|
273
281
|
throw new Error(`invalid value for INT32: ${value}`);
|
|
274
282
|
}
|
|
275
283
|
return v;
|
|
@@ -277,7 +285,7 @@ function decimalToPrimitive_INT32(value: number, field: ParquetField): number {
|
|
|
277
285
|
|
|
278
286
|
function toPrimitive_UINT32(value: any): number {
|
|
279
287
|
const v = parseInt(value, 10);
|
|
280
|
-
if (v < 0 || v > 0xffffffffffff || isNaN(v)) {
|
|
288
|
+
if (v < 0 || v > 0xffffffffffff || Number.isNaN(v)) {
|
|
281
289
|
throw new Error(`invalid value for UINT32: ${value}`);
|
|
282
290
|
}
|
|
283
291
|
return v;
|
|
@@ -285,7 +293,7 @@ function toPrimitive_UINT32(value: any): number {
|
|
|
285
293
|
|
|
286
294
|
function toPrimitive_INT64(value: any): number {
|
|
287
295
|
const v = parseInt(value, 10);
|
|
288
|
-
if (isNaN(v)) {
|
|
296
|
+
if (Number.isNaN(v)) {
|
|
289
297
|
throw new Error(`invalid value for INT64: ${value}`);
|
|
290
298
|
}
|
|
291
299
|
return v;
|
|
@@ -294,7 +302,7 @@ function toPrimitive_INT64(value: any): number {
|
|
|
294
302
|
function decimalToPrimitive_INT64(value: number, field: ParquetField) {
|
|
295
303
|
const primitiveValue = value * 10 ** (field.scale || 0);
|
|
296
304
|
const v = Math.round(((primitiveValue * 10 ** -field.presision!) % 1) * 10 ** field.presision!);
|
|
297
|
-
if (isNaN(v)) {
|
|
305
|
+
if (Number.isNaN(v)) {
|
|
298
306
|
throw new Error(`invalid value for INT64: ${value}`);
|
|
299
307
|
}
|
|
300
308
|
|
|
@@ -303,7 +311,7 @@ function decimalToPrimitive_INT64(value: number, field: ParquetField) {
|
|
|
303
311
|
|
|
304
312
|
function toPrimitive_UINT64(value: any) {
|
|
305
313
|
const v = parseInt(value, 10);
|
|
306
|
-
if (v < 0 || isNaN(v)) {
|
|
314
|
+
if (v < 0 || Number.isNaN(v)) {
|
|
307
315
|
throw new Error(`invalid value for UINT64: ${value}`);
|
|
308
316
|
}
|
|
309
317
|
|
|
@@ -312,52 +320,52 @@ function toPrimitive_UINT64(value: any) {
|
|
|
312
320
|
|
|
313
321
|
function toPrimitive_INT96(value: any) {
|
|
314
322
|
const v = parseInt(value, 10);
|
|
315
|
-
if (isNaN(v)) {
|
|
323
|
+
if (Number.isNaN(v)) {
|
|
316
324
|
throw new Error(`invalid value for INT96: ${value}`);
|
|
317
325
|
}
|
|
318
326
|
|
|
319
327
|
return v;
|
|
320
328
|
}
|
|
321
329
|
|
|
322
|
-
function toPrimitive_BYTE_ARRAY(value: any):
|
|
323
|
-
return
|
|
330
|
+
function toPrimitive_BYTE_ARRAY(value: any): Uint8Array {
|
|
331
|
+
return typeof value === 'string' ? encodeUtf8(value) : toUint8Array(value);
|
|
324
332
|
}
|
|
325
333
|
|
|
326
|
-
function decimalToPrimitive_BYTE_ARRAY(value: any):
|
|
334
|
+
function decimalToPrimitive_BYTE_ARRAY(value: any): Uint8Array {
|
|
327
335
|
// TBD
|
|
328
|
-
return
|
|
336
|
+
return typeof value === 'string' ? encodeUtf8(value) : toUint8Array(value);
|
|
329
337
|
}
|
|
330
338
|
|
|
331
|
-
function toPrimitive_UTF8(value: any):
|
|
332
|
-
return
|
|
339
|
+
function toPrimitive_UTF8(value: any): Uint8Array {
|
|
340
|
+
return encodeUtf8(String(value));
|
|
333
341
|
}
|
|
334
342
|
|
|
335
343
|
function fromPrimitive_UTF8(value: any): string {
|
|
336
|
-
return value
|
|
344
|
+
return decodeUtf8(toUint8Array(value));
|
|
337
345
|
}
|
|
338
346
|
|
|
339
|
-
function toPrimitive_JSON(value: any):
|
|
340
|
-
return
|
|
347
|
+
function toPrimitive_JSON(value: any): Uint8Array {
|
|
348
|
+
return encodeUtf8(JSON.stringify(value));
|
|
341
349
|
}
|
|
342
350
|
|
|
343
351
|
function fromPrimitive_JSON(value: any): unknown {
|
|
344
|
-
return JSON.parse(value);
|
|
352
|
+
return JSON.parse(decodeUtf8(toUint8Array(value)));
|
|
345
353
|
}
|
|
346
354
|
|
|
347
|
-
function toPrimitive_BSON(value: any):
|
|
355
|
+
function toPrimitive_BSON(value: any): Uint8Array {
|
|
348
356
|
// @ts-ignore
|
|
349
357
|
const arrayBuffer: ArrayBuffer = BSONWriter.encodeSync?.(value);
|
|
350
|
-
return
|
|
358
|
+
return toUint8Array(arrayBuffer);
|
|
351
359
|
}
|
|
352
360
|
|
|
353
361
|
function fromPrimitive_BSON(value: any) {
|
|
354
|
-
return
|
|
362
|
+
return parseBSONSync(toArrayBuffer(value));
|
|
355
363
|
}
|
|
356
364
|
|
|
357
365
|
function toPrimitive_TIME_MILLIS(value: any) {
|
|
358
366
|
const v = parseInt(value, 10);
|
|
359
367
|
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
|
|
360
|
-
if (v < 0 || v > 0xffffffffffffffff || isNaN(v)) {
|
|
368
|
+
if (v < 0 || v > 0xffffffffffffffff || Number.isNaN(v)) {
|
|
361
369
|
throw new Error(`invalid value for TIME_MILLIS: ${value}`);
|
|
362
370
|
}
|
|
363
371
|
|
|
@@ -366,7 +374,7 @@ function toPrimitive_TIME_MILLIS(value: any) {
|
|
|
366
374
|
|
|
367
375
|
function toPrimitive_TIME_MICROS(value: any): number {
|
|
368
376
|
const v = parseInt(value, 10);
|
|
369
|
-
if (v < 0 || isNaN(v)) {
|
|
377
|
+
if (v < 0 || Number.isNaN(v)) {
|
|
370
378
|
throw new Error(`invalid value for TIME_MICROS: ${value}`);
|
|
371
379
|
}
|
|
372
380
|
return v;
|
|
@@ -383,7 +391,7 @@ function toPrimitive_DATE(value: any): number {
|
|
|
383
391
|
/* convert from integer */
|
|
384
392
|
{
|
|
385
393
|
const v = parseInt(value, 10);
|
|
386
|
-
if (v < 0 || isNaN(v)) {
|
|
394
|
+
if (v < 0 || Number.isNaN(v)) {
|
|
387
395
|
throw new Error(`invalid value for DATE: ${value}`);
|
|
388
396
|
}
|
|
389
397
|
|
|
@@ -404,7 +412,7 @@ function toPrimitive_TIMESTAMP_MILLIS(value: any): number {
|
|
|
404
412
|
/* convert from integer */
|
|
405
413
|
{
|
|
406
414
|
const v = parseInt(value, 10);
|
|
407
|
-
if (v < 0 || isNaN(v)) {
|
|
415
|
+
if (v < 0 || Number.isNaN(v)) {
|
|
408
416
|
throw new Error(`invalid value for TIMESTAMP_MILLIS: ${value}`);
|
|
409
417
|
}
|
|
410
418
|
|
|
@@ -425,7 +433,7 @@ function toPrimitive_TIMESTAMP_MICROS(value: any) {
|
|
|
425
433
|
/* convert from integer */
|
|
426
434
|
{
|
|
427
435
|
const v = parseInt(value, 10);
|
|
428
|
-
if (v < 0 || isNaN(v)) {
|
|
436
|
+
if (v < 0 || Number.isNaN(v)) {
|
|
429
437
|
throw new Error(`invalid value for TIMESTAMP_MICROS: ${value}`);
|
|
430
438
|
}
|
|
431
439
|
|
|
@@ -444,19 +452,19 @@ function toPrimitive_INTERVAL(value: any) {
|
|
|
444
452
|
);
|
|
445
453
|
}
|
|
446
454
|
|
|
447
|
-
const buf =
|
|
455
|
+
const buf = new Uint8Array(12);
|
|
448
456
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
457
|
+
writeUInt32LE(buf, value.months, 0);
|
|
458
|
+
writeUInt32LE(buf, value.days, 4);
|
|
459
|
+
writeUInt32LE(buf, value.milliseconds, 8);
|
|
452
460
|
return buf;
|
|
453
461
|
}
|
|
454
462
|
|
|
455
463
|
function fromPrimitive_INTERVAL(value: any) {
|
|
456
|
-
const
|
|
457
|
-
const months =
|
|
458
|
-
const days =
|
|
459
|
-
const millis =
|
|
464
|
+
const bytes = toUint8Array(value);
|
|
465
|
+
const months = readUInt32LE(bytes, 0);
|
|
466
|
+
const days = readUInt32LE(bytes, 4);
|
|
467
|
+
const millis = readUInt32LE(bytes, 8);
|
|
460
468
|
|
|
461
469
|
return {months, days, milliseconds: millis};
|
|
462
470
|
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
const TEXT_DECODER = new TextDecoder();
|
|
6
|
+
const TEXT_ENCODER = new TextEncoder();
|
|
7
|
+
|
|
8
|
+
/** Returns bytes as an exact Uint8Array view. */
|
|
9
|
+
export function toUint8Array(binary: ArrayBuffer | ArrayBufferView): Uint8Array {
|
|
10
|
+
if (binary instanceof Uint8Array) {
|
|
11
|
+
return binary;
|
|
12
|
+
}
|
|
13
|
+
if (ArrayBuffer.isView(binary)) {
|
|
14
|
+
return new Uint8Array(binary.buffer, binary.byteOffset, binary.byteLength);
|
|
15
|
+
}
|
|
16
|
+
return new Uint8Array(binary);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Returns bytes as a copied ArrayBuffer with no extra prefix/suffix bytes. */
|
|
20
|
+
export function toArrayBuffer(binary: ArrayBuffer | ArrayBufferView): ArrayBuffer {
|
|
21
|
+
const bytes = toUint8Array(binary);
|
|
22
|
+
return bytes.slice().buffer;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Returns a copied Uint8Array. */
|
|
26
|
+
export function copyUint8Array(binary: Uint8Array): Uint8Array {
|
|
27
|
+
return binary.slice();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Decode UTF-8 bytes. */
|
|
31
|
+
export function decodeUtf8(binary: Uint8Array): string {
|
|
32
|
+
return TEXT_DECODER.decode(binary);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Encode text as UTF-8 bytes. */
|
|
36
|
+
export function encodeUtf8(text: string): Uint8Array {
|
|
37
|
+
return TEXT_ENCODER.encode(text);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Decode an ASCII/UTF-8 range from bytes. */
|
|
41
|
+
export function decodeString(
|
|
42
|
+
binary: Uint8Array,
|
|
43
|
+
start: number = 0,
|
|
44
|
+
end: number = binary.length
|
|
45
|
+
): string {
|
|
46
|
+
return decodeUtf8(binary.subarray(start, end));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getDataView(binary: Uint8Array): DataView {
|
|
50
|
+
return new DataView(binary.buffer, binary.byteOffset, binary.byteLength);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Read signed little-endian 32-bit integer. */
|
|
54
|
+
export function readInt32LE(binary: Uint8Array, offset: number): number {
|
|
55
|
+
return getDataView(binary).getInt32(offset, true);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Read unsigned little-endian 32-bit integer. */
|
|
59
|
+
export function readUInt32LE(binary: Uint8Array, offset: number): number {
|
|
60
|
+
return getDataView(binary).getUint32(offset, true);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Read signed little-endian 64-bit integer as number. */
|
|
64
|
+
export function readInt64LE(binary: Uint8Array, offset: number): number {
|
|
65
|
+
return Number(getDataView(binary).getBigInt64(offset, true));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Read little-endian 32-bit float. */
|
|
69
|
+
export function readFloatLE(binary: Uint8Array, offset: number): number {
|
|
70
|
+
return getDataView(binary).getFloat32(offset, true);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Read little-endian 64-bit float. */
|
|
74
|
+
export function readDoubleLE(binary: Uint8Array, offset: number): number {
|
|
75
|
+
return getDataView(binary).getFloat64(offset, true);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Concatenate bytes into one exact Uint8Array. */
|
|
79
|
+
export function concatUint8Arrays(chunks: Uint8Array[]): Uint8Array {
|
|
80
|
+
let byteLength = 0;
|
|
81
|
+
for (const chunk of chunks) {
|
|
82
|
+
byteLength += chunk.length;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const result = new Uint8Array(byteLength);
|
|
86
|
+
let offset = 0;
|
|
87
|
+
for (const chunk of chunks) {
|
|
88
|
+
result.set(chunk, offset);
|
|
89
|
+
offset += chunk.length;
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Write signed little-endian 16-bit integer. */
|
|
95
|
+
export function writeInt16LE(binary: Uint8Array, value: number, offset: number): void {
|
|
96
|
+
getDataView(binary).setInt16(offset, value, true);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Write unsigned little-endian 16-bit integer. */
|
|
100
|
+
export function writeUInt16LE(binary: Uint8Array, value: number, offset: number): void {
|
|
101
|
+
getDataView(binary).setUint16(offset, value, true);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Write signed little-endian 32-bit integer. */
|
|
105
|
+
export function writeInt32LE(binary: Uint8Array, value: number, offset: number): void {
|
|
106
|
+
getDataView(binary).setInt32(offset, value, true);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Write unsigned little-endian 32-bit integer. */
|
|
110
|
+
export function writeUInt32LE(binary: Uint8Array, value: number, offset: number): void {
|
|
111
|
+
getDataView(binary).setUint32(offset, value, true);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Write signed little-endian 64-bit integer. */
|
|
115
|
+
export function writeInt64LE(binary: Uint8Array, value: number | bigint, offset: number): void {
|
|
116
|
+
getDataView(binary).setBigInt64(offset, BigInt(value), true);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Write little-endian 32-bit float. */
|
|
120
|
+
export function writeFloatLE(binary: Uint8Array, value: number, offset: number): void {
|
|
121
|
+
getDataView(binary).setFloat32(offset, value, true);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Write little-endian 64-bit float. */
|
|
125
|
+
export function writeDoubleLE(binary: Uint8Array, value: number, offset: number): void {
|
|
126
|
+
getDataView(binary).setFloat64(offset, value, true);
|
|
127
|
+
}
|
|
@@ -19,9 +19,9 @@ export interface WriteStreamOptions {
|
|
|
19
19
|
start?: number;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export function oswrite(os: stream.Writable, buf:
|
|
22
|
+
export function oswrite(os: stream.Writable, buf: Uint8Array): Promise<void> {
|
|
23
23
|
return new Promise((resolve, reject) => {
|
|
24
|
-
os.write(buf,
|
|
24
|
+
os.write(buf, err => {
|
|
25
25
|
if (err) {
|
|
26
26
|
reject(err);
|
|
27
27
|
} else {
|
|
@@ -46,7 +46,7 @@ export function osclose(os: stream.Writable): Promise<void> {
|
|
|
46
46
|
export function osopen(path: string, opts?: WriteStreamOptions): Promise<fs.WriteStream> {
|
|
47
47
|
return new Promise((resolve, reject) => {
|
|
48
48
|
const outputStream = fs.createWriteStream(path, opts as any);
|
|
49
|
-
outputStream.once('open',
|
|
50
|
-
outputStream.once('error',
|
|
49
|
+
outputStream.once('open', _fd => resolve(outputStream));
|
|
50
|
+
outputStream.once('error', err => reject(err));
|
|
51
51
|
});
|
|
52
52
|
}
|
|
@@ -4,44 +4,29 @@
|
|
|
4
4
|
// Copyright (c) 2017 ironSource Ltd.
|
|
5
5
|
// Forked from https://github.com/kbajalc/parquets under MIT license
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
FileMetaData,
|
|
12
|
-
PageHeader
|
|
13
|
-
} from '../parquet-thrift/index';
|
|
14
|
-
|
|
15
|
-
class UFramedTransport extends TFramedTransport {
|
|
16
|
-
public readPos: number = 0;
|
|
17
|
-
}
|
|
7
|
+
import {FileMetaData, PageHeader} from '../parquet-thrift/index';
|
|
8
|
+
import {Uint8ArrayCompactProtocol} from './uint8-array-compact-protocol';
|
|
9
|
+
import {Uint8ArrayCompactProtocolWriter} from './uint8-array-compact-protocol-writer';
|
|
10
|
+
import {Uint8ArrayTransport} from './uint8-array-transport';
|
|
18
11
|
|
|
19
12
|
/**
|
|
20
13
|
* Helper function that serializes a thrift object into a buffer
|
|
21
14
|
*/
|
|
22
|
-
export function serializeThrift(obj: any):
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
output.push(buf as unknown as Buffer);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const protocol = new TCompactProtocol(transport);
|
|
30
|
-
obj.write(protocol);
|
|
31
|
-
transport.flush();
|
|
32
|
-
|
|
33
|
-
return Buffer.concat(output as Uint8Array[]);
|
|
15
|
+
export function serializeThrift(obj: any): Uint8Array {
|
|
16
|
+
const protocol = new Uint8ArrayCompactProtocolWriter();
|
|
17
|
+
obj.write(protocol as any);
|
|
18
|
+
return protocol.getBytes();
|
|
34
19
|
}
|
|
35
20
|
|
|
36
|
-
export function decodeThrift(obj: any, buf:
|
|
21
|
+
export function decodeThrift(obj: any, buf: Uint8Array, offset?: number) {
|
|
37
22
|
if (!offset) {
|
|
38
23
|
// tslint:disable-next-line:no-parameter-reassignment
|
|
39
24
|
offset = 0;
|
|
40
25
|
}
|
|
41
26
|
|
|
42
|
-
const transport = new
|
|
27
|
+
const transport = new Uint8ArrayTransport(buf);
|
|
43
28
|
transport.readPos = offset;
|
|
44
|
-
const protocol = new
|
|
29
|
+
const protocol = new Uint8ArrayCompactProtocol(transport);
|
|
45
30
|
obj.read(protocol);
|
|
46
31
|
return transport.readPos - offset;
|
|
47
32
|
}
|
|
@@ -58,29 +43,29 @@ export function getThriftEnum(klass: any, value: number | string): string {
|
|
|
58
43
|
throw new Error('Invalid ENUM value');
|
|
59
44
|
}
|
|
60
45
|
|
|
61
|
-
export function decodeFileMetadata(buf:
|
|
46
|
+
export function decodeFileMetadata(buf: Uint8Array, offset?: number) {
|
|
62
47
|
if (!offset) {
|
|
63
48
|
// tslint:disable-next-line:no-parameter-reassignment
|
|
64
49
|
offset = 0;
|
|
65
50
|
}
|
|
66
51
|
|
|
67
|
-
const transport = new
|
|
52
|
+
const transport = new Uint8ArrayTransport(buf);
|
|
68
53
|
transport.readPos = offset;
|
|
69
|
-
const protocol = new
|
|
70
|
-
const metadata = FileMetaData.read(protocol);
|
|
54
|
+
const protocol = new Uint8ArrayCompactProtocol(transport);
|
|
55
|
+
const metadata = FileMetaData.read(protocol as any);
|
|
71
56
|
return {length: transport.readPos - offset, metadata};
|
|
72
57
|
}
|
|
73
58
|
|
|
74
|
-
export function decodePageHeader(buf:
|
|
59
|
+
export function decodePageHeader(buf: Uint8Array, offset?: number) {
|
|
75
60
|
if (!offset) {
|
|
76
61
|
// tslint:disable-next-line:no-parameter-reassignment
|
|
77
62
|
offset = 0;
|
|
78
63
|
}
|
|
79
64
|
|
|
80
|
-
const transport = new
|
|
65
|
+
const transport = new Uint8ArrayTransport(buf);
|
|
81
66
|
transport.readPos = offset;
|
|
82
|
-
const protocol = new
|
|
83
|
-
const pageHeader = PageHeader.read(protocol);
|
|
67
|
+
const protocol = new Uint8ArrayCompactProtocol(transport);
|
|
68
|
+
const pageHeader = PageHeader.read(protocol as any);
|
|
84
69
|
return {length: transport.readPos - offset, pageHeader};
|
|
85
70
|
}
|
|
86
71
|
|