@loaders.gl/schema 4.2.0-alpha.4 → 4.2.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/dist.dev.js +216 -147
- package/dist/dist.min.js +9 -0
- package/dist/index.cjs +128 -97
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +30 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/lib/mesh/convert-mesh.d.ts +2 -2
- package/dist/lib/mesh/convert-mesh.d.ts.map +1 -1
- package/dist/lib/mesh/convert-mesh.js +33 -18
- package/dist/lib/mesh/deduce-mesh-schema.d.ts +2 -2
- package/dist/lib/mesh/deduce-mesh-schema.d.ts.map +1 -1
- package/dist/lib/mesh/deduce-mesh-schema.js +54 -40
- package/dist/lib/mesh/mesh-to-arrow-table.js +46 -1
- package/dist/lib/mesh/mesh-utils.d.ts +2 -2
- package/dist/lib/mesh/mesh-utils.d.ts.map +1 -1
- package/dist/lib/mesh/mesh-utils.js +41 -28
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts +1 -1
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts.map +1 -1
- package/dist/lib/table/arrow-api/arrow-like-field.js +34 -25
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts +2 -2
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts.map +1 -1
- package/dist/lib/table/arrow-api/arrow-like-schema.js +71 -56
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts +2 -2
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts.map +1 -1
- package/dist/lib/table/arrow-api/arrow-like-table.js +57 -45
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts +3 -3
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts.map +1 -1
- package/dist/lib/table/arrow-api/arrow-like-type.js +371 -321
- package/dist/lib/table/arrow-api/enum.js +97 -48
- package/dist/lib/table/arrow-api/get-type-info.d.ts +1 -1
- package/dist/lib/table/arrow-api/get-type-info.d.ts.map +1 -1
- package/dist/lib/table/arrow-api/get-type-info.js +20 -14
- package/dist/lib/table/arrow-api/index.d.ts +4 -4
- package/dist/lib/table/arrow-api/index.d.ts.map +1 -1
- package/dist/lib/table/arrow-api/index.js +3 -1
- package/dist/lib/table/batches/base-table-batch-aggregator.d.ts +3 -3
- package/dist/lib/table/batches/base-table-batch-aggregator.d.ts.map +1 -1
- package/dist/lib/table/batches/base-table-batch-aggregator.js +56 -52
- package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts +3 -3
- package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts.map +1 -1
- package/dist/lib/table/batches/columnar-table-batch-aggregator.js +82 -67
- package/dist/lib/table/batches/row-table-batch-aggregator.d.ts +3 -3
- package/dist/lib/table/batches/row-table-batch-aggregator.d.ts.map +1 -1
- package/dist/lib/table/batches/row-table-batch-aggregator.js +76 -67
- package/dist/lib/table/batches/table-batch-aggregator.d.ts +2 -2
- package/dist/lib/table/batches/table-batch-aggregator.d.ts.map +1 -1
- package/dist/lib/table/batches/table-batch-aggregator.js +3 -1
- package/dist/lib/table/batches/table-batch-builder.d.ts +3 -3
- package/dist/lib/table/batches/table-batch-builder.d.ts.map +1 -1
- package/dist/lib/table/batches/table-batch-builder.js +131 -116
- package/dist/lib/table/simple-table/convert-table.d.ts +1 -1
- package/dist/lib/table/simple-table/convert-table.d.ts.map +1 -1
- package/dist/lib/table/simple-table/convert-table.js +97 -62
- package/dist/lib/table/simple-table/data-type.d.ts +2 -2
- package/dist/lib/table/simple-table/data-type.d.ts.map +1 -1
- package/dist/lib/table/simple-table/data-type.js +79 -76
- package/dist/lib/table/simple-table/make-table-from-batches.js +70 -67
- package/dist/lib/table/simple-table/make-table.d.ts +1 -1
- package/dist/lib/table/simple-table/make-table.d.ts.map +1 -1
- package/dist/lib/table/simple-table/make-table.js +85 -41
- package/dist/lib/table/simple-table/row-utils.js +38 -31
- package/dist/lib/table/simple-table/table-accessors.d.ts +1 -1
- package/dist/lib/table/simple-table/table-accessors.d.ts.map +1 -1
- package/dist/lib/table/simple-table/table-accessors.js +314 -270
- package/dist/lib/table/simple-table/table-column.d.ts +1 -1
- package/dist/lib/table/simple-table/table-column.d.ts.map +1 -1
- package/dist/lib/table/simple-table/table-column.js +36 -3
- package/dist/lib/table/simple-table/table-schema.d.ts +2 -2
- package/dist/lib/table/simple-table/table-schema.d.ts.map +1 -1
- package/dist/lib/table/simple-table/table-schema.js +69 -56
- package/dist/lib/utils/assert.js +6 -4
- package/dist/lib/utils/async-queue.js +79 -82
- package/dist/types/batch.d.ts +1 -1
- package/dist/types/batch.d.ts.map +1 -1
- package/dist/types/batch.js +3 -1
- package/dist/types/binary-geometries.d.ts +1 -1
- package/dist/types/binary-geometries.d.ts.map +1 -1
- package/dist/types/binary-geometries.js +3 -1
- package/dist/types/category-gis.d.ts +2 -2
- package/dist/types/category-gis.d.ts.map +1 -1
- package/dist/types/category-gis.js +3 -1
- package/dist/types/category-image.js +3 -1
- package/dist/types/category-mesh.d.ts +3 -3
- package/dist/types/category-mesh.d.ts.map +1 -1
- package/dist/types/category-mesh.js +3 -1
- package/dist/types/category-table.d.ts +3 -3
- package/dist/types/category-table.d.ts.map +1 -1
- package/dist/types/category-table.js +3 -1
- package/dist/types/category-texture.d.ts +1 -1
- package/dist/types/category-texture.d.ts.map +1 -1
- package/dist/types/category-texture.js +3 -1
- package/dist/types/flat-geometries.js +3 -1
- package/dist/types/schema.js +3 -1
- package/dist/types/types.js +3 -1
- package/package.json +8 -4
- package/src/index.ts +1 -1
- package/src/lib/table/arrow-api/arrow-like-field.ts +2 -2
- package/src/lib/table/arrow-api/arrow-like-type.ts +4 -2
- package/dist/index.js.map +0 -1
- package/dist/lib/mesh/convert-mesh.js.map +0 -1
- package/dist/lib/mesh/deduce-mesh-schema.js.map +0 -1
- package/dist/lib/mesh/mesh-to-arrow-table.js.map +0 -1
- package/dist/lib/mesh/mesh-utils.js.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-field.js.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-schema.js.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-table.js.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-type.js.map +0 -1
- package/dist/lib/table/arrow-api/enum.js.map +0 -1
- package/dist/lib/table/arrow-api/get-type-info.js.map +0 -1
- package/dist/lib/table/arrow-api/index.js.map +0 -1
- package/dist/lib/table/batches/base-table-batch-aggregator.js.map +0 -1
- package/dist/lib/table/batches/columnar-table-batch-aggregator.js.map +0 -1
- package/dist/lib/table/batches/row-table-batch-aggregator.js.map +0 -1
- package/dist/lib/table/batches/table-batch-aggregator.js.map +0 -1
- package/dist/lib/table/batches/table-batch-builder.js.map +0 -1
- package/dist/lib/table/simple-table/convert-table.js.map +0 -1
- package/dist/lib/table/simple-table/data-type.js.map +0 -1
- package/dist/lib/table/simple-table/make-table-from-batches.js.map +0 -1
- package/dist/lib/table/simple-table/make-table.js.map +0 -1
- package/dist/lib/table/simple-table/row-utils.js.map +0 -1
- package/dist/lib/table/simple-table/table-accessors.js.map +0 -1
- package/dist/lib/table/simple-table/table-column.js.map +0 -1
- package/dist/lib/table/simple-table/table-schema.js.map +0 -1
- package/dist/lib/utils/assert.js.map +0 -1
- package/dist/lib/utils/async-queue.js.map +0 -1
- package/dist/types/batch.js.map +0 -1
- package/dist/types/binary-geometries.js.map +0 -1
- package/dist/types/category-gis.js.map +0 -1
- package/dist/types/category-image.js.map +0 -1
- package/dist/types/category-mesh.js.map +0 -1
- package/dist/types/category-table.js.map +0 -1
- package/dist/types/category-texture.js.map +0 -1
- package/dist/types/flat-geometries.js.map +0 -1
- package/dist/types/schema.js.map +0 -1
- package/dist/types/types.js.map +0 -1
|
@@ -1,76 +1,85 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { convertToArrayRow, convertToObjectRow, inferHeadersFromArrayRow, inferHeadersFromObjectRow } from "../simple-table/row-utils.js";
|
|
2
5
|
const DEFAULT_ROW_COUNT = 100;
|
|
3
6
|
export class RowTableBatchAggregator {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 (const key in schema) {
|
|
22
|
+
this._headers[schema[key].index] = schema[key].name;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
19
25
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return this.length;
|
|
23
|
-
}
|
|
24
|
-
addArrayRow(row, cursor) {
|
|
25
|
-
if (Number.isFinite(cursor)) {
|
|
26
|
-
this.cursor = cursor;
|
|
26
|
+
rowCount() {
|
|
27
|
+
return this.length;
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
+
}
|
|
39
47
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
}
|
|
44
66
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.objectRows =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
+
};
|
|
56
84
|
}
|
|
57
|
-
}
|
|
58
|
-
getBatch() {
|
|
59
|
-
let rows = this.arrayRows || this.objectRows;
|
|
60
|
-
if (!rows) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
rows = rows.slice(0, this.length);
|
|
64
|
-
this.arrayRows = null;
|
|
65
|
-
this.objectRows = null;
|
|
66
|
-
return {
|
|
67
|
-
shape: this.options.shape,
|
|
68
|
-
batchType: 'data',
|
|
69
|
-
data: rows,
|
|
70
|
-
length: this.length,
|
|
71
|
-
schema: this.schema,
|
|
72
|
-
cursor: this.cursor
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
85
|
}
|
|
76
|
-
//# sourceMappingURL=row-table-batch-aggregator.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Schema } from
|
|
2
|
-
import type { TableBatch } from
|
|
1
|
+
import type { Schema } from "../../../types/schema.js";
|
|
2
|
+
import type { TableBatch } from "../../../types/category-table.js";
|
|
3
3
|
export interface TableBatchOptions {
|
|
4
4
|
batchSize: number | string;
|
|
5
5
|
[key: string]: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-batch-aggregator.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batches/table-batch-aggregator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,
|
|
1
|
+
{"version":3,"file":"table-batch-aggregator.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batches/table-batch-aggregator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,iCAA8B;AAClD,OAAO,KAAK,EAAC,UAAU,EAAC,yCAAsC;AAE9D,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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Schema } from
|
|
2
|
-
import type { TableBatch } from
|
|
3
|
-
import type { TableBatchConstructor } from
|
|
1
|
+
import type { Schema } from "../../../types/schema.js";
|
|
2
|
+
import type { TableBatch } from "../../../types/category-table.js";
|
|
3
|
+
import type { TableBatchConstructor } from "./table-batch-aggregator.js";
|
|
4
4
|
type TableBatchBuilderOptions = {
|
|
5
5
|
shape?: 'array-row-table' | 'object-row-table' | 'columnar-table' | 'arrow-table';
|
|
6
6
|
batchSize?: number | 'auto';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-batch-builder.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batches/table-batch-builder.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,
|
|
1
|
+
{"version":3,"file":"table-batch-builder.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batches/table-batch-builder.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,iCAA8B;AAClD,OAAO,KAAK,EAAC,UAAU,EAAC,yCAAsC;AAC9D,OAAO,KAAK,EAAuB,qBAAqB,EAAC,oCAAiC;AAM1F,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;AAYF,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;CAgB3B"}
|
|
@@ -1,136 +1,151 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { BaseTableBatchAggregator } from "./base-table-batch-aggregator.js";
|
|
2
5
|
import { RowTableBatchAggregator } from "./row-table-batch-aggregator.js";
|
|
3
6
|
import { ColumnarTableBatchAggregator } from "./columnar-table-batch-aggregator.js";
|
|
4
7
|
const DEFAULT_OPTIONS = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
shape: undefined,
|
|
9
|
+
batchSize: 'auto',
|
|
10
|
+
batchDebounceMs: 0,
|
|
11
|
+
limit: 0,
|
|
12
|
+
_limitMB: 0
|
|
10
13
|
};
|
|
11
14
|
const ERR_MESSAGE = 'TableBatchBuilder';
|
|
15
|
+
/** Incrementally builds batches from a stream of rows */
|
|
12
16
|
export class TableBatchBuilder {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
...options
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
limitReached() {
|
|
31
|
-
var _this$options, _this$options2;
|
|
32
|
-
if (Boolean((_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.limit) && this.totalLength >= this.options.limit) {
|
|
33
|
-
return true;
|
|
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 };
|
|
34
31
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
this.totalLength++;
|
|
45
|
-
this.rowBytes = this.rowBytes || this._estimateRowMB(row);
|
|
46
|
-
this.totalBytes += this.rowBytes;
|
|
47
|
-
if (Array.isArray(row)) {
|
|
48
|
-
this.addArrayRow(row);
|
|
49
|
-
} else {
|
|
50
|
-
this.addObjectRow(row);
|
|
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;
|
|
51
40
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
+
}
|
|
57
55
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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);
|
|
64
63
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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);
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
-
|
|
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;
|
|
73
81
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
getFullBatch(options) {
|
|
77
|
-
return this._isFull() ? this._getBatch(options) : null;
|
|
78
|
-
}
|
|
79
|
-
getFinalBatch(options) {
|
|
80
|
-
return this._getBatch(options);
|
|
81
|
-
}
|
|
82
|
-
_estimateRowMB(row) {
|
|
83
|
-
return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
|
|
84
|
-
}
|
|
85
|
-
_isFull() {
|
|
86
|
-
if (!this.aggregator || this.aggregator.rowCount() === 0) {
|
|
87
|
-
return false;
|
|
82
|
+
getFullBatch(options) {
|
|
83
|
+
return this._isFull() ? this._getBatch(options) : null;
|
|
88
84
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
} else if (this.options.batchSize > this.aggregator.rowCount()) {
|
|
94
|
-
return false;
|
|
85
|
+
getFinalBatch(options) {
|
|
86
|
+
return this._getBatch(options);
|
|
95
87
|
}
|
|
96
|
-
|
|
97
|
-
|
|
88
|
+
// INTERNAL
|
|
89
|
+
_estimateRowMB(row) {
|
|
90
|
+
return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
|
|
98
91
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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;
|
|
106
115
|
}
|
|
107
|
-
|
|
108
|
-
|
|
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;
|
|
109
134
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
case 'arrow-table':
|
|
126
|
-
if (!TableBatchBuilder.ArrowBatch) {
|
|
127
|
-
throw new Error(ERR_MESSAGE);
|
|
128
|
-
}
|
|
129
|
-
return TableBatchBuilder.ArrowBatch;
|
|
130
|
-
default:
|
|
131
|
-
return BaseTableBatchAggregator;
|
|
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
|
+
if (!TableBatchBuilder.ArrowBatch) {
|
|
144
|
+
throw new Error(ERR_MESSAGE);
|
|
145
|
+
}
|
|
146
|
+
return TableBatchBuilder.ArrowBatch;
|
|
147
|
+
default:
|
|
148
|
+
return BaseTableBatchAggregator;
|
|
149
|
+
}
|
|
132
150
|
}
|
|
133
|
-
}
|
|
134
151
|
}
|
|
135
|
-
TableBatchBuilder.ArrowBatch = void 0;
|
|
136
|
-
//# sourceMappingURL=table-batch-builder.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Table, ArrayRowTable, ObjectRowTable, ColumnarTable, ArrowTable } from
|
|
1
|
+
import { Table, ArrayRowTable, ObjectRowTable, ColumnarTable, ArrowTable } from "../../../types/category-table.js";
|
|
2
2
|
export declare function convertTable(table: Table, shape: 'object-row-table'): ObjectRowTable;
|
|
3
3
|
export declare function convertTable(table: Table, shape: 'array-row-table'): ArrayRowTable;
|
|
4
4
|
export declare function convertTable(table: Table, shape: 'columnar-table'): ColumnarTable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convert-table.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/simple-table/convert-table.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,EACL,aAAa,EACb,cAAc,EACd,aAAa,EACb,UAAU,EACX,
|
|
1
|
+
{"version":3,"file":"convert-table.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/simple-table/convert-table.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,EACL,aAAa,EACb,cAAc,EACd,aAAa,EACb,UAAU,EACX,yCAAsC;AAIvC,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,kBAAkB,GAAG,cAAc,CAAC;AACtF,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,iBAAiB,GAAG,aAAa,CAAC;AACpF,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,gBAAgB,GAAG,aAAa,CAAC;AACnF,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,GAAG,UAAU,CAAC;AA0B7E;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAMlD;AAED,oDAAoD;AACpD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,aAAa,CAyB7D;AAED,8CAA8C;AAC9C,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,aAAa,CAc7D;AAED,+CAA+C;AAC/C,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,cAAc,CAc/D;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG"}
|
|
@@ -1,81 +1,116 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
import { getTableCell, getTableLength, getTableRowAsArray, getTableRowAsObject } from "./table-accessors.js";
|
|
2
5
|
import { deduceTableSchema } from "./table-schema.js";
|
|
3
6
|
import { makeColumnFromField } from "./table-column.js";
|
|
7
|
+
/**
|
|
8
|
+
* Convert a table to a different shape
|
|
9
|
+
* @param table
|
|
10
|
+
* @param shape
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
4
13
|
export function convertTable(table, shape) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
switch (shape) {
|
|
15
|
+
case 'object-row-table':
|
|
16
|
+
return makeObjectRowTable(table);
|
|
17
|
+
case 'array-row-table':
|
|
18
|
+
return makeArrayRowTable(table);
|
|
19
|
+
case 'columnar-table':
|
|
20
|
+
return makeColumnarTable(table);
|
|
21
|
+
case 'arrow-table':
|
|
22
|
+
return makeArrowTable(table);
|
|
23
|
+
default:
|
|
24
|
+
throw new Error(shape);
|
|
25
|
+
}
|
|
17
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Convert a table to apache arrow format
|
|
29
|
+
* @note this depends on the `@loaders.gl/arrow module being imported
|
|
30
|
+
*/
|
|
18
31
|
export function makeArrowTable(table) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return _makeArrowTable(table);
|
|
32
|
+
const _makeArrowTable = globalThis.__loaders?._makeArrowTable;
|
|
33
|
+
if (!_makeArrowTable) {
|
|
34
|
+
throw new Error('');
|
|
35
|
+
}
|
|
36
|
+
return _makeArrowTable(table);
|
|
25
37
|
}
|
|
38
|
+
/** Convert any simple table into columnar format */
|
|
26
39
|
export function makeColumnarTable(table) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
// TODO - should schema really be optional?
|
|
41
|
+
const schema = table.schema || deduceTableSchema(table);
|
|
42
|
+
const fields = table.schema?.fields || [];
|
|
43
|
+
if (table.shape === 'columnar-table') {
|
|
44
|
+
return { ...table, schema };
|
|
45
|
+
}
|
|
46
|
+
const length = getTableLength(table);
|
|
47
|
+
const columns = {};
|
|
48
|
+
for (const field of fields) {
|
|
49
|
+
const column = makeColumnFromField(field, length);
|
|
50
|
+
columns[field.name] = column;
|
|
51
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
52
|
+
column[rowIndex] = getTableCell(table, rowIndex, field.name);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
31
55
|
return {
|
|
32
|
-
|
|
33
|
-
|
|
56
|
+
shape: 'columnar-table',
|
|
57
|
+
schema,
|
|
58
|
+
data: columns
|
|
34
59
|
};
|
|
35
|
-
}
|
|
36
|
-
const length = getTableLength(table);
|
|
37
|
-
const columns = {};
|
|
38
|
-
for (const field of fields) {
|
|
39
|
-
const column = makeColumnFromField(field, length);
|
|
40
|
-
columns[field.name] = column;
|
|
41
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
42
|
-
column[rowIndex] = getTableCell(table, rowIndex, field.name);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
shape: 'columnar-table',
|
|
47
|
-
schema,
|
|
48
|
-
data: columns
|
|
49
|
-
};
|
|
50
60
|
}
|
|
61
|
+
/** Convert any table into array row format */
|
|
51
62
|
export function makeArrayRowTable(table) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
if (table.shape === 'array-row-table') {
|
|
64
|
+
return table;
|
|
65
|
+
}
|
|
66
|
+
const length = getTableLength(table);
|
|
67
|
+
const data = new Array(length);
|
|
68
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
69
|
+
data[rowIndex] = getTableRowAsArray(table, rowIndex);
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
shape: 'array-row-table',
|
|
73
|
+
schema: table.schema,
|
|
74
|
+
data
|
|
75
|
+
};
|
|
65
76
|
}
|
|
77
|
+
/** Convert any table into object row format */
|
|
66
78
|
export function makeObjectRowTable(table) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
79
|
+
if (table.shape === 'object-row-table') {
|
|
80
|
+
return table;
|
|
81
|
+
}
|
|
82
|
+
const length = getTableLength(table);
|
|
83
|
+
const data = new Array(length);
|
|
84
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
85
|
+
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
shape: 'object-row-table',
|
|
89
|
+
schema: table.schema,
|
|
90
|
+
data
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* @note - should be part of schema module
|
|
97
|
+
export function convertColumnarToRowFormatTable(columnarTable: ColumnarTable): ObjectRowTable {
|
|
98
|
+
const tableKeys = ;
|
|
99
|
+
const tableRowsCount = columnarTable[tableKeys[0]].length;
|
|
100
|
+
|
|
101
|
+
const objectRows: ObjectRowTable['data'] = [];
|
|
102
|
+
|
|
103
|
+
for (let index = 0; index < tableRowsCount; index++) {
|
|
104
|
+
const objectRow = {};
|
|
105
|
+
for (const fieldName of Object.keys(columnarTable.data)) {
|
|
106
|
+
objectRow[fieldName] = columnarTable[fieldName][index];
|
|
107
|
+
}
|
|
108
|
+
objectRows.push(objectRow);
|
|
74
109
|
}
|
|
110
|
+
|
|
75
111
|
return {
|
|
76
112
|
shape: 'object-row-table',
|
|
77
|
-
|
|
78
|
-
data
|
|
113
|
+
data: objectRows
|
|
79
114
|
};
|
|
80
115
|
}
|
|
81
|
-
|
|
116
|
+
*/
|