@loaders.gl/arrow 4.1.0-alpha.1 → 4.1.0-alpha.11
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/arrow-loader.d.ts +1 -0
- package/dist/arrow-loader.d.ts.map +1 -1
- package/dist/arrow-loader.js +1 -1
- package/dist/arrow-loader.js.map +1 -1
- package/dist/arrow-worker.js +6132 -5809
- package/dist/arrow-writer.js +1 -1
- package/dist/arrow-writer.js.map +1 -1
- package/dist/dist.dev.js +6193 -5806
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts +4 -2
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +1 -1
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js +25 -23
- package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js.map +1 -1
- package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.d.ts.map +1 -1
- package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.js.map +1 -1
- package/dist/geoarrow/get-arrow-bounds.d.ts.map +1 -1
- package/dist/geoarrow/get-arrow-bounds.js.map +1 -1
- package/dist/geoarrow-loader.d.ts.map +1 -1
- package/dist/geoarrow-loader.js.map +1 -1
- package/dist/geoarrow-writer.js +1 -1
- package/dist/geoarrow-writer.js.map +1 -1
- package/dist/index.cjs +77 -17
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/arrow-table-batch.d.ts.map +1 -1
- package/dist/lib/arrow-table-batch.js.map +1 -1
- package/dist/lib/arrow-table.d.ts.map +1 -1
- package/dist/lib/arrow-table.js.map +1 -1
- package/dist/lib/encode-arrow.d.ts.map +1 -1
- package/dist/lib/encode-arrow.js.map +1 -1
- package/dist/lib/encode-geoarrow.d.ts.map +1 -1
- package/dist/lib/encode-geoarrow.js.map +1 -1
- package/dist/parsers/parse-arrow-in-batches.d.ts +2 -1
- package/dist/parsers/parse-arrow-in-batches.d.ts.map +1 -1
- package/dist/parsers/parse-arrow-in-batches.js +8 -1
- package/dist/parsers/parse-arrow-in-batches.js.map +1 -1
- package/dist/parsers/parse-arrow-sync.d.ts.map +1 -1
- package/dist/parsers/parse-arrow-sync.js.map +1 -1
- package/dist/parsers/parse-geoarrow-in-batches.d.ts.map +1 -1
- package/dist/parsers/parse-geoarrow-in-batches.js.map +1 -1
- package/dist/parsers/parse-geoarrow-sync.d.ts.map +1 -1
- package/dist/parsers/parse-geoarrow-sync.js.map +1 -1
- package/dist/schema/arrow-type-utils.d.ts.map +1 -1
- package/dist/schema/arrow-type-utils.js.map +1 -1
- package/dist/schema/convert-arrow-schema.d.ts.map +1 -1
- package/dist/schema/convert-arrow-schema.js.map +1 -1
- package/dist/tables/convert-arrow-to-columnar-table.d.ts.map +1 -1
- package/dist/tables/convert-arrow-to-columnar-table.js.map +1 -1
- package/dist/tables/convert-arrow-to-geojson-table.d.ts.map +1 -1
- package/dist/tables/convert-arrow-to-geojson-table.js.map +1 -1
- package/dist/tables/convert-columnar-to-row-table.d.ts.map +1 -1
- package/dist/tables/convert-columnar-to-row-table.js.map +1 -1
- package/dist/tables/convert-table-to-arrow.d.ts.map +1 -1
- package/dist/tables/convert-table-to-arrow.js.map +1 -1
- package/dist/triangulate-on-worker.d.ts +39 -5
- package/dist/triangulate-on-worker.d.ts.map +1 -1
- package/dist/triangulate-on-worker.js +12 -2
- package/dist/triangulate-on-worker.js.map +1 -1
- package/dist/triangulation-worker.js +11992 -11
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/workers/arrow-worker.js.map +1 -1
- package/dist/workers/hard-clone.d.ts +23 -0
- package/dist/workers/hard-clone.d.ts.map +1 -0
- package/dist/workers/hard-clone.js +57 -0
- package/dist/workers/hard-clone.js.map +1 -0
- package/dist/workers/triangulation-worker-node.d.ts.map +1 -1
- package/dist/workers/triangulation-worker-node.js.map +1 -1
- package/dist/workers/triangulation-worker.js +34 -2
- package/dist/workers/triangulation-worker.js.map +1 -1
- package/package.json +9 -9
- package/src/arrow-loader.ts +3 -1
- package/src/geoarrow/convert-geoarrow-to-binary-geometry.ts +28 -20
- package/src/geoarrow/convert-geoarrow-to-geojson-geometry.ts +2 -1
- package/src/geoarrow/get-arrow-bounds.ts +2 -1
- package/src/geoarrow-loader.ts +2 -1
- package/src/index.ts +10 -3
- package/src/lib/arrow-table-batch.ts +2 -1
- package/src/lib/arrow-table.ts +2 -1
- package/src/lib/encode-arrow.ts +2 -1
- package/src/lib/encode-geoarrow.ts +2 -1
- package/src/parsers/parse-arrow-in-batches.ts +9 -2
- package/src/parsers/parse-arrow-sync.ts +2 -1
- package/src/parsers/parse-geoarrow-in-batches.ts +2 -1
- package/src/parsers/parse-geoarrow-sync.ts +2 -1
- package/src/schema/arrow-type-utils.ts +2 -1
- package/src/schema/convert-arrow-schema.ts +2 -1
- package/src/tables/convert-arrow-to-columnar-table.ts +2 -1
- package/src/tables/convert-arrow-to-geojson-table.ts +2 -1
- package/src/tables/convert-columnar-to-row-table.ts +2 -1
- package/src/tables/convert-table-to-arrow.ts +2 -1
- package/src/triangulate-on-worker.ts +52 -8
- package/src/types.ts +2 -1
- package/src/workers/arrow-worker.ts +2 -1
- package/src/workers/hard-clone.ts +162 -0
- package/src/workers/triangulation-worker-node.ts +2 -1
- package/src/workers/triangulation-worker.ts +58 -4
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,KAAK,aAAa,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;AAElG,KAAK,eAAe,GAAG,YAAY,GAAG,YAAY,CAAC;AAEnD,KAAK,UAAU,GAAG,aAAa,GAAG,eAAe,CAAC;AAElD,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC;AAEnD,oBAAY,YAAY;IACtB,KAAK,IAAA;IACL,IAAI,IAAA;CACL"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["VECTOR_TYPES"],"sources":["../src/types.ts"],"sourcesContent":["// loaders.gl
|
|
1
|
+
{"version":3,"file":"types.js","names":["VECTOR_TYPES"],"sources":["../src/types.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\ntype TypedIntArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array;\n\ntype TypedFloatArray = Float32Array | Float64Array;\n\ntype TypedArray = TypedIntArray | TypedFloatArray;\n\nexport type AnyArrayType = Array<any> | TypedArray;\n\nexport enum VECTOR_TYPES {\n FLOAT,\n DATE\n}\n"],"mappings":"AAYA,WAAYA,YAAY,aAAZA,YAAY;EAAZA,YAAY,CAAZA,YAAY;EAAZA,YAAY,CAAZA,YAAY;EAAA,OAAZA,YAAY;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrow-worker.js","names":["createLoaderWorker","ArrowLoader"],"sources":["../../src/workers/arrow-worker.ts"],"sourcesContent":["// loaders.gl
|
|
1
|
+
{"version":3,"file":"arrow-worker.js","names":["createLoaderWorker","ArrowLoader"],"sources":["../../src/workers/arrow-worker.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {createLoaderWorker} from '@loaders.gl/loader-utils';\nimport {ArrowLoader} from '../arrow-loader';\n\ncreateLoaderWorker(ArrowLoader);\n"],"mappings":"AAIA,SAAQA,kBAAkB,QAAO,0BAA0B;AAAC,SACpDC,WAAW;AAEnBD,kBAAkB,CAACC,WAAW,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as arrow from 'apache-arrow';
|
|
2
|
+
/**
|
|
3
|
+
* Clone an Arrow JS Data or Vector, detaching from an existing ArrayBuffer if
|
|
4
|
+
* it is shared with other.
|
|
5
|
+
*
|
|
6
|
+
* The purpose of this function is to enable transferring a `Data` instance,
|
|
7
|
+
* e.g. to a web worker, without neutering any other data.
|
|
8
|
+
*
|
|
9
|
+
* Any internal buffers that are a slice of a larger `ArrayBuffer` (i.e. where
|
|
10
|
+
* the typed array's `byteOffset` is not `0` and where its `byteLength` does not
|
|
11
|
+
* match its `array.buffer.byteLength`) are copied into new `ArrayBuffers`.
|
|
12
|
+
*
|
|
13
|
+
* If `force` is `true`, always clone internal buffers, even if not shared. If
|
|
14
|
+
* the default, `false`, any internal buffers that are **not** a slice of a
|
|
15
|
+
* larger `ArrayBuffer` will not be copied.
|
|
16
|
+
*/
|
|
17
|
+
export declare function hardClone<T extends arrow.DataType>(input: arrow.Data<T>, force?: boolean): arrow.Data<T>;
|
|
18
|
+
export declare function hardClone<T extends arrow.DataType>(input: arrow.Vector<T>, force?: boolean): arrow.Vector<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Test whether an arrow.Data instance is a slice of a larger `ArrayBuffer`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isShared<T extends arrow.DataType>(data: arrow.Data<T> | arrow.Vector<T>): boolean;
|
|
23
|
+
//# sourceMappingURL=hard-clone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hard-clone.d.ts","sourceRoot":"","sources":["../../src/workers/hard-clone.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AActC;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,KAAK,CAAC,QAAQ,EAChD,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EACpB,KAAK,CAAC,EAAE,OAAO,GACd,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,wBAAgB,SAAS,CAAC,CAAC,SAAS,KAAK,CAAC,QAAQ,EAChD,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EACtB,KAAK,CAAC,EAAE,OAAO,GACd,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAuDnB;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAiCjG"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as arrow from 'apache-arrow';
|
|
2
|
+
export function hardClone(data) {
|
|
3
|
+
let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
4
|
+
if ('data' in data) {
|
|
5
|
+
return new arrow.Vector(data.data.map(data => hardClone(data, force)));
|
|
6
|
+
}
|
|
7
|
+
const clonedChildren = [];
|
|
8
|
+
for (const childData of data.children) {
|
|
9
|
+
clonedChildren.push(hardClone(childData, force));
|
|
10
|
+
}
|
|
11
|
+
let clonedDictionary;
|
|
12
|
+
if (data.dictionary !== undefined) {
|
|
13
|
+
clonedDictionary = hardClone(data.dictionary, force);
|
|
14
|
+
}
|
|
15
|
+
const clonedBuffers = {
|
|
16
|
+
[arrow.BufferType.OFFSET]: cloneBuffer(data.buffers[arrow.BufferType.OFFSET], force),
|
|
17
|
+
[arrow.BufferType.DATA]: cloneBuffer(data.buffers[arrow.BufferType.DATA], force),
|
|
18
|
+
[arrow.BufferType.VALIDITY]: cloneBuffer(data.buffers[arrow.BufferType.VALIDITY], force),
|
|
19
|
+
[arrow.BufferType.TYPE]: cloneBuffer(data.buffers[arrow.BufferType.TYPE], force)
|
|
20
|
+
};
|
|
21
|
+
return new arrow.Data(data.type, data.offset, data.length, data._nullCount, clonedBuffers, clonedChildren, clonedDictionary);
|
|
22
|
+
}
|
|
23
|
+
export function isShared(data) {
|
|
24
|
+
if ('data' in data) {
|
|
25
|
+
return data.data.some(data => isShared(data));
|
|
26
|
+
}
|
|
27
|
+
for (const childData of data.children) {
|
|
28
|
+
if (isShared(childData)) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (data.dictionary !== undefined) {
|
|
33
|
+
if (isShared(data.dictionary)) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const bufferTypes = [arrow.BufferType.OFFSET, arrow.BufferType.DATA, arrow.BufferType.VALIDITY, arrow.BufferType.TYPE];
|
|
38
|
+
for (const bufferType of bufferTypes) {
|
|
39
|
+
if (data.buffers[bufferType] !== undefined && isTypedArraySliced(data.buffers[bufferType])) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
function isTypedArraySliced(arr) {
|
|
46
|
+
return !(arr.byteOffset === 0 && arr.byteLength === arr.buffer.byteLength);
|
|
47
|
+
}
|
|
48
|
+
function cloneBuffer(arr, force) {
|
|
49
|
+
if (arr === undefined) {
|
|
50
|
+
return arr;
|
|
51
|
+
}
|
|
52
|
+
if (!force && !isTypedArraySliced(arr)) {
|
|
53
|
+
return arr;
|
|
54
|
+
}
|
|
55
|
+
return arr.slice();
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=hard-clone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hard-clone.js","names":["arrow","hardClone","data","force","arguments","length","undefined","Vector","map","clonedChildren","childData","children","push","clonedDictionary","dictionary","clonedBuffers","BufferType","OFFSET","cloneBuffer","buffers","DATA","VALIDITY","TYPE","Data","type","offset","_nullCount","isShared","some","bufferTypes","bufferType","isTypedArraySliced","arr","byteOffset","byteLength","buffer","slice"],"sources":["../../src/workers/hard-clone.ts"],"sourcesContent":["import * as arrow from 'apache-arrow';\nimport type {Buffers} from 'apache-arrow/data';\n\ntype TypedArray =\n | Uint8Array\n | Uint8ClampedArray\n | Uint16Array\n | Uint32Array\n | Int8Array\n | Int16Array\n | Int32Array\n | Float32Array\n | Float64Array;\n\n/**\n * Clone an Arrow JS Data or Vector, detaching from an existing ArrayBuffer if\n * it is shared with other.\n *\n * The purpose of this function is to enable transferring a `Data` instance,\n * e.g. to a web worker, without neutering any other data.\n *\n * Any internal buffers that are a slice of a larger `ArrayBuffer` (i.e. where\n * the typed array's `byteOffset` is not `0` and where its `byteLength` does not\n * match its `array.buffer.byteLength`) are copied into new `ArrayBuffers`.\n *\n * If `force` is `true`, always clone internal buffers, even if not shared. If\n * the default, `false`, any internal buffers that are **not** a slice of a\n * larger `ArrayBuffer` will not be copied.\n */\nexport function hardClone<T extends arrow.DataType>(\n input: arrow.Data<T>,\n force?: boolean\n): arrow.Data<T>;\nexport function hardClone<T extends arrow.DataType>(\n input: arrow.Vector<T>,\n force?: boolean\n): arrow.Vector<T>;\n\nexport function hardClone<T extends arrow.DataType>(\n data: arrow.Data<T> | arrow.Vector<T>,\n force: boolean = false\n): arrow.Data<T> | arrow.Vector<T> {\n // Check if `data` is an arrow.Vector\n if ('data' in data) {\n return new arrow.Vector(data.data.map((data) => hardClone(data, force)));\n }\n\n // Clone each of the children, recursively\n const clonedChildren: arrow.Data[] = [];\n for (const childData of data.children) {\n clonedChildren.push(hardClone(childData, force));\n }\n\n // Clone the dictionary if there is one\n let clonedDictionary: arrow.Vector | undefined;\n if (data.dictionary !== undefined) {\n clonedDictionary = hardClone(data.dictionary, force);\n }\n\n // Buffers can have up to four entries. Each of these can be `undefined` for\n // one or more array types.\n //\n // - OFFSET: value offsets for variable size list types\n // - DATA: the underlying data\n // - VALIDITY: the null buffer. This may be empty or undefined if all elements\n // are non-null/valid.\n // - TYPE: type ids for a union type.\n const clonedBuffers: Buffers<T> = {\n [arrow.BufferType.OFFSET]: cloneBuffer(data.buffers[arrow.BufferType.OFFSET], force),\n [arrow.BufferType.DATA]: cloneBuffer(data.buffers[arrow.BufferType.DATA], force),\n [arrow.BufferType.VALIDITY]: cloneBuffer(data.buffers[arrow.BufferType.VALIDITY], force),\n [arrow.BufferType.TYPE]: cloneBuffer(data.buffers[arrow.BufferType.TYPE], force)\n };\n\n // Note: the data.offset is passed on so that a sliced Data instance will not\n // be \"un-sliced\". However keep in mind that this means we're cloning the\n // _original backing buffer_, not only the portion of the Data that was\n // sliced.\n return new arrow.Data(\n data.type,\n data.offset,\n data.length,\n // @ts-expect-error _nullCount is protected. We're using it here to mimic\n // `Data.clone`\n data._nullCount,\n clonedBuffers,\n clonedChildren,\n clonedDictionary\n );\n}\n\n/**\n * Test whether an arrow.Data instance is a slice of a larger `ArrayBuffer`.\n */\nexport function isShared<T extends arrow.DataType>(data: arrow.Data<T> | arrow.Vector<T>): boolean {\n // Loop over arrow.Vector\n if ('data' in data) {\n return data.data.some((data) => isShared(data));\n }\n\n // Check child data\n for (const childData of data.children) {\n if (isShared(childData)) {\n return true;\n }\n }\n\n // Check dictionary\n if (data.dictionary !== undefined) {\n if (isShared(data.dictionary)) {\n return true;\n }\n }\n\n const bufferTypes = [\n arrow.BufferType.OFFSET,\n arrow.BufferType.DATA,\n arrow.BufferType.VALIDITY,\n arrow.BufferType.TYPE\n ];\n for (const bufferType of bufferTypes) {\n if (data.buffers[bufferType] !== undefined && isTypedArraySliced(data.buffers[bufferType])) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Returns true if the current typed array is a partial slice on a larger\n * ArrayBuffer\n */\nfunction isTypedArraySliced(arr: TypedArray): boolean {\n return !(arr.byteOffset === 0 && arr.byteLength === arr.buffer.byteLength);\n}\n\n/**\n * If a slice of a larger ArrayBuffer, clone to a fresh `ArrayBuffer`.\n *\n * If `force` is `true`, always clone the array, even if not shared.\n */\nfunction cloneBuffer<A extends TypedArray | undefined>(arr: A, force: boolean): A {\n // Not all buffer types are defined for every type of Arrow array. E.g.\n // `arrow.BufferType.TYPE` is only defined for the Union type.\n if (arr === undefined) {\n return arr;\n }\n\n // The current array is not a part of a larger ArrayBuffer, don't clone it\n if (!force && !isTypedArraySliced(arr)) {\n return arr;\n }\n\n // Note: TypedArray.slice() **copies** into a new ArrayBuffer\n\n // @ts-expect-error 'Uint8Array' is assignable to the constraint of type 'A',\n // but 'A' could be instantiated with a different subtype of constraint\n // 'TypedArray'\n // We know from arr.slice that it will always return the same\n return arr.slice();\n}\n"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"triangulation-worker-node.d.ts","sourceRoot":"","sources":["../../src/workers/triangulation-worker-node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"triangulation-worker-node.d.ts","sourceRoot":"","sources":["../../src/workers/triangulation-worker-node.ts"],"names":[],"mappings":"AAIA,OAAO,wBAAwB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"triangulation-worker-node.js","names":[],"sources":["../../src/workers/triangulation-worker-node.ts"],"sourcesContent":["// loaders.gl
|
|
1
|
+
{"version":3,"file":"triangulation-worker-node.js","names":[],"sources":["../../src/workers/triangulation-worker-node.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport './triangulation-worker';\n"],"mappings":""}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import * as arrow from 'apache-arrow';
|
|
1
2
|
import { createWorker } from '@loaders.gl/worker-utils';
|
|
2
|
-
import { getTriangleIndices } from "../geoarrow/convert-geoarrow-to-binary-geometry.js";
|
|
3
|
+
import { getTriangleIndices, getBinaryGeometriesFromArrow } from "../geoarrow/convert-geoarrow-to-binary-geometry.js";
|
|
3
4
|
createWorker(async function (data) {
|
|
4
5
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
5
6
|
const input = data;
|
|
@@ -9,12 +10,13 @@ createWorker(async function (data) {
|
|
|
9
10
|
return input;
|
|
10
11
|
case 'triangulate':
|
|
11
12
|
return triangulateBatch(data);
|
|
13
|
+
case 'parse-geoarrow':
|
|
14
|
+
return parseGeoArrowBatch(data);
|
|
12
15
|
default:
|
|
13
16
|
throw new Error(`TriangulationWorker: Unsupported operation ${operation}. Expected 'triangulate'`);
|
|
14
17
|
}
|
|
15
18
|
});
|
|
16
19
|
function triangulateBatch(data) {
|
|
17
|
-
console.error('TriangulationWorker: tessellating batch', data);
|
|
18
20
|
const triangleIndices = getTriangleIndices(data.polygonIndices, data.primitivePolygonIndices, data.flatCoordinateArray, data.nDim);
|
|
19
21
|
return {
|
|
20
22
|
...data,
|
|
@@ -23,4 +25,34 @@ function triangulateBatch(data) {
|
|
|
23
25
|
} : {})
|
|
24
26
|
};
|
|
25
27
|
}
|
|
28
|
+
function parseGeoArrowBatch(data) {
|
|
29
|
+
let binaryDataFromGeoArrow = null;
|
|
30
|
+
const {
|
|
31
|
+
chunkData,
|
|
32
|
+
chunkIndex,
|
|
33
|
+
chunkOffset,
|
|
34
|
+
geometryEncoding,
|
|
35
|
+
calculateMeanCenters,
|
|
36
|
+
triangle
|
|
37
|
+
} = data;
|
|
38
|
+
const arrowData = new arrow.Data(chunkData.type, chunkData.offset, chunkData.length, chunkData.nullCount, chunkData.buffers, chunkData.children, chunkData.dictionary);
|
|
39
|
+
const geometryColumn = arrow.makeVector(arrowData);
|
|
40
|
+
if (geometryColumn) {
|
|
41
|
+
const options = {
|
|
42
|
+
calculateMeanCenters,
|
|
43
|
+
triangle,
|
|
44
|
+
chunkIndex: 0,
|
|
45
|
+
chunkOffset
|
|
46
|
+
};
|
|
47
|
+
binaryDataFromGeoArrow = getBinaryGeometriesFromArrow(geometryColumn, geometryEncoding, options);
|
|
48
|
+
return {
|
|
49
|
+
binaryDataFromGeoArrow,
|
|
50
|
+
chunkIndex
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
binaryDataFromGeoArrow,
|
|
55
|
+
chunkIndex
|
|
56
|
+
};
|
|
57
|
+
}
|
|
26
58
|
//# sourceMappingURL=triangulation-worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"triangulation-worker.js","names":["createWorker","getTriangleIndices","data","options","arguments","length","undefined","input","operation","triangulateBatch","
|
|
1
|
+
{"version":3,"file":"triangulation-worker.js","names":["arrow","createWorker","getTriangleIndices","getBinaryGeometriesFromArrow","data","options","arguments","length","undefined","input","operation","triangulateBatch","parseGeoArrowBatch","Error","triangleIndices","polygonIndices","primitivePolygonIndices","flatCoordinateArray","nDim","binaryDataFromGeoArrow","chunkData","chunkIndex","chunkOffset","geometryEncoding","calculateMeanCenters","triangle","arrowData","Data","type","offset","nullCount","buffers","children","dictionary","geometryColumn","makeVector"],"sources":["../../src/workers/triangulation-worker.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport * as arrow from 'apache-arrow';\nimport {createWorker} from '@loaders.gl/worker-utils';\nimport {\n getTriangleIndices,\n getBinaryGeometriesFromArrow,\n BinaryDataFromGeoArrow\n} from '../geoarrow/convert-geoarrow-to-binary-geometry';\nimport type {\n TriangulationWorkerInput,\n TriangulateInput,\n TriangulateResult,\n ParseGeoArrowInput,\n ParseGeoArrowResult\n} from '../triangulate-on-worker';\n\ncreateWorker(async (data, options = {}) => {\n const input = data as TriangulationWorkerInput;\n const operation = input?.operation;\n switch (operation) {\n case 'test':\n return input;\n case 'triangulate':\n return triangulateBatch(data);\n case 'parse-geoarrow':\n return parseGeoArrowBatch(data);\n default:\n throw new Error(\n `TriangulationWorker: Unsupported operation ${operation}. Expected 'triangulate'`\n );\n }\n});\n\nfunction triangulateBatch(data: TriangulateInput): TriangulateResult {\n // Parse any WKT/WKB geometries\n // Build binary geometries\n // Call earcut and triangulate\n const triangleIndices = getTriangleIndices(\n data.polygonIndices,\n data.primitivePolygonIndices,\n data.flatCoordinateArray,\n data.nDim\n );\n return {...data, ...(triangleIndices ? {triangleIndices} : {})};\n}\n\n/**\n * Reading the arrow file into memory is very fast. Parsing the geoarrow column is slow, and blocking the main thread.\n * To address this issue, we can move the parsing job from main thread to parallel web workers.\n * Each web worker will parse one chunk/batch of geoarrow column, and return binary geometries to main thread.\n * The app on the main thread will render the binary geometries and the parsing will not block the main thread.\n *\n * @param data\n * @returns\n */\nfunction parseGeoArrowBatch(data: ParseGeoArrowInput): ParseGeoArrowResult {\n let binaryDataFromGeoArrow: BinaryDataFromGeoArrow | null = null;\n const {chunkData, chunkIndex, chunkOffset, geometryEncoding, calculateMeanCenters, triangle} =\n data;\n // rebuild chunkData that is only for geoarrow column\n const arrowData = new arrow.Data(\n chunkData.type,\n chunkData.offset,\n chunkData.length,\n chunkData.nullCount,\n chunkData.buffers,\n chunkData.children,\n chunkData.dictionary\n );\n // rebuild geometry column with chunkData\n const geometryColumn = arrow.makeVector(arrowData);\n if (geometryColumn) {\n // NOTE: for a rebuild arrow.Vector, there is only one chunk, so chunkIndex is always 0\n const options = {calculateMeanCenters, triangle, chunkIndex: 0, chunkOffset};\n binaryDataFromGeoArrow = getBinaryGeometriesFromArrow(\n geometryColumn,\n geometryEncoding,\n options\n );\n // NOTE: here binaryGeometry will be copied to main thread\n return {\n binaryDataFromGeoArrow,\n chunkIndex\n };\n }\n return {\n binaryDataFromGeoArrow,\n chunkIndex\n };\n}\n"],"mappings":"AAIA,OAAO,KAAKA,KAAK,MAAM,cAAc;AACrC,SAAQC,YAAY,QAAO,0BAA0B;AAAC,SAEpDC,kBAAkB,EAClBC,4BAA4B;AAW9BF,YAAY,CAAC,gBAAOG,IAAI,EAAmB;EAAA,IAAjBC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EACpC,MAAMG,KAAK,GAAGL,IAAgC;EAC9C,MAAMM,SAAS,GAAGD,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAEC,SAAS;EAClC,QAAQA,SAAS;IACf,KAAK,MAAM;MACT,OAAOD,KAAK;IACd,KAAK,aAAa;MAChB,OAAOE,gBAAgB,CAACP,IAAI,CAAC;IAC/B,KAAK,gBAAgB;MACnB,OAAOQ,kBAAkB,CAACR,IAAI,CAAC;IACjC;MACE,MAAM,IAAIS,KAAK,CACZ,8CAA6CH,SAAU,0BAC1D,CAAC;EACL;AACF,CAAC,CAAC;AAEF,SAASC,gBAAgBA,CAACP,IAAsB,EAAqB;EAInE,MAAMU,eAAe,GAAGZ,kBAAkB,CACxCE,IAAI,CAACW,cAAc,EACnBX,IAAI,CAACY,uBAAuB,EAC5BZ,IAAI,CAACa,mBAAmB,EACxBb,IAAI,CAACc,IACP,CAAC;EACD,OAAO;IAAC,GAAGd,IAAI;IAAE,IAAIU,eAAe,GAAG;MAACA;IAAe,CAAC,GAAG,CAAC,CAAC;EAAC,CAAC;AACjE;AAWA,SAASF,kBAAkBA,CAACR,IAAwB,EAAuB;EACzE,IAAIe,sBAAqD,GAAG,IAAI;EAChE,MAAM;IAACC,SAAS;IAAEC,UAAU;IAAEC,WAAW;IAAEC,gBAAgB;IAAEC,oBAAoB;IAAEC;EAAQ,CAAC,GAC1FrB,IAAI;EAEN,MAAMsB,SAAS,GAAG,IAAI1B,KAAK,CAAC2B,IAAI,CAC9BP,SAAS,CAACQ,IAAI,EACdR,SAAS,CAACS,MAAM,EAChBT,SAAS,CAACb,MAAM,EAChBa,SAAS,CAACU,SAAS,EACnBV,SAAS,CAACW,OAAO,EACjBX,SAAS,CAACY,QAAQ,EAClBZ,SAAS,CAACa,UACZ,CAAC;EAED,MAAMC,cAAc,GAAGlC,KAAK,CAACmC,UAAU,CAACT,SAAS,CAAC;EAClD,IAAIQ,cAAc,EAAE;IAElB,MAAM7B,OAAO,GAAG;MAACmB,oBAAoB;MAAEC,QAAQ;MAAEJ,UAAU,EAAE,CAAC;MAAEC;IAAW,CAAC;IAC5EH,sBAAsB,GAAGhB,4BAA4B,CACnD+B,cAAc,EACdX,gBAAgB,EAChBlB,OACF,CAAC;IAED,OAAO;MACLc,sBAAsB;MACtBE;IACF,CAAC;EACH;EACA,OAAO;IACLF,sBAAsB;IACtBE;EACF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/arrow",
|
|
3
|
-
"version": "4.1.0-alpha.
|
|
3
|
+
"version": "4.1.0-alpha.11",
|
|
4
4
|
"description": "Simple columnar table loader for the Apache Arrow format",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"module": "dist/index.js",
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
32
33
|
"import": "./dist/index.js",
|
|
33
|
-
"require": "./dist/index.cjs"
|
|
34
|
-
"types": "./dist/index.d.ts"
|
|
34
|
+
"require": "./dist/index.cjs"
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"sideEffects": false,
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
"build-worker2": "esbuild src/workers/arrow-worker.ts --bundle --outfile=dist/arrow-worker.js --platform=browser --external:{stream}"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@loaders.gl/gis": "4.1.0-alpha.
|
|
56
|
-
"@loaders.gl/loader-utils": "4.1.0-alpha.
|
|
57
|
-
"@loaders.gl/schema": "4.1.0-alpha.
|
|
58
|
-
"@loaders.gl/wkt": "4.1.0-alpha.
|
|
55
|
+
"@loaders.gl/gis": "4.1.0-alpha.11",
|
|
56
|
+
"@loaders.gl/loader-utils": "4.1.0-alpha.11",
|
|
57
|
+
"@loaders.gl/schema": "4.1.0-alpha.11",
|
|
58
|
+
"@loaders.gl/wkt": "4.1.0-alpha.11",
|
|
59
59
|
"@math.gl/polygon": "4.0.0",
|
|
60
|
-
"apache-arrow": "
|
|
60
|
+
"apache-arrow": ">= 15.0.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "5d3e23bf93762b48c8c1d6d926ede7a97fe43ab0"
|
|
63
63
|
}
|
package/src/arrow-loader.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
@@ -19,6 +20,7 @@ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
|
19
20
|
export type ArrowLoaderOptions = LoaderOptions & {
|
|
20
21
|
arrow?: {
|
|
21
22
|
shape: 'arrow-table' | 'columnar-table' | 'array-row-table' | 'object-row-table';
|
|
23
|
+
batchDebounceMs?: number;
|
|
22
24
|
};
|
|
23
25
|
};
|
|
24
26
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import * as arrow from 'apache-arrow';
|
|
@@ -45,7 +46,7 @@ type BinaryGeometryContent = {
|
|
|
45
46
|
geomOffset: Int32Array;
|
|
46
47
|
/** Array of geometry indicies: the start index of each geometry */
|
|
47
48
|
geometryIndicies: Uint16Array;
|
|
48
|
-
/** (Optional) indices of triangels returned from polygon
|
|
49
|
+
/** (Optional) indices of triangels returned from polygon triangulation (Polygon only) */
|
|
49
50
|
triangles?: Uint32Array;
|
|
50
51
|
/** (Optional) array of mean center of each geometry */
|
|
51
52
|
meanCenters?: Float64Array;
|
|
@@ -54,17 +55,21 @@ type BinaryGeometryContent = {
|
|
|
54
55
|
/**
|
|
55
56
|
* binary geometry template, see deck.gl BinaryGeometry
|
|
56
57
|
*/
|
|
57
|
-
export
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
58
|
+
export function getBinaryGeometryTemplate() {
|
|
59
|
+
return {
|
|
60
|
+
globalFeatureIds: {value: new Uint32Array(0), size: 1},
|
|
61
|
+
positions: {value: new Float32Array(0), size: 2},
|
|
62
|
+
properties: [],
|
|
63
|
+
numericProps: {},
|
|
64
|
+
featureIds: {value: new Uint32Array(0), size: 1}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
64
67
|
|
|
65
68
|
export type BinaryGeometriesFromArrowOptions = {
|
|
66
69
|
/** option to specify which chunk to get binary geometries from, for progressive rendering */
|
|
67
70
|
chunkIndex?: number;
|
|
71
|
+
/** The offset (beginning index of rows) of input chunk. Used for reconstructing globalFeatureIds in web workers */
|
|
72
|
+
chunkOffset?: number;
|
|
68
73
|
/** option to get mean centers from geometries, for polygon filtering */
|
|
69
74
|
calculateMeanCenters?: boolean;
|
|
70
75
|
/** option to compute the triangle indices by tesselating polygons */
|
|
@@ -90,9 +95,12 @@ export function getBinaryGeometriesFromArrow(
|
|
|
90
95
|
line: geoEncoding === 'geoarrow.multilinestring' || geoEncoding === 'geoarrow.linestring'
|
|
91
96
|
};
|
|
92
97
|
|
|
93
|
-
const chunks =
|
|
98
|
+
const chunks =
|
|
99
|
+
options?.chunkIndex !== undefined && options?.chunkIndex >= 0
|
|
100
|
+
? [geoColumn.data[options?.chunkIndex]]
|
|
101
|
+
: geoColumn.data;
|
|
94
102
|
let bounds: [number, number, number, number] = [Infinity, Infinity, -Infinity, -Infinity];
|
|
95
|
-
let globalFeatureIdOffset = 0;
|
|
103
|
+
let globalFeatureIdOffset = options?.chunkOffset || 0;
|
|
96
104
|
const binaryGeometries: BinaryFeatures[] = [];
|
|
97
105
|
|
|
98
106
|
chunks.forEach((chunk) => {
|
|
@@ -111,6 +119,7 @@ export function getBinaryGeometriesFromArrow(
|
|
|
111
119
|
size: nDim
|
|
112
120
|
},
|
|
113
121
|
featureIds: {value: featureIds, size: 1},
|
|
122
|
+
// eslint-disable-next-line no-loop-func
|
|
114
123
|
properties: [...Array(chunk.length).keys()].map((i) => ({
|
|
115
124
|
index: i + globalFeatureIdOffset
|
|
116
125
|
}))
|
|
@@ -123,18 +132,18 @@ export function getBinaryGeometriesFromArrow(
|
|
|
123
132
|
shape: 'binary-feature-collection',
|
|
124
133
|
points: {
|
|
125
134
|
type: 'Point',
|
|
126
|
-
...
|
|
135
|
+
...getBinaryGeometryTemplate(),
|
|
127
136
|
...(featureTypes.point ? binaryContent : {})
|
|
128
137
|
},
|
|
129
138
|
lines: {
|
|
130
139
|
type: 'LineString',
|
|
131
|
-
...
|
|
140
|
+
...getBinaryGeometryTemplate(),
|
|
132
141
|
...(featureTypes.line ? binaryContent : {}),
|
|
133
142
|
pathIndices: {value: featureTypes.line ? geomOffset : new Uint16Array(0), size: 1}
|
|
134
143
|
},
|
|
135
144
|
polygons: {
|
|
136
145
|
type: 'Polygon',
|
|
137
|
-
...
|
|
146
|
+
...getBinaryGeometryTemplate(),
|
|
138
147
|
...(featureTypes.polygon ? binaryContent : {}),
|
|
139
148
|
polygonIndices: {
|
|
140
149
|
// use geomOffset as polygonIndices same as primitivePolygonIndices since we are using earcut to get triangule indices
|
|
@@ -281,7 +290,7 @@ function getBinaryGeometriesFromChunk(
|
|
|
281
290
|
* @param primitivePolygonIndices Indices within positions of the start of each primitive Polygon/ring
|
|
282
291
|
* @param flatCoordinateArray Array of x, y or x, y, z positions
|
|
283
292
|
* @param nDim - number of dimensions per position
|
|
284
|
-
* @returns
|
|
293
|
+
* @returns triangle indices or null if invalid polygon and earcut fails
|
|
285
294
|
*/
|
|
286
295
|
export function getTriangleIndices(
|
|
287
296
|
polygonIndices: Uint16Array,
|
|
@@ -306,13 +315,14 @@ export function getTriangleIndices(
|
|
|
306
315
|
}
|
|
307
316
|
primitiveIndex++;
|
|
308
317
|
}
|
|
318
|
+
// TODO check if each ring is closed
|
|
309
319
|
const triangleIndices = earcut(
|
|
310
320
|
slicedFlatCoords,
|
|
311
321
|
holeIndices.length > 0 ? holeIndices : undefined,
|
|
312
322
|
nDim
|
|
313
323
|
);
|
|
314
324
|
if (triangleIndices.length === 0) {
|
|
315
|
-
throw Error('
|
|
325
|
+
throw Error('earcut failed e.g. invalid polygon');
|
|
316
326
|
}
|
|
317
327
|
for (let j = 0; j < triangleIndices.length; j++) {
|
|
318
328
|
triangles.push(triangleIndices[j] + startIdx);
|
|
@@ -325,9 +335,7 @@ export function getTriangleIndices(
|
|
|
325
335
|
}
|
|
326
336
|
return trianglesUint32;
|
|
327
337
|
} catch (error) {
|
|
328
|
-
//
|
|
329
|
-
// there is an expection when tesselating invalid polygon, e.g. polygon with self-intersection
|
|
330
|
-
// return null to skip tesselating
|
|
338
|
+
// if earcut fails, return null
|
|
331
339
|
return null;
|
|
332
340
|
}
|
|
333
341
|
}
|
|
@@ -379,8 +387,8 @@ function getBinaryPolygonsFromChunk(
|
|
|
379
387
|
|
|
380
388
|
return {
|
|
381
389
|
featureIds,
|
|
382
|
-
flatCoordinateArray,
|
|
383
390
|
nDim,
|
|
391
|
+
flatCoordinateArray,
|
|
384
392
|
geomOffset,
|
|
385
393
|
geometryIndicies,
|
|
386
394
|
...(options?.triangulate && triangles ? {triangles} : {})
|
package/src/geoarrow-loader.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import type {ArrowLoaderOptions} from './arrow-loader';
|
|
@@ -52,7 +53,7 @@ export type {
|
|
|
52
53
|
BinaryGeometriesFromArrowOptions
|
|
53
54
|
} from './geoarrow/convert-geoarrow-to-binary-geometry';
|
|
54
55
|
export {
|
|
55
|
-
|
|
56
|
+
getBinaryGeometryTemplate,
|
|
56
57
|
getBinaryGeometriesFromArrow,
|
|
57
58
|
getTriangleIndices,
|
|
58
59
|
getMeanCentersFromBinaryGeometries
|
|
@@ -65,5 +66,11 @@ export {parseGeometryFromArrow} from './geoarrow/convert-geoarrow-to-geojson-geo
|
|
|
65
66
|
export {convertArrowToGeoJSONTable} from './tables/convert-arrow-to-geojson-table';
|
|
66
67
|
|
|
67
68
|
// EXPERIMENTAL WORKER
|
|
69
|
+
export {hardClone} from './workers/hard-clone';
|
|
68
70
|
|
|
69
|
-
export {
|
|
71
|
+
export type {ParseGeoArrowInput, ParseGeoArrowResult} from './triangulate-on-worker';
|
|
72
|
+
export {
|
|
73
|
+
TriangulationWorker,
|
|
74
|
+
triangulateOnWorker,
|
|
75
|
+
parseGeoArrowOnWorker
|
|
76
|
+
} from './triangulate-on-worker';
|
package/src/lib/arrow-table.ts
CHANGED
package/src/lib/encode-arrow.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import type {ArrowTableBatch} from '../lib/arrow-table';
|
|
5
6
|
import * as arrow from 'apache-arrow';
|
|
7
|
+
import {ArrowLoaderOptions} from '../arrow-loader';
|
|
6
8
|
// import {isIterable} from '@loaders.gl/core';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
*/
|
|
10
12
|
export function parseArrowInBatches(
|
|
11
|
-
asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer
|
|
13
|
+
asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
|
|
14
|
+
options?: ArrowLoaderOptions
|
|
12
15
|
): AsyncIterable<ArrowTableBatch> {
|
|
13
16
|
// Creates the appropriate arrow.RecordBatchReader subclasses from the input
|
|
14
17
|
// This will also close the underlying source in case of early termination or errors
|
|
@@ -33,6 +36,10 @@ export function parseArrowInBatches(
|
|
|
33
36
|
const readers = arrow.RecordBatchReader.readAll(asyncIterator);
|
|
34
37
|
for await (const reader of readers) {
|
|
35
38
|
for await (const recordBatch of reader) {
|
|
39
|
+
// use options.batchDebounceMs to add a delay between batches if needed (use case: incremental loading)
|
|
40
|
+
if (options?.arrow?.batchDebounceMs !== undefined && options?.arrow?.batchDebounceMs > 0) {
|
|
41
|
+
await new Promise((resolve) => setTimeout(resolve, options.arrow?.batchDebounceMs || 0));
|
|
42
|
+
}
|
|
36
43
|
const arrowTabledBatch: ArrowTableBatch = {
|
|
37
44
|
shape: 'arrow-table',
|
|
38
45
|
batchType: 'data',
|