@loaders.gl/arrow 4.0.0-alpha.9 → 4.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow-loader.d.ts +1 -2
- package/dist/arrow-loader.d.ts.map +1 -1
- package/dist/arrow-worker.js +9737 -9894
- package/dist/dist.min.js +10963 -11096
- package/dist/es5/arrow-loader.js +2 -4
- package/dist/es5/arrow-loader.js.map +1 -1
- package/dist/es5/arrow-writer.js +1 -1
- package/dist/es5/arrow-writer.js.map +1 -1
- package/dist/es5/index.js +3 -6
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/arrow-table-batch.js +4 -4
- package/dist/es5/lib/arrow-table-batch.js.map +1 -1
- package/dist/es5/lib/arrow-table.js +2 -0
- package/dist/es5/lib/arrow-table.js.map +1 -0
- package/dist/es5/lib/convert-table.js +57 -0
- package/dist/es5/lib/convert-table.js.map +1 -0
- package/dist/es5/lib/parse-arrow-in-batches.js +43 -48
- package/dist/es5/lib/parse-arrow-in-batches.js.map +1 -1
- package/dist/es5/lib/parse-arrow-sync.js +11 -37
- package/dist/es5/lib/parse-arrow-sync.js.map +1 -1
- package/dist/esm/arrow-loader.js +1 -2
- package/dist/esm/arrow-loader.js.map +1 -1
- package/dist/esm/arrow-writer.js +1 -1
- package/dist/esm/arrow-writer.js.map +1 -1
- package/dist/esm/index.js +2 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/arrow-table-batch.js +3 -3
- package/dist/esm/lib/arrow-table-batch.js.map +1 -1
- package/dist/esm/lib/arrow-table.js +2 -0
- package/dist/esm/lib/arrow-table.js.map +1 -0
- package/dist/esm/lib/convert-table.js +37 -0
- package/dist/esm/lib/convert-table.js.map +1 -0
- package/dist/esm/lib/parse-arrow-in-batches.js +9 -16
- package/dist/esm/lib/parse-arrow-in-batches.js.map +1 -1
- package/dist/esm/lib/parse-arrow-sync.js +11 -25
- package/dist/esm/lib/parse-arrow-sync.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/arrow-table-batch.d.ts +3 -3
- package/dist/lib/arrow-table-batch.d.ts.map +1 -1
- package/dist/lib/arrow-table.d.ts +23 -0
- package/dist/lib/arrow-table.d.ts.map +1 -0
- package/dist/lib/convert-table.d.ts +21 -0
- package/dist/lib/convert-table.d.ts.map +1 -0
- package/dist/lib/parse-arrow-in-batches.d.ts +2 -1
- package/dist/lib/parse-arrow-in-batches.d.ts.map +1 -1
- package/dist/lib/parse-arrow-sync.d.ts +3 -1
- package/dist/lib/parse-arrow-sync.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/arrow-loader.ts +1 -3
- package/src/index.ts +13 -5
- package/src/lib/arrow-table-batch.ts +5 -4
- package/src/lib/arrow-table.ts +26 -0
- package/src/lib/convert-table.ts +66 -0
- package/src/lib/parse-arrow-in-batches.ts +24 -16
- package/src/lib/parse-arrow-sync.ts +21 -35
- package/dist/arrow-loader.js +0 -29
- package/dist/arrow-writer.js +0 -25
- package/dist/bundle.js +0 -5
- package/dist/index.js +0 -28
- package/dist/lib/arrow-table-batch.js +0 -65
- package/dist/lib/encode-arrow.js +0 -38
- package/dist/lib/parse-arrow-in-batches.js +0 -47
- package/dist/lib/parse-arrow-sync.js +0 -41
- package/dist/types.js +0 -8
- package/dist/workers/arrow-worker.js +0 -5
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// TODO - this import defeats the sophisticated typescript checking in ArrowJS
|
|
2
|
-
import {
|
|
2
|
+
import type {ArrowTableBatch} from './arrow-table';
|
|
3
|
+
import {RecordBatchReader, Table as ApacheArrowTable} from 'apache-arrow';
|
|
3
4
|
// import {isIterable} from '@loaders.gl/core';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
*/
|
|
7
8
|
export function parseArrowInBatches(
|
|
8
9
|
asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>
|
|
9
|
-
): AsyncIterable<
|
|
10
|
+
): AsyncIterable<ArrowTableBatch> {
|
|
10
11
|
// Creates the appropriate RecordBatchReader subclasses from the input
|
|
11
12
|
// This will also close the underlying source in case of early termination or errors
|
|
12
13
|
|
|
@@ -25,25 +26,32 @@ export function parseArrowInBatches(
|
|
|
25
26
|
}
|
|
26
27
|
*/
|
|
27
28
|
|
|
28
|
-
async function* makeArrowAsyncIterator() {
|
|
29
|
+
async function* makeArrowAsyncIterator(): AsyncIterator<ArrowTableBatch> {
|
|
30
|
+
// @ts-ignore
|
|
29
31
|
const readers = RecordBatchReader.readAll(asyncIterator);
|
|
30
32
|
for await (const reader of readers) {
|
|
31
|
-
for await (const
|
|
32
|
-
|
|
33
|
+
for await (const recordBatch of reader) {
|
|
34
|
+
const arrowTabledBatch: ArrowTableBatch = {
|
|
35
|
+
shape: 'arrow-table',
|
|
36
|
+
batchType: 'data',
|
|
37
|
+
data: new ApacheArrowTable([recordBatch]),
|
|
38
|
+
length: recordBatch.data.length
|
|
39
|
+
};
|
|
40
|
+
// processBatch(recordBatch);
|
|
41
|
+
yield arrowTabledBatch;
|
|
33
42
|
}
|
|
34
43
|
break; // only processing one stream of batches
|
|
35
44
|
}
|
|
36
45
|
}
|
|
37
|
-
return makeArrowAsyncIterator();
|
|
38
|
-
}
|
|
39
46
|
|
|
40
|
-
|
|
41
|
-
const values = {
|
|
42
|
-
metadata: batch.schema.metadata,
|
|
43
|
-
length: batch.length
|
|
44
|
-
};
|
|
45
|
-
batch.schema.fields.forEach(({name}, index) => {
|
|
46
|
-
values[name] = batch.getChildAt(index).toArray();
|
|
47
|
-
});
|
|
48
|
-
return values;
|
|
47
|
+
return makeArrowAsyncIterator() as any; // as AsyncIterator<ArrowTableBatch>;
|
|
49
48
|
}
|
|
49
|
+
|
|
50
|
+
// function processBatch(batch: RecordBatch): ArrowTableBatch {
|
|
51
|
+
// const values = {};
|
|
52
|
+
// batch.schema.fields.forEach(({name}, index) => {
|
|
53
|
+
// values[name] = batch.getChildAt(index)?.toArray();
|
|
54
|
+
// });
|
|
55
|
+
// return {
|
|
56
|
+
// };
|
|
57
|
+
// }
|
|
@@ -1,46 +1,32 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';
|
|
2
|
+
import type {ArrowTable} from './arrow-table';
|
|
3
|
+
import {convertTable} from '@loaders.gl/schema';
|
|
2
4
|
import {tableFromIPC} from 'apache-arrow';
|
|
5
|
+
import type {ArrowLoaderOptions} from '../arrow-loader';
|
|
6
|
+
import {convertApacheArrowToArrowTable, convertArrowToColumnarTable} from './convert-table';
|
|
3
7
|
|
|
4
8
|
// Parses arrow to a columnar table
|
|
5
|
-
export default function parseArrowSync(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// Add options object?
|
|
12
|
-
const columnarTable = {};
|
|
9
|
+
export default function parseArrowSync(
|
|
10
|
+
arrayBuffer,
|
|
11
|
+
options?: ArrowLoaderOptions
|
|
12
|
+
): ArrowTable | ColumnarTable | ObjectRowTable {
|
|
13
|
+
const apacheArrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);
|
|
14
|
+
const arrowTable = convertApacheArrowToArrowTable(apacheArrowTable);
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const arrowColumn = arrowTable.getChild(field.name);
|
|
17
|
-
const values = arrowColumn?.toArray();
|
|
18
|
-
columnarTable[field.name] = values;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
switch (options?.arrow?.shape) {
|
|
16
|
+
const shape = options?.arrow?.shape || 'arrow-table';
|
|
17
|
+
switch (shape) {
|
|
22
18
|
case 'arrow-table':
|
|
23
19
|
return arrowTable;
|
|
24
|
-
|
|
25
|
-
return convertColumnarToRowFormatTable(columnarTable);
|
|
20
|
+
|
|
26
21
|
case 'columnar-table':
|
|
27
|
-
|
|
28
|
-
return columnarTable;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
22
|
+
return convertArrowToColumnarTable(arrowTable);
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const rowFormatTable: {}[] = [];
|
|
24
|
+
case 'object-row-table':
|
|
25
|
+
const columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
26
|
+
return convertTable(columnarTable, 'object-row-table');
|
|
36
27
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const fieldName = tableKeys[keyIndex];
|
|
41
|
-
tableItem[fieldName] = columnarTable[fieldName][index];
|
|
42
|
-
}
|
|
43
|
-
rowFormatTable.push(tableItem);
|
|
28
|
+
default:
|
|
29
|
+
// TODO
|
|
30
|
+
throw new Error(shape);
|
|
44
31
|
}
|
|
45
|
-
return rowFormatTable;
|
|
46
32
|
}
|
package/dist/arrow-loader.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._typecheckArrowLoader = exports.ArrowLoader = void 0;
|
|
4
|
-
// __VERSION__ is injected by babel-plugin-version-inline
|
|
5
|
-
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
6
|
-
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
7
|
-
/** ArrowJS table loader */
|
|
8
|
-
exports.ArrowLoader = {
|
|
9
|
-
name: 'Apache Arrow',
|
|
10
|
-
id: 'arrow',
|
|
11
|
-
module: 'arrow',
|
|
12
|
-
version: VERSION,
|
|
13
|
-
// worker: true,
|
|
14
|
-
category: 'table',
|
|
15
|
-
extensions: ['arrow', 'feather'],
|
|
16
|
-
mimeTypes: [
|
|
17
|
-
'application/vnd.apache.arrow.file',
|
|
18
|
-
'application/vnd.apache.arrow.stream',
|
|
19
|
-
'application/octet-stream'
|
|
20
|
-
],
|
|
21
|
-
binary: true,
|
|
22
|
-
tests: ['ARROW'],
|
|
23
|
-
options: {
|
|
24
|
-
arrow: {
|
|
25
|
-
shape: 'columnar-table'
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
exports._typecheckArrowLoader = exports.ArrowLoader;
|
package/dist/arrow-writer.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ArrowWriter = void 0;
|
|
4
|
-
const encode_arrow_1 = require("./lib/encode-arrow");
|
|
5
|
-
// __VERSION__ is injected by babel-plugin-version-inline
|
|
6
|
-
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
7
|
-
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
8
|
-
/** Apache Arrow writer */
|
|
9
|
-
exports.ArrowWriter = {
|
|
10
|
-
name: 'Apache Arrow',
|
|
11
|
-
id: 'arrow',
|
|
12
|
-
module: 'arrow',
|
|
13
|
-
version: VERSION,
|
|
14
|
-
extensions: ['arrow', 'feather'],
|
|
15
|
-
mimeTypes: [
|
|
16
|
-
'application/vnd.apache.arrow.file',
|
|
17
|
-
'application/vnd.apache.arrow.stream',
|
|
18
|
-
'application/octet-stream'
|
|
19
|
-
],
|
|
20
|
-
encodeSync(data, options) {
|
|
21
|
-
return (0, encode_arrow_1.encodeArrowSync)(data);
|
|
22
|
-
},
|
|
23
|
-
binary: true,
|
|
24
|
-
options: {}
|
|
25
|
-
};
|
package/dist/bundle.js
DELETED
package/dist/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports._typecheckArrowLoader = exports.ArrowLoader = exports.ArrowWorkerLoader = exports.ArrowWriter = exports.VECTOR_TYPES = void 0;
|
|
7
|
-
const arrow_loader_1 = require("./arrow-loader");
|
|
8
|
-
Object.defineProperty(exports, "ArrowWorkerLoader", { enumerable: true, get: function () { return arrow_loader_1.ArrowLoader; } });
|
|
9
|
-
const parse_arrow_sync_1 = __importDefault(require("./lib/parse-arrow-sync"));
|
|
10
|
-
const parse_arrow_in_batches_1 = require("./lib/parse-arrow-in-batches");
|
|
11
|
-
const schema_1 = require("@loaders.gl/schema");
|
|
12
|
-
const arrow_table_batch_1 = __importDefault(require("./lib/arrow-table-batch"));
|
|
13
|
-
// Make the ArrowBatch type available
|
|
14
|
-
schema_1.TableBatchBuilder.ArrowBatch = arrow_table_batch_1.default;
|
|
15
|
-
// Types
|
|
16
|
-
var types_1 = require("./types");
|
|
17
|
-
Object.defineProperty(exports, "VECTOR_TYPES", { enumerable: true, get: function () { return types_1.VECTOR_TYPES; } });
|
|
18
|
-
// Arrow writer
|
|
19
|
-
var arrow_writer_1 = require("./arrow-writer");
|
|
20
|
-
Object.defineProperty(exports, "ArrowWriter", { enumerable: true, get: function () { return arrow_writer_1.ArrowWriter; } });
|
|
21
|
-
/** ArrowJS table loader */
|
|
22
|
-
exports.ArrowLoader = {
|
|
23
|
-
...arrow_loader_1.ArrowLoader,
|
|
24
|
-
parse: async (arraybuffer, options) => (0, parse_arrow_sync_1.default)(arraybuffer, options),
|
|
25
|
-
parseSync: parse_arrow_sync_1.default,
|
|
26
|
-
parseInBatches: parse_arrow_in_batches_1.parseArrowInBatches
|
|
27
|
-
};
|
|
28
|
-
exports._typecheckArrowLoader = exports.ArrowLoader;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const apache_arrow_1 = require("apache-arrow");
|
|
4
|
-
const schema_1 = require("@loaders.gl/schema");
|
|
5
|
-
class ArrowTableBatchAggregator extends schema_1.ColumnarTableBatchAggregator {
|
|
6
|
-
constructor(schema, options) {
|
|
7
|
-
super(schema, options);
|
|
8
|
-
this.arrowSchema = null;
|
|
9
|
-
}
|
|
10
|
-
getBatch() {
|
|
11
|
-
const batch = super.getBatch();
|
|
12
|
-
if (batch) {
|
|
13
|
-
// Get the arrow schema
|
|
14
|
-
this.arrowSchema = this.arrowSchema || getArrowSchema(batch.schema);
|
|
15
|
-
// Get arrow format vectors
|
|
16
|
-
const arrowVectors = getArrowVectors(this.arrowSchema, batch.data);
|
|
17
|
-
// Create the record batch
|
|
18
|
-
const recordBatch = new apache_arrow_1.RecordBatch(this.arrowSchema, (0, apache_arrow_1.makeData)({
|
|
19
|
-
type: new apache_arrow_1.Struct(this.arrowSchema.fields),
|
|
20
|
-
children: arrowVectors.map(({ data }) => data[0])
|
|
21
|
-
}));
|
|
22
|
-
return {
|
|
23
|
-
shape: 'arrow-table',
|
|
24
|
-
batchType: 'data',
|
|
25
|
-
data: recordBatch,
|
|
26
|
-
length: batch.length
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.default = ArrowTableBatchAggregator;
|
|
33
|
-
// Convert from a simple loaders.gl schema to an Arrow schema
|
|
34
|
-
function getArrowSchema(schema) {
|
|
35
|
-
const arrowFields = [];
|
|
36
|
-
for (const key in schema) {
|
|
37
|
-
const field = schema[key];
|
|
38
|
-
if (field.type === Float32Array) {
|
|
39
|
-
// TODO - just store the original field as metadata?
|
|
40
|
-
const metadata = new Map(); // field;
|
|
41
|
-
// arrow: new Field(name, nullable, metadata)
|
|
42
|
-
const arrowField = new apache_arrow_1.Field(field.name, new apache_arrow_1.Float32(), field.nullable, metadata);
|
|
43
|
-
arrowFields.push(arrowField);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (arrowFields.length === 0) {
|
|
47
|
-
throw new Error('No arrow convertible fields');
|
|
48
|
-
}
|
|
49
|
-
return new apache_arrow_1.Schema(arrowFields);
|
|
50
|
-
}
|
|
51
|
-
// Convert from simple loaders.gl arrays to arrow vectors
|
|
52
|
-
function getArrowVectors(arrowSchema, data) {
|
|
53
|
-
const arrowVectors = [];
|
|
54
|
-
for (const field of arrowSchema.fields) {
|
|
55
|
-
const vector = data[field.name];
|
|
56
|
-
if (vector instanceof Float32Array) {
|
|
57
|
-
const arrowVector = (0, apache_arrow_1.makeVector)(vector);
|
|
58
|
-
arrowVectors.push(arrowVector);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (arrowSchema.fields.length !== arrowVectors.length) {
|
|
62
|
-
throw new Error('Some columns not arrow convertible');
|
|
63
|
-
}
|
|
64
|
-
return arrowVectors;
|
|
65
|
-
}
|
package/dist/lib/encode-arrow.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeArrowSync = void 0;
|
|
4
|
-
const apache_arrow_1 = require("apache-arrow");
|
|
5
|
-
const types_1 = require("../types");
|
|
6
|
-
/**
|
|
7
|
-
* Encodes set of arrays into the Apache Arrow columnar format
|
|
8
|
-
* https://arrow.apache.org/docs/format/Columnar.html#ipc-file-format
|
|
9
|
-
* @param data - columns data
|
|
10
|
-
* @param options - the writer options
|
|
11
|
-
* @returns - encoded ArrayBuffer
|
|
12
|
-
*/
|
|
13
|
-
function encodeArrowSync(data) {
|
|
14
|
-
const vectors = {};
|
|
15
|
-
for (const arrayData of data) {
|
|
16
|
-
const arrayVector = createVector(arrayData.array, arrayData.type);
|
|
17
|
-
vectors[arrayData.name] = arrayVector;
|
|
18
|
-
}
|
|
19
|
-
const table = new apache_arrow_1.Table(vectors);
|
|
20
|
-
const arrowBuffer = (0, apache_arrow_1.tableToIPC)(table);
|
|
21
|
-
return arrowBuffer;
|
|
22
|
-
}
|
|
23
|
-
exports.encodeArrowSync = encodeArrowSync;
|
|
24
|
-
/**
|
|
25
|
-
* Create Arrow Vector from given data and vector type
|
|
26
|
-
* @param array {import('../types').AnyArrayType} - columns data
|
|
27
|
-
* @param type {number} - the writer options
|
|
28
|
-
* @return a vector of one of vector's types defined in the Apache Arrow library
|
|
29
|
-
*/
|
|
30
|
-
function createVector(array, type) {
|
|
31
|
-
switch (type) {
|
|
32
|
-
case types_1.VECTOR_TYPES.DATE:
|
|
33
|
-
return (0, apache_arrow_1.vectorFromArray)(array);
|
|
34
|
-
case types_1.VECTOR_TYPES.FLOAT:
|
|
35
|
-
default:
|
|
36
|
-
return (0, apache_arrow_1.vectorFromArray)(array);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const arrowIterator = makeArrowIterator();
|
|
24
|
-
}
|
|
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();
|
|
36
|
-
}
|
|
37
|
-
exports.parseArrowInBatches = parseArrowInBatches;
|
|
38
|
-
function processBatch(batch) {
|
|
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;
|
|
47
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.default = parseArrowSync;
|
|
28
|
-
function convertColumnarToRowFormatTable(columnarTable) {
|
|
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);
|
|
39
|
-
}
|
|
40
|
-
return rowFormatTable;
|
|
41
|
-
}
|
package/dist/types.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VECTOR_TYPES = void 0;
|
|
4
|
-
var VECTOR_TYPES;
|
|
5
|
-
(function (VECTOR_TYPES) {
|
|
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 = {}));
|