@loaders.gl/arrow 4.0.0-alpha.4 → 4.0.0-alpha.6
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 +11 -0
- package/dist/arrow-loader.d.ts.map +1 -0
- package/dist/arrow-loader.js +28 -20
- package/dist/arrow-worker.js +10906 -14545
- package/dist/arrow-writer.d.ts +9 -0
- package/dist/arrow-writer.d.ts.map +1 -0
- package/dist/arrow-writer.js +24 -17
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2 -2
- package/dist/dist.min.js +12824 -0
- package/dist/es5/arrow-loader.js +27 -0
- package/dist/es5/arrow-loader.js.map +1 -0
- package/dist/es5/arrow-writer.js +23 -0
- package/dist/es5/arrow-writer.js.map +1 -0
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +64 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/arrow-table-batch.js +99 -0
- package/dist/es5/lib/arrow-table-batch.js.map +1 -0
- package/dist/es5/lib/encode-arrow.js +40 -0
- package/dist/es5/lib/encode-arrow.js.map +1 -0
- package/dist/es5/lib/parse-arrow-in-batches.js +140 -0
- package/dist/es5/lib/parse-arrow-in-batches.js.map +1 -0
- package/dist/es5/lib/parse-arrow-sync.js +53 -0
- package/dist/es5/lib/parse-arrow-sync.js.map +1 -0
- package/dist/es5/types.js +13 -0
- package/dist/es5/types.js.map +1 -0
- package/dist/es5/workers/arrow-worker.js +6 -0
- package/dist/es5/workers/arrow-worker.js.map +1 -0
- package/dist/esm/arrow-loader.js +19 -0
- package/dist/esm/arrow-loader.js.map +1 -0
- package/dist/esm/arrow-writer.js +16 -0
- package/dist/esm/arrow-writer.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/arrow-table-batch.js +63 -0
- package/dist/esm/lib/arrow-table-batch.js.map +1 -0
- package/dist/esm/lib/encode-arrow.js +22 -0
- package/dist/esm/lib/encode-arrow.js.map +1 -0
- package/dist/esm/lib/parse-arrow-in-batches.js +27 -0
- package/dist/esm/lib/parse-arrow-in-batches.js.map +1 -0
- package/dist/esm/lib/parse-arrow-sync.js +35 -0
- package/dist/esm/lib/parse-arrow-sync.js.map +1 -0
- package/dist/esm/types.js +6 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/workers/arrow-worker.js +4 -0
- package/dist/esm/workers/arrow-worker.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -15
- package/dist/lib/arrow-table-batch.d.ts +9 -0
- package/dist/lib/arrow-table-batch.d.ts.map +1 -0
- package/dist/lib/arrow-table-batch.js +57 -63
- package/dist/lib/encode-arrow.d.ts +15 -0
- package/dist/lib/encode-arrow.d.ts.map +1 -0
- package/dist/lib/encode-arrow.js +35 -25
- package/dist/lib/parse-arrow-in-batches.d.ts +4 -0
- package/dist/lib/parse-arrow-in-batches.d.ts.map +1 -0
- package/dist/lib/parse-arrow-in-batches.js +42 -25
- package/dist/lib/parse-arrow-sync.d.ts +3 -0
- package/dist/lib/parse-arrow-sync.d.ts.map +1 -0
- package/dist/lib/parse-arrow-sync.js +37 -40
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -6
- package/dist/workers/arrow-worker.d.ts +2 -0
- package/dist/workers/arrow-worker.d.ts.map +1 -0
- package/dist/workers/arrow-worker.js +5 -4
- package/package.json +13 -13
- package/src/arrow-loader.ts +14 -10
- package/src/arrow-writer.ts +15 -10
- package/src/lib/arrow-table-batch.ts +25 -7
- package/src/lib/encode-arrow.ts +9 -11
- package/src/lib/parse-arrow-sync.ts +6 -6
- package/dist/arrow-loader.js.map +0 -1
- package/dist/arrow-writer.js.map +0 -1
- package/dist/bundle.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/arrow-table-batch.js.map +0 -1
- package/dist/lib/encode-arrow.js.map +0 -1
- package/dist/lib/parse-arrow-in-batches.js.map +0 -1
- package/dist/lib/parse-arrow-sync.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/workers/arrow-worker.js.map +0 -1
|
@@ -1,30 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseArrowInBatches = void 0;
|
|
4
|
+
// TODO - this import defeats the sophisticated typescript checking in ArrowJS
|
|
5
|
+
const apache_arrow_1 = require("apache-arrow");
|
|
6
|
+
// import {isIterable} from '@loaders.gl/core';
|
|
7
|
+
/**
|
|
8
|
+
*/
|
|
9
|
+
function parseArrowInBatches(asyncIterator) {
|
|
10
|
+
// Creates the appropriate RecordBatchReader subclasses from the input
|
|
11
|
+
// This will also close the underlying source in case of early termination or errors
|
|
12
|
+
// As an optimization, return a non-async iterator
|
|
13
|
+
/*
|
|
14
|
+
if (isIterable(readers)) {
|
|
15
|
+
function* makeArrowIterator() {
|
|
16
|
+
for (const reader of readers) {
|
|
17
|
+
for (const batch of reader) {
|
|
18
|
+
yield processBatch(batch, reader);
|
|
19
|
+
}
|
|
20
|
+
break; // only processing one stream of batches
|
|
21
|
+
}
|
|
9
22
|
}
|
|
10
|
-
|
|
11
|
-
break;
|
|
23
|
+
const arrowIterator = makeArrowIterator();
|
|
12
24
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
*/
|
|
26
|
+
async function* makeArrowAsyncIterator() {
|
|
27
|
+
const readers = apache_arrow_1.RecordBatchReader.readAll(asyncIterator);
|
|
28
|
+
for await (const reader of readers) {
|
|
29
|
+
for await (const batch of reader) {
|
|
30
|
+
yield processBatch(batch);
|
|
31
|
+
}
|
|
32
|
+
break; // only processing one stream of batches
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return makeArrowAsyncIterator();
|
|
16
36
|
}
|
|
17
|
-
|
|
37
|
+
exports.parseArrowInBatches = parseArrowInBatches;
|
|
18
38
|
function processBatch(batch) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
values
|
|
27
|
-
});
|
|
28
|
-
return values;
|
|
39
|
+
const values = {
|
|
40
|
+
metadata: batch.schema.metadata,
|
|
41
|
+
length: batch.length
|
|
42
|
+
};
|
|
43
|
+
batch.schema.fields.forEach(({ name }, index) => {
|
|
44
|
+
values[name] = batch.getChildAt(index).toArray();
|
|
45
|
+
});
|
|
46
|
+
return values;
|
|
29
47
|
}
|
|
30
|
-
//# sourceMappingURL=parse-arrow-in-batches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-arrow-sync.d.ts","sourceRoot":"","sources":["../../src/lib/parse-arrow-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAIxD,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,WAAW,KAAA,EAAE,OAAO,CAAC,EAAE,kBAAkB,MAyB/E"}
|
|
@@ -1,44 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
columnarTable
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const apache_arrow_1 = require("apache-arrow");
|
|
4
|
+
// Parses arrow to a columnar table
|
|
5
|
+
function parseArrowSync(arrayBuffer, options) {
|
|
6
|
+
const arrowTable = (0, apache_arrow_1.tableFromIPC)([new Uint8Array(arrayBuffer)]);
|
|
7
|
+
// Extract columns
|
|
8
|
+
// TODO - avoid calling `getColumn` on columns we are not interested in?
|
|
9
|
+
// Add options object?
|
|
10
|
+
const columnarTable = {};
|
|
11
|
+
for (const field of arrowTable.schema.fields) {
|
|
12
|
+
// This (is intended to) coalesce all record batches into a single typed array
|
|
13
|
+
const arrowColumn = arrowTable.getChild(field.name);
|
|
14
|
+
const values = arrowColumn?.toArray();
|
|
15
|
+
columnarTable[field.name] = values;
|
|
16
|
+
}
|
|
17
|
+
switch (options?.arrow?.shape) {
|
|
18
|
+
case 'arrow-table':
|
|
19
|
+
return arrowTable;
|
|
20
|
+
case 'object-row-table':
|
|
21
|
+
return convertColumnarToRowFormatTable(columnarTable);
|
|
22
|
+
case 'columnar-table':
|
|
23
|
+
default:
|
|
24
|
+
return columnarTable;
|
|
25
|
+
}
|
|
24
26
|
}
|
|
25
|
-
|
|
27
|
+
exports.default = parseArrowSync;
|
|
26
28
|
function convertColumnarToRowFormatTable(columnarTable) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
const tableKeys = Object.keys(columnarTable);
|
|
30
|
+
const tableRowsCount = columnarTable[tableKeys[0]].length;
|
|
31
|
+
const rowFormatTable = [];
|
|
32
|
+
for (let index = 0; index < tableRowsCount; index++) {
|
|
33
|
+
const tableItem = {};
|
|
34
|
+
for (let keyIndex = 0; keyIndex < tableKeys.length; keyIndex++) {
|
|
35
|
+
const fieldName = tableKeys[keyIndex];
|
|
36
|
+
tableItem[fieldName] = columnarTable[fieldName][index];
|
|
37
|
+
}
|
|
38
|
+
rowFormatTable.push(tableItem);
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
rowFormatTable.push(tableItem);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return rowFormatTable;
|
|
40
|
+
return rowFormatTable;
|
|
43
41
|
}
|
|
44
|
-
//# sourceMappingURL=parse-arrow-sync.js.map
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type TypedIntArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Int32Array | Uint32Array;
|
|
2
|
+
type TypedFloatArray = Float32Array | Float64Array;
|
|
3
|
+
type TypedArray = TypedIntArray | TypedFloatArray;
|
|
4
|
+
export type AnyArrayType = Array<any> | TypedArray;
|
|
5
|
+
export declare enum VECTOR_TYPES {
|
|
6
|
+
FLOAT = 0,
|
|
7
|
+
DATE = 1
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,GACd,SAAS,GACT,UAAU,GACV,UAAU,GACV,WAAW,GACX,UAAU,GACV,WAAW,GACX,UAAU,GACV,WAAW,CAAC;AAEhB,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
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VECTOR_TYPES = void 0;
|
|
4
|
+
var VECTOR_TYPES;
|
|
3
5
|
(function (VECTOR_TYPES) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
})(VECTOR_TYPES || (VECTOR_TYPES = {}));
|
|
7
|
-
//# sourceMappingURL=types.js.map
|
|
6
|
+
VECTOR_TYPES[VECTOR_TYPES["FLOAT"] = 0] = "FLOAT";
|
|
7
|
+
VECTOR_TYPES[VECTOR_TYPES["DATE"] = 1] = "DATE";
|
|
8
|
+
})(VECTOR_TYPES = exports.VECTOR_TYPES || (exports.VECTOR_TYPES = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrow-worker.d.ts","sourceRoot":"","sources":["../../src/workers/arrow-worker.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
(0, loader_utils_1.createLoaderWorker)(index_1.ArrowLoader);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/arrow",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.6",
|
|
4
4
|
"description": "Simple columnar table loader for the Apache Arrow format",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"point cloud",
|
|
19
19
|
"PLY"
|
|
20
20
|
],
|
|
21
|
-
"types": "
|
|
22
|
-
"main": "dist/index.js",
|
|
23
|
-
"module": "dist/index.js",
|
|
21
|
+
"types": "dist/index.d.ts",
|
|
22
|
+
"main": "dist/es5/index.js",
|
|
23
|
+
"module": "dist/esm/index.js",
|
|
24
24
|
"sideEffects": false,
|
|
25
25
|
"files": [
|
|
26
26
|
"src",
|
|
@@ -32,16 +32,16 @@
|
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"pre-build": "npm run build-worker && npm run build-bundle",
|
|
35
|
-
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/
|
|
36
|
-
"build-worker": "esbuild src/workers/arrow-worker.ts --bundle --outfile=dist/arrow-worker.js"
|
|
35
|
+
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js --platform=browser --external:{stream}",
|
|
36
|
+
"build-worker": "esbuild src/workers/arrow-worker.ts --bundle --outfile=dist/arrow-worker.js --platform=browser --external:{stream} --define:__VERSION__=\\\"$npm_package_version\\\"",
|
|
37
|
+
"pre-build2": "cp fixed-package.json ../../node_modules/apache-arrow/package.json && npm run build-bundle && npm run build-worker",
|
|
38
|
+
"build-bundle2": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js --platform=browser --external:{stream}",
|
|
39
|
+
"build-worker2": "esbuild src/workers/arrow-worker.ts --bundle --outfile=dist/arrow-worker.js --platform=browser --external:{stream}"
|
|
37
40
|
},
|
|
38
41
|
"dependencies": {
|
|
39
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
40
|
-
"@loaders.gl/schema": "4.0.0-alpha.
|
|
41
|
-
"apache-arrow": "^
|
|
42
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.6",
|
|
43
|
+
"@loaders.gl/schema": "4.0.0-alpha.6",
|
|
44
|
+
"apache-arrow": "^9.0.0"
|
|
42
45
|
},
|
|
43
|
-
"
|
|
44
|
-
"@loaders.gl/core": "^3.0.0"
|
|
45
|
-
},
|
|
46
|
-
"gitHead": "53026061b3c8871f7e96d3a5826125cc6613bddc"
|
|
46
|
+
"gitHead": "acc1985050dfaa0f1f0c066f8da5bce7454a046c"
|
|
47
47
|
}
|
package/src/arrow-loader.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
1
2
|
import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
3
|
+
import type {ArrowTable} from '@loaders.gl/schema';
|
|
2
4
|
|
|
3
5
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
4
6
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
@@ -10,25 +12,27 @@ export type ArrowLoaderOptions = LoaderOptions & {
|
|
|
10
12
|
};
|
|
11
13
|
};
|
|
12
14
|
|
|
13
|
-
const DEFAULT_ARROW_LOADER_OPTIONS = {
|
|
14
|
-
arrow: {
|
|
15
|
-
shape: 'columnar-table'
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
15
|
/** ArrowJS table loader */
|
|
20
|
-
export const ArrowLoader = {
|
|
16
|
+
export const ArrowLoader: Loader<ArrowTable, never, ArrowLoaderOptions> = {
|
|
21
17
|
name: 'Apache Arrow',
|
|
22
18
|
id: 'arrow',
|
|
23
19
|
module: 'arrow',
|
|
24
20
|
version: VERSION,
|
|
25
|
-
worker: true,
|
|
21
|
+
// worker: true,
|
|
26
22
|
category: 'table',
|
|
27
23
|
extensions: ['arrow', 'feather'],
|
|
28
|
-
mimeTypes: [
|
|
24
|
+
mimeTypes: [
|
|
25
|
+
'application/vnd.apache.arrow.file',
|
|
26
|
+
'application/vnd.apache.arrow.stream',
|
|
27
|
+
'application/octet-stream'
|
|
28
|
+
],
|
|
29
29
|
binary: true,
|
|
30
30
|
tests: ['ARROW'],
|
|
31
|
-
options:
|
|
31
|
+
options: {
|
|
32
|
+
arrow: {
|
|
33
|
+
shape: 'columnar-table'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
32
36
|
};
|
|
33
37
|
|
|
34
38
|
export const _typecheckArrowLoader: Loader = ArrowLoader;
|
package/src/arrow-writer.ts
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
|
-
// import type {
|
|
2
|
-
import type {WriterOptions} from '@loaders.gl/loader-utils';
|
|
1
|
+
// import type {} from '@loaders.gl/loader-utils';
|
|
2
|
+
import type {Writer, WriterOptions} from '@loaders.gl/loader-utils';
|
|
3
|
+
import {ColumnarTable} from './lib/encode-arrow';
|
|
3
4
|
import {encodeArrowSync} from './lib/encode-arrow';
|
|
4
5
|
|
|
5
6
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
6
7
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
7
8
|
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
8
9
|
|
|
9
|
-
type ArrowWriterOptions = WriterOptions
|
|
10
|
+
type ArrowWriterOptions = WriterOptions & {
|
|
11
|
+
arrow?: {};
|
|
12
|
+
};
|
|
10
13
|
|
|
11
14
|
/** Apache Arrow writer */
|
|
12
|
-
export const ArrowWriter = {
|
|
15
|
+
export const ArrowWriter: Writer<ColumnarTable, never, ArrowWriterOptions> = {
|
|
13
16
|
name: 'Apache Arrow',
|
|
14
17
|
id: 'arrow',
|
|
15
18
|
module: 'arrow',
|
|
16
19
|
version: VERSION,
|
|
17
20
|
extensions: ['arrow', 'feather'],
|
|
18
|
-
mimeTypes: [
|
|
19
|
-
|
|
21
|
+
mimeTypes: [
|
|
22
|
+
'application/vnd.apache.arrow.file',
|
|
23
|
+
'application/vnd.apache.arrow.stream',
|
|
24
|
+
'application/octet-stream'
|
|
25
|
+
],
|
|
26
|
+
encodeSync(data, options?) {
|
|
27
|
+
return encodeArrowSync(data);
|
|
28
|
+
},
|
|
20
29
|
binary: true,
|
|
21
30
|
options: {}
|
|
22
31
|
};
|
|
23
|
-
|
|
24
|
-
function encodeSync(data, options?: ArrowWriterOptions) {
|
|
25
|
-
return encodeArrowSync(data);
|
|
26
|
-
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import type {ArrowTableBatch} from '@loaders.gl/schema';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Schema,
|
|
4
|
+
Field,
|
|
5
|
+
RecordBatch,
|
|
6
|
+
Struct,
|
|
7
|
+
makeVector,
|
|
8
|
+
makeData,
|
|
9
|
+
Vector,
|
|
10
|
+
Float32
|
|
11
|
+
} from 'apache-arrow';
|
|
3
12
|
import {ColumnarTableBatchAggregator} from '@loaders.gl/schema';
|
|
4
13
|
|
|
5
14
|
export default class ArrowTableBatchAggregator extends ColumnarTableBatchAggregator {
|
|
@@ -15,11 +24,19 @@ export default class ArrowTableBatchAggregator extends ColumnarTableBatchAggrega
|
|
|
15
24
|
if (batch) {
|
|
16
25
|
// Get the arrow schema
|
|
17
26
|
this.arrowSchema = this.arrowSchema || getArrowSchema(batch.schema);
|
|
27
|
+
|
|
18
28
|
// Get arrow format vectors
|
|
19
29
|
const arrowVectors = getArrowVectors(this.arrowSchema, batch.data);
|
|
30
|
+
|
|
20
31
|
// Create the record batch
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
const recordBatch = new RecordBatch(
|
|
33
|
+
this.arrowSchema,
|
|
34
|
+
makeData({
|
|
35
|
+
type: new Struct(this.arrowSchema.fields),
|
|
36
|
+
children: arrowVectors.map(({data}) => data[0])
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
|
|
23
40
|
return {
|
|
24
41
|
shape: 'arrow-table',
|
|
25
42
|
batchType: 'data',
|
|
@@ -33,12 +50,13 @@ export default class ArrowTableBatchAggregator extends ColumnarTableBatchAggrega
|
|
|
33
50
|
}
|
|
34
51
|
|
|
35
52
|
// Convert from a simple loaders.gl schema to an Arrow schema
|
|
36
|
-
function getArrowSchema(schema) {
|
|
53
|
+
function getArrowSchema(schema): Schema {
|
|
37
54
|
const arrowFields: Field[] = [];
|
|
38
55
|
for (const key in schema) {
|
|
39
56
|
const field = schema[key];
|
|
40
57
|
if (field.type === Float32Array) {
|
|
41
|
-
|
|
58
|
+
// TODO - just store the original field as metadata?
|
|
59
|
+
const metadata = new Map(); // field;
|
|
42
60
|
// arrow: new Field(name, nullable, metadata)
|
|
43
61
|
const arrowField = new Field(field.name, new Float32(), field.nullable, metadata);
|
|
44
62
|
arrowFields.push(arrowField);
|
|
@@ -52,12 +70,12 @@ function getArrowSchema(schema) {
|
|
|
52
70
|
}
|
|
53
71
|
|
|
54
72
|
// Convert from simple loaders.gl arrays to arrow vectors
|
|
55
|
-
function getArrowVectors(arrowSchema, data) {
|
|
73
|
+
function getArrowVectors(arrowSchema, data): Vector[] {
|
|
56
74
|
const arrowVectors: any[] = [];
|
|
57
75
|
for (const field of arrowSchema.fields) {
|
|
58
76
|
const vector = data[field.name];
|
|
59
77
|
if (vector instanceof Float32Array) {
|
|
60
|
-
const arrowVector =
|
|
78
|
+
const arrowVector = makeVector(vector);
|
|
61
79
|
arrowVectors.push(arrowVector);
|
|
62
80
|
}
|
|
63
81
|
}
|
package/src/lib/encode-arrow.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {Table,
|
|
1
|
+
import {Table, Vector, tableToIPC, vectorFromArray} from 'apache-arrow';
|
|
2
2
|
import {AnyArrayType, VECTOR_TYPES} from '../types';
|
|
3
3
|
|
|
4
|
-
type ColumnarTable = {
|
|
4
|
+
export type ColumnarTable = {
|
|
5
5
|
name: string;
|
|
6
6
|
array: AnyArrayType;
|
|
7
7
|
type: number;
|
|
@@ -15,15 +15,13 @@ type ColumnarTable = {
|
|
|
15
15
|
* @returns - encoded ArrayBuffer
|
|
16
16
|
*/
|
|
17
17
|
export function encodeArrowSync(data: ColumnarTable): ArrayBuffer {
|
|
18
|
-
const vectors:
|
|
19
|
-
const arrayNames: string[] = [];
|
|
18
|
+
const vectors: Record<string, Vector> = {};
|
|
20
19
|
for (const arrayData of data) {
|
|
21
|
-
arrayNames.push(arrayData.name);
|
|
22
20
|
const arrayVector = createVector(arrayData.array, arrayData.type);
|
|
23
|
-
vectors.
|
|
21
|
+
vectors[arrayData.name] = arrayVector;
|
|
24
22
|
}
|
|
25
|
-
const table = Table
|
|
26
|
-
const arrowBuffer = table
|
|
23
|
+
const table = new Table(vectors);
|
|
24
|
+
const arrowBuffer = tableToIPC(table);
|
|
27
25
|
return arrowBuffer;
|
|
28
26
|
}
|
|
29
27
|
|
|
@@ -33,12 +31,12 @@ export function encodeArrowSync(data: ColumnarTable): ArrayBuffer {
|
|
|
33
31
|
* @param type {number} - the writer options
|
|
34
32
|
* @return a vector of one of vector's types defined in the Apache Arrow library
|
|
35
33
|
*/
|
|
36
|
-
function createVector(array, type) {
|
|
34
|
+
function createVector(array, type): Vector {
|
|
37
35
|
switch (type) {
|
|
38
36
|
case VECTOR_TYPES.DATE:
|
|
39
|
-
return
|
|
37
|
+
return vectorFromArray(array);
|
|
40
38
|
case VECTOR_TYPES.FLOAT:
|
|
41
39
|
default:
|
|
42
|
-
return
|
|
40
|
+
return vectorFromArray(array);
|
|
43
41
|
}
|
|
44
42
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type {ArrowLoaderOptions} from '../arrow-loader';
|
|
2
|
-
import {
|
|
2
|
+
import {tableFromIPC} from 'apache-arrow';
|
|
3
3
|
|
|
4
4
|
// Parses arrow to a columnar table
|
|
5
5
|
export default function parseArrowSync(arrayBuffer, options?: ArrowLoaderOptions) {
|
|
6
|
-
const arrowTable =
|
|
6
|
+
const arrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);
|
|
7
7
|
|
|
8
8
|
// Extract columns
|
|
9
9
|
|
|
@@ -11,12 +11,12 @@ export default function parseArrowSync(arrayBuffer, options?: ArrowLoaderOptions
|
|
|
11
11
|
// Add options object?
|
|
12
12
|
const columnarTable = {};
|
|
13
13
|
|
|
14
|
-
arrowTable.schema.fields
|
|
14
|
+
for (const field of arrowTable.schema.fields) {
|
|
15
15
|
// This (is intended to) coalesce all record batches into a single typed array
|
|
16
|
-
const arrowColumn = arrowTable.
|
|
17
|
-
const values = arrowColumn
|
|
16
|
+
const arrowColumn = arrowTable.getChild(field.name);
|
|
17
|
+
const values = arrowColumn?.toArray();
|
|
18
18
|
columnarTable[field.name] = values;
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
20
|
|
|
21
21
|
switch (options?.arrow?.shape) {
|
|
22
22
|
case 'arrow-table':
|
package/dist/arrow-loader.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/arrow-loader.ts"],"names":["VERSION","DEFAULT_ARROW_LOADER_OPTIONS","arrow","shape","ArrowLoader","name","id","module","version","worker","category","extensions","mimeTypes","binary","tests","options","_typecheckArrowLoader"],"mappings":"AAIA,MAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAQA,MAAMC,4BAA4B,GAAG;AACnCC,EAAAA,KAAK,EAAE;AACLC,IAAAA,KAAK,EAAE;AADF;AAD4B,CAArC;AAOA,OAAO,MAAMC,WAAW,GAAG;AACzBC,EAAAA,IAAI,EAAE,cADmB;AAEzBC,EAAAA,EAAE,EAAE,OAFqB;AAGzBC,EAAAA,MAAM,EAAE,OAHiB;AAIzBC,EAAAA,OAAO,EAAER,OAJgB;AAKzBS,EAAAA,MAAM,EAAE,IALiB;AAMzBC,EAAAA,QAAQ,EAAE,OANe;AAOzBC,EAAAA,UAAU,EAAE,CAAC,OAAD,EAAU,SAAV,CAPa;AAQzBC,EAAAA,SAAS,EAAE,CAAC,0BAAD,CARc;AASzBC,EAAAA,MAAM,EAAE,IATiB;AAUzBC,EAAAA,KAAK,EAAE,CAAC,OAAD,CAVkB;AAWzBC,EAAAA,OAAO,EAAEd;AAXgB,CAApB;AAcP,OAAO,MAAMe,qBAA6B,GAAGZ,WAAtC","sourcesContent":["import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type ArrowLoaderOptions = LoaderOptions & {\n arrow?: {\n shape: 'arrow-table' | 'columnar-table' | 'row-table' | 'array-row-table' | 'object-row-table';\n };\n};\n\nconst DEFAULT_ARROW_LOADER_OPTIONS = {\n arrow: {\n shape: 'columnar-table'\n }\n};\n\n/** ArrowJS table loader */\nexport const ArrowLoader = {\n name: 'Apache Arrow',\n id: 'arrow',\n module: 'arrow',\n version: VERSION,\n worker: true,\n category: 'table',\n extensions: ['arrow', 'feather'],\n mimeTypes: ['application/octet-stream'],\n binary: true,\n tests: ['ARROW'],\n options: DEFAULT_ARROW_LOADER_OPTIONS\n};\n\nexport const _typecheckArrowLoader: Loader = ArrowLoader;\n"],"file":"arrow-loader.js"}
|
package/dist/arrow-writer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/arrow-writer.ts"],"names":["encodeArrowSync","VERSION","ArrowWriter","name","id","module","version","extensions","mimeTypes","encodeSync","binary","options","data"],"mappings":"AAEA,SAAQA,eAAR,QAA8B,oBAA9B;AAIA,MAAMC,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAKA,OAAO,MAAMC,WAAW,GAAG;AACzBC,EAAAA,IAAI,EAAE,cADmB;AAEzBC,EAAAA,EAAE,EAAE,OAFqB;AAGzBC,EAAAA,MAAM,EAAE,OAHiB;AAIzBC,EAAAA,OAAO,EAAEL,OAJgB;AAKzBM,EAAAA,UAAU,EAAE,CAAC,OAAD,EAAU,SAAV,CALa;AAMzBC,EAAAA,SAAS,EAAE,CAAC,0BAAD,CANc;AAOzBC,EAAAA,UAPyB;AAQzBC,EAAAA,MAAM,EAAE,IARiB;AASzBC,EAAAA,OAAO,EAAE;AATgB,CAApB;;AAYP,SAASF,UAAT,CAAoBG,IAApB,EAA0BD,OAA1B,EAAwD;AACtD,SAAOX,eAAe,CAACY,IAAD,CAAtB;AACD","sourcesContent":["// import type {Writer} from '@loaders.gl/loader-utils';\nimport type {WriterOptions} from '@loaders.gl/loader-utils';\nimport {encodeArrowSync} from './lib/encode-arrow';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\ntype ArrowWriterOptions = WriterOptions;\n\n/** Apache Arrow writer */\nexport const ArrowWriter = {\n name: 'Apache Arrow',\n id: 'arrow',\n module: 'arrow',\n version: VERSION,\n extensions: ['arrow', 'feather'],\n mimeTypes: ['application/octet-stream'],\n encodeSync,\n binary: true,\n options: {}\n};\n\nfunction encodeSync(data, options?: ArrowWriterOptions) {\n return encodeArrowSync(data);\n}\n"],"file":"arrow-writer.js"}
|
package/dist/bundle.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["ArrowLoader","ArrowWorkerLoader","parseSync","parseArrowInBatches","TableBatchBuilder","ArrowTableBatchAggregator","ArrowBatch","VECTOR_TYPES","ArrowWriter","parse","arraybuffer","options","parseInBatches","_typecheckArrowLoader"],"mappings":"AAEA,SAAQA,WAAW,IAAIC,iBAAvB,QAA+C,gBAA/C;AACA,OAAOC,SAAP,MAAsB,wBAAtB;AACA,SAAQC,mBAAR,QAAkC,8BAAlC;AAEA,SAAQC,iBAAR,QAAgC,oBAAhC;AACA,OAAOC,yBAAP,MAAsC,yBAAtC;AAGAD,iBAAiB,CAACE,UAAlB,GAA+BD,yBAA/B;AAGA,SAAQE,YAAR,QAA2B,SAA3B;AAIA,SAAQC,WAAR,QAA0B,gBAA1B;AAKA,SAAQP,iBAAR;AAGA,OAAO,MAAMD,WAA6B,GAAG,EAC3C,GAAGC,iBADwC;AAE3CQ,EAAAA,KAAK,EAAE,OAAOC,WAAP,EAAiCC,OAAjC,KACLT,SAAS,CAACQ,WAAD,EAAcC,OAAd,CAHgC;AAI3CT,EAAAA,SAJ2C;AAK3CU,EAAAA,cAAc,EAAET;AAL2B,CAAtC;AAQP,OAAO,MAAMU,qBAAuC,GAAGb,WAAhD","sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {ArrowLoaderOptions} from './arrow-loader';\nimport {ArrowLoader as ArrowWorkerLoader} from './arrow-loader';\nimport parseSync from './lib/parse-arrow-sync';\nimport {parseArrowInBatches} from './lib/parse-arrow-in-batches';\n\nimport {TableBatchBuilder} from '@loaders.gl/schema';\nimport ArrowTableBatchAggregator from './lib/arrow-table-batch';\n\n// Make the ArrowBatch type available\nTableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;\n\n// Types\nexport {VECTOR_TYPES} from './types';\n\n// Arrow writer\n\nexport {ArrowWriter} from './arrow-writer';\n\n// Arrow loader\n\nexport type {ArrowLoaderOptions};\nexport {ArrowWorkerLoader};\n\n/** ArrowJS table loader */\nexport const ArrowLoader: LoaderWithParser = {\n ...ArrowWorkerLoader,\n parse: async (arraybuffer: ArrayBuffer, options?: ArrowLoaderOptions) =>\n parseSync(arraybuffer, options),\n parseSync,\n parseInBatches: parseArrowInBatches\n};\n\nexport const _typecheckArrowLoader: LoaderWithParser = ArrowLoader;\n"],"file":"index.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/arrow-table-batch.ts"],"names":["Schema","Field","RecordBatch","Float32Vector","Float32","ColumnarTableBatchAggregator","ArrowTableBatchAggregator","constructor","schema","options","arrowSchema","getBatch","batch","getArrowSchema","arrowVectors","getArrowVectors","data","recordBatch","length","shape","batchType","arrowFields","key","field","type","Float32Array","metadata","arrowField","name","nullable","push","Error","fields","vector","arrowVector","from"],"mappings":";AACA,SAAQA,MAAR,EAAgBC,KAAhB,EAAuBC,WAAvB,EAAoCC,aAApC,EAAmDC,OAAnD,QAAiE,cAAjE;AACA,SAAQC,4BAAR,QAA2C,oBAA3C;AAEA,eAAe,MAAMC,yBAAN,SAAwCD,4BAAxC,CAAqE;AAGlFE,EAAAA,WAAW,CAACC,MAAD,EAASC,OAAT,EAAkB;AAC3B,UAAMD,MAAN,EAAcC,OAAd;;AAD2B;;AAE3B,SAAKC,WAAL,GAAmB,IAAnB;AACD;;AAEDC,EAAAA,QAAQ,GAA2B;AACjC,UAAMC,KAAK,GAAG,MAAMD,QAAN,EAAd;;AACA,QAAIC,KAAJ,EAAW;AAET,WAAKF,WAAL,GAAmB,KAAKA,WAAL,IAAoBG,cAAc,CAACD,KAAK,CAACJ,MAAP,CAArD;AAEA,YAAMM,YAAY,GAAGC,eAAe,CAAC,KAAKL,WAAN,EAAmBE,KAAK,CAACI,IAAzB,CAApC;AAGA,YAAMC,WAAW,GAAG,IAAIf,WAAJ,CAAgB,KAAKQ,WAArB,EAAkCE,KAAK,CAACM,MAAxC,EAAgDJ,YAAhD,CAApB;AACA,aAAO;AACLK,QAAAA,KAAK,EAAE,aADF;AAELC,QAAAA,SAAS,EAAE,MAFN;AAGLJ,QAAAA,IAAI,EAAEC,WAHD;AAILC,QAAAA,MAAM,EAAEN,KAAK,CAACM;AAJT,OAAP;AAMD;;AAED,WAAO,IAAP;AACD;;AA3BiF;;AA+BpF,SAASL,cAAT,CAAwBL,MAAxB,EAAgC;AAC9B,QAAMa,WAAoB,GAAG,EAA7B;;AACA,OAAK,MAAMC,GAAX,IAAkBd,MAAlB,EAA0B;AACxB,UAAMe,KAAK,GAAGf,MAAM,CAACc,GAAD,CAApB;;AACA,QAAIC,KAAK,CAACC,IAAN,KAAeC,YAAnB,EAAiC;AAC/B,YAAMC,QAAQ,GAAGH,KAAjB;AAEA,YAAMI,UAAU,GAAG,IAAI1B,KAAJ,CAAUsB,KAAK,CAACK,IAAhB,EAAsB,IAAIxB,OAAJ,EAAtB,EAAqCmB,KAAK,CAACM,QAA3C,EAAqDH,QAArD,CAAnB;AACAL,MAAAA,WAAW,CAACS,IAAZ,CAAiBH,UAAjB;AACD;AACF;;AACD,MAAIN,WAAW,CAACH,MAAZ,KAAuB,CAA3B,EAA8B;AAC5B,UAAM,IAAIa,KAAJ,CAAU,6BAAV,CAAN;AACD;;AAED,SAAO,IAAI/B,MAAJ,CAAWqB,WAAX,CAAP;AACD;;AAGD,SAASN,eAAT,CAAyBL,WAAzB,EAAsCM,IAAtC,EAA4C;AAC1C,QAAMF,YAAmB,GAAG,EAA5B;;AACA,OAAK,MAAMS,KAAX,IAAoBb,WAAW,CAACsB,MAAhC,EAAwC;AACtC,UAAMC,MAAM,GAAGjB,IAAI,CAACO,KAAK,CAACK,IAAP,CAAnB;;AACA,QAAIK,MAAM,YAAYR,YAAtB,EAAoC;AAClC,YAAMS,WAAW,GAAG/B,aAAa,CAACgC,IAAd,CAAmBF,MAAnB,CAApB;AACAnB,MAAAA,YAAY,CAACgB,IAAb,CAAkBI,WAAlB;AACD;AACF;;AACD,MAAIxB,WAAW,CAACsB,MAAZ,CAAmBd,MAAnB,KAA8BJ,YAAY,CAACI,MAA/C,EAAuD;AACrD,UAAM,IAAIa,KAAJ,CAAU,oCAAV,CAAN;AACD;;AACD,SAAOjB,YAAP;AACD","sourcesContent":["import type {ArrowTableBatch} from '@loaders.gl/schema';\nimport {Schema, Field, RecordBatch, Float32Vector, Float32} from 'apache-arrow';\nimport {ColumnarTableBatchAggregator} from '@loaders.gl/schema';\n\nexport default class ArrowTableBatchAggregator extends ColumnarTableBatchAggregator {\n arrowSchema: Schema | null;\n\n constructor(schema, options) {\n super(schema, options);\n this.arrowSchema = null;\n }\n\n getBatch(): ArrowTableBatch | null {\n const batch = super.getBatch();\n if (batch) {\n // Get the arrow schema\n this.arrowSchema = this.arrowSchema || getArrowSchema(batch.schema);\n // Get arrow format vectors\n const arrowVectors = getArrowVectors(this.arrowSchema, batch.data);\n // Create the record batch\n // new RecordBatch(schema, numRows, vectors, ...);\n const recordBatch = new RecordBatch(this.arrowSchema, batch.length, arrowVectors);\n return {\n shape: 'arrow-table',\n batchType: 'data',\n data: recordBatch,\n length: batch.length\n };\n }\n\n return null;\n }\n}\n\n// Convert from a simple loaders.gl schema to an Arrow schema\nfunction getArrowSchema(schema) {\n const arrowFields: Field[] = [];\n for (const key in schema) {\n const field = schema[key];\n if (field.type === Float32Array) {\n const metadata = field; // just store the original field as metadata\n // arrow: new Field(name, nullable, metadata)\n const arrowField = new Field(field.name, new Float32(), field.nullable, metadata);\n arrowFields.push(arrowField);\n }\n }\n if (arrowFields.length === 0) {\n throw new Error('No arrow convertible fields');\n }\n\n return new Schema(arrowFields);\n}\n\n// Convert from simple loaders.gl arrays to arrow vectors\nfunction getArrowVectors(arrowSchema, data) {\n const arrowVectors: any[] = [];\n for (const field of arrowSchema.fields) {\n const vector = data[field.name];\n if (vector instanceof Float32Array) {\n const arrowVector = Float32Vector.from(vector);\n arrowVectors.push(arrowVector);\n }\n }\n if (arrowSchema.fields.length !== arrowVectors.length) {\n throw new Error('Some columns not arrow convertible');\n }\n return arrowVectors;\n}\n"],"file":"arrow-table-batch.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/encode-arrow.ts"],"names":["Table","FloatVector","DateVector","VECTOR_TYPES","encodeArrowSync","data","vectors","arrayNames","arrayData","push","name","arrayVector","createVector","array","type","table","new","arrowBuffer","serialize","DATE","from","FLOAT"],"mappings":"AAAA,SAAQA,KAAR,EAAeC,WAAf,EAA4BC,UAA5B,QAA6C,cAA7C;AACA,SAAsBC,YAAtB,QAAyC,UAAzC;AAeA,OAAO,SAASC,eAAT,CAAyBC,IAAzB,EAA2D;AAChE,QAAMC,OAAc,GAAG,EAAvB;AACA,QAAMC,UAAoB,GAAG,EAA7B;;AACA,OAAK,MAAMC,SAAX,IAAwBH,IAAxB,EAA8B;AAC5BE,IAAAA,UAAU,CAACE,IAAX,CAAgBD,SAAS,CAACE,IAA1B;AACA,UAAMC,WAAW,GAAGC,YAAY,CAACJ,SAAS,CAACK,KAAX,EAAkBL,SAAS,CAACM,IAA5B,CAAhC;AACAR,IAAAA,OAAO,CAACG,IAAR,CAAaE,WAAb;AACD;;AACD,QAAMI,KAAK,GAAGf,KAAK,CAACgB,GAAN,CAAUV,OAAV,EAAmBC,UAAnB,CAAd;AACA,QAAMU,WAAW,GAAGF,KAAK,CAACG,SAAN,EAApB;AACA,SAAOD,WAAP;AACD;;AAQD,SAASL,YAAT,CAAsBC,KAAtB,EAA6BC,IAA7B,EAAmC;AACjC,UAAQA,IAAR;AACE,SAAKX,YAAY,CAACgB,IAAlB;AACE,aAAOjB,UAAU,CAACkB,IAAX,CAAgBP,KAAhB,CAAP;;AACF,SAAKV,YAAY,CAACkB,KAAlB;AACA;AACE,aAAOpB,WAAW,CAACmB,IAAZ,CAAiBP,KAAjB,CAAP;AALJ;AAOD","sourcesContent":["import {Table, FloatVector, DateVector} from 'apache-arrow';\nimport {AnyArrayType, VECTOR_TYPES} from '../types';\n\ntype ColumnarTable = {\n name: string;\n array: AnyArrayType;\n type: number;\n}[];\n\n/**\n * Encodes set of arrays into the Apache Arrow columnar format\n * https://arrow.apache.org/docs/format/Columnar.html#ipc-file-format\n * @param data - columns data\n * @param options - the writer options\n * @returns - encoded ArrayBuffer\n */\nexport function encodeArrowSync(data: ColumnarTable): ArrayBuffer {\n const vectors: any[] = [];\n const arrayNames: string[] = [];\n for (const arrayData of data) {\n arrayNames.push(arrayData.name);\n const arrayVector = createVector(arrayData.array, arrayData.type);\n vectors.push(arrayVector);\n }\n const table = Table.new(vectors, arrayNames);\n const arrowBuffer = table.serialize();\n return arrowBuffer;\n}\n\n/**\n * Create Arrow Vector from given data and vector type\n * @param array {import('../types').AnyArrayType} - columns data\n * @param type {number} - the writer options\n * @return a vector of one of vector's types defined in the Apache Arrow library\n */\nfunction createVector(array, type) {\n switch (type) {\n case VECTOR_TYPES.DATE:\n return DateVector.from(array);\n case VECTOR_TYPES.FLOAT:\n default:\n return FloatVector.from(array);\n }\n}\n"],"file":"encode-arrow.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/parse-arrow-in-batches.ts"],"names":["RecordBatchReader","parseArrowInBatches","asyncIterator","makeArrowAsyncIterator","readers","readAll","reader","batch","processBatch","values","metadata","schema","length","fields","forEach","name","index","getChildAt","toArray"],"mappings":"AACA,SAAQA,iBAAR,QAAgC,cAAhC;AAKA,OAAO,SAASC,mBAAT,CACLC,aADK,EAEe;AAmBpB,kBAAgBC,sBAAhB,GAAyC;AACvC,UAAMC,OAAO,GAAGJ,iBAAiB,CAACK,OAAlB,CAA0BH,aAA1B,CAAhB;;AACA,eAAW,MAAMI,MAAjB,IAA2BF,OAA3B,EAAoC;AAClC,iBAAW,MAAMG,KAAjB,IAA0BD,MAA1B,EAAkC;AAChC,cAAME,YAAY,CAACD,KAAD,CAAlB;AACD;;AACD;AACD;AACF;;AACD,SAAOJ,sBAAsB,EAA7B;AACD;;AAED,SAASK,YAAT,CAAsBD,KAAtB,EAA6B;AAC3B,QAAME,MAAM,GAAG;AACbC,IAAAA,QAAQ,EAAEH,KAAK,CAACI,MAAN,CAAaD,QADV;AAEbE,IAAAA,MAAM,EAAEL,KAAK,CAACK;AAFD,GAAf;AAIAL,EAAAA,KAAK,CAACI,MAAN,CAAaE,MAAb,CAAoBC,OAApB,CAA4B,CAAC;AAACC,IAAAA;AAAD,GAAD,EAASC,KAAT,KAAmB;AAC7CP,IAAAA,MAAM,CAACM,IAAD,CAAN,GAAeR,KAAK,CAACU,UAAN,CAAiBD,KAAjB,EAAwBE,OAAxB,EAAf;AACD,GAFD;AAGA,SAAOT,MAAP;AACD","sourcesContent":["// TODO - this import defeats the sophisticated typescript checking in ArrowJS\nimport {RecordBatchReader} from 'apache-arrow';\n// import {isIterable} from '@loaders.gl/core';\n\n/**\n */\nexport function parseArrowInBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>\n): AsyncIterable<any> {\n // Creates the appropriate RecordBatchReader subclasses from the input\n // This will also close the underlying source in case of early termination or errors\n\n // As an optimization, return a non-async iterator\n /*\n if (isIterable(readers)) {\n function* makeArrowIterator() {\n for (const reader of readers) {\n for (const batch of reader) {\n yield processBatch(batch, reader);\n }\n break; // only processing one stream of batches\n }\n }\n const arrowIterator = makeArrowIterator();\n }\n */\n\n async function* makeArrowAsyncIterator() {\n const readers = RecordBatchReader.readAll(asyncIterator);\n for await (const reader of readers) {\n for await (const batch of reader) {\n yield processBatch(batch);\n }\n break; // only processing one stream of batches\n }\n }\n return makeArrowAsyncIterator();\n}\n\nfunction processBatch(batch) {\n const values = {\n metadata: batch.schema.metadata,\n length: batch.length\n };\n batch.schema.fields.forEach(({name}, index) => {\n values[name] = batch.getChildAt(index).toArray();\n });\n return values;\n}\n"],"file":"parse-arrow-in-batches.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/parse-arrow-sync.ts"],"names":["Table","parseArrowSync","arrayBuffer","options","arrowTable","from","Uint8Array","columnarTable","schema","fields","forEach","field","arrowColumn","getColumn","name","values","toArray","arrow","shape","convertColumnarToRowFormatTable","tableKeys","Object","keys","tableRowsCount","length","rowFormatTable","index","tableItem","keyIndex","fieldName","push"],"mappings":"AACA,SAAQA,KAAR,QAAoB,cAApB;AAGA,eAAe,SAASC,cAAT,CAAwBC,WAAxB,EAAqCC,OAArC,EAAmE;AAAA;;AAChF,QAAMC,UAAU,GAAGJ,KAAK,CAACK,IAAN,CAAW,CAAC,IAAIC,UAAJ,CAAeJ,WAAf,CAAD,CAAX,CAAnB;AAMA,QAAMK,aAAa,GAAG,EAAtB;AAEAH,EAAAA,UAAU,CAACI,MAAX,CAAkBC,MAAlB,CAAyBC,OAAzB,CAAkCC,KAAD,IAAW;AAE1C,UAAMC,WAAW,GAAGR,UAAU,CAACS,SAAX,CAAqBF,KAAK,CAACG,IAA3B,CAApB;AACA,UAAMC,MAAM,GAAGH,WAAW,CAACI,OAAZ,EAAf;AACAT,IAAAA,aAAa,CAACI,KAAK,CAACG,IAAP,CAAb,GAA4BC,MAA5B;AACD,GALD;;AAOA,UAAQZ,OAAR,aAAQA,OAAR,yCAAQA,OAAO,CAAEc,KAAjB,mDAAQ,eAAgBC,KAAxB;AACE,SAAK,aAAL;AACE,aAAOd,UAAP;;AACF,SAAK,kBAAL;AACE,aAAOe,+BAA+B,CAACZ,aAAD,CAAtC;;AACF,SAAK,gBAAL;AACA;AACE,aAAOA,aAAP;AAPJ;AASD;;AAED,SAASY,+BAAT,CAAyCZ,aAAzC,EAAwD;AACtD,QAAMa,SAAS,GAAGC,MAAM,CAACC,IAAP,CAAYf,aAAZ,CAAlB;AACA,QAAMgB,cAAc,GAAGhB,aAAa,CAACa,SAAS,CAAC,CAAD,CAAV,CAAb,CAA4BI,MAAnD;AACA,QAAMC,cAAoB,GAAG,EAA7B;;AAEA,OAAK,IAAIC,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGH,cAA5B,EAA4CG,KAAK,EAAjD,EAAqD;AACnD,UAAMC,SAAS,GAAG,EAAlB;;AACA,SAAK,IAAIC,QAAQ,GAAG,CAApB,EAAuBA,QAAQ,GAAGR,SAAS,CAACI,MAA5C,EAAoDI,QAAQ,EAA5D,EAAgE;AAC9D,YAAMC,SAAS,GAAGT,SAAS,CAACQ,QAAD,CAA3B;AACAD,MAAAA,SAAS,CAACE,SAAD,CAAT,GAAuBtB,aAAa,CAACsB,SAAD,CAAb,CAAyBH,KAAzB,CAAvB;AACD;;AACDD,IAAAA,cAAc,CAACK,IAAf,CAAoBH,SAApB;AACD;;AACD,SAAOF,cAAP;AACD","sourcesContent":["import type {ArrowLoaderOptions} from '../arrow-loader';\nimport {Table} from 'apache-arrow';\n\n// Parses arrow to a columnar table\nexport default function parseArrowSync(arrayBuffer, options?: ArrowLoaderOptions) {\n const arrowTable = Table.from([new Uint8Array(arrayBuffer)]);\n\n // Extract columns\n\n // TODO - avoid calling `getColumn` on columns we are not interested in?\n // Add options object?\n const columnarTable = {};\n\n arrowTable.schema.fields.forEach((field) => {\n // This (is intended to) coalesce all record batches into a single typed array\n const arrowColumn = arrowTable.getColumn(field.name);\n const values = arrowColumn.toArray();\n columnarTable[field.name] = values;\n });\n\n switch (options?.arrow?.shape) {\n case 'arrow-table':\n return arrowTable;\n case 'object-row-table':\n return convertColumnarToRowFormatTable(columnarTable);\n case 'columnar-table':\n default:\n return columnarTable;\n }\n}\n\nfunction convertColumnarToRowFormatTable(columnarTable) {\n const tableKeys = Object.keys(columnarTable);\n const tableRowsCount = columnarTable[tableKeys[0]].length;\n const rowFormatTable: {}[] = [];\n\n for (let index = 0; index < tableRowsCount; index++) {\n const tableItem = {};\n for (let keyIndex = 0; keyIndex < tableKeys.length; keyIndex++) {\n const fieldName = tableKeys[keyIndex];\n tableItem[fieldName] = columnarTable[fieldName][index];\n }\n rowFormatTable.push(tableItem);\n }\n return rowFormatTable;\n}\n"],"file":"parse-arrow-sync.js"}
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"names":["VECTOR_TYPES"],"mappings":"AAgBA,WAAYA,YAAZ;;WAAYA,Y;AAAAA,EAAAA,Y,CAAAA,Y;AAAAA,EAAAA,Y,CAAAA,Y;GAAAA,Y,KAAAA,Y","sourcesContent":["type TypedIntArray =\n | Int8Array\n | Uint8Array\n | Int16Array\n | Uint16Array\n | Int32Array\n | Uint32Array\n | Int32Array\n | 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"],"file":"types.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/workers/arrow-worker.ts"],"names":["createLoaderWorker","ArrowLoader"],"mappings":"AAAA,SAAQA,kBAAR,QAAiC,0BAAjC;AACA,SAAQC,WAAR,QAA0B,UAA1B;AAEAD,kBAAkB,CAACC,WAAD,CAAlB","sourcesContent":["import {createLoaderWorker} from '@loaders.gl/loader-utils';\nimport {ArrowLoader} from '../index';\n\ncreateLoaderWorker(ArrowLoader);\n"],"file":"arrow-worker.js"}
|