@loaders.gl/schema 4.3.2 → 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/dist/categories/category-gis.d.ts +6 -0
- package/dist/categories/category-gis.d.ts.map +1 -0
- package/dist/categories/category-image.d.ts.map +1 -0
- package/dist/{types → categories}/category-mesh.d.ts +2 -2
- package/dist/categories/category-mesh.d.ts.map +1 -0
- package/dist/{types → categories}/category-table.d.ts +14 -14
- package/dist/categories/category-table.d.ts.map +1 -0
- package/dist/categories/category-texture.d.ts.map +1 -0
- package/dist/{lib/mesh → deprecated}/mesh-utils.d.ts +4 -2
- package/dist/deprecated/mesh-utils.d.ts.map +1 -0
- package/dist/{lib/mesh → deprecated}/mesh-utils.js +2 -0
- package/dist/dist.dev.js +0 -1836
- package/dist/dist.min.js +1 -1
- package/dist/geometry/binary-features.d.ts +30 -0
- package/dist/geometry/binary-features.d.ts.map +1 -0
- package/dist/geometry/binary-geometries.d.ts +33 -0
- package/dist/geometry/binary-geometries.d.ts.map +1 -0
- package/dist/geometry/flat-geometries.d.ts +61 -0
- package/dist/geometry/flat-geometries.d.ts.map +1 -0
- package/dist/index.cjs +2 -1792
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +10 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -23
- package/dist/types/batch.d.ts +3 -1
- package/dist/types/batch.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/{types → categories}/category-gis.ts +7 -18
- package/src/{types → categories}/category-mesh.ts +2 -2
- package/src/{types → categories}/category-table.ts +14 -17
- package/src/{lib/mesh → deprecated}/mesh-utils.ts +4 -2
- package/src/geometry/binary-features.ts +43 -0
- package/src/geometry/binary-geometries.ts +45 -0
- package/src/{types → geometry}/flat-geometries.ts +44 -14
- package/src/index.ts +15 -101
- package/src/types/batch.ts +3 -1
- package/dist/lib/mesh/convert-mesh.d.ts +0 -15
- package/dist/lib/mesh/convert-mesh.d.ts.map +0 -1
- package/dist/lib/mesh/convert-mesh.js +0 -37
- package/dist/lib/mesh/deduce-mesh-schema.d.ts +0 -24
- package/dist/lib/mesh/deduce-mesh-schema.d.ts.map +0 -1
- package/dist/lib/mesh/deduce-mesh-schema.js +0 -62
- package/dist/lib/mesh/mesh-to-arrow-table.d.ts +0 -1
- package/dist/lib/mesh/mesh-to-arrow-table.d.ts.map +0 -1
- package/dist/lib/mesh/mesh-to-arrow-table.js +0 -47
- package/dist/lib/mesh/mesh-utils.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts +0 -19
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-field.js +0 -36
- package/dist/lib/table/arrow-api/arrow-like-interface.d.ts +0 -43
- package/dist/lib/table/arrow-api/arrow-like-interface.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts +0 -12
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-schema.js +0 -81
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts +0 -24
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-table.js +0 -63
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts +0 -177
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-type.js +0 -442
- package/dist/lib/table/arrow-api/enum.d.ts +0 -92
- package/dist/lib/table/arrow-api/enum.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/enum.js +0 -97
- package/dist/lib/table/arrow-api/get-type-info.d.ts +0 -13
- package/dist/lib/table/arrow-api/get-type-info.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/get-type-info.js +0 -27
- package/dist/lib/table/arrow-api/index.d.ts +0 -5
- package/dist/lib/table/arrow-api/index.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/index.js +0 -7
- package/dist/lib/table/batches/base-table-batch-aggregator.d.ts +0 -20
- package/dist/lib/table/batches/base-table-batch-aggregator.d.ts.map +0 -1
- package/dist/lib/table/batches/base-table-batch-aggregator.js +0 -63
- package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts +0 -23
- package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts.map +0 -1
- package/dist/lib/table/batches/columnar-table-batch-aggregator.js +0 -91
- package/dist/lib/table/batches/row-table-batch-aggregator.d.ts +0 -22
- package/dist/lib/table/batches/row-table-batch-aggregator.d.ts.map +0 -1
- package/dist/lib/table/batches/row-table-batch-aggregator.js +0 -85
- package/dist/lib/table/batches/table-batch-aggregator.d.ts +0 -25
- package/dist/lib/table/batches/table-batch-aggregator.d.ts.map +0 -1
- package/dist/lib/table/batches/table-batch-aggregator.js +0 -4
- package/dist/lib/table/batches/table-batch-builder.d.ts +0 -53
- package/dist/lib/table/batches/table-batch-builder.d.ts.map +0 -1
- package/dist/lib/table/batches/table-batch-builder.js +0 -151
- package/dist/lib/table/simple-table/convert-table.d.ts +0 -43
- package/dist/lib/table/simple-table/convert-table.d.ts.map +0 -1
- package/dist/lib/table/simple-table/convert-table.js +0 -118
- package/dist/lib/table/simple-table/data-type.d.ts +0 -17
- package/dist/lib/table/simple-table/data-type.d.ts.map +0 -1
- package/dist/lib/table/simple-table/data-type.js +0 -88
- package/dist/lib/table/simple-table/make-table-from-batches.d.ts +0 -22
- package/dist/lib/table/simple-table/make-table-from-batches.d.ts.map +0 -1
- package/dist/lib/table/simple-table/make-table-from-batches.js +0 -79
- package/dist/lib/table/simple-table/make-table.d.ts +0 -65
- package/dist/lib/table/simple-table/make-table.d.ts.map +0 -1
- package/dist/lib/table/simple-table/make-table.js +0 -94
- package/dist/lib/table/simple-table/row-utils.d.ts +0 -15
- package/dist/lib/table/simple-table/row-utils.d.ts.map +0 -1
- package/dist/lib/table/simple-table/row-utils.js +0 -49
- package/dist/lib/table/simple-table/table-accessors.d.ts +0 -68
- package/dist/lib/table/simple-table/table-accessors.d.ts.map +0 -1
- package/dist/lib/table/simple-table/table-accessors.js +0 -350
- package/dist/lib/table/simple-table/table-column.d.ts +0 -7
- package/dist/lib/table/simple-table/table-column.d.ts.map +0 -1
- package/dist/lib/table/simple-table/table-column.js +0 -39
- package/dist/lib/table/simple-table/table-schema.d.ts +0 -15
- package/dist/lib/table/simple-table/table-schema.d.ts.map +0 -1
- package/dist/lib/table/simple-table/table-schema.js +0 -100
- package/dist/lib/utils/assert.d.ts +0 -2
- package/dist/lib/utils/assert.d.ts.map +0 -1
- package/dist/lib/utils/assert.js +0 -8
- package/dist/lib/utils/async-queue.d.ts +0 -18
- package/dist/lib/utils/async-queue.d.ts.map +0 -1
- package/dist/lib/utils/async-queue.js +0 -90
- package/dist/types/binary-geometries.d.ts +0 -57
- package/dist/types/binary-geometries.d.ts.map +0 -1
- package/dist/types/category-gis.d.ts +0 -18
- package/dist/types/category-gis.d.ts.map +0 -1
- package/dist/types/category-image.d.ts.map +0 -1
- package/dist/types/category-mesh.d.ts.map +0 -1
- package/dist/types/category-table.d.ts.map +0 -1
- package/dist/types/category-texture.d.ts.map +0 -1
- package/dist/types/flat-geometries.d.ts +0 -30
- package/dist/types/flat-geometries.d.ts.map +0 -1
- package/src/lib/mesh/convert-mesh.ts +0 -51
- package/src/lib/mesh/deduce-mesh-schema.ts +0 -76
- package/src/lib/mesh/mesh-to-arrow-table.ts +0 -47
- package/src/lib/table/arrow-api/arrow-like-field.ts +0 -53
- package/src/lib/table/arrow-api/arrow-like-interface.ts +0 -84
- package/src/lib/table/arrow-api/arrow-like-schema.ts +0 -101
- package/src/lib/table/arrow-api/arrow-like-table.ts +0 -86
- package/src/lib/table/arrow-api/arrow-like-type.ts +0 -502
- package/src/lib/table/arrow-api/enum.ts +0 -99
- package/src/lib/table/arrow-api/get-type-info.ts +0 -38
- package/src/lib/table/arrow-api/index.ts +0 -8
- package/src/lib/table/batches/base-table-batch-aggregator.ts +0 -83
- package/src/lib/table/batches/columnar-table-batch-aggregator.ts +0 -112
- package/src/lib/table/batches/row-table-batch-aggregator.ts +0 -109
- package/src/lib/table/batches/table-batch-aggregator.ts +0 -29
- package/src/lib/table/batches/table-batch-builder.ts +0 -190
- package/src/lib/table/simple-table/convert-table.ts +0 -149
- package/src/lib/table/simple-table/data-type.ts +0 -104
- package/src/lib/table/simple-table/make-table-from-batches.ts +0 -98
- package/src/lib/table/simple-table/make-table.ts +0 -111
- package/src/lib/table/simple-table/row-utils.ts +0 -59
- package/src/lib/table/simple-table/table-accessors.ts +0 -417
- package/src/lib/table/simple-table/table-column.ts +0 -49
- package/src/lib/table/simple-table/table-schema.ts +0 -121
- package/src/lib/utils/assert.ts +0 -8
- package/src/lib/utils/async-queue.ts +0 -104
- package/src/types/binary-geometries.ts +0 -67
- /package/dist/{types → categories}/category-gis.js +0 -0
- /package/dist/{types → categories}/category-image.d.ts +0 -0
- /package/dist/{types → categories}/category-image.js +0 -0
- /package/dist/{types → categories}/category-mesh.js +0 -0
- /package/dist/{types → categories}/category-table.js +0 -0
- /package/dist/{types → categories}/category-texture.d.ts +0 -0
- /package/dist/{types → categories}/category-texture.js +0 -0
- /package/dist/{lib/table/arrow-api/arrow-like-interface.js → geometry/binary-features.js} +0 -0
- /package/dist/{types → geometry}/binary-geometries.js +0 -0
- /package/dist/{types → geometry}/flat-geometries.js +0 -0
- /package/src/{types → categories}/category-image.ts +0 -0
- /package/src/{types → categories}/category-texture.ts +0 -0
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {Schema} from '../../../types/schema';
|
|
6
|
-
import type {TableBatch} from '../../../types/category-table';
|
|
7
|
-
import {TableBatchAggregator, TableBatchOptions} from './table-batch-aggregator';
|
|
8
|
-
|
|
9
|
-
const DEFAULT_ROW_COUNT = 100;
|
|
10
|
-
|
|
11
|
-
export class BaseTableBatchAggregator implements TableBatchAggregator {
|
|
12
|
-
schema: Schema;
|
|
13
|
-
options: TableBatchOptions;
|
|
14
|
-
|
|
15
|
-
shape?: 'array-row-table' | 'object-row-table';
|
|
16
|
-
length: number = 0;
|
|
17
|
-
rows: any[] | null = null;
|
|
18
|
-
cursor: number = 0;
|
|
19
|
-
private _headers: string[] = [];
|
|
20
|
-
|
|
21
|
-
constructor(schema: Schema, options: TableBatchOptions) {
|
|
22
|
-
this.options = options;
|
|
23
|
-
this.schema = schema;
|
|
24
|
-
|
|
25
|
-
// schema is an array if there're no headers
|
|
26
|
-
// object if there are headers
|
|
27
|
-
if (!Array.isArray(schema)) {
|
|
28
|
-
this._headers = [];
|
|
29
|
-
for (const key in schema) {
|
|
30
|
-
this._headers[schema[key].index] = schema[key].name;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
rowCount(): number {
|
|
36
|
-
return this.length;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
addArrayRow(row: any[], cursor?: number): void {
|
|
40
|
-
if (Number.isFinite(cursor)) {
|
|
41
|
-
this.cursor = cursor as number;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
this.shape = 'array-row-table';
|
|
45
|
-
|
|
46
|
-
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
47
|
-
this.rows[this.length] = row;
|
|
48
|
-
this.length++;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
addObjectRow(row: {[columnName: string]: any}, cursor?: number): void {
|
|
52
|
-
if (Number.isFinite(cursor)) {
|
|
53
|
-
this.cursor = cursor as number;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
this.shape = 'object-row-table';
|
|
57
|
-
|
|
58
|
-
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
59
|
-
this.rows[this.length] = row;
|
|
60
|
-
this.length++;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
getBatch(): TableBatch | null {
|
|
64
|
-
let rows = this.rows;
|
|
65
|
-
if (!rows) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
rows = rows.slice(0, this.length);
|
|
70
|
-
this.rows = null;
|
|
71
|
-
|
|
72
|
-
const batch: TableBatch = {
|
|
73
|
-
shape: this.shape || 'array-row-table',
|
|
74
|
-
batchType: 'data',
|
|
75
|
-
data: rows,
|
|
76
|
-
length: this.length,
|
|
77
|
-
schema: this.schema,
|
|
78
|
-
cursor: this.cursor
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
return batch;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {Schema} from '../../../types/schema';
|
|
6
|
-
import type {ColumnarTableBatch, ArrowTableBatch} from '../../../types/category-table';
|
|
7
|
-
import {TableBatchAggregator} from './table-batch-aggregator';
|
|
8
|
-
|
|
9
|
-
type ColumnarTableBatchOptions = {};
|
|
10
|
-
|
|
11
|
-
const DEFAULT_ROW_COUNT = 100;
|
|
12
|
-
|
|
13
|
-
export class ColumnarTableBatchAggregator implements TableBatchAggregator {
|
|
14
|
-
schema: Schema;
|
|
15
|
-
length: number = 0;
|
|
16
|
-
allocated: number = 0;
|
|
17
|
-
columns: {[columnName: string]: any[]} = {};
|
|
18
|
-
|
|
19
|
-
constructor(schema: Schema, options: ColumnarTableBatchOptions) {
|
|
20
|
-
this.schema = schema;
|
|
21
|
-
this._reallocateColumns();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
rowCount(): number {
|
|
25
|
-
return this.length;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
addArrayRow(row: any[]) {
|
|
29
|
-
// If user keeps pushing rows beyond batch size, reallocate
|
|
30
|
-
this._reallocateColumns();
|
|
31
|
-
let i = 0;
|
|
32
|
-
// TODO what if no csv header, columns not populated?
|
|
33
|
-
for (const fieldName in this.columns) {
|
|
34
|
-
this.columns[fieldName][this.length] = row[i++];
|
|
35
|
-
}
|
|
36
|
-
this.length++;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
addObjectRow(row: {[columnName: string]: any}): void {
|
|
40
|
-
// If user keeps pushing rows beyond batch size, reallocate
|
|
41
|
-
this._reallocateColumns();
|
|
42
|
-
for (const fieldName in row) {
|
|
43
|
-
this.columns[fieldName][this.length] = row[fieldName];
|
|
44
|
-
}
|
|
45
|
-
this.length++;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
getBatch(): ColumnarTableBatch | ArrowTableBatch | null {
|
|
49
|
-
this._pruneColumns();
|
|
50
|
-
const columns = Array.isArray(this.schema) ? this.columns : {};
|
|
51
|
-
|
|
52
|
-
// schema is an array if there're no headers
|
|
53
|
-
// object if there are headers
|
|
54
|
-
// columns should match schema format
|
|
55
|
-
if (!Array.isArray(this.schema)) {
|
|
56
|
-
for (const fieldName in this.schema) {
|
|
57
|
-
const field = this.schema[fieldName];
|
|
58
|
-
columns[field.name] = this.columns[field.index];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
this.columns = {};
|
|
63
|
-
|
|
64
|
-
const batch: ColumnarTableBatch = {
|
|
65
|
-
shape: 'columnar-table',
|
|
66
|
-
batchType: 'data',
|
|
67
|
-
data: columns,
|
|
68
|
-
schema: this.schema,
|
|
69
|
-
length: this.length
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
return batch;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// HELPERS
|
|
76
|
-
|
|
77
|
-
_reallocateColumns() {
|
|
78
|
-
if (this.length < this.allocated) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// @ts-ignore TODO
|
|
83
|
-
this.allocated = this.allocated > 0 ? (this.allocated *= 2) : DEFAULT_ROW_COUNT;
|
|
84
|
-
this.columns = {};
|
|
85
|
-
|
|
86
|
-
for (const fieldName in this.schema) {
|
|
87
|
-
const field = this.schema[fieldName];
|
|
88
|
-
const ArrayType = field.type || Float32Array;
|
|
89
|
-
const oldColumn = this.columns[field.index];
|
|
90
|
-
|
|
91
|
-
if (oldColumn && ArrayBuffer.isView(oldColumn)) {
|
|
92
|
-
// Copy the old data to the new array
|
|
93
|
-
const typedArray = new ArrayType(this.allocated);
|
|
94
|
-
typedArray.set(oldColumn);
|
|
95
|
-
this.columns[field.index] = typedArray;
|
|
96
|
-
} else if (oldColumn) {
|
|
97
|
-
// Plain array
|
|
98
|
-
oldColumn.length = this.allocated;
|
|
99
|
-
this.columns[field.index] = oldColumn;
|
|
100
|
-
} else {
|
|
101
|
-
// Create new
|
|
102
|
-
this.columns[field.index] = new ArrayType(this.allocated);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
_pruneColumns() {
|
|
108
|
-
for (const [columnName, column] of Object.entries(this.columns)) {
|
|
109
|
-
this.columns[columnName] = column.slice(0, this.length);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {Schema} from '../../../types/schema';
|
|
6
|
-
import type {TableBatch} from '../../../types/category-table';
|
|
7
|
-
import {TableBatchAggregator, TableBatchOptions} from './table-batch-aggregator';
|
|
8
|
-
import {
|
|
9
|
-
convertToArrayRow,
|
|
10
|
-
convertToObjectRow,
|
|
11
|
-
inferHeadersFromArrayRow,
|
|
12
|
-
inferHeadersFromObjectRow
|
|
13
|
-
} from '../simple-table/row-utils';
|
|
14
|
-
|
|
15
|
-
const DEFAULT_ROW_COUNT = 100;
|
|
16
|
-
|
|
17
|
-
export class RowTableBatchAggregator implements TableBatchAggregator {
|
|
18
|
-
schema: Schema | null;
|
|
19
|
-
options: TableBatchOptions;
|
|
20
|
-
|
|
21
|
-
length: number = 0;
|
|
22
|
-
objectRows: {[columnName: string]: unknown}[] | null = null;
|
|
23
|
-
arrayRows: unknown[][] | null = null;
|
|
24
|
-
cursor: number = 0;
|
|
25
|
-
private _headers: string[] | null = null;
|
|
26
|
-
|
|
27
|
-
constructor(schema: Schema | null, options: TableBatchOptions) {
|
|
28
|
-
this.options = options;
|
|
29
|
-
this.schema = schema;
|
|
30
|
-
|
|
31
|
-
// schema is an array if there're no headers
|
|
32
|
-
// object if there are headers
|
|
33
|
-
if (schema) {
|
|
34
|
-
this._headers = [];
|
|
35
|
-
for (const key in schema) {
|
|
36
|
-
this._headers[schema[key].index] = schema[key].name;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
rowCount(): number {
|
|
42
|
-
return this.length;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
addArrayRow(row: any[], cursor?: number): void {
|
|
46
|
-
if (Number.isFinite(cursor)) {
|
|
47
|
-
this.cursor = cursor as number;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// TODO - infer schema at a higher level, instead of hacking headers here?
|
|
51
|
-
this._headers ||= inferHeadersFromArrayRow(row);
|
|
52
|
-
|
|
53
|
-
// eslint-disable-next-line default-case
|
|
54
|
-
switch (this.options.shape) {
|
|
55
|
-
case 'object-row-table':
|
|
56
|
-
const rowObject = convertToObjectRow(row, this._headers);
|
|
57
|
-
this.addObjectRow(rowObject, cursor);
|
|
58
|
-
break;
|
|
59
|
-
case 'array-row-table':
|
|
60
|
-
this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT);
|
|
61
|
-
this.arrayRows[this.length] = row;
|
|
62
|
-
this.length++;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
addObjectRow(row: {[columnName: string]: any}, cursor?: number): void {
|
|
68
|
-
if (Number.isFinite(cursor)) {
|
|
69
|
-
this.cursor = cursor as number;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// TODO - infer schema at a higher level, instead of hacking headers here?
|
|
73
|
-
this._headers ||= inferHeadersFromObjectRow(row);
|
|
74
|
-
|
|
75
|
-
// eslint-disable-next-line default-case
|
|
76
|
-
switch (this.options.shape) {
|
|
77
|
-
case 'array-row-table':
|
|
78
|
-
const rowArray = convertToArrayRow(row, this._headers);
|
|
79
|
-
this.addArrayRow(rowArray, cursor);
|
|
80
|
-
break;
|
|
81
|
-
case 'object-row-table':
|
|
82
|
-
this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT);
|
|
83
|
-
this.objectRows[this.length] = row;
|
|
84
|
-
this.length++;
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
getBatch(): TableBatch | null {
|
|
90
|
-
let rows = this.arrayRows || this.objectRows;
|
|
91
|
-
if (!rows) {
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
rows = rows.slice(0, this.length);
|
|
96
|
-
this.arrayRows = null;
|
|
97
|
-
this.objectRows = null;
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
shape: this.options.shape,
|
|
101
|
-
batchType: 'data',
|
|
102
|
-
data: rows,
|
|
103
|
-
length: this.length,
|
|
104
|
-
// @ts-expect-error we should infer a schema
|
|
105
|
-
schema: this.schema,
|
|
106
|
-
cursor: this.cursor
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {Schema} from '../../../types/schema';
|
|
6
|
-
import type {TableBatch} from '../../../types/category-table';
|
|
7
|
-
|
|
8
|
-
export interface TableBatchOptions {
|
|
9
|
-
batchSize: number | string;
|
|
10
|
-
[key: string]: any;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface TableBatchConstructor {
|
|
14
|
-
new (schema: Schema, options: TableBatchOptions): TableBatchAggregator;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* TableBatchBuilder delegates batch building to this interface
|
|
19
|
-
*/
|
|
20
|
-
export interface TableBatchAggregator {
|
|
21
|
-
/** Number of rows */
|
|
22
|
-
rowCount(): number;
|
|
23
|
-
/** Add one row */
|
|
24
|
-
addArrayRow(row: any[]): void;
|
|
25
|
-
/** Add one row */
|
|
26
|
-
addObjectRow(row: {[columnName: string]: any}): void;
|
|
27
|
-
/** return a batch object */
|
|
28
|
-
getBatch(): TableBatch | null;
|
|
29
|
-
}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {Schema} from '../../../types/schema';
|
|
6
|
-
import type {TableBatch} from '../../../types/category-table';
|
|
7
|
-
import type {TableBatchAggregator, TableBatchConstructor} from './table-batch-aggregator';
|
|
8
|
-
import {BaseTableBatchAggregator} from './base-table-batch-aggregator';
|
|
9
|
-
import {RowTableBatchAggregator} from './row-table-batch-aggregator';
|
|
10
|
-
import {ColumnarTableBatchAggregator} from './columnar-table-batch-aggregator';
|
|
11
|
-
|
|
12
|
-
// TODO define interface instead
|
|
13
|
-
type TableBatchBuilderOptions = {
|
|
14
|
-
shape?: 'array-row-table' | 'object-row-table' | 'columnar-table' | 'arrow-table';
|
|
15
|
-
batchSize?: number | 'auto';
|
|
16
|
-
batchDebounceMs?: number;
|
|
17
|
-
limit?: number;
|
|
18
|
-
_limitMB?: number;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
type GetBatchOptions = {
|
|
22
|
-
bytesUsed?: number;
|
|
23
|
-
[key: string]: any;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const DEFAULT_OPTIONS: Required<TableBatchBuilderOptions> = {
|
|
27
|
-
shape: undefined!,
|
|
28
|
-
batchSize: 'auto',
|
|
29
|
-
batchDebounceMs: 0,
|
|
30
|
-
limit: 0,
|
|
31
|
-
_limitMB: 0
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const ERR_MESSAGE = 'TableBatchBuilder';
|
|
35
|
-
|
|
36
|
-
/** Incrementally builds batches from a stream of rows */
|
|
37
|
-
export class TableBatchBuilder {
|
|
38
|
-
schema: Schema;
|
|
39
|
-
options: Required<TableBatchBuilderOptions>;
|
|
40
|
-
|
|
41
|
-
private aggregator: TableBatchAggregator | null = null;
|
|
42
|
-
private batchCount: number = 0;
|
|
43
|
-
private bytesUsed: number = 0;
|
|
44
|
-
private isChunkComplete: boolean = false;
|
|
45
|
-
private lastBatchEmittedMs: number = Date.now();
|
|
46
|
-
private totalLength: number = 0;
|
|
47
|
-
private totalBytes: number = 0;
|
|
48
|
-
private rowBytes: number = 0;
|
|
49
|
-
|
|
50
|
-
static ArrowBatch?: TableBatchConstructor;
|
|
51
|
-
|
|
52
|
-
constructor(schema: Schema, options?: TableBatchBuilderOptions) {
|
|
53
|
-
this.schema = schema;
|
|
54
|
-
this.options = {...DEFAULT_OPTIONS, ...options};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
limitReached(): boolean {
|
|
58
|
-
if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
if (Boolean(this.options?._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** @deprecated Use addArrayRow or addObjectRow */
|
|
68
|
-
addRow(row: any[] | {[columnName: string]: any}): void {
|
|
69
|
-
if (this.limitReached()) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
this.totalLength++;
|
|
73
|
-
this.rowBytes = this.rowBytes || this._estimateRowMB(row);
|
|
74
|
-
this.totalBytes += this.rowBytes;
|
|
75
|
-
if (Array.isArray(row)) {
|
|
76
|
-
this.addArrayRow(row);
|
|
77
|
-
} else {
|
|
78
|
-
this.addObjectRow(row);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Add one row to the batch */
|
|
83
|
-
protected addArrayRow(row: any[]) {
|
|
84
|
-
if (!this.aggregator) {
|
|
85
|
-
const TableBatchType = this._getTableBatchType();
|
|
86
|
-
this.aggregator = new TableBatchType(this.schema, this.options);
|
|
87
|
-
}
|
|
88
|
-
this.aggregator.addArrayRow(row);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** Add one row to the batch */
|
|
92
|
-
protected addObjectRow(row: {[columnName: string]: any}): void {
|
|
93
|
-
if (!this.aggregator) {
|
|
94
|
-
const TableBatchType = this._getTableBatchType();
|
|
95
|
-
this.aggregator = new TableBatchType(this.schema, this.options);
|
|
96
|
-
}
|
|
97
|
-
this.aggregator.addObjectRow(row);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** Mark an incoming raw memory chunk has completed */
|
|
101
|
-
chunkComplete(chunk: ArrayBuffer | string): void {
|
|
102
|
-
if (chunk instanceof ArrayBuffer) {
|
|
103
|
-
this.bytesUsed += chunk.byteLength;
|
|
104
|
-
}
|
|
105
|
-
if (typeof chunk === 'string') {
|
|
106
|
-
this.bytesUsed += chunk.length;
|
|
107
|
-
}
|
|
108
|
-
this.isChunkComplete = true;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
getFullBatch(options?: GetBatchOptions): TableBatch | null {
|
|
112
|
-
return this._isFull() ? this._getBatch(options) : null;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
getFinalBatch(options?: GetBatchOptions): TableBatch | null {
|
|
116
|
-
return this._getBatch(options);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// INTERNAL
|
|
120
|
-
|
|
121
|
-
_estimateRowMB(row: any[] | object): number {
|
|
122
|
-
return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
private _isFull(): boolean {
|
|
126
|
-
// No batch, not ready
|
|
127
|
-
if (!this.aggregator || this.aggregator.rowCount() === 0) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// if batchSize === 'auto' we wait for chunk to complete
|
|
132
|
-
// if batchSize === number, ensure we have enough rows
|
|
133
|
-
if (this.options.batchSize === 'auto') {
|
|
134
|
-
if (!this.isChunkComplete) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
} else if (this.options.batchSize > this.aggregator.rowCount()) {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Debounce batches
|
|
142
|
-
if (this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs) {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Emit batch
|
|
147
|
-
this.isChunkComplete = false;
|
|
148
|
-
this.lastBatchEmittedMs = Date.now();
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* bytesUsed can be set via chunkComplete or via getBatch*
|
|
154
|
-
*/
|
|
155
|
-
private _getBatch(options?: GetBatchOptions): TableBatch | null {
|
|
156
|
-
if (!this.aggregator) {
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// TODO - this can overly increment bytes used?
|
|
161
|
-
if (options?.bytesUsed) {
|
|
162
|
-
this.bytesUsed = options.bytesUsed;
|
|
163
|
-
}
|
|
164
|
-
const normalizedBatch = this.aggregator.getBatch() as TableBatch;
|
|
165
|
-
normalizedBatch.count = this.batchCount;
|
|
166
|
-
normalizedBatch.bytesUsed = this.bytesUsed;
|
|
167
|
-
Object.assign(normalizedBatch, options);
|
|
168
|
-
|
|
169
|
-
this.batchCount++;
|
|
170
|
-
this.aggregator = null;
|
|
171
|
-
return normalizedBatch;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
private _getTableBatchType(): TableBatchConstructor {
|
|
175
|
-
switch (this.options.shape) {
|
|
176
|
-
case 'array-row-table':
|
|
177
|
-
case 'object-row-table':
|
|
178
|
-
return RowTableBatchAggregator;
|
|
179
|
-
case 'columnar-table':
|
|
180
|
-
return ColumnarTableBatchAggregator;
|
|
181
|
-
case 'arrow-table':
|
|
182
|
-
if (!TableBatchBuilder.ArrowBatch) {
|
|
183
|
-
throw new Error(ERR_MESSAGE);
|
|
184
|
-
}
|
|
185
|
-
return TableBatchBuilder.ArrowBatch;
|
|
186
|
-
default:
|
|
187
|
-
return BaseTableBatchAggregator;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
getTableCell,
|
|
7
|
-
getTableLength,
|
|
8
|
-
getTableRowAsArray,
|
|
9
|
-
getTableRowAsObject
|
|
10
|
-
} from './table-accessors';
|
|
11
|
-
import {
|
|
12
|
-
Table,
|
|
13
|
-
ArrayRowTable,
|
|
14
|
-
ObjectRowTable,
|
|
15
|
-
ColumnarTable,
|
|
16
|
-
ArrowTable
|
|
17
|
-
} from '../../../types/category-table';
|
|
18
|
-
import {deduceTableSchema} from './table-schema';
|
|
19
|
-
import {makeColumnFromField} from './table-column';
|
|
20
|
-
|
|
21
|
-
export function convertTable(table: Table, shape: 'object-row-table'): ObjectRowTable;
|
|
22
|
-
export function convertTable(table: Table, shape: 'array-row-table'): ArrayRowTable;
|
|
23
|
-
export function convertTable(table: Table, shape: 'columnar-table'): ColumnarTable;
|
|
24
|
-
export function convertTable(table: Table, shape: 'arrow-table'): ArrowTable;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Convert a table to a different shape
|
|
28
|
-
* @param table
|
|
29
|
-
* @param shape
|
|
30
|
-
* @returns
|
|
31
|
-
*/
|
|
32
|
-
export function convertTable(
|
|
33
|
-
table: Table,
|
|
34
|
-
shape: 'object-row-table' | 'array-row-table' | 'columnar-table' | 'arrow-table'
|
|
35
|
-
) {
|
|
36
|
-
switch (shape) {
|
|
37
|
-
case 'object-row-table':
|
|
38
|
-
return makeObjectRowTable(table);
|
|
39
|
-
case 'array-row-table':
|
|
40
|
-
return makeArrayRowTable(table);
|
|
41
|
-
case 'columnar-table':
|
|
42
|
-
return makeColumnarTable(table);
|
|
43
|
-
case 'arrow-table':
|
|
44
|
-
return makeArrowTable(table);
|
|
45
|
-
default:
|
|
46
|
-
throw new Error(shape);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Convert a table to apache arrow format
|
|
52
|
-
* @note this depends on the `@loaders.gl/arrow module being imported
|
|
53
|
-
*/
|
|
54
|
-
export function makeArrowTable(table: Table): Table {
|
|
55
|
-
const _makeArrowTable = globalThis.__loaders?._makeArrowTable;
|
|
56
|
-
if (!_makeArrowTable) {
|
|
57
|
-
throw new Error('');
|
|
58
|
-
}
|
|
59
|
-
return _makeArrowTable(table);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Convert any simple table into columnar format */
|
|
63
|
-
export function makeColumnarTable(table: Table): ColumnarTable {
|
|
64
|
-
// TODO - should schema really be optional?
|
|
65
|
-
const schema = table.schema || deduceTableSchema(table);
|
|
66
|
-
const fields = table.schema?.fields || [];
|
|
67
|
-
|
|
68
|
-
if (table.shape === 'columnar-table') {
|
|
69
|
-
return {...table, schema};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const length = getTableLength(table);
|
|
73
|
-
|
|
74
|
-
const columns: {[column: string]: ArrayLike<unknown>} = {};
|
|
75
|
-
for (const field of fields) {
|
|
76
|
-
const column = makeColumnFromField(field, length);
|
|
77
|
-
columns[field.name] = column;
|
|
78
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
79
|
-
column[rowIndex] = getTableCell(table, rowIndex, field.name);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
shape: 'columnar-table',
|
|
85
|
-
schema,
|
|
86
|
-
data: columns
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** Convert any table into array row format */
|
|
91
|
-
export function makeArrayRowTable(table: Table): ArrayRowTable {
|
|
92
|
-
if (table.shape === 'array-row-table') {
|
|
93
|
-
return table;
|
|
94
|
-
}
|
|
95
|
-
const length = getTableLength(table);
|
|
96
|
-
const data = new Array<unknown[]>(length);
|
|
97
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
98
|
-
data[rowIndex] = getTableRowAsArray(table, rowIndex);
|
|
99
|
-
}
|
|
100
|
-
return {
|
|
101
|
-
shape: 'array-row-table',
|
|
102
|
-
schema: table.schema,
|
|
103
|
-
data
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/** Convert any table into object row format */
|
|
108
|
-
export function makeObjectRowTable(table: Table): ObjectRowTable {
|
|
109
|
-
if (table.shape === 'object-row-table') {
|
|
110
|
-
return table;
|
|
111
|
-
}
|
|
112
|
-
const length = getTableLength(table);
|
|
113
|
-
const data = new Array<{[key: string]: unknown}>(length);
|
|
114
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
115
|
-
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
shape: 'object-row-table',
|
|
119
|
-
schema: table.schema,
|
|
120
|
-
data
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
*
|
|
126
|
-
* @note - should be part of schema module
|
|
127
|
-
*
|
|
128
|
-
export function convertColumnarToRowFormatTable(columnarTable: ColumnarTable): ObjectRowTable {
|
|
129
|
-
const tableKeys = Object.keys(columnarTable);
|
|
130
|
-
const tableRowsCount = columnarTable[tableKeys[0]].length;
|
|
131
|
-
|
|
132
|
-
const rowFormatTable: {}[] = [];
|
|
133
|
-
|
|
134
|
-
for (let index = 0; index < tableRowsCount; index++) {
|
|
135
|
-
const tableItem = {};
|
|
136
|
-
for (let keyIndex = 0; keyIndex < tableKeys.length; keyIndex++) {
|
|
137
|
-
const fieldName = tableKeys[keyIndex];
|
|
138
|
-
tableItem[fieldName] = columnarTable[fieldName][index];
|
|
139
|
-
}
|
|
140
|
-
rowFormatTable.push(tableItem);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
shape: 'object-row-table',
|
|
145
|
-
schema: columnarTable.schema,
|
|
146
|
-
data: rowFormatTable
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
*/
|