@loaders.gl/schema-utils 4.4.0-alpha.1
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/LICENSE +41 -0
- package/README.md +9 -0
- package/dist/dist.dev.js +14269 -0
- package/dist/dist.min.js +18 -0
- package/dist/index.cjs +2436 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/lib/arrow-utils/arrow-fixed-size-list-utils.d.ts +11 -0
- package/dist/lib/arrow-utils/arrow-fixed-size-list-utils.d.ts.map +1 -0
- package/dist/lib/arrow-utils/arrow-fixed-size-list-utils.js +40 -0
- package/dist/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.d.ts +11 -0
- package/dist/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.d.ts.map +1 -0
- package/dist/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.js +32 -0
- package/dist/lib/mesh/convert-mesh-to-table.d.ts +18 -0
- package/dist/lib/mesh/convert-mesh-to-table.d.ts.map +1 -0
- package/dist/lib/mesh/convert-mesh-to-table.js +60 -0
- package/dist/lib/mesh/convert-table-to-mesh.d.ts +7 -0
- package/dist/lib/mesh/convert-table-to-mesh.d.ts.map +1 -0
- package/dist/lib/mesh/convert-table-to-mesh.js +40 -0
- package/dist/lib/mesh/deduce-mesh-schema.d.ts +23 -0
- package/dist/lib/mesh/deduce-mesh-schema.d.ts.map +1 -0
- package/dist/lib/mesh/deduce-mesh-schema.js +62 -0
- package/dist/lib/mesh/mesh-utils.d.ts +23 -0
- package/dist/lib/mesh/mesh-utils.d.ts.map +1 -0
- package/dist/lib/mesh/mesh-utils.js +46 -0
- package/dist/lib/schema/convert-arrow-schema.d.ts +23 -0
- package/dist/lib/schema/convert-arrow-schema.d.ts.map +1 -0
- package/dist/lib/schema/convert-arrow-schema.js +280 -0
- package/dist/lib/schema/data-type.d.ts +16 -0
- package/dist/lib/schema/data-type.d.ts.map +1 -0
- package/dist/lib/schema/data-type.js +88 -0
- package/dist/lib/schema/deduce-table-schema.d.ts +14 -0
- package/dist/lib/schema/deduce-table-schema.d.ts.map +1 -0
- package/dist/lib/schema/deduce-table-schema.js +100 -0
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts +19 -0
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-field.js +36 -0
- package/dist/lib/table/arrow-api/arrow-like-interface.d.ts +43 -0
- package/dist/lib/table/arrow-api/arrow-like-interface.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-interface.js +4 -0
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts +12 -0
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-schema.js +81 -0
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts +28 -0
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-table.js +63 -0
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts +177 -0
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-type.js +442 -0
- package/dist/lib/table/arrow-api/enum.d.ts +92 -0
- package/dist/lib/table/arrow-api/enum.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/enum.js +97 -0
- package/dist/lib/table/arrow-api/get-type-info.d.ts +13 -0
- package/dist/lib/table/arrow-api/get-type-info.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/get-type-info.js +27 -0
- package/dist/lib/table/arrow-api/index.d.ts +5 -0
- package/dist/lib/table/arrow-api/index.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/index.js +7 -0
- package/dist/lib/table/batch-builder/arrow-table-batch-aggregator.d.ts +10 -0
- package/dist/lib/table/batch-builder/arrow-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/arrow-table-batch-aggregator.js +67 -0
- package/dist/lib/table/batch-builder/arrow-table-builder.d.ts +25 -0
- package/dist/lib/table/batch-builder/arrow-table-builder.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/arrow-table-builder.js +99 -0
- package/dist/lib/table/batch-builder/base-table-batch-aggregator.d.ts +19 -0
- package/dist/lib/table/batch-builder/base-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/base-table-batch-aggregator.js +63 -0
- package/dist/lib/table/batch-builder/columnar-table-batch-aggregator.d.ts +20 -0
- package/dist/lib/table/batch-builder/columnar-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/columnar-table-batch-aggregator.js +83 -0
- package/dist/lib/table/batch-builder/row-table-batch-aggregator.d.ts +21 -0
- package/dist/lib/table/batch-builder/row-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/row-table-batch-aggregator.js +85 -0
- package/dist/lib/table/batch-builder/table-batch-aggregator.d.ts +24 -0
- package/dist/lib/table/batch-builder/table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/table-batch-aggregator.js +4 -0
- package/dist/lib/table/batch-builder/table-batch-builder.d.ts +52 -0
- package/dist/lib/table/batch-builder/table-batch-builder.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/table-batch-builder.js +148 -0
- package/dist/lib/table/batches/convert-batches.d.ts +10 -0
- package/dist/lib/table/batches/convert-batches.d.ts.map +1 -0
- package/dist/lib/table/batches/convert-batches.js +45 -0
- package/dist/lib/table/batches/make-arrow-batch-iterator.d.ts +17 -0
- package/dist/lib/table/batches/make-arrow-batch-iterator.d.ts.map +1 -0
- package/dist/lib/table/batches/make-arrow-batch-iterator.js +57 -0
- package/dist/lib/table/batches/make-table-batch-iterator.d.ts +15 -0
- package/dist/lib/table/batches/make-table-batch-iterator.d.ts.map +1 -0
- package/dist/lib/table/batches/make-table-batch-iterator.js +21 -0
- package/dist/lib/table/batches/make-table-from-batches.d.ts +9 -0
- package/dist/lib/table/batches/make-table-from-batches.d.ts.map +1 -0
- package/dist/lib/table/batches/make-table-from-batches.js +62 -0
- package/dist/lib/table/tables/convert-arrow-table.d.ts +24 -0
- package/dist/lib/table/tables/convert-arrow-table.d.ts.map +1 -0
- package/dist/lib/table/tables/convert-arrow-table.js +150 -0
- package/dist/lib/table/tables/convert-table.d.ts +43 -0
- package/dist/lib/table/tables/convert-table.d.ts.map +1 -0
- package/dist/lib/table/tables/convert-table.js +120 -0
- package/dist/lib/table/tables/make-table.d.ts +67 -0
- package/dist/lib/table/tables/make-table.d.ts.map +1 -0
- package/dist/lib/table/tables/make-table.js +101 -0
- package/dist/lib/table/tables/row-utils.d.ts +15 -0
- package/dist/lib/table/tables/row-utils.d.ts.map +1 -0
- package/dist/lib/table/tables/row-utils.js +49 -0
- package/dist/lib/table/tables/table-accessors.d.ts +68 -0
- package/dist/lib/table/tables/table-accessors.d.ts.map +1 -0
- package/dist/lib/table/tables/table-accessors.js +350 -0
- package/dist/lib/table/tables/table-column.d.ts +7 -0
- package/dist/lib/table/tables/table-column.d.ts.map +1 -0
- package/dist/lib/table/tables/table-column.js +39 -0
- package/dist/lib/table/tables/table-types.d.ts +12 -0
- package/dist/lib/table/tables/table-types.d.ts.map +1 -0
- package/dist/lib/table/tables/table-types.js +23 -0
- package/dist/lib/utils/assert.d.ts +2 -0
- package/dist/lib/utils/assert.d.ts.map +1 -0
- package/dist/lib/utils/assert.js +8 -0
- package/dist/lib/utils/async-queue.d.ts +18 -0
- package/dist/lib/utils/async-queue.d.ts.map +1 -0
- package/dist/lib/utils/async-queue.js +90 -0
- package/dist/types/types.d.ts +15 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +4 -0
- package/package.json +52 -0
- package/src/index.ts +134 -0
- package/src/lib/arrow-utils/arrow-fixed-size-list-utils.ts +63 -0
- package/src/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.ts +48 -0
- package/src/lib/mesh/convert-mesh-to-table.ts +77 -0
- package/src/lib/mesh/convert-table-to-mesh.ts +49 -0
- package/src/lib/mesh/deduce-mesh-schema.ts +75 -0
- package/src/lib/mesh/mesh-utils.ts +64 -0
- package/src/lib/schema/convert-arrow-schema.ts +301 -0
- package/src/lib/schema/data-type.ts +103 -0
- package/src/lib/schema/deduce-table-schema.ts +119 -0
- package/src/lib/table/arrow-api/arrow-like-field.ts +53 -0
- package/src/lib/table/arrow-api/arrow-like-interface.ts +84 -0
- package/src/lib/table/arrow-api/arrow-like-schema.ts +101 -0
- package/src/lib/table/arrow-api/arrow-like-table.ts +85 -0
- package/src/lib/table/arrow-api/arrow-like-type.ts +502 -0
- package/src/lib/table/arrow-api/enum.ts +99 -0
- package/src/lib/table/arrow-api/get-type-info.ts +38 -0
- package/src/lib/table/arrow-api/index.ts +8 -0
- package/src/lib/table/batch-builder/arrow-table-batch-aggregator-builders.ts.disabled +190 -0
- package/src/lib/table/batch-builder/arrow-table-batch-aggregator.ts +82 -0
- package/src/lib/table/batch-builder/arrow-table-builder.ts +112 -0
- package/src/lib/table/batch-builder/base-table-batch-aggregator.ts +82 -0
- package/src/lib/table/batch-builder/columnar-table-batch-aggregator.ts +99 -0
- package/src/lib/table/batch-builder/row-table-batch-aggregator.ts +108 -0
- package/src/lib/table/batch-builder/table-batch-aggregator.ts +28 -0
- package/src/lib/table/batch-builder/table-batch-builder.ts +185 -0
- package/src/lib/table/batches/convert-batches.ts +83 -0
- package/src/lib/table/batches/make-arrow-batch-iterator.ts +75 -0
- package/src/lib/table/batches/make-table-batch-iterator.ts +25 -0
- package/src/lib/table/batches/make-table-from-batches.ts +84 -0
- package/src/lib/table/tables/convert-arrow-table.ts +198 -0
- package/src/lib/table/tables/convert-table.ts +151 -0
- package/src/lib/table/tables/make-table.ts +127 -0
- package/src/lib/table/tables/row-utils.ts +59 -0
- package/src/lib/table/tables/table-accessors.ts +417 -0
- package/src/lib/table/tables/table-column.ts +49 -0
- package/src/lib/table/tables/table-types.ts +37 -0
- package/src/lib/utils/assert.ts +8 -0
- package/src/lib/utils/async-queue.ts +104 -0
- package/src/types/types.ts +45 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { convertToArrayRow, convertToObjectRow, inferHeadersFromArrayRow, inferHeadersFromObjectRow } from "../tables/row-utils.js";
|
|
5
|
+
const DEFAULT_ROW_COUNT = 100;
|
|
6
|
+
export class RowTableBatchAggregator {
|
|
7
|
+
schema;
|
|
8
|
+
options;
|
|
9
|
+
length = 0;
|
|
10
|
+
objectRows = null;
|
|
11
|
+
arrayRows = null;
|
|
12
|
+
cursor = 0;
|
|
13
|
+
_headers = null;
|
|
14
|
+
constructor(schema, options) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.schema = schema;
|
|
17
|
+
// schema is an array if there're no headers
|
|
18
|
+
// object if there are headers
|
|
19
|
+
if (schema) {
|
|
20
|
+
this._headers = [];
|
|
21
|
+
for (let i = 0; i < schema.fields.length; i++) {
|
|
22
|
+
this._headers[i] = schema.fields[i].name;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
rowCount() {
|
|
27
|
+
return this.length;
|
|
28
|
+
}
|
|
29
|
+
addArrayRow(row, cursor) {
|
|
30
|
+
if (Number.isFinite(cursor)) {
|
|
31
|
+
this.cursor = cursor;
|
|
32
|
+
}
|
|
33
|
+
// TODO - infer schema at a higher level, instead of hacking headers here?
|
|
34
|
+
this._headers ||= inferHeadersFromArrayRow(row);
|
|
35
|
+
// eslint-disable-next-line default-case
|
|
36
|
+
switch (this.options.shape) {
|
|
37
|
+
case 'object-row-table':
|
|
38
|
+
const rowObject = convertToObjectRow(row, this._headers);
|
|
39
|
+
this.addObjectRow(rowObject, cursor);
|
|
40
|
+
break;
|
|
41
|
+
case 'array-row-table':
|
|
42
|
+
this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT);
|
|
43
|
+
this.arrayRows[this.length] = row;
|
|
44
|
+
this.length++;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
addObjectRow(row, cursor) {
|
|
49
|
+
if (Number.isFinite(cursor)) {
|
|
50
|
+
this.cursor = cursor;
|
|
51
|
+
}
|
|
52
|
+
// TODO - infer schema at a higher level, instead of hacking headers here?
|
|
53
|
+
this._headers ||= inferHeadersFromObjectRow(row);
|
|
54
|
+
// eslint-disable-next-line default-case
|
|
55
|
+
switch (this.options.shape) {
|
|
56
|
+
case 'array-row-table':
|
|
57
|
+
const rowArray = convertToArrayRow(row, this._headers);
|
|
58
|
+
this.addArrayRow(rowArray, cursor);
|
|
59
|
+
break;
|
|
60
|
+
case 'object-row-table':
|
|
61
|
+
this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT);
|
|
62
|
+
this.objectRows[this.length] = row;
|
|
63
|
+
this.length++;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
getBatch() {
|
|
68
|
+
let rows = this.arrayRows || this.objectRows;
|
|
69
|
+
if (!rows) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
rows = rows.slice(0, this.length);
|
|
73
|
+
this.arrayRows = null;
|
|
74
|
+
this.objectRows = null;
|
|
75
|
+
return {
|
|
76
|
+
shape: this.options.shape,
|
|
77
|
+
batchType: 'data',
|
|
78
|
+
data: rows,
|
|
79
|
+
length: this.length,
|
|
80
|
+
// @ts-expect-error we should infer a schema
|
|
81
|
+
schema: this.schema,
|
|
82
|
+
cursor: this.cursor
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Schema, TableBatch } from '@loaders.gl/schema';
|
|
2
|
+
export interface TableBatchOptions {
|
|
3
|
+
batchSize: number | string;
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}
|
|
6
|
+
export interface TableBatchConstructor {
|
|
7
|
+
new (schema: Schema, options: TableBatchOptions): TableBatchAggregator;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* TableBatchBuilder delegates batch building to this interface
|
|
11
|
+
*/
|
|
12
|
+
export interface TableBatchAggregator {
|
|
13
|
+
/** Number of rows */
|
|
14
|
+
rowCount(): number;
|
|
15
|
+
/** Add one row */
|
|
16
|
+
addArrayRow(row: any[]): void;
|
|
17
|
+
/** Add one row */
|
|
18
|
+
addObjectRow(row: {
|
|
19
|
+
[columnName: string]: any;
|
|
20
|
+
}): void;
|
|
21
|
+
/** return a batch object */
|
|
22
|
+
getBatch(): TableBatch | null;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=table-batch-aggregator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-batch-aggregator.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batch-builder/table-batch-aggregator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAE3D,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,oBAAoB,CAAC;CACxE;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,qBAAqB;IACrB,QAAQ,IAAI,MAAM,CAAC;IACnB,kBAAkB;IAClB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC9B,kBAAkB;IAClB,YAAY,CAAC,GAAG,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,GAAG,IAAI,CAAC;IACrD,4BAA4B;IAC5B,QAAQ,IAAI,UAAU,GAAG,IAAI,CAAC;CAC/B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Schema, TableBatch } from '@loaders.gl/schema';
|
|
2
|
+
import type { TableBatchConstructor } from "./table-batch-aggregator.js";
|
|
3
|
+
type TableBatchBuilderOptions = {
|
|
4
|
+
shape?: 'array-row-table' | 'object-row-table' | 'columnar-table' | 'arrow-table';
|
|
5
|
+
batchSize?: number | 'auto';
|
|
6
|
+
batchDebounceMs?: number;
|
|
7
|
+
limit?: number;
|
|
8
|
+
_limitMB?: number;
|
|
9
|
+
};
|
|
10
|
+
type GetBatchOptions = {
|
|
11
|
+
bytesUsed?: number;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
};
|
|
14
|
+
/** Incrementally builds batches from a stream of rows */
|
|
15
|
+
export declare class TableBatchBuilder {
|
|
16
|
+
schema: Schema;
|
|
17
|
+
options: Required<TableBatchBuilderOptions>;
|
|
18
|
+
private aggregator;
|
|
19
|
+
private batchCount;
|
|
20
|
+
private bytesUsed;
|
|
21
|
+
private isChunkComplete;
|
|
22
|
+
private lastBatchEmittedMs;
|
|
23
|
+
private totalLength;
|
|
24
|
+
private totalBytes;
|
|
25
|
+
private rowBytes;
|
|
26
|
+
static ArrowBatch?: TableBatchConstructor;
|
|
27
|
+
constructor(schema: Schema, options?: TableBatchBuilderOptions);
|
|
28
|
+
limitReached(): boolean;
|
|
29
|
+
/** @deprecated Use addArrayRow or addObjectRow */
|
|
30
|
+
addRow(row: any[] | {
|
|
31
|
+
[columnName: string]: any;
|
|
32
|
+
}): void;
|
|
33
|
+
/** Add one row to the batch */
|
|
34
|
+
protected addArrayRow(row: any[]): void;
|
|
35
|
+
/** Add one row to the batch */
|
|
36
|
+
protected addObjectRow(row: {
|
|
37
|
+
[columnName: string]: any;
|
|
38
|
+
}): void;
|
|
39
|
+
/** Mark an incoming raw memory chunk has completed */
|
|
40
|
+
chunkComplete(chunk: ArrayBuffer | string): void;
|
|
41
|
+
getFullBatch(options?: GetBatchOptions): TableBatch | null;
|
|
42
|
+
getFinalBatch(options?: GetBatchOptions): TableBatch | null;
|
|
43
|
+
_estimateRowMB(row: any[] | object): number;
|
|
44
|
+
private _isFull;
|
|
45
|
+
/**
|
|
46
|
+
* bytesUsed can be set via chunkComplete or via getBatch*
|
|
47
|
+
*/
|
|
48
|
+
private _getBatch;
|
|
49
|
+
private _getTableBatchType;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=table-batch-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-batch-builder.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batch-builder/table-batch-builder.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAuB,qBAAqB,EAAC,oCAAiC;AAO1F,KAAK,wBAAwB,GAAG;IAC9B,KAAK,CAAC,EAAE,iBAAiB,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,aAAa,CAAC;IAClF,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AAUF,yDAAyD;AACzD,qBAAa,iBAAiB;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,QAAQ,CAAC,wBAAwB,CAAC,CAAC;IAE5C,OAAO,CAAC,UAAU,CAAqC;IACvD,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,kBAAkB,CAAsB;IAChD,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,QAAQ,CAAa;IAE7B,MAAM,CAAC,UAAU,CAAC,EAAE,qBAAqB,CAAC;gBAE9B,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,wBAAwB;IAK9D,YAAY,IAAI,OAAO;IAUvB,kDAAkD;IAClD,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,GAAG,IAAI;IActD,+BAA+B;IAC/B,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE;IAQhC,+BAA+B;IAC/B,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,GAAG,IAAI;IAQ9D,sDAAsD;IACtD,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI;IAUhD,YAAY,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,UAAU,GAAG,IAAI;IAI1D,aAAa,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,UAAU,GAAG,IAAI;IAM3D,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,GAAG,MAAM;IAI3C,OAAO,CAAC,OAAO;IA2Bf;;OAEG;IACH,OAAO,CAAC,SAAS;IAmBjB,OAAO,CAAC,kBAAkB;CAa3B"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { BaseTableBatchAggregator } from "./base-table-batch-aggregator.js";
|
|
5
|
+
import { RowTableBatchAggregator } from "./row-table-batch-aggregator.js";
|
|
6
|
+
import { ColumnarTableBatchAggregator } from "./columnar-table-batch-aggregator.js";
|
|
7
|
+
import { ArrowTableBatchAggregator } from "./arrow-table-batch-aggregator.js";
|
|
8
|
+
const DEFAULT_OPTIONS = {
|
|
9
|
+
shape: undefined,
|
|
10
|
+
batchSize: 'auto',
|
|
11
|
+
batchDebounceMs: 0,
|
|
12
|
+
limit: 0,
|
|
13
|
+
_limitMB: 0
|
|
14
|
+
};
|
|
15
|
+
/** Incrementally builds batches from a stream of rows */
|
|
16
|
+
export class TableBatchBuilder {
|
|
17
|
+
schema;
|
|
18
|
+
options;
|
|
19
|
+
aggregator = null;
|
|
20
|
+
batchCount = 0;
|
|
21
|
+
bytesUsed = 0;
|
|
22
|
+
isChunkComplete = false;
|
|
23
|
+
lastBatchEmittedMs = Date.now();
|
|
24
|
+
totalLength = 0;
|
|
25
|
+
totalBytes = 0;
|
|
26
|
+
rowBytes = 0;
|
|
27
|
+
static ArrowBatch;
|
|
28
|
+
constructor(schema, options) {
|
|
29
|
+
this.schema = schema;
|
|
30
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
31
|
+
}
|
|
32
|
+
limitReached() {
|
|
33
|
+
if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (Boolean(this.options?._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
/** @deprecated Use addArrayRow or addObjectRow */
|
|
42
|
+
addRow(row) {
|
|
43
|
+
if (this.limitReached()) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this.totalLength++;
|
|
47
|
+
this.rowBytes = this.rowBytes || this._estimateRowMB(row);
|
|
48
|
+
this.totalBytes += this.rowBytes;
|
|
49
|
+
if (Array.isArray(row)) {
|
|
50
|
+
this.addArrayRow(row);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this.addObjectRow(row);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Add one row to the batch */
|
|
57
|
+
addArrayRow(row) {
|
|
58
|
+
if (!this.aggregator) {
|
|
59
|
+
const TableBatchType = this._getTableBatchType();
|
|
60
|
+
this.aggregator = new TableBatchType(this.schema, this.options);
|
|
61
|
+
}
|
|
62
|
+
this.aggregator.addArrayRow(row);
|
|
63
|
+
}
|
|
64
|
+
/** Add one row to the batch */
|
|
65
|
+
addObjectRow(row) {
|
|
66
|
+
if (!this.aggregator) {
|
|
67
|
+
const TableBatchType = this._getTableBatchType();
|
|
68
|
+
this.aggregator = new TableBatchType(this.schema, this.options);
|
|
69
|
+
}
|
|
70
|
+
this.aggregator.addObjectRow(row);
|
|
71
|
+
}
|
|
72
|
+
/** Mark an incoming raw memory chunk has completed */
|
|
73
|
+
chunkComplete(chunk) {
|
|
74
|
+
if (chunk instanceof ArrayBuffer) {
|
|
75
|
+
this.bytesUsed += chunk.byteLength;
|
|
76
|
+
}
|
|
77
|
+
if (typeof chunk === 'string') {
|
|
78
|
+
this.bytesUsed += chunk.length;
|
|
79
|
+
}
|
|
80
|
+
this.isChunkComplete = true;
|
|
81
|
+
}
|
|
82
|
+
getFullBatch(options) {
|
|
83
|
+
return this._isFull() ? this._getBatch(options) : null;
|
|
84
|
+
}
|
|
85
|
+
getFinalBatch(options) {
|
|
86
|
+
return this._getBatch(options);
|
|
87
|
+
}
|
|
88
|
+
// INTERNAL
|
|
89
|
+
_estimateRowMB(row) {
|
|
90
|
+
return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
|
|
91
|
+
}
|
|
92
|
+
_isFull() {
|
|
93
|
+
// No batch, not ready
|
|
94
|
+
if (!this.aggregator || this.aggregator.rowCount() === 0) {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
// if batchSize === 'auto' we wait for chunk to complete
|
|
98
|
+
// if batchSize === number, ensure we have enough rows
|
|
99
|
+
if (this.options.batchSize === 'auto') {
|
|
100
|
+
if (!this.isChunkComplete) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (this.options.batchSize > this.aggregator.rowCount()) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
// Debounce batches
|
|
108
|
+
if (this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
// Emit batch
|
|
112
|
+
this.isChunkComplete = false;
|
|
113
|
+
this.lastBatchEmittedMs = Date.now();
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* bytesUsed can be set via chunkComplete or via getBatch*
|
|
118
|
+
*/
|
|
119
|
+
_getBatch(options) {
|
|
120
|
+
if (!this.aggregator) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
// TODO - this can overly increment bytes used?
|
|
124
|
+
if (options?.bytesUsed) {
|
|
125
|
+
this.bytesUsed = options.bytesUsed;
|
|
126
|
+
}
|
|
127
|
+
const normalizedBatch = this.aggregator.getBatch();
|
|
128
|
+
normalizedBatch.count = this.batchCount;
|
|
129
|
+
normalizedBatch.bytesUsed = this.bytesUsed;
|
|
130
|
+
Object.assign(normalizedBatch, options);
|
|
131
|
+
this.batchCount++;
|
|
132
|
+
this.aggregator = null;
|
|
133
|
+
return normalizedBatch;
|
|
134
|
+
}
|
|
135
|
+
_getTableBatchType() {
|
|
136
|
+
switch (this.options.shape) {
|
|
137
|
+
case 'array-row-table':
|
|
138
|
+
case 'object-row-table':
|
|
139
|
+
return RowTableBatchAggregator;
|
|
140
|
+
case 'columnar-table':
|
|
141
|
+
return ColumnarTableBatchAggregator;
|
|
142
|
+
case 'arrow-table':
|
|
143
|
+
return ArrowTableBatchAggregator;
|
|
144
|
+
default:
|
|
145
|
+
return BaseTableBatchAggregator;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TableBatch, ArrayRowTableBatch, ObjectRowTableBatch, ColumnarTableBatch, ArrowTableBatch } from '@loaders.gl/schema';
|
|
2
|
+
export declare function convertBatch(batches: TableBatch, shape: 'object-row-table'): ObjectRowTableBatch;
|
|
3
|
+
export declare function convertBatch(batches: TableBatch, shape: 'array-row-table'): ArrayRowTableBatch;
|
|
4
|
+
export declare function convertBatch(batches: TableBatch, shape: 'columnar-table'): ColumnarTableBatch;
|
|
5
|
+
export declare function convertBatch(batches: TableBatch, shape: 'arrow-table'): ArrowTableBatch;
|
|
6
|
+
export declare function convertBatches(batches: Iterable<TableBatch> | AsyncIterable<TableBatch>, shape: 'object-row-table'): AsyncIterableIterator<ObjectRowTableBatch>;
|
|
7
|
+
export declare function convertBatches(batches: Iterable<TableBatch> | AsyncIterable<TableBatch>, shape: 'array-row-table'): AsyncIterableIterator<ArrayRowTableBatch>;
|
|
8
|
+
export declare function convertBatches(batches: Iterable<TableBatch> | AsyncIterable<TableBatch>, shape: 'columnar-table'): AsyncIterableIterator<ColumnarTableBatch>;
|
|
9
|
+
export declare function convertBatches(batches: Iterable<TableBatch> | AsyncIterable<TableBatch>, shape: 'arrow-table'): AsyncIterableIterator<ArrowTableBatch>;
|
|
10
|
+
//# sourceMappingURL=convert-batches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-batches.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batches/convert-batches.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAG5B,wBAAgB,YAAY,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,kBAAkB,GAAG,mBAAmB,CAAC;AAClG,wBAAgB,YAAY,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,iBAAiB,GAAG,kBAAkB,CAAC;AAChG,wBAAgB,YAAY,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,gBAAgB,GAAG,kBAAkB,CAAC;AAC/F,wBAAgB,YAAY,CAAC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,aAAa,GAAG,eAAe,CAAC;AAqBzF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,EACzD,KAAK,EAAE,kBAAkB,GACxB,qBAAqB,CAAC,mBAAmB,CAAC,CAAC;AAC9C,wBAAgB,cAAc,CAC5B,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,EACzD,KAAK,EAAE,iBAAiB,GACvB,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;AAC7C,wBAAgB,cAAc,CAC5B,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,EACzD,KAAK,EAAE,gBAAgB,GACtB,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;AAC7C,wBAAgB,cAAc,CAC5B,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,EACzD,KAAK,EAAE,aAAa,GACnB,qBAAqB,CAAC,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { convertTable } from "../tables/convert-table.js";
|
|
5
|
+
/** Convert a table batch to a different shape */
|
|
6
|
+
export function convertBatch(batch, shape) {
|
|
7
|
+
switch (shape) {
|
|
8
|
+
case 'object-row-table':
|
|
9
|
+
return { ...batch, ...convertTable(batch, 'object-row-table') };
|
|
10
|
+
case 'array-row-table':
|
|
11
|
+
return { ...batch, ...convertTable(batch, 'array-row-table') };
|
|
12
|
+
case 'columnar-table':
|
|
13
|
+
return { ...batch, ...convertTable(batch, 'columnar-table') };
|
|
14
|
+
case 'arrow-table':
|
|
15
|
+
return { ...batch, ...convertTable(batch, 'arrow-table') };
|
|
16
|
+
default:
|
|
17
|
+
throw new Error(shape);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Convert batches to a different shape
|
|
22
|
+
* @param table
|
|
23
|
+
* @param shape
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export async function* convertBatches(batches, shape) {
|
|
27
|
+
for await (const batch of batches) {
|
|
28
|
+
switch (shape) {
|
|
29
|
+
case 'object-row-table':
|
|
30
|
+
yield convertBatch(batch, 'object-row-table');
|
|
31
|
+
break;
|
|
32
|
+
case 'array-row-table':
|
|
33
|
+
yield convertBatch(batch, 'array-row-table');
|
|
34
|
+
break;
|
|
35
|
+
case 'columnar-table':
|
|
36
|
+
yield convertBatch(batch, 'columnar-table');
|
|
37
|
+
break;
|
|
38
|
+
case 'arrow-table':
|
|
39
|
+
yield convertBatch(batch, 'arrow-table');
|
|
40
|
+
break;
|
|
41
|
+
default:
|
|
42
|
+
throw new Error(shape);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as arrow from 'apache-arrow';
|
|
2
|
+
import type { Table, ArrowTableBatch } from '@loaders.gl/schema';
|
|
3
|
+
/**
|
|
4
|
+
* Returns an iterator that yields a single table as a sequence of ArrowTable batches.
|
|
5
|
+
* @note All batches will have the same shape and schema as the original table.
|
|
6
|
+
*/
|
|
7
|
+
export declare function makeArrowTableBatchIterator(table: Table, options?: {
|
|
8
|
+
batchSize?: number;
|
|
9
|
+
}): IterableIterator<ArrowTableBatch>;
|
|
10
|
+
/**
|
|
11
|
+
* Returns an iterator that yields a single table as a sequence of arrow.RecordBatch batches.
|
|
12
|
+
* @note All batches will have the same shape and schema as the original table.
|
|
13
|
+
*/
|
|
14
|
+
export declare function makeArrowRecordBatchIterator(table: Table, options?: {
|
|
15
|
+
batchSize?: number;
|
|
16
|
+
}): IterableIterator<arrow.RecordBatch>;
|
|
17
|
+
//# sourceMappingURL=make-arrow-batch-iterator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-arrow-batch-iterator.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batches/make-arrow-batch-iterator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAC,KAAK,EAAE,eAAe,EAAC,MAAM,oBAAoB,CAAC;AAK/D;;;GAGG;AACH,wBAAiB,2BAA2B,CAC1C,KAAK,EAAE,KAAK,EACZ,OAAO,CAAC,EAAE;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAC,GAC7B,gBAAgB,CAAC,eAAe,CAAC,CAYnC;AAED;;;GAGG;AACH,wBAAiB,4BAA4B,CAC3C,KAAK,EAAE,KAAK,EACZ,OAAO,CAAC,EAAE;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAC,GAC7B,gBAAgB,CAAC,KAAK,CAAC,WAAW,CAAC,CAoCrC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import * as arrow from 'apache-arrow';
|
|
5
|
+
import { convertSchemaToArrow } from "../../schema/convert-arrow-schema.js";
|
|
6
|
+
import { getTableLength, getTableNumCols, getTableCellAt } from "../tables/table-accessors.js";
|
|
7
|
+
/**
|
|
8
|
+
* Returns an iterator that yields a single table as a sequence of ArrowTable batches.
|
|
9
|
+
* @note All batches will have the same shape and schema as the original table.
|
|
10
|
+
*/
|
|
11
|
+
export function* makeArrowTableBatchIterator(table, options) {
|
|
12
|
+
for (const batch of makeArrowRecordBatchIterator(table, options)) {
|
|
13
|
+
const arrowTable = new arrow.Table([batch]);
|
|
14
|
+
yield {
|
|
15
|
+
...batch,
|
|
16
|
+
shape: 'arrow-table',
|
|
17
|
+
schema: table.schema,
|
|
18
|
+
batchType: 'data',
|
|
19
|
+
length: arrowTable.numRows,
|
|
20
|
+
data: arrowTable
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns an iterator that yields a single table as a sequence of arrow.RecordBatch batches.
|
|
26
|
+
* @note All batches will have the same shape and schema as the original table.
|
|
27
|
+
*/
|
|
28
|
+
export function* makeArrowRecordBatchIterator(table, options) {
|
|
29
|
+
const arrowSchema = convertSchemaToArrow(table.schema);
|
|
30
|
+
const length = getTableLength(table);
|
|
31
|
+
const numColumns = getTableNumCols(table);
|
|
32
|
+
const batchSize = options?.batchSize || length;
|
|
33
|
+
const builders = arrowSchema?.fields.map((arrowField) => arrow.makeBuilder(arrowField));
|
|
34
|
+
const structField = new arrow.Struct(arrowSchema.fields);
|
|
35
|
+
let batchLength = 0;
|
|
36
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
37
|
+
for (let columnIndex = 0; columnIndex < numColumns; ++columnIndex) {
|
|
38
|
+
const value = getTableCellAt(table, rowIndex, columnIndex);
|
|
39
|
+
const builder = builders[columnIndex];
|
|
40
|
+
builder.append(value);
|
|
41
|
+
batchLength++;
|
|
42
|
+
if (batchLength >= batchSize) {
|
|
43
|
+
const datas = builders.map((builder) => builder.flush());
|
|
44
|
+
const structData = new arrow.Data(structField, 0, batchLength, 0, undefined, datas);
|
|
45
|
+
yield new arrow.RecordBatch(arrowSchema, structData);
|
|
46
|
+
batchLength = 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (batchLength > 0) {
|
|
51
|
+
const datas = builders.map((builder) => builder.flush());
|
|
52
|
+
const structData = new arrow.Data(structField, 0, batchLength, 0, undefined, datas);
|
|
53
|
+
yield new arrow.RecordBatch(arrowSchema, structData);
|
|
54
|
+
batchLength = 0;
|
|
55
|
+
}
|
|
56
|
+
builders.map((builder) => builder.finish());
|
|
57
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TableBatch, Table } from '@loaders.gl/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an iterator that yields the contents of a table as a sequence of batches.
|
|
4
|
+
* @todo Currently only a single batch is yielded.
|
|
5
|
+
* @note All batches will have the same shape and schema as the original table.
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function makeTableBatchIterator(table: Table): IterableIterator<TableBatch>;
|
|
9
|
+
/**
|
|
10
|
+
* Returns a table packaged as a single table batch
|
|
11
|
+
* @note The batch will have the same shape and schema as the original table.
|
|
12
|
+
* @returns `null` if no batches are yielded by the async iterator
|
|
13
|
+
*/
|
|
14
|
+
export declare function makeBatchFromTable(table: Table): TableBatch;
|
|
15
|
+
//# sourceMappingURL=make-table-batch-iterator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-table-batch-iterator.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batches/make-table-batch-iterator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAAE,KAAK,EAAC,MAAM,oBAAoB,CAAC;AAG1D;;;;;GAKG;AACH,wBAAiB,sBAAsB,CAAC,KAAK,EAAE,KAAK,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAElF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,CAE3D"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { getTableLength } from "../tables/table-accessors.js";
|
|
5
|
+
/**
|
|
6
|
+
* Returns an iterator that yields the contents of a table as a sequence of batches.
|
|
7
|
+
* @todo Currently only a single batch is yielded.
|
|
8
|
+
* @note All batches will have the same shape and schema as the original table.
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export function* makeTableBatchIterator(table) {
|
|
12
|
+
yield makeBatchFromTable(table);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Returns a table packaged as a single table batch
|
|
16
|
+
* @note The batch will have the same shape and schema as the original table.
|
|
17
|
+
* @returns `null` if no batches are yielded by the async iterator
|
|
18
|
+
*/
|
|
19
|
+
export function makeBatchFromTable(table) {
|
|
20
|
+
return { ...table, length: getTableLength(table), batchType: 'data' };
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TableBatch, Table } from '@loaders.gl/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Assembles all batches from an async iterator into a single table.
|
|
4
|
+
* @note All batches must have the same shape and schema
|
|
5
|
+
* @param batchIterator
|
|
6
|
+
* @returns `null` if no batches are yielded by the async iterator
|
|
7
|
+
*/
|
|
8
|
+
export declare function makeTableFromBatches(batchIterator: AsyncIterable<TableBatch> | Iterable<TableBatch>): Promise<Table | null>;
|
|
9
|
+
//# sourceMappingURL=make-table-from-batches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-table-from-batches.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batches/make-table-from-batches.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,UAAU,EACV,KAAK,EAIN,MAAM,oBAAoB,CAAC;AAG5B;;;;;GAKG;AAEH,wBAAsB,oBAAoB,CACxC,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,GAC9D,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CA4DvB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { getTableLength } from "../tables/table-accessors.js";
|
|
5
|
+
/**
|
|
6
|
+
* Assembles all batches from an async iterator into a single table.
|
|
7
|
+
* @note All batches must have the same shape and schema
|
|
8
|
+
* @param batchIterator
|
|
9
|
+
* @returns `null` if no batches are yielded by the async iterator
|
|
10
|
+
*/
|
|
11
|
+
// eslint-disable-next-line complexity
|
|
12
|
+
export async function makeTableFromBatches(batchIterator) {
|
|
13
|
+
let arrayRows;
|
|
14
|
+
let objectRows;
|
|
15
|
+
let features;
|
|
16
|
+
let shape = null;
|
|
17
|
+
let schema;
|
|
18
|
+
for await (const batch of batchIterator) {
|
|
19
|
+
shape = shape || batch.shape;
|
|
20
|
+
schema = schema || batch.schema;
|
|
21
|
+
switch (batch.shape) {
|
|
22
|
+
case 'array-row-table':
|
|
23
|
+
arrayRows = arrayRows || [];
|
|
24
|
+
for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
|
|
25
|
+
const row = batch.data[rowIndex];
|
|
26
|
+
arrayRows.push(row);
|
|
27
|
+
}
|
|
28
|
+
break;
|
|
29
|
+
case 'object-row-table':
|
|
30
|
+
objectRows = objectRows || [];
|
|
31
|
+
for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
|
|
32
|
+
const row = batch.data[rowIndex];
|
|
33
|
+
objectRows.push(row);
|
|
34
|
+
}
|
|
35
|
+
break;
|
|
36
|
+
case 'geojson-table':
|
|
37
|
+
features = features || [];
|
|
38
|
+
for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
|
|
39
|
+
const row = batch.features[rowIndex];
|
|
40
|
+
features.push(row);
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
case 'columnar-table':
|
|
44
|
+
case 'arrow-table':
|
|
45
|
+
default:
|
|
46
|
+
throw new Error('shape');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!shape) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
switch (shape) {
|
|
53
|
+
case 'array-row-table':
|
|
54
|
+
return { shape: 'array-row-table', data: arrayRows, schema };
|
|
55
|
+
case 'object-row-table':
|
|
56
|
+
return { shape: 'object-row-table', data: objectRows, schema };
|
|
57
|
+
case 'geojson-table':
|
|
58
|
+
return { shape: 'geojson-table', type: 'FeatureCollection', features: features, schema };
|
|
59
|
+
default:
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as arrow from 'apache-arrow';
|
|
2
|
+
import type { Table, ArrayRowTable, ColumnarTable, ObjectRowTable, GeoJSONTable, ArrowTable } from '@loaders.gl/schema';
|
|
3
|
+
/**
|
|
4
|
+
* * Convert a loaders.gl Table to an Apache Arrow Table
|
|
5
|
+
* @param mesh
|
|
6
|
+
* @param metadata
|
|
7
|
+
* @param batchSize
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function convertTableToArrow(table: Table, options?: {
|
|
11
|
+
batchSize?: number;
|
|
12
|
+
}): arrow.Table;
|
|
13
|
+
/**
|
|
14
|
+
* Convert an Apache Arrow table to a loaders.gl Table
|
|
15
|
+
* @note Currently does not convert schema
|
|
16
|
+
*/
|
|
17
|
+
export declare function convertArrowToTable(arrow: arrow.Table, shape: 'arrow-table'): ArrowTable;
|
|
18
|
+
export declare function convertArrowToTable(arrow: arrow.Table, shape: 'columnar-table'): ColumnarTable;
|
|
19
|
+
export declare function convertArrowToTable(arrow: arrow.Table, shape: 'object-row-table'): ObjectRowTable;
|
|
20
|
+
export declare function convertArrowToTable(arrow: arrow.Table, shape: 'array-row-table'): ArrayRowTable;
|
|
21
|
+
export declare function convertArrowToTable(arrow: arrow.Table, shape: 'geojson-table'): GeoJSONTable;
|
|
22
|
+
export declare function convertArrowToTable(arrow: arrow.Table, shape: 'columnar-table'): ColumnarTable;
|
|
23
|
+
export declare function convertArrowToTable(arrow: arrow.Table, shape: Table['shape']): Table;
|
|
24
|
+
//# sourceMappingURL=convert-arrow-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-arrow-table.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/tables/convert-arrow-table.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EACV,KAAK,EACL,aAAa,EACb,aAAa,EACb,cAAc,EACd,YAAY,EACZ,UAAU,EAEX,MAAM,oBAAoB,CAAC;AAM5B;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAC,GAAG,KAAK,CAAC,KAAK,CAe7F;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,aAAa,GAAG,UAAU,CAAC;AAC1F,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB,GAAG,aAAa,CAAC;AAChG,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,kBAAkB,GAAG,cAAc,CAAC;AACnG,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,iBAAiB,GAAG,aAAa,CAAC;AACjG,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,eAAe,GAAG,YAAY,CAAC;AAC9F,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB,GAAG,aAAa,CAAC;AAChG,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC"}
|