@loaders.gl/arrow 4.0.0-alpha.4 → 4.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow-loader.d.ts +11 -0
- package/dist/arrow-loader.d.ts.map +1 -0
- package/dist/arrow-loader.js +28 -20
- package/dist/arrow-worker.js +10906 -14545
- package/dist/arrow-writer.d.ts +9 -0
- package/dist/arrow-writer.d.ts.map +1 -0
- package/dist/arrow-writer.js +24 -17
- package/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2 -2
- package/dist/dist.min.js +12824 -0
- package/dist/es5/arrow-loader.js +27 -0
- package/dist/es5/arrow-loader.js.map +1 -0
- package/dist/es5/arrow-writer.js +23 -0
- package/dist/es5/arrow-writer.js.map +1 -0
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +64 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/arrow-table-batch.js +99 -0
- package/dist/es5/lib/arrow-table-batch.js.map +1 -0
- package/dist/es5/lib/encode-arrow.js +40 -0
- package/dist/es5/lib/encode-arrow.js.map +1 -0
- package/dist/es5/lib/parse-arrow-in-batches.js +140 -0
- package/dist/es5/lib/parse-arrow-in-batches.js.map +1 -0
- package/dist/es5/lib/parse-arrow-sync.js +53 -0
- package/dist/es5/lib/parse-arrow-sync.js.map +1 -0
- package/dist/es5/types.js +13 -0
- package/dist/es5/types.js.map +1 -0
- package/dist/es5/workers/arrow-worker.js +6 -0
- package/dist/es5/workers/arrow-worker.js.map +1 -0
- package/dist/esm/arrow-loader.js +19 -0
- package/dist/esm/arrow-loader.js.map +1 -0
- package/dist/esm/arrow-writer.js +16 -0
- package/dist/esm/arrow-writer.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/arrow-table-batch.js +63 -0
- package/dist/esm/lib/arrow-table-batch.js.map +1 -0
- package/dist/esm/lib/encode-arrow.js +22 -0
- package/dist/esm/lib/encode-arrow.js.map +1 -0
- package/dist/esm/lib/parse-arrow-in-batches.js +27 -0
- package/dist/esm/lib/parse-arrow-in-batches.js.map +1 -0
- package/dist/esm/lib/parse-arrow-sync.js +35 -0
- package/dist/esm/lib/parse-arrow-sync.js.map +1 -0
- package/dist/esm/types.js +6 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/workers/arrow-worker.js +4 -0
- package/dist/esm/workers/arrow-worker.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -15
- package/dist/lib/arrow-table-batch.d.ts +9 -0
- package/dist/lib/arrow-table-batch.d.ts.map +1 -0
- package/dist/lib/arrow-table-batch.js +57 -63
- package/dist/lib/encode-arrow.d.ts +15 -0
- package/dist/lib/encode-arrow.d.ts.map +1 -0
- package/dist/lib/encode-arrow.js +35 -25
- package/dist/lib/parse-arrow-in-batches.d.ts +4 -0
- package/dist/lib/parse-arrow-in-batches.d.ts.map +1 -0
- package/dist/lib/parse-arrow-in-batches.js +42 -25
- package/dist/lib/parse-arrow-sync.d.ts +3 -0
- package/dist/lib/parse-arrow-sync.d.ts.map +1 -0
- package/dist/lib/parse-arrow-sync.js +37 -40
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -6
- package/dist/workers/arrow-worker.d.ts +2 -0
- package/dist/workers/arrow-worker.d.ts.map +1 -0
- package/dist/workers/arrow-worker.js +5 -4
- package/package.json +13 -13
- package/src/arrow-loader.ts +14 -10
- package/src/arrow-writer.ts +15 -10
- package/src/lib/arrow-table-batch.ts +25 -7
- package/src/lib/encode-arrow.ts +9 -11
- package/src/lib/parse-arrow-sync.ts +6 -6
- package/dist/arrow-loader.js.map +0 -1
- package/dist/arrow-writer.js.map +0 -1
- package/dist/bundle.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/arrow-table-batch.js.map +0 -1
- package/dist/lib/encode-arrow.js.map +0 -1
- package/dist/lib/parse-arrow-in-batches.js.map +0 -1
- package/dist/lib/parse-arrow-sync.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/workers/arrow-worker.js.map +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { encodeArrowSync } from './lib/encode-arrow';
|
|
2
|
+
const VERSION = typeof "4.0.0-alpha.6" !== 'undefined' ? "4.0.0-alpha.6" : 'latest';
|
|
3
|
+
export const ArrowWriter = {
|
|
4
|
+
name: 'Apache Arrow',
|
|
5
|
+
id: 'arrow',
|
|
6
|
+
module: 'arrow',
|
|
7
|
+
version: VERSION,
|
|
8
|
+
extensions: ['arrow', 'feather'],
|
|
9
|
+
mimeTypes: ['application/vnd.apache.arrow.file', 'application/vnd.apache.arrow.stream', 'application/octet-stream'],
|
|
10
|
+
encodeSync(data, options) {
|
|
11
|
+
return encodeArrowSync(data);
|
|
12
|
+
},
|
|
13
|
+
binary: true,
|
|
14
|
+
options: {}
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=arrow-writer.js.map
|
|
@@ -0,0 +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,sBAAkB,KAAK,WAAW,qBAAiB,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.js","names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"sources":["../../src/bundle.ts"],"sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAS,CAAC;AACxCC,UAAU,CAACC,OAAO,GAAGD,UAAU,CAACC,OAAO,IAAI,CAAC,CAAC;AAC7CC,MAAM,CAACC,OAAO,GAAGC,MAAM,CAACC,MAAM,CAACL,UAAU,CAACC,OAAO,EAAEH,aAAa,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ArrowLoader as ArrowWorkerLoader } from './arrow-loader';
|
|
2
|
+
import parseSync from './lib/parse-arrow-sync';
|
|
3
|
+
import { parseArrowInBatches } from './lib/parse-arrow-in-batches';
|
|
4
|
+
import { TableBatchBuilder } from '@loaders.gl/schema';
|
|
5
|
+
import ArrowTableBatchAggregator from './lib/arrow-table-batch';
|
|
6
|
+
TableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;
|
|
7
|
+
export { VECTOR_TYPES } from './types';
|
|
8
|
+
export { ArrowWriter } from './arrow-writer';
|
|
9
|
+
export { ArrowWorkerLoader };
|
|
10
|
+
export const ArrowLoader = {
|
|
11
|
+
...ArrowWorkerLoader,
|
|
12
|
+
parse: async (arraybuffer, options) => parseSync(arraybuffer, options),
|
|
13
|
+
parseSync,
|
|
14
|
+
parseInBatches: parseArrowInBatches
|
|
15
|
+
};
|
|
16
|
+
export const _typecheckArrowLoader = ArrowLoader;
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["ArrowLoader","ArrowWorkerLoader","parseSync","parseArrowInBatches","TableBatchBuilder","ArrowTableBatchAggregator","ArrowBatch","VECTOR_TYPES","ArrowWriter","parse","arraybuffer","options","parseInBatches","_typecheckArrowLoader"],"sources":["../../src/index.ts"],"sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {ArrowLoaderOptions} from './arrow-loader';\nimport {ArrowLoader as ArrowWorkerLoader} from './arrow-loader';\nimport parseSync from './lib/parse-arrow-sync';\nimport {parseArrowInBatches} from './lib/parse-arrow-in-batches';\n\nimport {TableBatchBuilder} from '@loaders.gl/schema';\nimport ArrowTableBatchAggregator from './lib/arrow-table-batch';\n\n// Make the ArrowBatch type available\nTableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;\n\n// Types\nexport {VECTOR_TYPES} from './types';\n\n// Arrow writer\n\nexport {ArrowWriter} from './arrow-writer';\n\n// Arrow loader\n\nexport type {ArrowLoaderOptions};\nexport {ArrowWorkerLoader};\n\n/** ArrowJS table loader */\nexport const ArrowLoader: LoaderWithParser = {\n ...ArrowWorkerLoader,\n parse: async (arraybuffer: ArrayBuffer, options?: ArrowLoaderOptions) =>\n parseSync(arraybuffer, options),\n parseSync,\n parseInBatches: parseArrowInBatches\n};\n\nexport const _typecheckArrowLoader: LoaderWithParser = ArrowLoader;\n"],"mappings":"AAEA,SAAQA,WAAW,IAAIC,iBAAiB,QAAO,gBAAgB;AAC/D,OAAOC,SAAS,MAAM,wBAAwB;AAC9C,SAAQC,mBAAmB,QAAO,8BAA8B;AAEhE,SAAQC,iBAAiB,QAAO,oBAAoB;AACpD,OAAOC,yBAAyB,MAAM,yBAAyB;AAG/DD,iBAAiB,CAACE,UAAU,GAAGD,yBAAyB;AAGxD,SAAQE,YAAY,QAAO,SAAS;AAIpC,SAAQC,WAAW,QAAO,gBAAgB;AAK1C,SAAQP,iBAAiB;AAGzB,OAAO,MAAMD,WAA6B,GAAG;EAC3C,GAAGC,iBAAiB;EACpBQ,KAAK,EAAE,MAAAA,CAAOC,WAAwB,EAAEC,OAA4B,KAClET,SAAS,CAACQ,WAAW,EAAEC,OAAO,CAAC;EACjCT,SAAS;EACTU,cAAc,EAAET;AAClB,CAAC;AAED,OAAO,MAAMU,qBAAuC,GAAGb,WAAW"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import { Schema, Field, RecordBatch, Struct, makeVector, makeData, Float32 } from 'apache-arrow';
|
|
3
|
+
import { ColumnarTableBatchAggregator } from '@loaders.gl/schema';
|
|
4
|
+
export default class ArrowTableBatchAggregator extends ColumnarTableBatchAggregator {
|
|
5
|
+
constructor(schema, options) {
|
|
6
|
+
super(schema, options);
|
|
7
|
+
_defineProperty(this, "arrowSchema", void 0);
|
|
8
|
+
this.arrowSchema = null;
|
|
9
|
+
}
|
|
10
|
+
getBatch() {
|
|
11
|
+
const batch = super.getBatch();
|
|
12
|
+
if (batch) {
|
|
13
|
+
this.arrowSchema = this.arrowSchema || getArrowSchema(batch.schema);
|
|
14
|
+
const arrowVectors = getArrowVectors(this.arrowSchema, batch.data);
|
|
15
|
+
const recordBatch = new RecordBatch(this.arrowSchema, makeData({
|
|
16
|
+
type: new Struct(this.arrowSchema.fields),
|
|
17
|
+
children: arrowVectors.map(_ref => {
|
|
18
|
+
let {
|
|
19
|
+
data
|
|
20
|
+
} = _ref;
|
|
21
|
+
return data[0];
|
|
22
|
+
})
|
|
23
|
+
}));
|
|
24
|
+
return {
|
|
25
|
+
shape: 'arrow-table',
|
|
26
|
+
batchType: 'data',
|
|
27
|
+
data: recordBatch,
|
|
28
|
+
length: batch.length
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function getArrowSchema(schema) {
|
|
35
|
+
const arrowFields = [];
|
|
36
|
+
for (const key in schema) {
|
|
37
|
+
const field = schema[key];
|
|
38
|
+
if (field.type === Float32Array) {
|
|
39
|
+
const metadata = new Map();
|
|
40
|
+
const arrowField = new Field(field.name, new Float32(), field.nullable, metadata);
|
|
41
|
+
arrowFields.push(arrowField);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (arrowFields.length === 0) {
|
|
45
|
+
throw new Error('No arrow convertible fields');
|
|
46
|
+
}
|
|
47
|
+
return new Schema(arrowFields);
|
|
48
|
+
}
|
|
49
|
+
function getArrowVectors(arrowSchema, data) {
|
|
50
|
+
const arrowVectors = [];
|
|
51
|
+
for (const field of arrowSchema.fields) {
|
|
52
|
+
const vector = data[field.name];
|
|
53
|
+
if (vector instanceof Float32Array) {
|
|
54
|
+
const arrowVector = makeVector(vector);
|
|
55
|
+
arrowVectors.push(arrowVector);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (arrowSchema.fields.length !== arrowVectors.length) {
|
|
59
|
+
throw new Error('Some columns not arrow convertible');
|
|
60
|
+
}
|
|
61
|
+
return arrowVectors;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=arrow-table-batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrow-table-batch.js","names":["Schema","Field","RecordBatch","Struct","makeVector","makeData","Float32","ColumnarTableBatchAggregator","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 type {ArrowTableBatch} from '@loaders.gl/schema';\nimport {\n Schema,\n Field,\n RecordBatch,\n Struct,\n makeVector,\n makeData,\n Vector,\n Float32\n} from 'apache-arrow';\nimport {ColumnarTableBatchAggregator} from '@loaders.gl/schema';\n\nexport default class ArrowTableBatchAggregator extends ColumnarTableBatchAggregator {\n arrowSchema: Schema | null;\n\n constructor(schema, options) {\n super(schema, options);\n this.arrowSchema = null;\n }\n\n getBatch(): ArrowTableBatch | null {\n const batch = super.getBatch();\n if (batch) {\n // Get the arrow schema\n this.arrowSchema = this.arrowSchema || getArrowSchema(batch.schema);\n\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: 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":";AACA,SACEA,MAAM,EACNC,KAAK,EACLC,WAAW,EACXC,MAAM,EACNC,UAAU,EACVC,QAAQ,EAERC,OAAO,QACF,cAAc;AACrB,SAAQC,4BAA4B,QAAO,oBAAoB;AAE/D,eAAe,MAAMC,yBAAyB,SAASD,4BAA4B,CAAC;EAGlFE,WAAWA,CAACC,MAAM,EAAEC,OAAO,EAAE;IAC3B,KAAK,CAACD,MAAM,EAAEC,OAAO,CAAC;IAACC,eAAA;IACvB,IAAI,CAACC,WAAW,GAAG,IAAI;EACzB;EAEAC,QAAQA,CAAA,EAA2B;IACjC,MAAMC,KAAK,GAAG,KAAK,CAACD,QAAQ,CAAC,CAAC;IAC9B,IAAIC,KAAK,EAAE;MAET,IAAI,CAACF,WAAW,GAAG,IAAI,CAACA,WAAW,IAAIG,cAAc,CAACD,KAAK,CAACL,MAAM,CAAC;MAGnE,MAAMO,YAAY,GAAGC,eAAe,CAAC,IAAI,CAACL,WAAW,EAAEE,KAAK,CAACI,IAAI,CAAC;MAGlE,MAAMC,WAAW,GAAG,IAAIlB,WAAW,CACjC,IAAI,CAACW,WAAW,EAChBR,QAAQ,CAAC;QACPgB,IAAI,EAAE,IAAIlB,MAAM,CAAC,IAAI,CAACU,WAAW,CAACS,MAAM,CAAC;QACzCC,QAAQ,EAAEN,YAAY,CAACO,GAAG,CAACC,IAAA;UAAA,IAAC;YAACN;UAAI,CAAC,GAAAM,IAAA;UAAA,OAAKN,IAAI,CAAC,CAAC,CAAC;QAAA;MAChD,CAAC,CACH,CAAC;MAED,OAAO;QACLO,KAAK,EAAE,aAAa;QACpBC,SAAS,EAAE,MAAM;QACjBR,IAAI,EAAEC,WAAW;QACjBQ,MAAM,EAAEb,KAAK,CAACa;MAChB,CAAC;IACH;IAEA,OAAO,IAAI;EACb;AACF;AAGA,SAASZ,cAAcA,CAACN,MAAM,EAAU;EACtC,MAAMmB,WAAoB,GAAG,EAAE;EAC/B,KAAK,MAAMC,GAAG,IAAIpB,MAAM,EAAE;IACxB,MAAMqB,KAAK,GAAGrB,MAAM,CAACoB,GAAG,CAAC;IACzB,IAAIC,KAAK,CAACV,IAAI,KAAKW,YAAY,EAAE;MAE/B,MAAMC,QAAQ,GAAG,IAAIC,GAAG,CAAC,CAAC;MAE1B,MAAMC,UAAU,GAAG,IAAIlC,KAAK,CAAC8B,KAAK,CAACK,IAAI,EAAE,IAAI9B,OAAO,CAAC,CAAC,EAAEyB,KAAK,CAACM,QAAQ,EAAEJ,QAAQ,CAAC;MACjFJ,WAAW,CAACS,IAAI,CAACH,UAAU,CAAC;IAC9B;EACF;EACA,IAAIN,WAAW,CAACD,MAAM,KAAK,CAAC,EAAE;IAC5B,MAAM,IAAIW,KAAK,CAAC,6BAA6B,CAAC;EAChD;EAEA,OAAO,IAAIvC,MAAM,CAAC6B,WAAW,CAAC;AAChC;AAGA,SAASX,eAAeA,CAACL,WAAW,EAAEM,IAAI,EAAY;EACpD,MAAMF,YAAmB,GAAG,EAAE;EAC9B,KAAK,MAAMc,KAAK,IAAIlB,WAAW,CAACS,MAAM,EAAE;IACtC,MAAMkB,MAAM,GAAGrB,IAAI,CAACY,KAAK,CAACK,IAAI,CAAC;IAC/B,IAAII,MAAM,YAAYR,YAAY,EAAE;MAClC,MAAMS,WAAW,GAAGrC,UAAU,CAACoC,MAAM,CAAC;MACtCvB,YAAY,CAACqB,IAAI,CAACG,WAAW,CAAC;IAChC;EACF;EACA,IAAI5B,WAAW,CAACS,MAAM,CAACM,MAAM,KAAKX,YAAY,CAACW,MAAM,EAAE;IACrD,MAAM,IAAIW,KAAK,CAAC,oCAAoC,CAAC;EACvD;EACA,OAAOtB,YAAY;AACrB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Table, tableToIPC, vectorFromArray } from 'apache-arrow';
|
|
2
|
+
import { VECTOR_TYPES } from '../types';
|
|
3
|
+
export function encodeArrowSync(data) {
|
|
4
|
+
const vectors = {};
|
|
5
|
+
for (const arrayData of data) {
|
|
6
|
+
const arrayVector = createVector(arrayData.array, arrayData.type);
|
|
7
|
+
vectors[arrayData.name] = arrayVector;
|
|
8
|
+
}
|
|
9
|
+
const table = new Table(vectors);
|
|
10
|
+
const arrowBuffer = tableToIPC(table);
|
|
11
|
+
return arrowBuffer;
|
|
12
|
+
}
|
|
13
|
+
function createVector(array, type) {
|
|
14
|
+
switch (type) {
|
|
15
|
+
case VECTOR_TYPES.DATE:
|
|
16
|
+
return vectorFromArray(array);
|
|
17
|
+
case VECTOR_TYPES.FLOAT:
|
|
18
|
+
default:
|
|
19
|
+
return vectorFromArray(array);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=encode-arrow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-arrow.js","names":["Table","tableToIPC","vectorFromArray","VECTOR_TYPES","encodeArrowSync","data","vectors","arrayData","arrayVector","createVector","array","type","name","table","arrowBuffer","DATE","FLOAT"],"sources":["../../../src/lib/encode-arrow.ts"],"sourcesContent":["import {Table, Vector, tableToIPC, vectorFromArray} from 'apache-arrow';\nimport {AnyArrayType, VECTOR_TYPES} from '../types';\n\nexport type ColumnarTable = {\n name: string;\n array: AnyArrayType;\n type: number;\n}[];\n\n/**\n * Encodes set of arrays into the Apache Arrow columnar format\n * https://arrow.apache.org/docs/format/Columnar.html#ipc-file-format\n * @param data - columns data\n * @param options - the writer options\n * @returns - encoded ArrayBuffer\n */\nexport function encodeArrowSync(data: ColumnarTable): ArrayBuffer {\n const vectors: Record<string, Vector> = {};\n for (const arrayData of data) {\n const arrayVector = createVector(arrayData.array, arrayData.type);\n vectors[arrayData.name] = arrayVector;\n }\n const table = new Table(vectors);\n const arrowBuffer = tableToIPC(table);\n return arrowBuffer;\n}\n\n/**\n * Create Arrow Vector from given data and vector type\n * @param array {import('../types').AnyArrayType} - columns data\n * @param type {number} - the writer options\n * @return a vector of one of vector's types defined in the Apache Arrow library\n */\nfunction createVector(array, type): Vector {\n switch (type) {\n case VECTOR_TYPES.DATE:\n return vectorFromArray(array);\n case VECTOR_TYPES.FLOAT:\n default:\n return vectorFromArray(array);\n }\n}\n"],"mappings":"AAAA,SAAQA,KAAK,EAAUC,UAAU,EAAEC,eAAe,QAAO,cAAc;AACvE,SAAsBC,YAAY,QAAO,UAAU;AAenD,OAAO,SAASC,eAAeA,CAACC,IAAmB,EAAe;EAChE,MAAMC,OAA+B,GAAG,CAAC,CAAC;EAC1C,KAAK,MAAMC,SAAS,IAAIF,IAAI,EAAE;IAC5B,MAAMG,WAAW,GAAGC,YAAY,CAACF,SAAS,CAACG,KAAK,EAAEH,SAAS,CAACI,IAAI,CAAC;IACjEL,OAAO,CAACC,SAAS,CAACK,IAAI,CAAC,GAAGJ,WAAW;EACvC;EACA,MAAMK,KAAK,GAAG,IAAIb,KAAK,CAACM,OAAO,CAAC;EAChC,MAAMQ,WAAW,GAAGb,UAAU,CAACY,KAAK,CAAC;EACrC,OAAOC,WAAW;AACpB;AAQA,SAASL,YAAYA,CAACC,KAAK,EAAEC,IAAI,EAAU;EACzC,QAAQA,IAAI;IACV,KAAKR,YAAY,CAACY,IAAI;MACpB,OAAOb,eAAe,CAACQ,KAAK,CAAC;IAC/B,KAAKP,YAAY,CAACa,KAAK;IACvB;MACE,OAAOd,eAAe,CAACQ,KAAK,CAAC;EACjC;AACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { RecordBatchReader } from 'apache-arrow';
|
|
2
|
+
export function parseArrowInBatches(asyncIterator) {
|
|
3
|
+
async function* makeArrowAsyncIterator() {
|
|
4
|
+
const readers = RecordBatchReader.readAll(asyncIterator);
|
|
5
|
+
for await (const reader of readers) {
|
|
6
|
+
for await (const batch of reader) {
|
|
7
|
+
yield processBatch(batch);
|
|
8
|
+
}
|
|
9
|
+
break;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return makeArrowAsyncIterator();
|
|
13
|
+
}
|
|
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
|
+
//# sourceMappingURL=parse-arrow-in-batches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-arrow-in-batches.js","names":["RecordBatchReader","parseArrowInBatches","asyncIterator","makeArrowAsyncIterator","readers","readAll","reader","batch","processBatch","values","metadata","schema","length","fields","forEach","_ref","index","name","getChildAt","toArray"],"sources":["../../../src/lib/parse-arrow-in-batches.ts"],"sourcesContent":["// TODO - this import defeats the sophisticated typescript checking in ArrowJS\nimport {RecordBatchReader} from 'apache-arrow';\n// import {isIterable} from '@loaders.gl/core';\n\n/**\n */\nexport function parseArrowInBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>\n): AsyncIterable<any> {\n // Creates the appropriate RecordBatchReader subclasses from the input\n // This will also close the underlying source in case of early termination or errors\n\n // As an optimization, return a non-async iterator\n /*\n if (isIterable(readers)) {\n function* makeArrowIterator() {\n for (const reader of readers) {\n for (const batch of reader) {\n yield processBatch(batch, reader);\n }\n break; // only processing one stream of batches\n }\n }\n const arrowIterator = makeArrowIterator();\n }\n */\n\n async function* makeArrowAsyncIterator() {\n const readers = RecordBatchReader.readAll(asyncIterator);\n for await (const reader of readers) {\n for await (const batch of reader) {\n yield processBatch(batch);\n }\n break; // only processing one stream of batches\n }\n }\n return makeArrowAsyncIterator();\n}\n\nfunction processBatch(batch) {\n const values = {\n metadata: batch.schema.metadata,\n length: batch.length\n };\n batch.schema.fields.forEach(({name}, index) => {\n values[name] = batch.getChildAt(index).toArray();\n });\n return values;\n}\n"],"mappings":"AACA,SAAQA,iBAAiB,QAAO,cAAc;AAK9C,OAAO,SAASC,mBAAmBA,CACjCC,aAAiE,EAC7C;EAmBpB,gBAAgBC,sBAAsBA,CAAA,EAAG;IACvC,MAAMC,OAAO,GAAGJ,iBAAiB,CAACK,OAAO,CAACH,aAAa,CAAC;IACxD,WAAW,MAAMI,MAAM,IAAIF,OAAO,EAAE;MAClC,WAAW,MAAMG,KAAK,IAAID,MAAM,EAAE;QAChC,MAAME,YAAY,CAACD,KAAK,CAAC;MAC3B;MACA;IACF;EACF;EACA,OAAOJ,sBAAsB,CAAC,CAAC;AACjC;AAEA,SAASK,YAAYA,CAACD,KAAK,EAAE;EAC3B,MAAME,MAAM,GAAG;IACbC,QAAQ,EAAEH,KAAK,CAACI,MAAM,CAACD,QAAQ;IAC/BE,MAAM,EAAEL,KAAK,CAACK;EAChB,CAAC;EACDL,KAAK,CAACI,MAAM,CAACE,MAAM,CAACC,OAAO,CAAC,CAAAC,IAAA,EAASC,KAAK,KAAK;IAAA,IAAlB;MAACC;IAAI,CAAC,GAAAF,IAAA;IACjCN,MAAM,CAACQ,IAAI,CAAC,GAAGV,KAAK,CAACW,UAAU,CAACF,KAAK,CAAC,CAACG,OAAO,CAAC,CAAC;EAClD,CAAC,CAAC;EACF,OAAOV,MAAM;AACf"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { tableFromIPC } from 'apache-arrow';
|
|
2
|
+
export default function parseArrowSync(arrayBuffer, options) {
|
|
3
|
+
var _options$arrow;
|
|
4
|
+
const arrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);
|
|
5
|
+
const columnarTable = {};
|
|
6
|
+
for (const field of arrowTable.schema.fields) {
|
|
7
|
+
const arrowColumn = arrowTable.getChild(field.name);
|
|
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) {
|
|
12
|
+
case 'arrow-table':
|
|
13
|
+
return arrowTable;
|
|
14
|
+
case 'object-row-table':
|
|
15
|
+
return convertColumnarToRowFormatTable(columnarTable);
|
|
16
|
+
case 'columnar-table':
|
|
17
|
+
default:
|
|
18
|
+
return columnarTable;
|
|
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);
|
|
32
|
+
}
|
|
33
|
+
return rowFormatTable;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=parse-arrow-sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-arrow-sync.js","names":["tableFromIPC","parseArrowSync","arrayBuffer","options","_options$arrow","arrowTable","Uint8Array","columnarTable","field","schema","fields","arrowColumn","getChild","name","values","toArray","arrow","shape","convertColumnarToRowFormatTable","tableKeys","Object","keys","tableRowsCount","length","rowFormatTable","index","tableItem","keyIndex","fieldName","push"],"sources":["../../../src/lib/parse-arrow-sync.ts"],"sourcesContent":["import type {ArrowLoaderOptions} from '../arrow-loader';\nimport {tableFromIPC} from 'apache-arrow';\n\n// Parses arrow to a columnar table\nexport default function parseArrowSync(arrayBuffer, options?: ArrowLoaderOptions) {\n const arrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);\n\n // Extract columns\n\n // TODO - avoid calling `getColumn` on columns we are not interested in?\n // Add options object?\n const columnarTable = {};\n\n 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 switch (options?.arrow?.shape) {\n case 'arrow-table':\n return arrowTable;\n case 'object-row-table':\n return convertColumnarToRowFormatTable(columnarTable);\n case 'columnar-table':\n default:\n return columnarTable;\n }\n}\n\nfunction convertColumnarToRowFormatTable(columnarTable) {\n const tableKeys = Object.keys(columnarTable);\n const tableRowsCount = columnarTable[tableKeys[0]].length;\n const rowFormatTable: {}[] = [];\n\n for (let index = 0; index < tableRowsCount; index++) {\n const tableItem = {};\n for (let keyIndex = 0; keyIndex < tableKeys.length; keyIndex++) {\n const fieldName = tableKeys[keyIndex];\n tableItem[fieldName] = columnarTable[fieldName][index];\n }\n rowFormatTable.push(tableItem);\n }\n return rowFormatTable;\n}\n"],"mappings":"AACA,SAAQA,YAAY,QAAO,cAAc;AAGzC,eAAe,SAASC,cAAcA,CAACC,WAAW,EAAEC,OAA4B,EAAE;EAAA,IAAAC,cAAA;EAChF,MAAMC,UAAU,GAAGL,YAAY,CAAC,CAAC,IAAIM,UAAU,CAACJ,WAAW,CAAC,CAAC,CAAC;EAM9D,MAAMK,aAAa,GAAG,CAAC,CAAC;EAExB,KAAK,MAAMC,KAAK,IAAIH,UAAU,CAACI,MAAM,CAACC,MAAM,EAAE;IAE5C,MAAMC,WAAW,GAAGN,UAAU,CAACO,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,QAAQX,OAAO,aAAPA,OAAO,wBAAAC,cAAA,GAAPD,OAAO,CAAEa,KAAK,cAAAZ,cAAA,uBAAdA,cAAA,CAAgBa,KAAK;IAC3B,KAAK,aAAa;MAChB,OAAOZ,UAAU;IACnB,KAAK,kBAAkB;MACrB,OAAOa,+BAA+B,CAACX,aAAa,CAAC;IACvD,KAAK,gBAAgB;IACrB;MACE,OAAOA,aAAa;EACxB;AACF;AAEA,SAASW,+BAA+BA,CAACX,aAAa,EAAE;EACtD,MAAMY,SAAS,GAAGC,MAAM,CAACC,IAAI,CAACd,aAAa,CAAC;EAC5C,MAAMe,cAAc,GAAGf,aAAa,CAACY,SAAS,CAAC,CAAC,CAAC,CAAC,CAACI,MAAM;EACzD,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,GAAGrB,aAAa,CAACqB,SAAS,CAAC,CAACH,KAAK,CAAC;IACxD;IACAD,cAAc,CAACK,IAAI,CAACH,SAAS,CAAC;EAChC;EACA,OAAOF,cAAc;AACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":["VECTOR_TYPES"],"sources":["../../src/types.ts"],"sourcesContent":["type TypedIntArray =\n | Int8Array\n | Uint8Array\n | Int16Array\n | Uint16Array\n | Int32Array\n | Uint32Array\n | Int32Array\n | Uint32Array;\n\ntype TypedFloatArray = Float32Array | Float64Array;\n\ntype TypedArray = TypedIntArray | TypedFloatArray;\n\nexport type AnyArrayType = Array<any> | TypedArray;\n\nexport enum VECTOR_TYPES {\n FLOAT,\n DATE\n}\n"],"mappings":"AAgBA,WAAYA,YAAY,aAAZA,YAAY;EAAZA,YAAY,CAAZA,YAAY;EAAZA,YAAY,CAAZA,YAAY;EAAA,OAAZA,YAAY;AAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrow-worker.js","names":["createLoaderWorker","ArrowLoader"],"sources":["../../../src/workers/arrow-worker.ts"],"sourcesContent":["import {createLoaderWorker} from '@loaders.gl/loader-utils';\nimport {ArrowLoader} from '../index';\n\ncreateLoaderWorker(ArrowLoader);\n"],"mappings":"AAAA,SAAQA,kBAAkB,QAAO,0BAA0B;AAC3D,SAAQC,WAAW,QAAO,UAAU;AAEpCD,kBAAkB,CAACC,WAAW,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
|
+
import type { ArrowLoaderOptions } from './arrow-loader';
|
|
3
|
+
import { ArrowLoader as ArrowWorkerLoader } from './arrow-loader';
|
|
4
|
+
export { VECTOR_TYPES } from './types';
|
|
5
|
+
export { ArrowWriter } from './arrow-writer';
|
|
6
|
+
export type { ArrowLoaderOptions };
|
|
7
|
+
export { ArrowWorkerLoader };
|
|
8
|
+
/** ArrowJS table loader */
|
|
9
|
+
export declare const ArrowLoader: LoaderWithParser;
|
|
10
|
+
export declare const _typecheckArrowLoader: LoaderWithParser;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;AAWhE,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,gBAMzB,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,gBAA8B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { TableBatchBuilder } from '@loaders.gl/schema';
|
|
5
|
-
import ArrowTableBatchAggregator from './lib/arrow-table-batch';
|
|
6
|
-
TableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;
|
|
7
|
-
export { VECTOR_TYPES } from './types';
|
|
8
|
-
export { ArrowWriter } from './arrow-writer';
|
|
9
|
-
export { ArrowWorkerLoader };
|
|
10
|
-
export const ArrowLoader = { ...ArrowWorkerLoader,
|
|
11
|
-
parse: async (arraybuffer, options) => parseSync(arraybuffer, options),
|
|
12
|
-
parseSync,
|
|
13
|
-
parseInBatches: parseArrowInBatches
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
4
|
};
|
|
15
|
-
|
|
16
|
-
|
|
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;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ArrowTableBatch } from '@loaders.gl/schema';
|
|
2
|
+
import { Schema } from 'apache-arrow';
|
|
3
|
+
import { ColumnarTableBatchAggregator } from '@loaders.gl/schema';
|
|
4
|
+
export default class ArrowTableBatchAggregator extends ColumnarTableBatchAggregator {
|
|
5
|
+
arrowSchema: Schema | null;
|
|
6
|
+
constructor(schema: any, options: any);
|
|
7
|
+
getBatch(): ArrowTableBatch | null;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=arrow-table-batch.d.ts.map
|
|
@@ -0,0 +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,MAAM,CAAC,OAAO,OAAO,yBAA0B,SAAQ,4BAA4B;IACjF,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;gBAEf,MAAM,KAAA,EAAE,OAAO,KAAA;IAK3B,QAAQ,IAAI,eAAe,GAAG,IAAI;CA4BnC"}
|
|
@@ -1,71 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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;
|
|
26
30
|
}
|
|
27
|
-
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
exports.default = ArrowTableBatchAggregator;
|
|
33
|
+
// Convert from a simple loaders.gl schema to an Arrow schema
|
|
33
34
|
function getArrowSchema(schema) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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');
|
|
43
48
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (arrowFields.length === 0) {
|
|
47
|
-
throw new Error('No arrow convertible fields');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return new Schema(arrowFields);
|
|
49
|
+
return new apache_arrow_1.Schema(arrowFields);
|
|
51
50
|
}
|
|
52
|
-
|
|
51
|
+
// Convert from simple loaders.gl arrays to arrow vectors
|
|
53
52
|
function getArrowVectors(arrowSchema, data) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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');
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (arrowSchema.fields.length !== arrowVectors.length) {
|
|
66
|
-
throw new Error('Some columns not arrow convertible');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return arrowVectors;
|
|
64
|
+
return arrowVectors;
|
|
70
65
|
}
|
|
71
|
-
//# sourceMappingURL=arrow-table-batch.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AnyArrayType } from '../types';
|
|
2
|
+
export type ColumnarTable = {
|
|
3
|
+
name: string;
|
|
4
|
+
array: AnyArrayType;
|
|
5
|
+
type: number;
|
|
6
|
+
}[];
|
|
7
|
+
/**
|
|
8
|
+
* Encodes set of arrays into the Apache Arrow columnar format
|
|
9
|
+
* https://arrow.apache.org/docs/format/Columnar.html#ipc-file-format
|
|
10
|
+
* @param data - columns data
|
|
11
|
+
* @param options - the writer options
|
|
12
|
+
* @returns - encoded ArrayBuffer
|
|
13
|
+
*/
|
|
14
|
+
export declare function encodeArrowSync(data: ColumnarTable): ArrayBuffer;
|
|
15
|
+
//# sourceMappingURL=encode-arrow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode-arrow.d.ts","sourceRoot":"","sources":["../../src/lib/encode-arrow.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAe,MAAM,UAAU,CAAC;AAEpD,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,EAAE,CAAC;AAEJ;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,aAAa,GAAG,WAAW,CAShE"}
|
package/dist/lib/encode-arrow.js
CHANGED
|
@@ -1,28 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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;
|
|
16
22
|
}
|
|
17
|
-
|
|
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
|
+
*/
|
|
18
30
|
function createVector(array, type) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
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
|
+
}
|
|
27
38
|
}
|
|
28
|
-
//# sourceMappingURL=encode-arrow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-arrow-in-batches.d.ts","sourceRoot":"","sources":["../../src/lib/parse-arrow-in-batches.ts"],"names":[],"mappings":"AAIA;GACG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,GAChE,aAAa,CAAC,GAAG,CAAC,CA6BpB"}
|