@loaders.gl/arrow 4.0.0-alpha.23 → 4.0.0-alpha.24
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-worker.js +9706 -9890
- package/dist/dist.min.js +6271 -6424
- package/dist/es5/arrow-loader.js +1 -1
- package/dist/es5/arrow-writer.js +1 -1
- package/dist/es5/index.js +3 -3
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/arrow-table-batch.js +2 -2
- package/dist/es5/lib/arrow-table-batch.js.map +1 -1
- 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 -1
- package/dist/esm/arrow-writer.js +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/arrow-table-batch.js +1 -1
- package/dist/esm/lib/arrow-table-batch.js.map +1 -1
- 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 +8 -15
- 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 +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/arrow-table-batch.d.ts +1 -1
- package/dist/lib/arrow-table-batch.d.ts.map +1 -1
- package/dist/lib/convert-table.d.ts +20 -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 +2 -1
- package/dist/lib/parse-arrow-sync.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +8 -3
- package/src/lib/arrow-table-batch.ts +1 -1
- package/src/lib/convert-table.ts +65 -0
- package/src/lib/parse-arrow-in-batches.ts +24 -15
- package/src/lib/parse-arrow-sync.ts +20 -35
- package/dist/arrow-loader.js +0 -28
- package/dist/arrow-writer.js +0 -25
- package/dist/bundle.js +0 -5
- package/dist/index.js +0 -27
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-table.js","names":["convertApacheArrowToArrowTable","arrowTable","shape","data","convertArrowToColumnarTable","table","columnarTable","field","schema","fields","arrowColumn","getChild","name","values","toArray","convertColumnarToRowFormatTable","tableKeys","Object","keys","tableRowsCount","length","rowFormatTable","index","tableItem","keyIndex","fieldName","push"],"sources":["../../../src/lib/convert-table.ts"],"sourcesContent":["// loaders.gl, MIT license\nimport type {ColumnarTable, ObjectRowTable, ArrowTable} from '@loaders.gl/schema';\nimport type {Table as ApacheArrowTable} from 'apache-arrow';\n\n/**\n * Wrap an apache arrow table in a loaders.gl table wrapper.\n * From this additional conversions are available.\n * @param arrowTable\n * @returns\n */\nexport function convertApacheArrowToArrowTable(arrowTable: ApacheArrowTable): ArrowTable {\n return {\n shape: 'arrow-table',\n data: arrowTable\n };\n}\n\n/**\n * Convert an Apache Arrow table to a ColumnarTable\n * @note Currently does not convert schema\n */\nexport function convertArrowToColumnarTable(table: ArrowTable): ColumnarTable {\n // TODO - avoid calling `getColumn` on columns we are not interested in?\n // Add options object?\n\n const arrowTable = table.data;\n const columnarTable = {};\n\n for (const field of arrowTable.schema.fields) {\n // This (is intended to) coalesce all record batches into a single typed array\n const arrowColumn = arrowTable.getChild(field.name);\n const values = arrowColumn?.toArray();\n columnarTable[field.name] = values;\n }\n\n return {\n shape: 'columnar-table',\n data: columnarTable\n };\n}\n\n/**\n *\n * @note - should be part of schema module\n */\nexport function convertColumnarToRowFormatTable(columnarTable: ColumnarTable): ObjectRowTable {\n const tableKeys = Object.keys(columnarTable);\n const tableRowsCount = columnarTable[tableKeys[0]].length;\n\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\n return {\n shape: 'object-row-table',\n data: rowFormatTable\n };\n}\n"],"mappings":"AAUA,OAAO,SAASA,8BAA8BA,CAACC,UAA4B,EAAc;EACvF,OAAO;IACLC,KAAK,EAAE,aAAa;IACpBC,IAAI,EAAEF;EACR,CAAC;AACH;AAMA,OAAO,SAASG,2BAA2BA,CAACC,KAAiB,EAAiB;EAI5E,MAAMJ,UAAU,GAAGI,KAAK,CAACF,IAAI;EAC7B,MAAMG,aAAa,GAAG,CAAC,CAAC;EAExB,KAAK,MAAMC,KAAK,IAAIN,UAAU,CAACO,MAAM,CAACC,MAAM,EAAE;IAE5C,MAAMC,WAAW,GAAGT,UAAU,CAACU,QAAQ,CAACJ,KAAK,CAACK,IAAI,CAAC;IACnD,MAAMC,MAAM,GAAGH,WAAW,aAAXA,WAAW,uBAAXA,WAAW,CAAEI,OAAO,CAAC,CAAC;IACrCR,aAAa,CAACC,KAAK,CAACK,IAAI,CAAC,GAAGC,MAAM;EACpC;EAEA,OAAO;IACLX,KAAK,EAAE,gBAAgB;IACvBC,IAAI,EAAEG;EACR,CAAC;AACH;AAMA,OAAO,SAASS,+BAA+BA,CAACT,aAA4B,EAAkB;EAC5F,MAAMU,SAAS,GAAGC,MAAM,CAACC,IAAI,CAACZ,aAAa,CAAC;EAC5C,MAAMa,cAAc,GAAGb,aAAa,CAACU,SAAS,CAAC,CAAC,CAAC,CAAC,CAACI,MAAM;EAEzD,MAAMC,cAAoB,GAAG,EAAE;EAE/B,KAAK,IAAIC,KAAK,GAAG,CAAC,EAAEA,KAAK,GAAGH,cAAc,EAAEG,KAAK,EAAE,EAAE;IACnD,MAAMC,SAAS,GAAG,CAAC,CAAC;IACpB,KAAK,IAAIC,QAAQ,GAAG,CAAC,EAAEA,QAAQ,GAAGR,SAAS,CAACI,MAAM,EAAEI,QAAQ,EAAE,EAAE;MAC9D,MAAMC,SAAS,GAAGT,SAAS,CAACQ,QAAQ,CAAC;MACrCD,SAAS,CAACE,SAAS,CAAC,GAAGnB,aAAa,CAACmB,SAAS,CAAC,CAACH,KAAK,CAAC;IACxD;IACAD,cAAc,CAACK,IAAI,CAACH,SAAS,CAAC;EAChC;EAEA,OAAO;IACLrB,KAAK,EAAE,kBAAkB;IACzBC,IAAI,EAAEkB;EACR,CAAC;AACH"}
|
|
@@ -3,25 +3,18 @@ export function parseArrowInBatches(asyncIterator) {
|
|
|
3
3
|
async function* makeArrowAsyncIterator() {
|
|
4
4
|
const readers = RecordBatchReader.readAll(asyncIterator);
|
|
5
5
|
for await (const reader of readers) {
|
|
6
|
-
for await (const
|
|
7
|
-
|
|
6
|
+
for await (const recordBatch of reader) {
|
|
7
|
+
const arrowTabledBatch = {
|
|
8
|
+
shape: 'arrow-table',
|
|
9
|
+
batchType: 'data',
|
|
10
|
+
data: recordBatch,
|
|
11
|
+
length: recordBatch.data.length
|
|
12
|
+
};
|
|
13
|
+
yield arrowTabledBatch;
|
|
8
14
|
}
|
|
9
15
|
break;
|
|
10
16
|
}
|
|
11
17
|
}
|
|
12
18
|
return makeArrowAsyncIterator();
|
|
13
19
|
}
|
|
14
|
-
function processBatch(batch) {
|
|
15
|
-
const values = {
|
|
16
|
-
metadata: batch.schema.metadata,
|
|
17
|
-
length: batch.length
|
|
18
|
-
};
|
|
19
|
-
batch.schema.fields.forEach((_ref, index) => {
|
|
20
|
-
let {
|
|
21
|
-
name
|
|
22
|
-
} = _ref;
|
|
23
|
-
values[name] = batch.getChildAt(index).toArray();
|
|
24
|
-
});
|
|
25
|
-
return values;
|
|
26
|
-
}
|
|
27
20
|
//# sourceMappingURL=parse-arrow-in-batches.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-arrow-in-batches.js","names":["RecordBatchReader","parseArrowInBatches","asyncIterator","makeArrowAsyncIterator","readers","readAll","reader","
|
|
1
|
+
{"version":3,"file":"parse-arrow-in-batches.js","names":["RecordBatchReader","parseArrowInBatches","asyncIterator","makeArrowAsyncIterator","readers","readAll","reader","recordBatch","arrowTabledBatch","shape","batchType","data","length"],"sources":["../../../src/lib/parse-arrow-in-batches.ts"],"sourcesContent":["// TODO - this import defeats the sophisticated typescript checking in ArrowJS\nimport {ArrowTableBatch} from '@loaders.gl/schema';\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<ArrowTableBatch> {\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(): AsyncIterator<ArrowTableBatch> {\n // @ts-ignore\n const readers = RecordBatchReader.readAll(asyncIterator);\n for await (const reader of readers) {\n for await (const recordBatch of reader) {\n const arrowTabledBatch: ArrowTableBatch = {\n shape: 'arrow-table',\n batchType: 'data',\n data: recordBatch,\n length: recordBatch.data.length\n };\n // processBatch(recordBatch);\n yield arrowTabledBatch;\n }\n break; // only processing one stream of batches\n }\n }\n\n return makeArrowAsyncIterator() as any; // as AsyncIterator<ArrowTableBatch>;\n}\n\n// function processBatch(batch: RecordBatch): ArrowTableBatch {\n// const values = {};\n// batch.schema.fields.forEach(({name}, index) => {\n// values[name] = batch.getChildAt(index)?.toArray();\n// });\n// return {\n\n// };\n// }\n"],"mappings":"AAEA,SAAQA,iBAAiB,QAAO,cAAc;AAK9C,OAAO,SAASC,mBAAmBA,CACjCC,aAAiE,EACjC;EAmBhC,gBAAgBC,sBAAsBA,CAAA,EAAmC;IAEvE,MAAMC,OAAO,GAAGJ,iBAAiB,CAACK,OAAO,CAACH,aAAa,CAAC;IACxD,WAAW,MAAMI,MAAM,IAAIF,OAAO,EAAE;MAClC,WAAW,MAAMG,WAAW,IAAID,MAAM,EAAE;QACtC,MAAME,gBAAiC,GAAG;UACxCC,KAAK,EAAE,aAAa;UACpBC,SAAS,EAAE,MAAM;UACjBC,IAAI,EAAEJ,WAAW;UACjBK,MAAM,EAAEL,WAAW,CAACI,IAAI,CAACC;QAC3B,CAAC;QAED,MAAMJ,gBAAgB;MACxB;MACA;IACF;EACF;EAEA,OAAOL,sBAAsB,CAAC,CAAC;AACjC"}
|
|
@@ -1,35 +1,21 @@
|
|
|
1
|
+
import { convertTable } from '@loaders.gl/schema';
|
|
1
2
|
import { tableFromIPC } from 'apache-arrow';
|
|
3
|
+
import { convertApacheArrowToArrowTable, convertArrowToColumnarTable } from './convert-table';
|
|
2
4
|
export default function parseArrowSync(arrayBuffer, options) {
|
|
3
5
|
var _options$arrow;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const values = arrowColumn === null || arrowColumn === void 0 ? void 0 : arrowColumn.toArray();
|
|
9
|
-
columnarTable[field.name] = values;
|
|
10
|
-
}
|
|
11
|
-
switch (options === null || options === void 0 ? void 0 : (_options$arrow = options.arrow) === null || _options$arrow === void 0 ? void 0 : _options$arrow.shape) {
|
|
6
|
+
const apacheArrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);
|
|
7
|
+
const arrowTable = convertApacheArrowToArrowTable(apacheArrowTable);
|
|
8
|
+
const shape = (options === null || options === void 0 ? void 0 : (_options$arrow = options.arrow) === null || _options$arrow === void 0 ? void 0 : _options$arrow.shape) || 'arrow-table';
|
|
9
|
+
switch (shape) {
|
|
12
10
|
case 'arrow-table':
|
|
13
11
|
return arrowTable;
|
|
14
|
-
case 'object-row-table':
|
|
15
|
-
return convertColumnarToRowFormatTable(columnarTable);
|
|
16
12
|
case 'columnar-table':
|
|
13
|
+
return convertArrowToColumnarTable(arrowTable);
|
|
14
|
+
case 'object-row-table':
|
|
15
|
+
const columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
16
|
+
return convertTable(columnarTable, 'object-row-table');
|
|
17
17
|
default:
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function convertColumnarToRowFormatTable(columnarTable) {
|
|
22
|
-
const tableKeys = Object.keys(columnarTable);
|
|
23
|
-
const tableRowsCount = columnarTable[tableKeys[0]].length;
|
|
24
|
-
const rowFormatTable = [];
|
|
25
|
-
for (let index = 0; index < tableRowsCount; index++) {
|
|
26
|
-
const tableItem = {};
|
|
27
|
-
for (let keyIndex = 0; keyIndex < tableKeys.length; keyIndex++) {
|
|
28
|
-
const fieldName = tableKeys[keyIndex];
|
|
29
|
-
tableItem[fieldName] = columnarTable[fieldName][index];
|
|
30
|
-
}
|
|
31
|
-
rowFormatTable.push(tableItem);
|
|
18
|
+
throw new Error(shape);
|
|
32
19
|
}
|
|
33
|
-
return rowFormatTable;
|
|
34
20
|
}
|
|
35
21
|
//# sourceMappingURL=parse-arrow-sync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-arrow-sync.js","names":["
|
|
1
|
+
{"version":3,"file":"parse-arrow-sync.js","names":["convertTable","tableFromIPC","convertApacheArrowToArrowTable","convertArrowToColumnarTable","parseArrowSync","arrayBuffer","options","_options$arrow","apacheArrowTable","Uint8Array","arrowTable","shape","arrow","columnarTable","Error"],"sources":["../../../src/lib/parse-arrow-sync.ts"],"sourcesContent":["import type {ArrowTable, ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';\nimport {convertTable} from '@loaders.gl/schema';\nimport {tableFromIPC} from 'apache-arrow';\nimport type {ArrowLoaderOptions} from '../arrow-loader';\nimport {convertApacheArrowToArrowTable, convertArrowToColumnarTable} from './convert-table';\n\n// Parses arrow to a columnar table\nexport default function parseArrowSync(\n arrayBuffer,\n options?: ArrowLoaderOptions\n): ArrowTable | ColumnarTable | ObjectRowTable {\n const apacheArrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);\n const arrowTable = convertApacheArrowToArrowTable(apacheArrowTable);\n\n const shape = options?.arrow?.shape || 'arrow-table';\n switch (shape) {\n case 'arrow-table':\n return arrowTable;\n\n case 'columnar-table':\n return convertArrowToColumnarTable(arrowTable);\n\n case 'object-row-table':\n const columnarTable = convertArrowToColumnarTable(arrowTable);\n return convertTable(columnarTable, 'object-row-table');\n\n default:\n // TODO\n throw new Error(shape);\n }\n}\n"],"mappings":"AACA,SAAQA,YAAY,QAAO,oBAAoB;AAC/C,SAAQC,YAAY,QAAO,cAAc;AAEzC,SAAQC,8BAA8B,EAAEC,2BAA2B,QAAO,iBAAiB;AAG3F,eAAe,SAASC,cAAcA,CACpCC,WAAW,EACXC,OAA4B,EACiB;EAAA,IAAAC,cAAA;EAC7C,MAAMC,gBAAgB,GAAGP,YAAY,CAAC,CAAC,IAAIQ,UAAU,CAACJ,WAAW,CAAC,CAAC,CAAC;EACpE,MAAMK,UAAU,GAAGR,8BAA8B,CAACM,gBAAgB,CAAC;EAEnE,MAAMG,KAAK,GAAG,CAAAL,OAAO,aAAPA,OAAO,wBAAAC,cAAA,GAAPD,OAAO,CAAEM,KAAK,cAAAL,cAAA,uBAAdA,cAAA,CAAgBI,KAAK,KAAI,aAAa;EACpD,QAAQA,KAAK;IACX,KAAK,aAAa;MAChB,OAAOD,UAAU;IAEnB,KAAK,gBAAgB;MACnB,OAAOP,2BAA2B,CAACO,UAAU,CAAC;IAEhD,KAAK,kBAAkB;MACrB,MAAMG,aAAa,GAAGV,2BAA2B,CAACO,UAAU,CAAC;MAC7D,OAAOV,YAAY,CAACa,aAAa,EAAE,kBAAkB,CAAC;IAExD;MAEE,MAAM,IAAIC,KAAK,CAACH,KAAK,CAAC;EAC1B;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
2
|
import type { ArrowLoaderOptions } from './arrow-loader';
|
|
3
|
+
import { ArrowTable, ArrowTableBatch, ColumnarTable, ObjectRowTable } from '@loaders.gl/schema';
|
|
3
4
|
import { ArrowLoader as ArrowWorkerLoader } from './arrow-loader';
|
|
4
5
|
export { VECTOR_TYPES } from './types';
|
|
5
6
|
export { ArrowWriter } from './arrow-writer';
|
|
6
7
|
export type { ArrowLoaderOptions };
|
|
7
8
|
export { ArrowWorkerLoader };
|
|
8
9
|
/** ArrowJS table loader */
|
|
9
|
-
export declare const ArrowLoader: LoaderWithParser
|
|
10
|
+
export declare const ArrowLoader: LoaderWithParser<ArrowTable | ColumnarTable | ObjectRowTable, ArrowTableBatch, ArrowLoaderOptions>;
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAC,WAAW,IAAI,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAC,UAAU,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAE9F,OAAO,EAAC,WAAW,IAAI,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAUhE,OAAO,EAAC,YAAY,EAAC,MAAM,SAAS,CAAC;AAIrC,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAI3C,YAAY,EAAC,kBAAkB,EAAC,CAAC;AACjC,OAAO,EAAC,iBAAiB,EAAC,CAAC;AAE3B,2BAA2B;AAC3B,eAAO,MAAM,WAAW,EAAE,gBAAgB,CACxC,UAAU,GAAG,aAAa,GAAG,cAAc,EAC3C,eAAe,EACf,kBAAkB,CAOnB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ArrowTableBatch } from '@loaders.gl/schema';
|
|
2
2
|
import { Schema } from 'apache-arrow';
|
|
3
3
|
import { ColumnarTableBatchAggregator } from '@loaders.gl/schema';
|
|
4
|
-
export
|
|
4
|
+
export declare class ArrowTableBatchAggregator extends ColumnarTableBatchAggregator {
|
|
5
5
|
arrowSchema: Schema | null;
|
|
6
6
|
constructor(schema: any, options: any);
|
|
7
7
|
getBatch(): ArrowTableBatch | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrow-table-batch.d.ts","sourceRoot":"","sources":["../../src/lib/arrow-table-batch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACL,MAAM,EAQP,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,4BAA4B,EAAC,MAAM,oBAAoB,CAAC;AAEhE,
|
|
1
|
+
{"version":3,"file":"arrow-table-batch.d.ts","sourceRoot":"","sources":["../../src/lib/arrow-table-batch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACL,MAAM,EAQP,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,4BAA4B,EAAC,MAAM,oBAAoB,CAAC;AAEhE,qBAAa,yBAA0B,SAAQ,4BAA4B;IACzE,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEf,MAAM,KAAA,EAAE,OAAO,KAAA;IAK3B,QAAQ,IAAI,eAAe,GAAG,IAAI;CA4BnC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ColumnarTable, ObjectRowTable, ArrowTable } from '@loaders.gl/schema';
|
|
2
|
+
import type { Table as ApacheArrowTable } from 'apache-arrow';
|
|
3
|
+
/**
|
|
4
|
+
* Wrap an apache arrow table in a loaders.gl table wrapper.
|
|
5
|
+
* From this additional conversions are available.
|
|
6
|
+
* @param arrowTable
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function convertApacheArrowToArrowTable(arrowTable: ApacheArrowTable): ArrowTable;
|
|
10
|
+
/**
|
|
11
|
+
* Convert an Apache Arrow table to a ColumnarTable
|
|
12
|
+
* @note Currently does not convert schema
|
|
13
|
+
*/
|
|
14
|
+
export declare function convertArrowToColumnarTable(table: ArrowTable): ColumnarTable;
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @note - should be part of schema module
|
|
18
|
+
*/
|
|
19
|
+
export declare function convertColumnarToRowFormatTable(columnarTable: ColumnarTable): ObjectRowTable;
|
|
20
|
+
//# sourceMappingURL=convert-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-table.d.ts","sourceRoot":"","sources":["../../src/lib/convert-table.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,aAAa,EAAE,cAAc,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAClF,OAAO,KAAK,EAAC,KAAK,IAAI,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAE5D;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAAC,UAAU,EAAE,gBAAgB,GAAG,UAAU,CAKvF;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,UAAU,GAAG,aAAa,CAkB5E;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,aAAa,GAAG,cAAc,CAmB5F"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { ArrowTableBatch } from '@loaders.gl/schema';
|
|
1
2
|
/**
|
|
2
3
|
*/
|
|
3
|
-
export declare function parseArrowInBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>): AsyncIterable<
|
|
4
|
+
export declare function parseArrowInBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>): AsyncIterable<ArrowTableBatch>;
|
|
4
5
|
//# sourceMappingURL=parse-arrow-in-batches.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-arrow-in-batches.d.ts","sourceRoot":"","sources":["../../src/lib/parse-arrow-in-batches.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-arrow-in-batches.d.ts","sourceRoot":"","sources":["../../src/lib/parse-arrow-in-batches.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AAInD;GACG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,GAChE,aAAa,CAAC,eAAe,CAAC,CAsChC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ArrowTable, ColumnarTable, ObjectRowTable } from '@loaders.gl/schema';
|
|
1
2
|
import type { ArrowLoaderOptions } from '../arrow-loader';
|
|
2
|
-
export default function parseArrowSync(arrayBuffer: any, options?: ArrowLoaderOptions):
|
|
3
|
+
export default function parseArrowSync(arrayBuffer: any, options?: ArrowLoaderOptions): ArrowTable | ColumnarTable | ObjectRowTable;
|
|
3
4
|
//# sourceMappingURL=parse-arrow-sync.d.ts.map
|
|
@@ -1 +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,
|
|
1
|
+
{"version":3,"file":"parse-arrow-sync.d.ts","sourceRoot":"","sources":["../../src/lib/parse-arrow-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAE,aAAa,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAGlF,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAIxD,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,WAAW,KAAA,EACX,OAAO,CAAC,EAAE,kBAAkB,GAC3B,UAAU,GAAG,aAAa,GAAG,cAAc,CAoB7C"}
|
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.24",
|
|
4
4
|
"description": "Simple columnar table loader for the Apache Arrow format",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"build-worker2": "esbuild src/workers/arrow-worker.ts --bundle --outfile=dist/arrow-worker.js --platform=browser --external:{stream}"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
43
|
-
"@loaders.gl/schema": "4.0.0-alpha.
|
|
44
|
-
"apache-arrow": "^
|
|
42
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.24",
|
|
43
|
+
"@loaders.gl/schema": "4.0.0-alpha.24",
|
|
44
|
+
"apache-arrow": "^13.0.0"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "97a8990595c132fb14e3445a8768d9f4cb98ff05"
|
|
47
47
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type {LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
2
2
|
import type {ArrowLoaderOptions} from './arrow-loader';
|
|
3
|
+
import {ArrowTable, ArrowTableBatch, ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';
|
|
4
|
+
import {TableBatchBuilder} from '@loaders.gl/schema';
|
|
3
5
|
import {ArrowLoader as ArrowWorkerLoader} from './arrow-loader';
|
|
4
6
|
import parseSync from './lib/parse-arrow-sync';
|
|
5
7
|
import {parseArrowInBatches} from './lib/parse-arrow-in-batches';
|
|
6
8
|
|
|
7
|
-
import {
|
|
8
|
-
import ArrowTableBatchAggregator from './lib/arrow-table-batch';
|
|
9
|
+
import {ArrowTableBatchAggregator} from './lib/arrow-table-batch';
|
|
9
10
|
|
|
10
11
|
// Make the ArrowBatch type available
|
|
11
12
|
TableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;
|
|
@@ -23,7 +24,11 @@ export type {ArrowLoaderOptions};
|
|
|
23
24
|
export {ArrowWorkerLoader};
|
|
24
25
|
|
|
25
26
|
/** ArrowJS table loader */
|
|
26
|
-
export const ArrowLoader: LoaderWithParser
|
|
27
|
+
export const ArrowLoader: LoaderWithParser<
|
|
28
|
+
ArrowTable | ColumnarTable | ObjectRowTable,
|
|
29
|
+
ArrowTableBatch,
|
|
30
|
+
ArrowLoaderOptions
|
|
31
|
+
> = {
|
|
27
32
|
...ArrowWorkerLoader,
|
|
28
33
|
parse: async (arraybuffer: ArrayBuffer, options?: ArrowLoaderOptions) =>
|
|
29
34
|
parseSync(arraybuffer, options),
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from 'apache-arrow';
|
|
12
12
|
import {ColumnarTableBatchAggregator} from '@loaders.gl/schema';
|
|
13
13
|
|
|
14
|
-
export
|
|
14
|
+
export class ArrowTableBatchAggregator extends ColumnarTableBatchAggregator {
|
|
15
15
|
arrowSchema: Schema | null;
|
|
16
16
|
|
|
17
17
|
constructor(schema, options) {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
import type {ColumnarTable, ObjectRowTable, ArrowTable} from '@loaders.gl/schema';
|
|
3
|
+
import type {Table as ApacheArrowTable} from 'apache-arrow';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Wrap an apache arrow table in a loaders.gl table wrapper.
|
|
7
|
+
* From this additional conversions are available.
|
|
8
|
+
* @param arrowTable
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export function convertApacheArrowToArrowTable(arrowTable: ApacheArrowTable): ArrowTable {
|
|
12
|
+
return {
|
|
13
|
+
shape: 'arrow-table',
|
|
14
|
+
data: arrowTable
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Convert an Apache Arrow table to a ColumnarTable
|
|
20
|
+
* @note Currently does not convert schema
|
|
21
|
+
*/
|
|
22
|
+
export function convertArrowToColumnarTable(table: ArrowTable): ColumnarTable {
|
|
23
|
+
// TODO - avoid calling `getColumn` on columns we are not interested in?
|
|
24
|
+
// Add options object?
|
|
25
|
+
|
|
26
|
+
const arrowTable = table.data;
|
|
27
|
+
const columnarTable = {};
|
|
28
|
+
|
|
29
|
+
for (const field of arrowTable.schema.fields) {
|
|
30
|
+
// This (is intended to) coalesce all record batches into a single typed array
|
|
31
|
+
const arrowColumn = arrowTable.getChild(field.name);
|
|
32
|
+
const values = arrowColumn?.toArray();
|
|
33
|
+
columnarTable[field.name] = values;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
shape: 'columnar-table',
|
|
38
|
+
data: columnarTable
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @note - should be part of schema module
|
|
45
|
+
*/
|
|
46
|
+
export function convertColumnarToRowFormatTable(columnarTable: ColumnarTable): ObjectRowTable {
|
|
47
|
+
const tableKeys = Object.keys(columnarTable);
|
|
48
|
+
const tableRowsCount = columnarTable[tableKeys[0]].length;
|
|
49
|
+
|
|
50
|
+
const rowFormatTable: {}[] = [];
|
|
51
|
+
|
|
52
|
+
for (let index = 0; index < tableRowsCount; index++) {
|
|
53
|
+
const tableItem = {};
|
|
54
|
+
for (let keyIndex = 0; keyIndex < tableKeys.length; keyIndex++) {
|
|
55
|
+
const fieldName = tableKeys[keyIndex];
|
|
56
|
+
tableItem[fieldName] = columnarTable[fieldName][index];
|
|
57
|
+
}
|
|
58
|
+
rowFormatTable.push(tableItem);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
shape: 'object-row-table',
|
|
63
|
+
data: rowFormatTable
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// TODO - this import defeats the sophisticated typescript checking in ArrowJS
|
|
2
|
+
import {ArrowTableBatch} from '@loaders.gl/schema';
|
|
2
3
|
import {RecordBatchReader} from 'apache-arrow';
|
|
3
4
|
// import {isIterable} from '@loaders.gl/core';
|
|
4
5
|
|
|
@@ -6,7 +7,7 @@ import {RecordBatchReader} from 'apache-arrow';
|
|
|
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,33 @@ 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: 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
|
+
// };
|
|
58
|
+
// }
|
|
@@ -1,46 +1,31 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {ArrowTable, ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';
|
|
2
|
+
import {convertTable} from '@loaders.gl/schema';
|
|
2
3
|
import {tableFromIPC} from 'apache-arrow';
|
|
4
|
+
import type {ArrowLoaderOptions} from '../arrow-loader';
|
|
5
|
+
import {convertApacheArrowToArrowTable, convertArrowToColumnarTable} from './convert-table';
|
|
3
6
|
|
|
4
7
|
// Parses arrow to a columnar table
|
|
5
|
-
export default function parseArrowSync(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// Add options object?
|
|
12
|
-
const columnarTable = {};
|
|
8
|
+
export default function parseArrowSync(
|
|
9
|
+
arrayBuffer,
|
|
10
|
+
options?: ArrowLoaderOptions
|
|
11
|
+
): ArrowTable | ColumnarTable | ObjectRowTable {
|
|
12
|
+
const apacheArrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);
|
|
13
|
+
const arrowTable = convertApacheArrowToArrowTable(apacheArrowTable);
|
|
13
14
|
|
|
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) {
|
|
15
|
+
const shape = options?.arrow?.shape || 'arrow-table';
|
|
16
|
+
switch (shape) {
|
|
22
17
|
case 'arrow-table':
|
|
23
18
|
return arrowTable;
|
|
24
|
-
|
|
25
|
-
return convertColumnarToRowFormatTable(columnarTable);
|
|
19
|
+
|
|
26
20
|
case 'columnar-table':
|
|
27
|
-
|
|
28
|
-
return columnarTable;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
21
|
+
return convertArrowToColumnarTable(arrowTable);
|
|
31
22
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const rowFormatTable: {}[] = [];
|
|
23
|
+
case 'object-row-table':
|
|
24
|
+
const columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
25
|
+
return convertTable(columnarTable, 'object-row-table');
|
|
36
26
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const fieldName = tableKeys[keyIndex];
|
|
41
|
-
tableItem[fieldName] = columnarTable[fieldName][index];
|
|
42
|
-
}
|
|
43
|
-
rowFormatTable.push(tableItem);
|
|
27
|
+
default:
|
|
28
|
+
// TODO
|
|
29
|
+
throw new Error(shape);
|
|
44
30
|
}
|
|
45
|
-
return rowFormatTable;
|
|
46
31
|
}
|
package/dist/arrow-loader.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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
|
-
};
|
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,27 +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.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
|
-
};
|
|
@@ -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
|
-
}
|