@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
|
@@ -4,14 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
// loaders.gl
|
|
6
6
|
import {Schema} from '@loaders.gl/schema';
|
|
7
|
-
import {unpackGeoMetadata, unpackJSONStringMetadata} from '@loaders.gl/
|
|
7
|
+
import {unpackGeoMetadata, unpackJSONStringMetadata} from '@loaders.gl/gis';
|
|
8
8
|
import {ParquetReader} from '../../parquetjs/parser/parquet-reader';
|
|
9
9
|
import {convertParquetSchema} from '../arrow/convert-schema-from-parquet';
|
|
10
|
+
import {applyGeoParquetToFieldMetadata} from '../geo/geospatial-metadata';
|
|
10
11
|
|
|
11
12
|
export async function getSchemaFromParquetReader(reader: ParquetReader): Promise<Schema> {
|
|
12
13
|
const parquetSchema = await reader.getSchema();
|
|
13
14
|
const parquetMetadata = await reader.getFileMetadata();
|
|
14
15
|
const schema = convertParquetSchema(parquetSchema, parquetMetadata);
|
|
16
|
+
applyGeoParquetToFieldMetadata(schema);
|
|
15
17
|
unpackGeoMetadata(schema.metadata);
|
|
16
18
|
unpackJSONStringMetadata(schema.metadata, 'pandas');
|
|
17
19
|
return schema;
|
|
@@ -6,31 +6,44 @@ import type {ReadableFile} from '@loaders.gl/loader-utils';
|
|
|
6
6
|
import type {
|
|
7
7
|
GeoJSONTable,
|
|
8
8
|
GeoJSONTableBatch,
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
ArrowTableBatch,
|
|
10
|
+
ObjectRowTable
|
|
11
11
|
} from '@loaders.gl/schema';
|
|
12
12
|
import {convertWKBTableToGeoJSON} from '@loaders.gl/gis';
|
|
13
|
+
import {convertArrowToTable} from '@loaders.gl/schema-utils';
|
|
13
14
|
|
|
14
|
-
import type {
|
|
15
|
-
|
|
16
|
-
import {parseParquetFile, parseParquetFileInBatches} from './parse-parquet-to-json';
|
|
15
|
+
import type {ParquetLoaderOptions} from '../../parquet-loader-options';
|
|
16
|
+
import {parseParquetArrowTable, parseParquetArrowTableInBatches} from './parse-parquet-tables';
|
|
17
17
|
|
|
18
18
|
export async function parseGeoParquetFile(
|
|
19
19
|
file: ReadableFile,
|
|
20
|
-
options?:
|
|
21
|
-
): Promise<
|
|
22
|
-
const
|
|
23
|
-
|
|
20
|
+
options?: ParquetLoaderOptions
|
|
21
|
+
): Promise<GeoJSONTable> {
|
|
22
|
+
const arrowTable = await parseParquetArrowTable(file, options || {});
|
|
23
|
+
const objectRowTable = convertArrowToTable(arrowTable.data, 'object-row-table') as ObjectRowTable;
|
|
24
|
+
return convertWKBTableToGeoJSON(objectRowTable, objectRowTable.schema!);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export async function* parseGeoParquetFileInBatches(
|
|
27
28
|
file: ReadableFile,
|
|
28
|
-
options?:
|
|
29
|
-
): AsyncIterable<
|
|
30
|
-
const tableBatches =
|
|
29
|
+
options?: ParquetLoaderOptions
|
|
30
|
+
): AsyncIterable<GeoJSONTableBatch> {
|
|
31
|
+
const tableBatches = parseParquetArrowTableInBatches(file, options || {});
|
|
31
32
|
|
|
32
33
|
for await (const batch of tableBatches) {
|
|
33
|
-
|
|
34
|
-
yield {...batch, ...geojson};
|
|
34
|
+
yield convertGeoParquetArrowBatch(batch);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
function convertGeoParquetArrowBatch(batch: ArrowTableBatch): GeoJSONTableBatch {
|
|
39
|
+
const objectRowTable = convertArrowToTable(batch.data, 'object-row-table') as ObjectRowTable;
|
|
40
|
+
const geojsonTable = convertWKBTableToGeoJSON(objectRowTable, objectRowTable.schema!);
|
|
41
|
+
return {
|
|
42
|
+
batchType: batch.batchType,
|
|
43
|
+
shape: geojsonTable.shape,
|
|
44
|
+
type: geojsonTable.type,
|
|
45
|
+
schema: geojsonTable.schema,
|
|
46
|
+
features: geojsonTable.features,
|
|
47
|
+
length: batch.length
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {ReadableFile} from '@loaders.gl/loader-utils';
|
|
6
|
+
import {convertArrowToTable} from '@loaders.gl/schema-utils';
|
|
7
|
+
import type {
|
|
8
|
+
ArrowTable,
|
|
9
|
+
ArrowTableBatch,
|
|
10
|
+
ObjectRowTable,
|
|
11
|
+
ObjectRowTableBatch
|
|
12
|
+
} from '@loaders.gl/schema';
|
|
13
|
+
|
|
14
|
+
import type {ParquetLoaderOptions} from '../../parquet-loader-options';
|
|
15
|
+
import {parseParquetFile, parseParquetFileInBatches} from './parse-parquet-to-json';
|
|
16
|
+
import {parseParquetFileToArrow, parseParquetFileToArrowInBatches} from './parse-parquet-to-arrow';
|
|
17
|
+
import {
|
|
18
|
+
parseParquetFileToArrowWithJs,
|
|
19
|
+
parseParquetFileToArrowInBatchesWithJs
|
|
20
|
+
} from './parse-parquet-to-arrow-js';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Parses a parquet file into an Arrow-backed table.
|
|
24
|
+
*
|
|
25
|
+
* @param file - Parquet file abstraction.
|
|
26
|
+
* @param options - Normalized parquet options.
|
|
27
|
+
* @returns Arrow table output.
|
|
28
|
+
*/
|
|
29
|
+
export function parseParquetArrowTable(
|
|
30
|
+
file: ReadableFile,
|
|
31
|
+
options: ParquetLoaderOptions
|
|
32
|
+
): Promise<ArrowTable> {
|
|
33
|
+
switch (getParquetBackend(options)) {
|
|
34
|
+
case 'typescript':
|
|
35
|
+
return parseParquetFileToArrowWithJs(file, options);
|
|
36
|
+
|
|
37
|
+
case 'wasm':
|
|
38
|
+
default:
|
|
39
|
+
return parseParquetFileToArrow(file, options.parquet);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Parses a parquet file into Arrow-backed table batches.
|
|
45
|
+
*
|
|
46
|
+
* @param file - Parquet file abstraction.
|
|
47
|
+
* @param options - Normalized parquet options.
|
|
48
|
+
* @returns Async iterable of Arrow table batches.
|
|
49
|
+
*/
|
|
50
|
+
export function parseParquetArrowTableInBatches(
|
|
51
|
+
file: ReadableFile,
|
|
52
|
+
options: ParquetLoaderOptions
|
|
53
|
+
): AsyncIterable<ArrowTableBatch> {
|
|
54
|
+
switch (getParquetBackend(options)) {
|
|
55
|
+
case 'typescript':
|
|
56
|
+
return parseParquetFileToArrowInBatchesWithJs(file, options);
|
|
57
|
+
|
|
58
|
+
case 'wasm':
|
|
59
|
+
default:
|
|
60
|
+
return parseParquetFileToArrowInBatches(file, options.parquet);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Parses a parquet file into plain object rows.
|
|
66
|
+
*
|
|
67
|
+
* @param file - Parquet file abstraction.
|
|
68
|
+
* @param options - Normalized parquet options.
|
|
69
|
+
* @returns Object-row table output.
|
|
70
|
+
*/
|
|
71
|
+
export async function parseParquetObjectRowTable(
|
|
72
|
+
file: ReadableFile,
|
|
73
|
+
options: ParquetLoaderOptions
|
|
74
|
+
): Promise<ObjectRowTable> {
|
|
75
|
+
if (getParquetBackend(options) === 'typescript') {
|
|
76
|
+
return await parseParquetFile(file, options);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const arrowTable = await parseParquetArrowTable(file, options);
|
|
80
|
+
return convertArrowTableToObjectRows(arrowTable);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Parses a parquet file into object-row batches.
|
|
85
|
+
*
|
|
86
|
+
* @param file - Parquet file abstraction.
|
|
87
|
+
* @param options - Normalized parquet options.
|
|
88
|
+
* @returns Async iterable of object-row table batches.
|
|
89
|
+
*/
|
|
90
|
+
export async function* parseParquetObjectRowTableInBatches(
|
|
91
|
+
file: ReadableFile,
|
|
92
|
+
options: ParquetLoaderOptions
|
|
93
|
+
): AsyncIterable<ObjectRowTableBatch> {
|
|
94
|
+
if (getParquetBackend(options) === 'typescript') {
|
|
95
|
+
yield* parseParquetFileInBatches(file, options);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
for await (const batch of parseParquetArrowTableInBatches(file, options)) {
|
|
100
|
+
yield convertArrowBatchToObjectRows(batch);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function getParquetBackend(options: ParquetLoaderOptions): 'wasm' | 'typescript' {
|
|
105
|
+
if (options.parquet?.backend) {
|
|
106
|
+
return options.parquet.backend;
|
|
107
|
+
}
|
|
108
|
+
return options.parquet?.implementation === 'js' ? 'typescript' : 'wasm';
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Converts an Arrow-backed table into object rows.
|
|
113
|
+
*
|
|
114
|
+
* @param arrowTable - Arrow table wrapper.
|
|
115
|
+
* @returns Object-row table.
|
|
116
|
+
*/
|
|
117
|
+
export function convertArrowTableToObjectRows(arrowTable: ArrowTable): ObjectRowTable {
|
|
118
|
+
return convertArrowToTable(arrowTable.data, 'object-row-table') as ObjectRowTable;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Converts an Arrow batch into object-row output.
|
|
123
|
+
*
|
|
124
|
+
* @param batch - Arrow table batch wrapper.
|
|
125
|
+
* @returns Object-row batch.
|
|
126
|
+
*/
|
|
127
|
+
export function convertArrowBatchToObjectRows(batch: ArrowTableBatch): ObjectRowTableBatch {
|
|
128
|
+
const objectRowTable = convertArrowToTable(batch.data, 'object-row-table') as ObjectRowTable;
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
batchType: batch.batchType,
|
|
132
|
+
shape: objectRowTable.shape,
|
|
133
|
+
schema: objectRowTable.schema,
|
|
134
|
+
data: objectRowTable.data,
|
|
135
|
+
length: batch.length
|
|
136
|
+
};
|
|
137
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {ReadableFile} from '@loaders.gl/loader-utils';
|
|
6
|
+
import type {ArrowTable, ArrowTableBatch} from '@loaders.gl/schema';
|
|
7
|
+
import {convertTable} from '@loaders.gl/schema-utils';
|
|
8
|
+
|
|
9
|
+
import type {ParquetLoaderOptions} from '../../parquet-loader-options';
|
|
10
|
+
import {normalizeArrowTableGeoMetadata} from '../geo/geospatial-metadata';
|
|
11
|
+
import {parseParquetFile, parseParquetFileInBatches} from './parse-parquet-to-json';
|
|
12
|
+
|
|
13
|
+
export async function parseParquetFileToArrowWithJs(
|
|
14
|
+
file: ReadableFile,
|
|
15
|
+
options?: ParquetLoaderOptions
|
|
16
|
+
): Promise<ArrowTable> {
|
|
17
|
+
const objectRowTable = await parseParquetFile(file, options);
|
|
18
|
+
return normalizeArrowTableGeoMetadata(convertTable(objectRowTable, 'arrow-table'));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function* parseParquetFileToArrowInBatchesWithJs(
|
|
22
|
+
file: ReadableFile,
|
|
23
|
+
options?: ParquetLoaderOptions
|
|
24
|
+
): AsyncIterable<ArrowTableBatch> {
|
|
25
|
+
for await (const batch of parseParquetFileInBatches(file, options)) {
|
|
26
|
+
const arrowTable = normalizeArrowTableGeoMetadata(convertTable(batch, 'arrow-table'));
|
|
27
|
+
|
|
28
|
+
yield {
|
|
29
|
+
batchType: batch.batchType,
|
|
30
|
+
shape: arrowTable.shape,
|
|
31
|
+
schema: arrowTable.schema,
|
|
32
|
+
data: arrowTable.data,
|
|
33
|
+
length: batch.length
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -5,68 +5,95 @@
|
|
|
5
5
|
// eslint-disable
|
|
6
6
|
import type {ReadableFile} from '@loaders.gl/loader-utils';
|
|
7
7
|
import type {ArrowTable, ArrowTableBatch, Schema} from '@loaders.gl/schema';
|
|
8
|
-
import {convertArrowToSchema} from '@loaders.gl/schema-utils';
|
|
9
8
|
|
|
10
|
-
import type * as parquetWasm from 'parquet-wasm';
|
|
9
|
+
import type * as parquetWasm from 'parquet-wasm/esm/parquet_wasm.js';
|
|
11
10
|
import * as arrow from 'apache-arrow';
|
|
12
11
|
|
|
12
|
+
import {
|
|
13
|
+
normalizeArrowTableGeoMetadata,
|
|
14
|
+
getParquetFileMetadataMap
|
|
15
|
+
} from '../geo/geospatial-metadata';
|
|
13
16
|
import {loadWasm} from '../utils/load-wasm';
|
|
14
17
|
import {makeStreamIterator} from '../utils/make-stream-iterator';
|
|
15
18
|
|
|
19
|
+
type ParquetWasmReaderOptions = parquetWasm.ReaderOptions & {wasmUrl?: string};
|
|
20
|
+
|
|
16
21
|
export async function parseParquetFileToArrow(
|
|
17
22
|
file: ReadableFile,
|
|
18
|
-
options?:
|
|
23
|
+
options?: ParquetWasmReaderOptions
|
|
19
24
|
): Promise<ArrowTable> {
|
|
20
25
|
const wasmUrl = options?.wasmUrl;
|
|
26
|
+
const readerOptions = getReaderOptions(options);
|
|
21
27
|
|
|
22
28
|
const wasm = await loadWasm(wasmUrl);
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
const parquetFile = await createParquetFile(file, wasm);
|
|
31
|
+
try {
|
|
32
|
+
const wasmTable = await parquetFile.read(readerOptions);
|
|
33
|
+
const ipcStream = wasmTable.intoIPCStream();
|
|
34
|
+
const arrowTable = arrow.tableFromIPC(ipcStream);
|
|
35
|
+
return normalizeArrowTableGeoMetadata(
|
|
36
|
+
{
|
|
37
|
+
shape: 'arrow-table',
|
|
38
|
+
data: arrowTable
|
|
39
|
+
},
|
|
40
|
+
getParquetFileMetadataMap(parquetFile.metadata())
|
|
41
|
+
);
|
|
42
|
+
} finally {
|
|
43
|
+
parquetFile.free();
|
|
30
44
|
}
|
|
31
|
-
|
|
32
|
-
const wasmTable = await parquetFile.read(options);
|
|
33
|
-
const ipcStream = wasmTable.intoIPCStream();
|
|
34
|
-
const arrowTable = arrow.tableFromIPC(ipcStream);
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
shape: 'arrow-table',
|
|
38
|
-
schema: convertArrowToSchema(arrowTable.schema),
|
|
39
|
-
data: arrowTable
|
|
40
|
-
};
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
export async function* parseParquetFileToArrowInBatches(
|
|
44
48
|
file: ReadableFile,
|
|
45
|
-
options
|
|
49
|
+
options?: ParquetWasmReaderOptions
|
|
46
50
|
): AsyncIterable<ArrowTableBatch> {
|
|
47
51
|
const wasmUrl = options?.wasmUrl;
|
|
52
|
+
const readerOptions = getReaderOptions(options);
|
|
48
53
|
|
|
49
54
|
const wasm = await loadWasm(wasmUrl);
|
|
50
55
|
|
|
51
|
-
|
|
56
|
+
const parquetFile = await createParquetFile(file, wasm);
|
|
57
|
+
try {
|
|
58
|
+
const stream = await parquetFile.stream(readerOptions);
|
|
59
|
+
const schemaMetadata = getParquetFileMetadataMap(parquetFile.metadata());
|
|
60
|
+
|
|
61
|
+
let schema: Schema | undefined;
|
|
62
|
+
for await (const wasmRecordBatch of makeStreamIterator<parquetWasm.RecordBatch>(stream)) {
|
|
63
|
+
const normalizedArrowTable = normalizeArrowTableGeoMetadata(
|
|
64
|
+
{
|
|
65
|
+
shape: 'arrow-table',
|
|
66
|
+
data: arrow.tableFromIPC(wasmRecordBatch.intoIPCStream())
|
|
67
|
+
},
|
|
68
|
+
schemaMetadata
|
|
69
|
+
);
|
|
70
|
+
schema ||= normalizedArrowTable.schema;
|
|
71
|
+
yield {
|
|
72
|
+
batchType: 'data',
|
|
73
|
+
shape: 'arrow-table',
|
|
74
|
+
schema,
|
|
75
|
+
data: normalizedArrowTable.data,
|
|
76
|
+
length: normalizedArrowTable.data.numRows
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
} finally {
|
|
80
|
+
parquetFile.free();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function createParquetFile(
|
|
85
|
+
file: ReadableFile,
|
|
86
|
+
wasm: typeof parquetWasm
|
|
87
|
+
): Promise<parquetWasm.ParquetFile> {
|
|
52
88
|
if (file.handle instanceof Blob) {
|
|
53
89
|
// Works on Blobs: https://kylebarron.dev/parquet-wasm/classes/esm_parquet_wasm.ParquetFile.html#fromFile
|
|
54
|
-
|
|
55
|
-
} else {
|
|
56
|
-
parquetFile = await wasm.ParquetFile.fromUrl(file.url);
|
|
90
|
+
return await wasm.ParquetFile.fromFile(file.handle as File);
|
|
57
91
|
}
|
|
58
92
|
|
|
59
|
-
|
|
93
|
+
return await wasm.ParquetFile.fromUrl(file.url);
|
|
94
|
+
}
|
|
60
95
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
yield {
|
|
65
|
-
batchType: 'data',
|
|
66
|
-
shape: 'arrow-table',
|
|
67
|
-
schema,
|
|
68
|
-
data: new arrow.Table(recordBatch),
|
|
69
|
-
length: recordBatch.numRows
|
|
70
|
-
};
|
|
71
|
-
}
|
|
96
|
+
function getReaderOptions(options?: ParquetWasmReaderOptions): parquetWasm.ReaderOptions {
|
|
97
|
+
const {wasmUrl, ...readerOptions} = options || {};
|
|
98
|
+
return readerOptions;
|
|
72
99
|
}
|
|
@@ -4,13 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import type {ColumnarTable, ColumnarTableBatch, Schema} from '@loaders.gl/schema';
|
|
6
6
|
import type {ReadableFile} from '@loaders.gl/loader-utils';
|
|
7
|
-
import type {
|
|
7
|
+
import type {ParquetLoaderOptions} from '../../parquet-loader';
|
|
8
8
|
import {ParquetReader} from '../../parquetjs/parser/parquet-reader';
|
|
9
9
|
import {ParquetRowGroup} from '../../parquetjs/schema/declare';
|
|
10
10
|
import {ParquetSchema} from '../../parquetjs/schema/schema';
|
|
11
11
|
import {materializeColumns} from '../../parquetjs/schema/shred';
|
|
12
12
|
import {getSchemaFromParquetReader} from './get-parquet-schema';
|
|
13
|
-
import {installBufferPolyfill} from '../../polyfills/buffer/index';
|
|
14
13
|
import {preloadCompressions} from '../../parquetjs/compression';
|
|
15
14
|
|
|
16
15
|
/**
|
|
@@ -18,9 +17,8 @@ import {preloadCompressions} from '../../parquetjs/compression';
|
|
|
18
17
|
*/
|
|
19
18
|
export async function parseParquetFileInColumns(
|
|
20
19
|
file: ReadableFile,
|
|
21
|
-
options?:
|
|
20
|
+
options?: ParquetLoaderOptions
|
|
22
21
|
): Promise<ColumnarTable> {
|
|
23
|
-
installBufferPolyfill();
|
|
24
22
|
await preloadCompressions(options);
|
|
25
23
|
|
|
26
24
|
for await (const batch of parseParquetFileInColumnarBatches(file, options)) {
|
|
@@ -38,9 +36,8 @@ export async function parseParquetFileInColumns(
|
|
|
38
36
|
*/
|
|
39
37
|
export async function* parseParquetFileInColumnarBatches(
|
|
40
38
|
file: ReadableFile,
|
|
41
|
-
options?:
|
|
39
|
+
options?: ParquetLoaderOptions
|
|
42
40
|
): AsyncIterable<ColumnarTableBatch> {
|
|
43
|
-
installBufferPolyfill();
|
|
44
41
|
await preloadCompressions(options);
|
|
45
42
|
|
|
46
43
|
const reader = new ParquetReader(file);
|
|
@@ -51,7 +48,9 @@ export async function* parseParquetFileInColumnarBatches(
|
|
|
51
48
|
const parquetSchema = await reader.getSchema();
|
|
52
49
|
|
|
53
50
|
// Iterate over row batches
|
|
54
|
-
const rowGroups = reader.rowGroupIterator(
|
|
51
|
+
const rowGroups = reader.rowGroupIterator(
|
|
52
|
+
options?.parquet?.columns?.length ? {columnList: options.parquet.columns} : undefined
|
|
53
|
+
);
|
|
55
54
|
for await (const rowGroup of rowGroups) {
|
|
56
55
|
yield convertRowGroupToTableBatch(rowGroup, parquetSchema, schema);
|
|
57
56
|
}
|
|
@@ -4,13 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import {default as log} from '@probe.gl/log';
|
|
6
6
|
import type {ReadableFile} from '@loaders.gl/loader-utils';
|
|
7
|
-
import type {ObjectRowTable, ObjectRowTableBatch} from '@loaders.gl/schema';
|
|
7
|
+
import type {ObjectRowTable, ObjectRowTableBatch, Schema} from '@loaders.gl/schema';
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type {ParquetLoaderOptions} from '../../parquet-loader-options';
|
|
10
10
|
import type {ParquetRow} from '../../parquetjs/schema/declare';
|
|
11
11
|
import {ParquetReader} from '../../parquetjs/parser/parquet-reader';
|
|
12
12
|
import {getSchemaFromParquetReader} from './get-parquet-schema';
|
|
13
|
-
import {installBufferPolyfill} from '../../polyfills/buffer/index';
|
|
14
13
|
import {preloadCompressions} from '../../parquetjs/compression';
|
|
15
14
|
|
|
16
15
|
/**
|
|
@@ -21,9 +20,8 @@ import {preloadCompressions} from '../../parquetjs/compression';
|
|
|
21
20
|
*/
|
|
22
21
|
export async function parseParquetFile(
|
|
23
22
|
file: ReadableFile,
|
|
24
|
-
options?:
|
|
23
|
+
options?: ParquetLoaderOptions
|
|
25
24
|
): Promise<ObjectRowTable> {
|
|
26
|
-
installBufferPolyfill();
|
|
27
25
|
await preloadCompressions(options);
|
|
28
26
|
|
|
29
27
|
const reader = new ParquetReader(file, {
|
|
@@ -31,30 +29,37 @@ export async function parseParquetFile(
|
|
|
31
29
|
});
|
|
32
30
|
|
|
33
31
|
const schema = await getSchemaFromParquetReader(reader);
|
|
32
|
+
const projectedSchema = projectSchema(schema, options?.parquet?.columns);
|
|
34
33
|
|
|
35
34
|
const rows: ParquetRow[] = [];
|
|
36
35
|
|
|
37
|
-
const rowBatches = reader.rowBatchIterator(options
|
|
36
|
+
const rowBatches = reader.rowBatchIterator(getParquetIterationProps(options));
|
|
37
|
+
const rowOffset = options?.parquet?.offset || 0;
|
|
38
|
+
const rowLimit = options?.parquet?.limit;
|
|
39
|
+
let rowsSkipped = 0;
|
|
38
40
|
for await (const rowBatch of rowBatches) {
|
|
39
|
-
let limitHasReached = false;
|
|
40
|
-
// we have only one input batch so return
|
|
41
41
|
for (const row of rowBatch) {
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
if (rowsSkipped < rowOffset) {
|
|
43
|
+
rowsSkipped++;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (rowLimit !== undefined && rows.length >= rowLimit) {
|
|
48
|
+
log.warn(`Rows number limit has been reached. Only first ${rowLimit} are loaded`)();
|
|
49
|
+
return {
|
|
50
|
+
shape: 'object-row-table',
|
|
51
|
+
schema: projectedSchema,
|
|
52
|
+
data: rows
|
|
53
|
+
};
|
|
45
54
|
}
|
|
55
|
+
|
|
46
56
|
rows.push(row);
|
|
47
57
|
}
|
|
48
|
-
if (limitHasReached) {
|
|
49
|
-
log.warn(
|
|
50
|
-
`Rows number limit has been reached. Only first ${options?.core?.limit} are loaded`
|
|
51
|
-
)();
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
58
|
}
|
|
59
|
+
|
|
55
60
|
const objectRowTable: ObjectRowTable = {
|
|
56
61
|
shape: 'object-row-table',
|
|
57
|
-
schema,
|
|
62
|
+
schema: projectedSchema,
|
|
58
63
|
data: rows
|
|
59
64
|
};
|
|
60
65
|
|
|
@@ -68,9 +73,8 @@ export async function parseParquetFile(
|
|
|
68
73
|
*/
|
|
69
74
|
export async function* parseParquetFileInBatches(
|
|
70
75
|
file: ReadableFile,
|
|
71
|
-
options?:
|
|
76
|
+
options?: ParquetLoaderOptions
|
|
72
77
|
): AsyncIterable<ObjectRowTableBatch> {
|
|
73
|
-
installBufferPolyfill();
|
|
74
78
|
await preloadCompressions(options);
|
|
75
79
|
|
|
76
80
|
const reader = new ParquetReader(file, {
|
|
@@ -78,19 +82,83 @@ export async function* parseParquetFileInBatches(
|
|
|
78
82
|
});
|
|
79
83
|
|
|
80
84
|
const schema = await getSchemaFromParquetReader(reader);
|
|
81
|
-
const
|
|
85
|
+
const projectedSchema = projectSchema(schema, options?.parquet?.columns);
|
|
86
|
+
const rowBatches = reader.rowBatchIterator(getParquetIterationProps(options));
|
|
87
|
+
const rowOffset = options?.parquet?.offset || 0;
|
|
88
|
+
const rowLimit = options?.parquet?.limit;
|
|
89
|
+
const outputBatchSize = options?.parquet?.batchSize;
|
|
90
|
+
let rowsSkipped = 0;
|
|
91
|
+
let rowsYielded = 0;
|
|
92
|
+
let reachedLimit = false;
|
|
93
|
+
|
|
82
94
|
for await (const rows of rowBatches) {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
const nextRows: ParquetRow[] = [];
|
|
96
|
+
for (const row of rows) {
|
|
97
|
+
if (rowsSkipped < rowOffset) {
|
|
98
|
+
rowsSkipped++;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (rowLimit !== undefined && rowsYielded >= rowLimit) {
|
|
103
|
+
reachedLimit = true;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
nextRows.push(row);
|
|
108
|
+
rowsYielded++;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (nextRows.length === 0) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (!outputBatchSize || outputBatchSize <= 0) {
|
|
116
|
+
yield makeObjectRowBatch(projectedSchema, nextRows);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
for (let rowIndex = 0; rowIndex < nextRows.length; rowIndex += outputBatchSize) {
|
|
121
|
+
yield makeObjectRowBatch(
|
|
122
|
+
projectedSchema,
|
|
123
|
+
nextRows.slice(rowIndex, rowIndex + outputBatchSize)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (reachedLimit) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
95
130
|
}
|
|
96
131
|
}
|
|
132
|
+
|
|
133
|
+
function getParquetIterationProps(
|
|
134
|
+
options?: ParquetLoaderOptions
|
|
135
|
+
): {columnList?: string[] | string[][]} | undefined {
|
|
136
|
+
const columnList = options?.parquet?.columns;
|
|
137
|
+
return columnList?.length ? {columnList} : undefined;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function makeObjectRowBatch(schema: Schema, rows: ParquetRow[]): ObjectRowTableBatch {
|
|
141
|
+
const objectRowTable: ObjectRowTable = {
|
|
142
|
+
shape: 'object-row-table',
|
|
143
|
+
schema,
|
|
144
|
+
data: rows
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
batchType: 'data',
|
|
149
|
+
schema,
|
|
150
|
+
...objectRowTable,
|
|
151
|
+
length: rows.length
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function projectSchema(schema: Schema, columns?: string[]): Schema {
|
|
156
|
+
if (!columns?.length) {
|
|
157
|
+
return schema;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
...schema,
|
|
162
|
+
fields: schema.fields.filter(field => columns.includes(field.name))
|
|
163
|
+
};
|
|
164
|
+
}
|
|
@@ -2,21 +2,28 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
import initWasm from 'parquet-wasm';
|
|
7
|
-
import * as parquetWasm from 'parquet-wasm';
|
|
5
|
+
import type * as ParquetWasm from 'parquet-wasm/esm/parquet_wasm.js';
|
|
8
6
|
import {PARQUET_WASM_URL} from '../constants';
|
|
9
7
|
|
|
10
|
-
let initializePromise:
|
|
8
|
+
let initializePromise: Promise<typeof ParquetWasm>;
|
|
11
9
|
|
|
12
|
-
export async function loadWasm(
|
|
13
|
-
|
|
10
|
+
export async function loadWasm(
|
|
11
|
+
wasmUrl: ParquetWasm.InitInput | Promise<ParquetWasm.InitInput> = PARQUET_WASM_URL
|
|
12
|
+
): Promise<typeof ParquetWasm> {
|
|
13
|
+
if (!initializePromise) {
|
|
14
14
|
if (!wasmUrl) {
|
|
15
15
|
throw new Error('ParquetLoader: No wasmUrl provided');
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
initializePromise = initWasm(wasmUrl);
|
|
17
|
+
initializePromise = loadAndInitializeWasm(wasmUrl);
|
|
19
18
|
}
|
|
20
|
-
|
|
19
|
+
|
|
20
|
+
return await initializePromise;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function loadAndInitializeWasm(
|
|
24
|
+
wasmUrl: ParquetWasm.InitInput | Promise<ParquetWasm.InitInput>
|
|
25
|
+
): Promise<typeof ParquetWasm> {
|
|
26
|
+
const parquetWasm = await import('parquet-wasm/esm/parquet_wasm.js');
|
|
27
|
+
await parquetWasm.default({module_or_path: wasmUrl});
|
|
21
28
|
return parquetWasm;
|
|
22
29
|
}
|
|
@@ -65,7 +65,7 @@ async function* makeBrowserStreamIterator<T>(
|
|
|
65
65
|
yield value;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
} catch (
|
|
68
|
+
} catch (_error) {
|
|
69
69
|
// TODO - examples makes it look like this should always be called,
|
|
70
70
|
// but that generates exceptions so only call it if we do not reach the end
|
|
71
71
|
reader.releaseLock();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** Merge caller options with default parquet options while preserving top-level option bags. */
|
|
6
|
+
export function normalizeParquetOptions<OptionsT extends {parquet?: unknown}>(
|
|
7
|
+
options: OptionsT | undefined,
|
|
8
|
+
parquetDefaults: Record<string, unknown>
|
|
9
|
+
): OptionsT {
|
|
10
|
+
return {
|
|
11
|
+
...options,
|
|
12
|
+
parquet: {...parquetDefaults, ...(options?.parquet as Record<string, unknown> | undefined)}
|
|
13
|
+
} as unknown as OptionsT;
|
|
14
|
+
}
|