@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrow-writer.js","names":["encodeArrowSync","VERSION","ArrowWriter","name","id","module","version","extensions","mimeTypes","encodeSync","data","options","binary"],"sources":["../../src/arrow-writer.ts"],"sourcesContent":["// import type {} from '@loaders.gl/loader-utils';\nimport type {Writer, WriterOptions} from '@loaders.gl/loader-utils';\nimport {ColumnarTable} from './lib/encode-arrow';\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 arrow?: {};\n};\n\n/** Apache Arrow writer */\nexport const ArrowWriter: Writer<ColumnarTable, never, ArrowWriterOptions> = {\n name: 'Apache Arrow',\n id: 'arrow',\n module: 'arrow',\n version: VERSION,\n extensions: ['arrow', 'feather'],\n mimeTypes: [\n 'application/vnd.apache.arrow.file',\n 'application/vnd.apache.arrow.stream',\n 'application/octet-stream'\n ],\n encodeSync(data, options?) {\n return encodeArrowSync(data);\n },\n binary: true,\n options: {}\n};\n"],"mappings":"AAGA,SAAQA,eAAe,QAAO,oBAAoB;AAIlD,MAAMC,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"arrow-writer.js","names":["encodeArrowSync","VERSION","ArrowWriter","name","id","module","version","extensions","mimeTypes","encodeSync","data","options","binary"],"sources":["../../src/arrow-writer.ts"],"sourcesContent":["// import type {} from '@loaders.gl/loader-utils';\nimport type {Writer, WriterOptions} from '@loaders.gl/loader-utils';\nimport {ColumnarTable} from './lib/encode-arrow';\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 arrow?: {};\n};\n\n/** Apache Arrow writer */\nexport const ArrowWriter: Writer<ColumnarTable, never, ArrowWriterOptions> = {\n name: 'Apache Arrow',\n id: 'arrow',\n module: 'arrow',\n version: VERSION,\n extensions: ['arrow', 'feather'],\n mimeTypes: [\n 'application/vnd.apache.arrow.file',\n 'application/vnd.apache.arrow.stream',\n 'application/octet-stream'\n ],\n encodeSync(data, options?) {\n return encodeArrowSync(data);\n },\n binary: true,\n options: {}\n};\n"],"mappings":"AAGA,SAAQA,eAAe,QAAO,oBAAoB;AAIlD,MAAMC,OAAO,GAAG,qBAAkB,KAAK,WAAW,oBAAiB,QAAQ;AAO3E,OAAO,MAAMC,WAA6D,GAAG;EAC3EC,IAAI,EAAE,cAAc;EACpBC,EAAE,EAAE,OAAO;EACXC,MAAM,EAAE,OAAO;EACfC,OAAO,EAAEL,OAAO;EAChBM,UAAU,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC;EAChCC,SAAS,EAAE,CACT,mCAAmC,EACnC,qCAAqC,EACrC,0BAA0B,CAC3B;EACDC,UAAUA,CAACC,IAAI,EAAEC,OAAQ,EAAE;IACzB,OAAOX,eAAe,CAACU,IAAI,CAAC;EAC9B,CAAC;EACDE,MAAM,EAAE,IAAI;EACZD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { TableBatchBuilder } from '@loaders.gl/schema';
|
|
1
2
|
import { ArrowLoader as ArrowWorkerLoader } from './arrow-loader';
|
|
2
3
|
import parseSync from './lib/parse-arrow-sync';
|
|
3
4
|
import { parseArrowInBatches } from './lib/parse-arrow-in-batches';
|
|
4
|
-
import {
|
|
5
|
-
import ArrowTableBatchAggregator from './lib/arrow-table-batch';
|
|
5
|
+
import { ArrowTableBatchAggregator } from './lib/arrow-table-batch';
|
|
6
6
|
TableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;
|
|
7
7
|
export { VECTOR_TYPES } from './types';
|
|
8
8
|
export { ArrowWriter } from './arrow-writer';
|
|
@@ -13,5 +13,4 @@ export const ArrowLoader = {
|
|
|
13
13
|
parseSync,
|
|
14
14
|
parseInBatches: parseArrowInBatches
|
|
15
15
|
};
|
|
16
|
-
export const _typecheckArrowLoader = ArrowLoader;
|
|
17
16
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["ArrowLoader","ArrowWorkerLoader","parseSync","parseArrowInBatches","
|
|
1
|
+
{"version":3,"file":"index.js","names":["TableBatchBuilder","ArrowLoader","ArrowWorkerLoader","parseSync","parseArrowInBatches","ArrowTableBatchAggregator","ArrowBatch","VECTOR_TYPES","ArrowWriter","parse","arraybuffer","options","parseInBatches"],"sources":["../../src/index.ts"],"sourcesContent":["// loaders.gl, MIT\n\nimport type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {ArrowLoaderOptions} from './arrow-loader';\nimport type {ArrowTableBatch, ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';\nimport type {ArrowTable} from './lib/arrow-table';\n\nimport {TableBatchBuilder} from '@loaders.gl/schema';\nimport {ArrowLoader as ArrowWorkerLoader} from './arrow-loader';\nimport parseSync from './lib/parse-arrow-sync';\nimport {parseArrowInBatches} from './lib/parse-arrow-in-batches';\n\nimport {ArrowTableBatchAggregator} from './lib/arrow-table-batch';\n\n// Make the ArrowBatch type available\nTableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;\n\n// Types\nexport type {ArrowTable, ArrowTableBatch} from './lib/arrow-table';\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 ArrowTable | ColumnarTable | ObjectRowTable,\n ArrowTableBatch,\n ArrowLoaderOptions\n> = {\n ...ArrowWorkerLoader,\n parse: async (arraybuffer: ArrayBuffer, options?: ArrowLoaderOptions) =>\n parseSync(arraybuffer, options),\n parseSync,\n parseInBatches: parseArrowInBatches\n};\n"],"mappings":"AAOA,SAAQA,iBAAiB,QAAO,oBAAoB;AACpD,SAAQC,WAAW,IAAIC,iBAAiB,QAAO,gBAAgB;AAC/D,OAAOC,SAAS,MAAM,wBAAwB;AAC9C,SAAQC,mBAAmB,QAAO,8BAA8B;AAEhE,SAAQC,yBAAyB,QAAO,yBAAyB;AAGjEL,iBAAiB,CAACM,UAAU,GAAGD,yBAAyB;AAIxD,SAAQE,YAAY,QAAO,SAAS;AAIpC,SAAQC,WAAW,QAAO,gBAAgB;AAK1C,SAAQN,iBAAiB;AAGzB,OAAO,MAAMD,WAIZ,GAAG;EACF,GAAGC,iBAAiB;EACpBO,KAAK,EAAE,MAAAA,CAAOC,WAAwB,EAAEC,OAA4B,KAClER,SAAS,CAACO,WAAW,EAAEC,OAAO,CAAC;EACjCR,SAAS;EACTS,cAAc,EAAER;AAClB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
import { Schema, Field, RecordBatch, Struct, makeVector, makeData, Float32 } from 'apache-arrow';
|
|
3
2
|
import { ColumnarTableBatchAggregator } from '@loaders.gl/schema';
|
|
4
|
-
|
|
3
|
+
import { Table as ApacheArrowTable, Schema, Field, RecordBatch, Struct, makeVector, makeData, Float32 } from 'apache-arrow';
|
|
4
|
+
export class ArrowTableBatchAggregator extends ColumnarTableBatchAggregator {
|
|
5
5
|
constructor(schema, options) {
|
|
6
6
|
super(schema, options);
|
|
7
7
|
_defineProperty(this, "arrowSchema", void 0);
|
|
@@ -24,7 +24,7 @@ export default class ArrowTableBatchAggregator extends ColumnarTableBatchAggrega
|
|
|
24
24
|
return {
|
|
25
25
|
shape: 'arrow-table',
|
|
26
26
|
batchType: 'data',
|
|
27
|
-
data: recordBatch,
|
|
27
|
+
data: new ApacheArrowTable([recordBatch]),
|
|
28
28
|
length: batch.length
|
|
29
29
|
};
|
|
30
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrow-table-batch.js","names":["Schema","Field","RecordBatch","Struct","makeVector","makeData","Float32","
|
|
1
|
+
{"version":3,"file":"arrow-table-batch.js","names":["ColumnarTableBatchAggregator","Table","ApacheArrowTable","Schema","Field","RecordBatch","Struct","makeVector","makeData","Float32","ArrowTableBatchAggregator","constructor","schema","options","_defineProperty","arrowSchema","getBatch","batch","getArrowSchema","arrowVectors","getArrowVectors","data","recordBatch","type","fields","children","map","_ref","shape","batchType","length","arrowFields","key","field","Float32Array","metadata","Map","arrowField","name","nullable","push","Error","vector","arrowVector"],"sources":["../../../src/lib/arrow-table-batch.ts"],"sourcesContent":["import {ColumnarTableBatchAggregator} from '@loaders.gl/schema';\nimport type {ArrowTableBatch} from './arrow-table';\nimport {\n Table as ApacheArrowTable,\n Schema,\n Field,\n RecordBatch,\n Struct,\n makeVector,\n makeData,\n Vector,\n Float32\n} from 'apache-arrow';\n\nexport 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\n // Get arrow format vectors\n const arrowVectors = getArrowVectors(this.arrowSchema, batch.data);\n\n // Create the record batch\n const recordBatch = new RecordBatch(\n this.arrowSchema,\n makeData({\n type: new Struct(this.arrowSchema.fields),\n children: arrowVectors.map(({data}) => data[0])\n })\n );\n\n return {\n shape: 'arrow-table',\n batchType: 'data',\n data: new ApacheArrowTable([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): Schema {\n const arrowFields: Field[] = [];\n for (const key in schema) {\n const field = schema[key];\n if (field.type === Float32Array) {\n // TODO - just store the original field as metadata?\n const metadata = new Map(); // field;\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): Vector[] {\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 = makeVector(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"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrow-table.js","names":[],"sources":["../../../src/lib/arrow-table.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {Batch, Schema} from '@loaders.gl/schema';\nimport type {Table as ApacheArrowTable} from 'apache-arrow';\n\n/**\n * A table organized as an Apache Arrow table\n * @note This is a variant of the type from loaders.gl/schema\n */\nexport type ArrowTable = {\n shape: 'arrow-table';\n schema?: Schema;\n data: ApacheArrowTable;\n};\n\n/**\n * Batch for a table organized as an Apache Arrow table\n * @note This is a variant of the type from loaders.gl/schema\n */\nexport type ArrowTableBatch = Batch & {\n shape: 'arrow-table';\n schemaType?: 'explicit' | 'deduced';\n schema?: Schema;\n data: ApacheArrowTable; // ApacheRecordBatch;\n length: number;\n};\n"],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function convertApacheArrowToArrowTable(arrowTable) {
|
|
2
|
+
return {
|
|
3
|
+
shape: 'arrow-table',
|
|
4
|
+
data: arrowTable
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export function convertArrowToColumnarTable(table) {
|
|
8
|
+
const arrowTable = table.data;
|
|
9
|
+
const columnarTable = {};
|
|
10
|
+
for (const field of arrowTable.schema.fields) {
|
|
11
|
+
const arrowColumn = arrowTable.getChild(field.name);
|
|
12
|
+
const values = arrowColumn === null || arrowColumn === void 0 ? void 0 : arrowColumn.toArray();
|
|
13
|
+
columnarTable[field.name] = values;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
shape: 'columnar-table',
|
|
17
|
+
data: columnarTable
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function convertColumnarToRowFormatTable(columnarTable) {
|
|
21
|
+
const tableKeys = Object.keys(columnarTable);
|
|
22
|
+
const tableRowsCount = columnarTable[tableKeys[0]].length;
|
|
23
|
+
const rowFormatTable = [];
|
|
24
|
+
for (let index = 0; index < tableRowsCount; index++) {
|
|
25
|
+
const tableItem = {};
|
|
26
|
+
for (let keyIndex = 0; keyIndex < tableKeys.length; keyIndex++) {
|
|
27
|
+
const fieldName = tableKeys[keyIndex];
|
|
28
|
+
tableItem[fieldName] = columnarTable[fieldName][index];
|
|
29
|
+
}
|
|
30
|
+
rowFormatTable.push(tableItem);
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
shape: 'object-row-table',
|
|
34
|
+
data: rowFormatTable
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=convert-table.js.map
|
|
@@ -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} from '@loaders.gl/schema';\nimport type {Table as ApacheArrowTable} from 'apache-arrow';\nimport type {ArrowTable} from './arrow-table';\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":"AAWA,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"}
|
|
@@ -1,27 +1,20 @@
|
|
|
1
|
-
import { RecordBatchReader } from 'apache-arrow';
|
|
1
|
+
import { RecordBatchReader, Table as ApacheArrowTable } from 'apache-arrow';
|
|
2
2
|
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: new ApacheArrowTable([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","Table","ApacheArrowTable","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 type {ArrowTableBatch} from './arrow-table';\nimport {RecordBatchReader, Table as ApacheArrowTable} 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: new ApacheArrowTable([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"],"mappings":"AAEA,SAAQA,iBAAiB,EAAEC,KAAK,IAAIC,gBAAgB,QAAO,cAAc;AAKzE,OAAO,SAASC,mBAAmBA,CACjCC,aAAiE,EACjC;EAmBhC,gBAAgBC,sBAAsBA,CAAA,EAAmC;IAEvE,MAAMC,OAAO,GAAGN,iBAAiB,CAACO,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,EAAE,IAAIX,gBAAgB,CAAC,CAACO,WAAW,CAAC,CAAC;UACzCK,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 {ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';\nimport type {ArrowTable} from './arrow-table';\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":"AAEA,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,11 +1,13 @@
|
|
|
1
1
|
import type { LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
2
|
import type { ArrowLoaderOptions } from './arrow-loader';
|
|
3
|
+
import type { ArrowTableBatch, ColumnarTable, ObjectRowTable } from '@loaders.gl/schema';
|
|
4
|
+
import type { ArrowTable } from './lib/arrow-table';
|
|
3
5
|
import { ArrowLoader as ArrowWorkerLoader } from './arrow-loader';
|
|
6
|
+
export type { ArrowTable, ArrowTableBatch } from './lib/arrow-table';
|
|
4
7
|
export { VECTOR_TYPES } from './types';
|
|
5
8
|
export { ArrowWriter } from './arrow-writer';
|
|
6
9
|
export type { ArrowLoaderOptions };
|
|
7
10
|
export { ArrowWorkerLoader };
|
|
8
11
|
/** ArrowJS table loader */
|
|
9
|
-
export declare const ArrowLoader: LoaderWithParser
|
|
10
|
-
export declare const _typecheckArrowLoader: LoaderWithParser;
|
|
12
|
+
export declare const ArrowLoader: LoaderWithParser<ArrowTable | ColumnarTable | ObjectRowTable, ArrowTableBatch, ArrowLoaderOptions>;
|
|
11
13
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAC,eAAe,EAAE,aAAa,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AACvF,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAC,WAAW,IAAI,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAUhE,YAAY,EAAC,UAAU,EAAE,eAAe,EAAC,MAAM,mBAAmB,CAAC;AACnE,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
|
-
import type { ArrowTableBatch } from '@loaders.gl/schema';
|
|
2
|
-
import { Schema } from 'apache-arrow';
|
|
3
1
|
import { ColumnarTableBatchAggregator } from '@loaders.gl/schema';
|
|
4
|
-
|
|
2
|
+
import type { ArrowTableBatch } from './arrow-table';
|
|
3
|
+
import { Schema } from 'apache-arrow';
|
|
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,
|
|
1
|
+
{"version":3,"file":"arrow-table-batch.d.ts","sourceRoot":"","sources":["../../src/lib/arrow-table-batch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,4BAA4B,EAAC,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,eAAe,CAAC;AACnD,OAAO,EAEL,MAAM,EAQP,MAAM,cAAc,CAAC;AAEtB,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,23 @@
|
|
|
1
|
+
import type { Batch, Schema } from '@loaders.gl/schema';
|
|
2
|
+
import type { Table as ApacheArrowTable } from 'apache-arrow';
|
|
3
|
+
/**
|
|
4
|
+
* A table organized as an Apache Arrow table
|
|
5
|
+
* @note This is a variant of the type from loaders.gl/schema
|
|
6
|
+
*/
|
|
7
|
+
export type ArrowTable = {
|
|
8
|
+
shape: 'arrow-table';
|
|
9
|
+
schema?: Schema;
|
|
10
|
+
data: ApacheArrowTable;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Batch for a table organized as an Apache Arrow table
|
|
14
|
+
* @note This is a variant of the type from loaders.gl/schema
|
|
15
|
+
*/
|
|
16
|
+
export type ArrowTableBatch = Batch & {
|
|
17
|
+
shape: 'arrow-table';
|
|
18
|
+
schemaType?: 'explicit' | 'deduced';
|
|
19
|
+
schema?: Schema;
|
|
20
|
+
data: ApacheArrowTable;
|
|
21
|
+
length: number;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=arrow-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrow-table.d.ts","sourceRoot":"","sources":["../../src/lib/arrow-table.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,KAAK,EAAE,MAAM,EAAC,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAC,KAAK,IAAI,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,aAAa,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,gBAAgB,CAAC;CACxB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG;IACpC,KAAK,EAAE,aAAa,CAAC;IACrB,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,gBAAgB,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ColumnarTable, ObjectRowTable } from '@loaders.gl/schema';
|
|
2
|
+
import type { Table as ApacheArrowTable } from 'apache-arrow';
|
|
3
|
+
import type { ArrowTable } from './arrow-table';
|
|
4
|
+
/**
|
|
5
|
+
* Wrap an apache arrow table in a loaders.gl table wrapper.
|
|
6
|
+
* From this additional conversions are available.
|
|
7
|
+
* @param arrowTable
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function convertApacheArrowToArrowTable(arrowTable: ApacheArrowTable): ArrowTable;
|
|
11
|
+
/**
|
|
12
|
+
* Convert an Apache Arrow table to a ColumnarTable
|
|
13
|
+
* @note Currently does not convert schema
|
|
14
|
+
*/
|
|
15
|
+
export declare function convertArrowToColumnarTable(table: ArrowTable): ColumnarTable;
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @note - should be part of schema module
|
|
19
|
+
*/
|
|
20
|
+
export declare function convertColumnarToRowFormatTable(columnarTable: ColumnarTable): ObjectRowTable;
|
|
21
|
+
//# 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,EAAC,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EAAC,KAAK,IAAI,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAE9C;;;;;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 type { ArrowTableBatch } from './arrow-table';
|
|
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,KAAK,EAAC,eAAe,EAAC,MAAM,eAAe,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,5 @@
|
|
|
1
|
+
import type { ColumnarTable, ObjectRowTable } from '@loaders.gl/schema';
|
|
2
|
+
import type { ArrowTable } from './arrow-table';
|
|
1
3
|
import type { ArrowLoaderOptions } from '../arrow-loader';
|
|
2
|
-
export default function parseArrowSync(arrayBuffer: any, options?: ArrowLoaderOptions):
|
|
4
|
+
export default function parseArrowSync(arrayBuffer: any, options?: ArrowLoaderOptions): ArrowTable | ColumnarTable | ObjectRowTable;
|
|
3
5
|
//# 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,aAAa,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AACtE,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAG9C,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-
|
|
3
|
+
"version": "4.0.0-beta.2",
|
|
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-
|
|
43
|
-
"@loaders.gl/schema": "4.0.0-
|
|
44
|
-
"apache-arrow": "^
|
|
42
|
+
"@loaders.gl/loader-utils": "4.0.0-beta.2",
|
|
43
|
+
"@loaders.gl/schema": "4.0.0-beta.2",
|
|
44
|
+
"apache-arrow": "^13.0.0"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "79c2033f755e88e11bc30a04428e3666b177b8fc"
|
|
47
47
|
}
|
package/src/arrow-loader.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// loaders.gl, MIT license
|
|
2
2
|
import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
3
|
-
import type {ArrowTable} from '
|
|
3
|
+
import type {ArrowTable} from './lib/arrow-table';
|
|
4
4
|
|
|
5
5
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
6
6
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
@@ -34,5 +34,3 @@ export const ArrowLoader: Loader<ArrowTable, never, ArrowLoaderOptions> = {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
|
|
38
|
-
export const _typecheckArrowLoader: Loader = ArrowLoader;
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
+
// loaders.gl, MIT
|
|
2
|
+
|
|
1
3
|
import type {LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
2
4
|
import type {ArrowLoaderOptions} from './arrow-loader';
|
|
5
|
+
import type {ArrowTableBatch, ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';
|
|
6
|
+
import type {ArrowTable} from './lib/arrow-table';
|
|
7
|
+
|
|
8
|
+
import {TableBatchBuilder} from '@loaders.gl/schema';
|
|
3
9
|
import {ArrowLoader as ArrowWorkerLoader} from './arrow-loader';
|
|
4
10
|
import parseSync from './lib/parse-arrow-sync';
|
|
5
11
|
import {parseArrowInBatches} from './lib/parse-arrow-in-batches';
|
|
6
12
|
|
|
7
|
-
import {
|
|
8
|
-
import ArrowTableBatchAggregator from './lib/arrow-table-batch';
|
|
13
|
+
import {ArrowTableBatchAggregator} from './lib/arrow-table-batch';
|
|
9
14
|
|
|
10
15
|
// Make the ArrowBatch type available
|
|
11
16
|
TableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;
|
|
12
17
|
|
|
13
18
|
// Types
|
|
19
|
+
export type {ArrowTable, ArrowTableBatch} from './lib/arrow-table';
|
|
14
20
|
export {VECTOR_TYPES} from './types';
|
|
15
21
|
|
|
16
22
|
// Arrow writer
|
|
@@ -23,12 +29,14 @@ export type {ArrowLoaderOptions};
|
|
|
23
29
|
export {ArrowWorkerLoader};
|
|
24
30
|
|
|
25
31
|
/** ArrowJS table loader */
|
|
26
|
-
export const ArrowLoader: LoaderWithParser
|
|
32
|
+
export const ArrowLoader: LoaderWithParser<
|
|
33
|
+
ArrowTable | ColumnarTable | ObjectRowTable,
|
|
34
|
+
ArrowTableBatch,
|
|
35
|
+
ArrowLoaderOptions
|
|
36
|
+
> = {
|
|
27
37
|
...ArrowWorkerLoader,
|
|
28
38
|
parse: async (arraybuffer: ArrayBuffer, options?: ArrowLoaderOptions) =>
|
|
29
39
|
parseSync(arraybuffer, options),
|
|
30
40
|
parseSync,
|
|
31
41
|
parseInBatches: parseArrowInBatches
|
|
32
42
|
};
|
|
33
|
-
|
|
34
|
-
export const _typecheckArrowLoader: LoaderWithParser = ArrowLoader;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {ColumnarTableBatchAggregator} from '@loaders.gl/schema';
|
|
2
|
+
import type {ArrowTableBatch} from './arrow-table';
|
|
2
3
|
import {
|
|
4
|
+
Table as ApacheArrowTable,
|
|
3
5
|
Schema,
|
|
4
6
|
Field,
|
|
5
7
|
RecordBatch,
|
|
@@ -9,9 +11,8 @@ import {
|
|
|
9
11
|
Vector,
|
|
10
12
|
Float32
|
|
11
13
|
} from 'apache-arrow';
|
|
12
|
-
import {ColumnarTableBatchAggregator} from '@loaders.gl/schema';
|
|
13
14
|
|
|
14
|
-
export
|
|
15
|
+
export class ArrowTableBatchAggregator extends ColumnarTableBatchAggregator {
|
|
15
16
|
arrowSchema: Schema | null;
|
|
16
17
|
|
|
17
18
|
constructor(schema, options) {
|
|
@@ -40,7 +41,7 @@ export default class ArrowTableBatchAggregator extends ColumnarTableBatchAggrega
|
|
|
40
41
|
return {
|
|
41
42
|
shape: 'arrow-table',
|
|
42
43
|
batchType: 'data',
|
|
43
|
-
data: recordBatch,
|
|
44
|
+
data: new ApacheArrowTable([recordBatch]),
|
|
44
45
|
length: batch.length
|
|
45
46
|
};
|
|
46
47
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
import type {Batch, Schema} from '@loaders.gl/schema';
|
|
4
|
+
import type {Table as ApacheArrowTable} from 'apache-arrow';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A table organized as an Apache Arrow table
|
|
8
|
+
* @note This is a variant of the type from loaders.gl/schema
|
|
9
|
+
*/
|
|
10
|
+
export type ArrowTable = {
|
|
11
|
+
shape: 'arrow-table';
|
|
12
|
+
schema?: Schema;
|
|
13
|
+
data: ApacheArrowTable;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Batch for a table organized as an Apache Arrow table
|
|
18
|
+
* @note This is a variant of the type from loaders.gl/schema
|
|
19
|
+
*/
|
|
20
|
+
export type ArrowTableBatch = Batch & {
|
|
21
|
+
shape: 'arrow-table';
|
|
22
|
+
schemaType?: 'explicit' | 'deduced';
|
|
23
|
+
schema?: Schema;
|
|
24
|
+
data: ApacheArrowTable; // ApacheRecordBatch;
|
|
25
|
+
length: number;
|
|
26
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
import type {ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';
|
|
3
|
+
import type {Table as ApacheArrowTable} from 'apache-arrow';
|
|
4
|
+
import type {ArrowTable} from './arrow-table';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Wrap an apache arrow table in a loaders.gl table wrapper.
|
|
8
|
+
* From this additional conversions are available.
|
|
9
|
+
* @param arrowTable
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export function convertApacheArrowToArrowTable(arrowTable: ApacheArrowTable): ArrowTable {
|
|
13
|
+
return {
|
|
14
|
+
shape: 'arrow-table',
|
|
15
|
+
data: arrowTable
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Convert an Apache Arrow table to a ColumnarTable
|
|
21
|
+
* @note Currently does not convert schema
|
|
22
|
+
*/
|
|
23
|
+
export function convertArrowToColumnarTable(table: ArrowTable): ColumnarTable {
|
|
24
|
+
// TODO - avoid calling `getColumn` on columns we are not interested in?
|
|
25
|
+
// Add options object?
|
|
26
|
+
|
|
27
|
+
const arrowTable = table.data;
|
|
28
|
+
const columnarTable = {};
|
|
29
|
+
|
|
30
|
+
for (const field of arrowTable.schema.fields) {
|
|
31
|
+
// This (is intended to) coalesce all record batches into a single typed array
|
|
32
|
+
const arrowColumn = arrowTable.getChild(field.name);
|
|
33
|
+
const values = arrowColumn?.toArray();
|
|
34
|
+
columnarTable[field.name] = values;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
shape: 'columnar-table',
|
|
39
|
+
data: columnarTable
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @note - should be part of schema module
|
|
46
|
+
*/
|
|
47
|
+
export function convertColumnarToRowFormatTable(columnarTable: ColumnarTable): ObjectRowTable {
|
|
48
|
+
const tableKeys = Object.keys(columnarTable);
|
|
49
|
+
const tableRowsCount = columnarTable[tableKeys[0]].length;
|
|
50
|
+
|
|
51
|
+
const rowFormatTable: {}[] = [];
|
|
52
|
+
|
|
53
|
+
for (let index = 0; index < tableRowsCount; index++) {
|
|
54
|
+
const tableItem = {};
|
|
55
|
+
for (let keyIndex = 0; keyIndex < tableKeys.length; keyIndex++) {
|
|
56
|
+
const fieldName = tableKeys[keyIndex];
|
|
57
|
+
tableItem[fieldName] = columnarTable[fieldName][index];
|
|
58
|
+
}
|
|
59
|
+
rowFormatTable.push(tableItem);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
shape: 'object-row-table',
|
|
64
|
+
data: rowFormatTable
|
|
65
|
+
};
|
|
66
|
+
}
|