@loaders.gl/schema 4.0.0-alpha.23 → 4.0.0-alpha.25
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.min.js +543 -934
- package/dist/es5/index.js +7 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/table/arrow-api/arrow-like-table.js +1 -1
- package/dist/es5/lib/table/arrow-api/arrow-like-table.js.map +1 -1
- package/dist/es5/lib/table/batches/row-table-batch-aggregator.js.map +1 -1
- package/dist/es5/lib/table/simple-table/convert-table.js +24 -0
- package/dist/es5/lib/table/simple-table/convert-table.js.map +1 -1
- package/dist/es5/lib/table/simple-table/table-accessors.js +52 -31
- package/dist/es5/lib/table/simple-table/table-accessors.js.map +1 -1
- package/dist/es5/types/batch.js +2 -0
- package/dist/es5/types/batch.js.map +1 -0
- package/dist/es5/types/binary-geometries.js.map +1 -1
- package/dist/es5/types/category-gis.js.map +1 -1
- package/dist/es5/types/category-table.js.map +1 -1
- package/dist/es5/types/schema.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/table/arrow-api/arrow-like-table.js +1 -1
- package/dist/esm/lib/table/arrow-api/arrow-like-table.js.map +1 -1
- package/dist/esm/lib/table/batches/row-table-batch-aggregator.js.map +1 -1
- package/dist/esm/lib/table/simple-table/convert-table.js +22 -0
- package/dist/esm/lib/table/simple-table/convert-table.js.map +1 -1
- package/dist/esm/lib/table/simple-table/table-accessors.js +32 -11
- package/dist/esm/lib/table/simple-table/table-accessors.js.map +1 -1
- package/dist/esm/types/batch.js +2 -0
- package/dist/esm/types/batch.js.map +1 -0
- package/dist/esm/types/binary-geometries.js.map +1 -1
- package/dist/esm/types/category-gis.js.map +1 -1
- package/dist/esm/types/category-table.js.map +1 -1
- package/dist/esm/types/schema.js.map +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- 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/simple-table/convert-table.d.ts +34 -1
- package/dist/lib/table/simple-table/convert-table.d.ts.map +1 -1
- package/dist/lib/table/simple-table/table-accessors.d.ts.map +1 -1
- package/dist/types/batch.d.ts +34 -0
- package/dist/types/batch.d.ts.map +1 -0
- package/dist/types/binary-geometries.d.ts +9 -7
- package/dist/types/binary-geometries.d.ts.map +1 -1
- package/dist/types/category-gis.d.ts +1 -1
- package/dist/types/category-gis.d.ts.map +1 -1
- package/dist/types/category-table.d.ts +21 -13
- package/dist/types/category-table.d.ts.map +1 -1
- package/dist/types/schema.d.ts +0 -15
- package/dist/types/schema.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +13 -7
- package/src/lib/table/arrow-api/arrow-like-table.ts +1 -1
- package/src/lib/table/batches/row-table-batch-aggregator.ts +2 -2
- package/src/lib/table/simple-table/convert-table.ts +73 -1
- package/src/lib/table/simple-table/table-accessors.ts +41 -13
- package/src/types/batch.ts +41 -0
- package/src/types/binary-geometries.ts +10 -7
- package/src/types/category-gis.ts +5 -4
- package/src/types/category-table.ts +22 -13
- package/src/types/schema.ts +0 -17
- package/dist/bundle.js +0 -5
- package/dist/index.js +0 -92
- package/dist/lib/mesh/convert-mesh.js +0 -40
- package/dist/lib/mesh/deduce-mesh-schema.js +0 -66
- package/dist/lib/mesh/mesh-to-arrow-table.js +0 -44
- package/dist/lib/mesh/mesh-utils.js +0 -51
- package/dist/lib/table/arrow/arrow-type-utils.js +0 -53
- package/dist/lib/table/arrow/convert-schema-arrow.js +0 -187
- package/dist/lib/table/arrow/convert-table-to-arrow.js +0 -57
- package/dist/lib/table/arrow-api/arrow-like-field.js +0 -34
- package/dist/lib/table/arrow-api/arrow-like-schema.js +0 -81
- package/dist/lib/table/arrow-api/arrow-like-table.js +0 -53
- package/dist/lib/table/arrow-api/arrow-like-type.js +0 -463
- package/dist/lib/table/arrow-api/enum.js +0 -97
- package/dist/lib/table/arrow-api/get-type-info.js +0 -29
- package/dist/lib/table/arrow-api/index.js +0 -25
- package/dist/lib/table/batches/base-table-batch-aggregator.js +0 -60
- package/dist/lib/table/batches/columnar-table-batch-aggregator.js +0 -92
- package/dist/lib/table/batches/row-table-batch-aggregator.js +0 -81
- package/dist/lib/table/batches/table-batch-aggregator.js +0 -3
- package/dist/lib/table/batches/table-batch-builder.js +0 -152
- package/dist/lib/table/simple-table/convert-table.js +0 -65
- package/dist/lib/table/simple-table/data-type.js +0 -93
- package/dist/lib/table/simple-table/make-table.js +0 -95
- package/dist/lib/table/simple-table/row-utils.js +0 -33
- package/dist/lib/table/simple-table/table-accessors.js +0 -319
- package/dist/lib/table/simple-table/table-column.js +0 -41
- package/dist/lib/table/simple-table/table-schema.js +0 -85
- package/dist/lib/utils/assert.js +0 -12
- package/dist/lib/utils/async-queue.js +0 -92
- package/dist/types/binary-geometries.js +0 -2
- package/dist/types/category-gis.js +0 -3
- package/dist/types/category-image.js +0 -2
- package/dist/types/category-mesh.js +0 -3
- package/dist/types/category-table.js +0 -3
- package/dist/types/category-texture.js +0 -3
- package/dist/types/flat-geometries.js +0 -3
- package/dist/types/schema.js +0 -3
- package/dist/types/types.js +0 -2
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This code is adapted from ArrowJS https://github.com/apache/arrow
|
|
3
|
-
// under Apache license http://www.apache.org/licenses/LICENSE-2.0
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.Type = void 0;
|
|
6
|
-
/**
|
|
7
|
-
* Main data type enumeration.
|
|
8
|
-
*
|
|
9
|
-
* Data types in this library are all *logical*. They can be expressed as
|
|
10
|
-
* either a primitive physical type (bytes or bits of some fixed size), a
|
|
11
|
-
* nested type consisting of other data types, or another data type (e.g. a
|
|
12
|
-
* timestamp encoded as an int64).
|
|
13
|
-
*
|
|
14
|
-
* **Note**: Only enum values 0-17 (NONE through Map) are written to an Arrow
|
|
15
|
-
* IPC payload.
|
|
16
|
-
*
|
|
17
|
-
* The rest of the values are specified here so TypeScript can narrow the type
|
|
18
|
-
* signatures further beyond the base Arrow Types. The Arrow DataTypes include
|
|
19
|
-
* metadata like `bitWidth` that impact the type signatures of the values we
|
|
20
|
-
* accept and return.
|
|
21
|
-
*
|
|
22
|
-
* For example, the `Int8Vector` reads 1-byte numbers from an `Int8Array`, an
|
|
23
|
-
* `Int32Vector` reads a 4-byte number from an `Int32Array`, and an `Int64Vector`
|
|
24
|
-
* reads a pair of 4-byte lo, hi 32-bit integers as a zero-copy slice from the
|
|
25
|
-
* underlying `Int32Array`.
|
|
26
|
-
*
|
|
27
|
-
* Library consumers benefit by knowing the narrowest type, since we can ensure
|
|
28
|
-
* the types across all public methods are propagated, and never bail to `any`.
|
|
29
|
-
* These values are _never_ used at runtime, and they will _never_ be written
|
|
30
|
-
* to the flatbuffers metadata of serialized Arrow IPC payloads.
|
|
31
|
-
*/
|
|
32
|
-
var Type;
|
|
33
|
-
(function (Type) {
|
|
34
|
-
/** The default placeholder type */
|
|
35
|
-
Type[Type["NONE"] = 0] = "NONE";
|
|
36
|
-
/** A NULL type having no physical storage */
|
|
37
|
-
Type[Type["Null"] = 1] = "Null";
|
|
38
|
-
/** Signed or unsigned 8, 16, 32, or 64-bit little-endian integer */
|
|
39
|
-
Type[Type["Int"] = 2] = "Int";
|
|
40
|
-
/** 2, 4, or 8-byte floating point value */
|
|
41
|
-
Type[Type["Float"] = 3] = "Float";
|
|
42
|
-
/** Variable-length bytes (no guarantee of UTF8-ness) */
|
|
43
|
-
Type[Type["Binary"] = 4] = "Binary";
|
|
44
|
-
/** UTF8 variable-length string as List<Char> */
|
|
45
|
-
Type[Type["Utf8"] = 5] = "Utf8";
|
|
46
|
-
/** Boolean as 1 bit, LSB bit-packed ordering */
|
|
47
|
-
Type[Type["Bool"] = 6] = "Bool";
|
|
48
|
-
/** Precision-and-scale-based decimal type. Storage type depends on the parameters. */
|
|
49
|
-
Type[Type["Decimal"] = 7] = "Decimal";
|
|
50
|
-
/** int32_t days or int64_t milliseconds since the UNIX epoch */
|
|
51
|
-
Type[Type["Date"] = 8] = "Date";
|
|
52
|
-
/** Time as signed 32 or 64-bit integer, representing either seconds, milliseconds, microseconds, or nanoseconds since midnight since midnight */
|
|
53
|
-
Type[Type["Time"] = 9] = "Time";
|
|
54
|
-
/** Exact timestamp encoded with int64 since UNIX epoch (Default unit millisecond) */
|
|
55
|
-
Type[Type["Timestamp"] = 10] = "Timestamp";
|
|
56
|
-
/** YEAR_MONTH or DAY_TIME interval in SQL style */
|
|
57
|
-
Type[Type["Interval"] = 11] = "Interval";
|
|
58
|
-
/** A list of some logical data type */
|
|
59
|
-
Type[Type["List"] = 12] = "List";
|
|
60
|
-
/** Struct of logical types */
|
|
61
|
-
Type[Type["Struct"] = 13] = "Struct";
|
|
62
|
-
/** Union of logical types */
|
|
63
|
-
Type[Type["Union"] = 14] = "Union";
|
|
64
|
-
/** Fixed-size binary. Each value occupies the same number of bytes */
|
|
65
|
-
Type[Type["FixedSizeBinary"] = 15] = "FixedSizeBinary";
|
|
66
|
-
/** Fixed-size list. Each value occupies the same number of bytes */
|
|
67
|
-
Type[Type["FixedSizeList"] = 16] = "FixedSizeList";
|
|
68
|
-
/** Map of named logical types */
|
|
69
|
-
Type[Type["Map"] = 17] = "Map";
|
|
70
|
-
/** Dictionary aka Category type */
|
|
71
|
-
Type[Type["Dictionary"] = -1] = "Dictionary";
|
|
72
|
-
Type[Type["Int8"] = -2] = "Int8";
|
|
73
|
-
Type[Type["Int16"] = -3] = "Int16";
|
|
74
|
-
Type[Type["Int32"] = -4] = "Int32";
|
|
75
|
-
Type[Type["Int64"] = -5] = "Int64";
|
|
76
|
-
Type[Type["Uint8"] = -6] = "Uint8";
|
|
77
|
-
Type[Type["Uint16"] = -7] = "Uint16";
|
|
78
|
-
Type[Type["Uint32"] = -8] = "Uint32";
|
|
79
|
-
Type[Type["Uint64"] = -9] = "Uint64";
|
|
80
|
-
Type[Type["Float16"] = -10] = "Float16";
|
|
81
|
-
Type[Type["Float32"] = -11] = "Float32";
|
|
82
|
-
Type[Type["Float64"] = -12] = "Float64";
|
|
83
|
-
Type[Type["DateDay"] = -13] = "DateDay";
|
|
84
|
-
Type[Type["DateMillisecond"] = -14] = "DateMillisecond";
|
|
85
|
-
Type[Type["TimestampSecond"] = -15] = "TimestampSecond";
|
|
86
|
-
Type[Type["TimestampMillisecond"] = -16] = "TimestampMillisecond";
|
|
87
|
-
Type[Type["TimestampMicrosecond"] = -17] = "TimestampMicrosecond";
|
|
88
|
-
Type[Type["TimestampNanosecond"] = -18] = "TimestampNanosecond";
|
|
89
|
-
Type[Type["TimeSecond"] = -19] = "TimeSecond";
|
|
90
|
-
Type[Type["TimeMillisecond"] = -20] = "TimeMillisecond";
|
|
91
|
-
Type[Type["TimeMicrosecond"] = -21] = "TimeMicrosecond";
|
|
92
|
-
Type[Type["TimeNanosecond"] = -22] = "TimeNanosecond";
|
|
93
|
-
Type[Type["DenseUnion"] = -23] = "DenseUnion";
|
|
94
|
-
Type[Type["SparseUnion"] = -24] = "SparseUnion";
|
|
95
|
-
Type[Type["IntervalDayTime"] = -25] = "IntervalDayTime";
|
|
96
|
-
Type[Type["IntervalYearMonth"] = -26] = "IntervalYearMonth";
|
|
97
|
-
})(Type || (exports.Type = Type = {}));
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.getTypeInfo = void 0;
|
|
5
|
-
const arrow_like_type_1 = require("./arrow-like-type");
|
|
6
|
-
/**
|
|
7
|
-
* Gets type information from an Arrow type object or "mock" Arrow type object
|
|
8
|
-
* @param arrowTypeLike Arrow Type or type object of similar shape
|
|
9
|
-
*/
|
|
10
|
-
function getTypeInfo(arrowTypeLike) {
|
|
11
|
-
return {
|
|
12
|
-
typeId: arrowTypeLike.typeId,
|
|
13
|
-
ArrayType: arrowTypeLike.ArrayType,
|
|
14
|
-
typeName: arrowTypeLike.toString(),
|
|
15
|
-
typeEnumName: getTypeKey(arrowTypeLike.typeId),
|
|
16
|
-
precision: arrowTypeLike.precision
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
exports.getTypeInfo = getTypeInfo;
|
|
20
|
-
let ReverseType = null;
|
|
21
|
-
function getTypeKey(typeKey) {
|
|
22
|
-
if (!ReverseType) {
|
|
23
|
-
ReverseType = {};
|
|
24
|
-
for (const key in arrow_like_type_1.Type) {
|
|
25
|
-
ReverseType[arrow_like_type_1.Type[key]] = key;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return ReverseType[typeKey];
|
|
29
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.Table = exports.Schema = exports.Field = void 0;
|
|
19
|
-
var arrow_like_field_1 = require("./arrow-like-field");
|
|
20
|
-
Object.defineProperty(exports, "Field", { enumerable: true, get: function () { return arrow_like_field_1.ArrowLikeField; } });
|
|
21
|
-
var arrow_like_schema_1 = require("./arrow-like-schema");
|
|
22
|
-
Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return arrow_like_schema_1.ArrowLikeSchema; } });
|
|
23
|
-
var arrow_like_table_1 = require("./arrow-like-table");
|
|
24
|
-
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return arrow_like_table_1.ArrowLikeTable; } });
|
|
25
|
-
__exportStar(require("./arrow-like-type"), exports);
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.BaseTableBatchAggregator = void 0;
|
|
5
|
-
const DEFAULT_ROW_COUNT = 100;
|
|
6
|
-
class BaseTableBatchAggregator {
|
|
7
|
-
constructor(schema, options) {
|
|
8
|
-
this.length = 0;
|
|
9
|
-
this.rows = null;
|
|
10
|
-
this.cursor = 0;
|
|
11
|
-
this._headers = [];
|
|
12
|
-
this.options = options;
|
|
13
|
-
this.schema = schema;
|
|
14
|
-
// schema is an array if there're no headers
|
|
15
|
-
// object if there are headers
|
|
16
|
-
if (!Array.isArray(schema)) {
|
|
17
|
-
this._headers = [];
|
|
18
|
-
for (const key in schema) {
|
|
19
|
-
this._headers[schema[key].index] = schema[key].name;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
rowCount() {
|
|
24
|
-
return this.length;
|
|
25
|
-
}
|
|
26
|
-
addArrayRow(row, cursor) {
|
|
27
|
-
if (Number.isFinite(cursor)) {
|
|
28
|
-
this.cursor = cursor;
|
|
29
|
-
}
|
|
30
|
-
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
31
|
-
this.rows[this.length] = row;
|
|
32
|
-
this.length++;
|
|
33
|
-
}
|
|
34
|
-
addObjectRow(row, cursor) {
|
|
35
|
-
if (Number.isFinite(cursor)) {
|
|
36
|
-
this.cursor = cursor;
|
|
37
|
-
}
|
|
38
|
-
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
39
|
-
this.rows[this.length] = row;
|
|
40
|
-
this.length++;
|
|
41
|
-
}
|
|
42
|
-
getBatch() {
|
|
43
|
-
let rows = this.rows;
|
|
44
|
-
if (!rows) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
rows = rows.slice(0, this.length);
|
|
48
|
-
this.rows = null;
|
|
49
|
-
const batch = {
|
|
50
|
-
shape: this.options.shape,
|
|
51
|
-
batchType: 'data',
|
|
52
|
-
data: rows,
|
|
53
|
-
length: this.length,
|
|
54
|
-
schema: this.schema,
|
|
55
|
-
cursor: this.cursor
|
|
56
|
-
};
|
|
57
|
-
return batch;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.BaseTableBatchAggregator = BaseTableBatchAggregator;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.ColumnarTableBatchAggregator = void 0;
|
|
5
|
-
const DEFAULT_ROW_COUNT = 100;
|
|
6
|
-
class ColumnarTableBatchAggregator {
|
|
7
|
-
constructor(schema, options) {
|
|
8
|
-
this.length = 0;
|
|
9
|
-
this.allocated = 0;
|
|
10
|
-
this.columns = {};
|
|
11
|
-
this.schema = schema;
|
|
12
|
-
this._reallocateColumns();
|
|
13
|
-
}
|
|
14
|
-
rowCount() {
|
|
15
|
-
return this.length;
|
|
16
|
-
}
|
|
17
|
-
addArrayRow(row) {
|
|
18
|
-
// If user keeps pushing rows beyond batch size, reallocate
|
|
19
|
-
this._reallocateColumns();
|
|
20
|
-
let i = 0;
|
|
21
|
-
// TODO what if no csv header, columns not populated?
|
|
22
|
-
for (const fieldName in this.columns) {
|
|
23
|
-
this.columns[fieldName][this.length] = row[i++];
|
|
24
|
-
}
|
|
25
|
-
this.length++;
|
|
26
|
-
}
|
|
27
|
-
addObjectRow(row) {
|
|
28
|
-
// If user keeps pushing rows beyond batch size, reallocate
|
|
29
|
-
this._reallocateColumns();
|
|
30
|
-
for (const fieldName in row) {
|
|
31
|
-
this.columns[fieldName][this.length] = row[fieldName];
|
|
32
|
-
}
|
|
33
|
-
this.length++;
|
|
34
|
-
}
|
|
35
|
-
getBatch() {
|
|
36
|
-
this._pruneColumns();
|
|
37
|
-
const columns = Array.isArray(this.schema) ? this.columns : {};
|
|
38
|
-
// schema is an array if there're no headers
|
|
39
|
-
// object if there are headers
|
|
40
|
-
// columns should match schema format
|
|
41
|
-
if (!Array.isArray(this.schema)) {
|
|
42
|
-
for (const fieldName in this.schema) {
|
|
43
|
-
const field = this.schema[fieldName];
|
|
44
|
-
columns[field.name] = this.columns[field.index];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
this.columns = {};
|
|
48
|
-
const batch = {
|
|
49
|
-
shape: 'columnar-table',
|
|
50
|
-
batchType: 'data',
|
|
51
|
-
data: columns,
|
|
52
|
-
schema: this.schema,
|
|
53
|
-
length: this.length
|
|
54
|
-
};
|
|
55
|
-
return batch;
|
|
56
|
-
}
|
|
57
|
-
// HELPERS
|
|
58
|
-
_reallocateColumns() {
|
|
59
|
-
if (this.length < this.allocated) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
// @ts-ignore TODO
|
|
63
|
-
this.allocated = this.allocated > 0 ? (this.allocated *= 2) : DEFAULT_ROW_COUNT;
|
|
64
|
-
this.columns = {};
|
|
65
|
-
for (const fieldName in this.schema) {
|
|
66
|
-
const field = this.schema[fieldName];
|
|
67
|
-
const ArrayType = field.type || Float32Array;
|
|
68
|
-
const oldColumn = this.columns[field.index];
|
|
69
|
-
if (oldColumn && ArrayBuffer.isView(oldColumn)) {
|
|
70
|
-
// Copy the old data to the new array
|
|
71
|
-
const typedArray = new ArrayType(this.allocated);
|
|
72
|
-
typedArray.set(oldColumn);
|
|
73
|
-
this.columns[field.index] = typedArray;
|
|
74
|
-
}
|
|
75
|
-
else if (oldColumn) {
|
|
76
|
-
// Plain array
|
|
77
|
-
oldColumn.length = this.allocated;
|
|
78
|
-
this.columns[field.index] = oldColumn;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
// Create new
|
|
82
|
-
this.columns[field.index] = new ArrayType(this.allocated);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
_pruneColumns() {
|
|
87
|
-
for (const [columnName, column] of Object.entries(this.columns)) {
|
|
88
|
-
this.columns[columnName] = column.slice(0, this.length);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
exports.ColumnarTableBatchAggregator = ColumnarTableBatchAggregator;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.RowTableBatchAggregator = void 0;
|
|
5
|
-
// import type {ArrayRowTableBatch, ObjectRowTableBatch} from '../../category/table';
|
|
6
|
-
const row_utils_1 = require("../simple-table/row-utils");
|
|
7
|
-
const DEFAULT_ROW_COUNT = 100;
|
|
8
|
-
class RowTableBatchAggregator {
|
|
9
|
-
constructor(schema, options) {
|
|
10
|
-
this.length = 0;
|
|
11
|
-
this.objectRows = null;
|
|
12
|
-
this.arrayRows = null;
|
|
13
|
-
this.cursor = 0;
|
|
14
|
-
this._headers = [];
|
|
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 (!Array.isArray(schema)) {
|
|
20
|
-
this._headers = [];
|
|
21
|
-
for (const key in schema) {
|
|
22
|
-
this._headers[schema[key].index] = schema[key].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
|
-
// eslint-disable-next-line default-case
|
|
34
|
-
switch (this.options.shape) {
|
|
35
|
-
case 'object-row-table':
|
|
36
|
-
const rowObject = (0, row_utils_1.convertToObjectRow)(row, this._headers);
|
|
37
|
-
this.addObjectRow(rowObject, cursor);
|
|
38
|
-
break;
|
|
39
|
-
case 'array-row-table':
|
|
40
|
-
this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT);
|
|
41
|
-
this.arrayRows[this.length] = row;
|
|
42
|
-
this.length++;
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
addObjectRow(row, cursor) {
|
|
47
|
-
if (Number.isFinite(cursor)) {
|
|
48
|
-
this.cursor = cursor;
|
|
49
|
-
}
|
|
50
|
-
// eslint-disable-next-line default-case
|
|
51
|
-
switch (this.options.shape) {
|
|
52
|
-
case 'array-row-table':
|
|
53
|
-
const rowArray = (0, row_utils_1.convertToArrayRow)(row, this._headers);
|
|
54
|
-
this.addArrayRow(rowArray, cursor);
|
|
55
|
-
break;
|
|
56
|
-
case 'object-row-table':
|
|
57
|
-
this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT);
|
|
58
|
-
this.objectRows[this.length] = row;
|
|
59
|
-
this.length++;
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
getBatch() {
|
|
64
|
-
let rows = this.arrayRows || this.objectRows;
|
|
65
|
-
if (!rows) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
rows = rows.slice(0, this.length);
|
|
69
|
-
this.arrayRows = null;
|
|
70
|
-
this.objectRows = null;
|
|
71
|
-
return {
|
|
72
|
-
shape: this.options.shape,
|
|
73
|
-
batchType: 'data',
|
|
74
|
-
data: rows,
|
|
75
|
-
length: this.length,
|
|
76
|
-
schema: this.schema,
|
|
77
|
-
cursor: this.cursor
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.RowTableBatchAggregator = RowTableBatchAggregator;
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.TableBatchBuilder = void 0;
|
|
5
|
-
const base_table_batch_aggregator_1 = require("./base-table-batch-aggregator");
|
|
6
|
-
const row_table_batch_aggregator_1 = require("./row-table-batch-aggregator");
|
|
7
|
-
const columnar_table_batch_aggregator_1 = require("./columnar-table-batch-aggregator");
|
|
8
|
-
const DEFAULT_OPTIONS = {
|
|
9
|
-
shape: 'array-row-table',
|
|
10
|
-
batchSize: 'auto',
|
|
11
|
-
batchDebounceMs: 0,
|
|
12
|
-
limit: 0,
|
|
13
|
-
_limitMB: 0
|
|
14
|
-
};
|
|
15
|
-
const ERR_MESSAGE = 'TableBatchBuilder';
|
|
16
|
-
/** Incrementally builds batches from a stream of rows */
|
|
17
|
-
class TableBatchBuilder {
|
|
18
|
-
constructor(schema, options) {
|
|
19
|
-
this.aggregator = null;
|
|
20
|
-
this.batchCount = 0;
|
|
21
|
-
this.bytesUsed = 0;
|
|
22
|
-
this.isChunkComplete = false;
|
|
23
|
-
this.lastBatchEmittedMs = Date.now();
|
|
24
|
-
this.totalLength = 0;
|
|
25
|
-
this.totalBytes = 0;
|
|
26
|
-
this.rowBytes = 0;
|
|
27
|
-
this.schema = schema;
|
|
28
|
-
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
29
|
-
}
|
|
30
|
-
limitReached() {
|
|
31
|
-
if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
if (Boolean(this.options?._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
/** @deprecated Use addArrayRow or addObjectRow */
|
|
40
|
-
addRow(row) {
|
|
41
|
-
if (this.limitReached()) {
|
|
42
|
-
return;
|
|
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
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
this.addObjectRow(row);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
/** Add one row to the batch */
|
|
55
|
-
addArrayRow(row) {
|
|
56
|
-
if (!this.aggregator) {
|
|
57
|
-
const TableBatchType = this._getTableBatchType();
|
|
58
|
-
this.aggregator = new TableBatchType(this.schema, this.options);
|
|
59
|
-
}
|
|
60
|
-
this.aggregator.addArrayRow(row);
|
|
61
|
-
}
|
|
62
|
-
/** Add one row to the batch */
|
|
63
|
-
addObjectRow(row) {
|
|
64
|
-
if (!this.aggregator) {
|
|
65
|
-
const TableBatchType = this._getTableBatchType();
|
|
66
|
-
this.aggregator = new TableBatchType(this.schema, this.options);
|
|
67
|
-
}
|
|
68
|
-
this.aggregator.addObjectRow(row);
|
|
69
|
-
}
|
|
70
|
-
/** Mark an incoming raw memory chunk has completed */
|
|
71
|
-
chunkComplete(chunk) {
|
|
72
|
-
if (chunk instanceof ArrayBuffer) {
|
|
73
|
-
this.bytesUsed += chunk.byteLength;
|
|
74
|
-
}
|
|
75
|
-
if (typeof chunk === 'string') {
|
|
76
|
-
this.bytesUsed += chunk.length;
|
|
77
|
-
}
|
|
78
|
-
this.isChunkComplete = true;
|
|
79
|
-
}
|
|
80
|
-
getFullBatch(options) {
|
|
81
|
-
return this._isFull() ? this._getBatch(options) : null;
|
|
82
|
-
}
|
|
83
|
-
getFinalBatch(options) {
|
|
84
|
-
return this._getBatch(options);
|
|
85
|
-
}
|
|
86
|
-
// INTERNAL
|
|
87
|
-
_estimateRowMB(row) {
|
|
88
|
-
return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
|
|
89
|
-
}
|
|
90
|
-
_isFull() {
|
|
91
|
-
// No batch, not ready
|
|
92
|
-
if (!this.aggregator || this.aggregator.rowCount() === 0) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
// if batchSize === 'auto' we wait for chunk to complete
|
|
96
|
-
// if batchSize === number, ensure we have enough rows
|
|
97
|
-
if (this.options.batchSize === 'auto') {
|
|
98
|
-
if (!this.isChunkComplete) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else if (this.options.batchSize > this.aggregator.rowCount()) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
// Debounce batches
|
|
106
|
-
if (this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs) {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
// Emit batch
|
|
110
|
-
this.isChunkComplete = false;
|
|
111
|
-
this.lastBatchEmittedMs = Date.now();
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* bytesUsed can be set via chunkComplete or via getBatch*
|
|
116
|
-
*/
|
|
117
|
-
_getBatch(options) {
|
|
118
|
-
if (!this.aggregator) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
// TODO - this can overly increment bytes used?
|
|
122
|
-
if (options?.bytesUsed) {
|
|
123
|
-
this.bytesUsed = options.bytesUsed;
|
|
124
|
-
}
|
|
125
|
-
const normalizedBatch = this.aggregator.getBatch();
|
|
126
|
-
normalizedBatch.count = this.batchCount;
|
|
127
|
-
normalizedBatch.bytesUsed = this.bytesUsed;
|
|
128
|
-
Object.assign(normalizedBatch, options);
|
|
129
|
-
this.batchCount++;
|
|
130
|
-
this.aggregator = null;
|
|
131
|
-
return normalizedBatch;
|
|
132
|
-
}
|
|
133
|
-
_getTableBatchType() {
|
|
134
|
-
switch (this.options.shape) {
|
|
135
|
-
case 'row-table':
|
|
136
|
-
return base_table_batch_aggregator_1.BaseTableBatchAggregator;
|
|
137
|
-
case 'array-row-table':
|
|
138
|
-
case 'object-row-table':
|
|
139
|
-
return row_table_batch_aggregator_1.RowTableBatchAggregator;
|
|
140
|
-
case 'columnar-table':
|
|
141
|
-
return columnar_table_batch_aggregator_1.ColumnarTableBatchAggregator;
|
|
142
|
-
case 'arrow-table':
|
|
143
|
-
if (!TableBatchBuilder.ArrowBatch) {
|
|
144
|
-
throw new Error(ERR_MESSAGE);
|
|
145
|
-
}
|
|
146
|
-
return TableBatchBuilder.ArrowBatch;
|
|
147
|
-
default:
|
|
148
|
-
throw new Error(ERR_MESSAGE);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
exports.TableBatchBuilder = TableBatchBuilder;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeObjectRowTable = exports.makeArrayRowTable = exports.makeColumnarTable = void 0;
|
|
4
|
-
// loaders.gl, MIT license
|
|
5
|
-
const table_accessors_1 = require("./table-accessors");
|
|
6
|
-
const table_schema_1 = require("./table-schema");
|
|
7
|
-
const table_column_1 = require("./table-column");
|
|
8
|
-
/** Convert any simple table into columnar format */
|
|
9
|
-
function makeColumnarTable(table) {
|
|
10
|
-
// TODO - should schema really be optional?
|
|
11
|
-
const schema = table.schema || (0, table_schema_1.deduceTableSchema)(table);
|
|
12
|
-
const fields = table.schema?.fields || [];
|
|
13
|
-
if (table.shape === 'columnar-table') {
|
|
14
|
-
return { ...table, schema };
|
|
15
|
-
}
|
|
16
|
-
const length = (0, table_accessors_1.getTableLength)(table);
|
|
17
|
-
const columns = {};
|
|
18
|
-
for (const field of fields) {
|
|
19
|
-
const column = (0, table_column_1.makeColumnFromField)(field, length);
|
|
20
|
-
columns[field.name] = column;
|
|
21
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
22
|
-
column[rowIndex] = (0, table_accessors_1.getTableCell)(table, rowIndex, field.name);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
shape: 'columnar-table',
|
|
27
|
-
schema,
|
|
28
|
-
data: columns
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
exports.makeColumnarTable = makeColumnarTable;
|
|
32
|
-
/** Convert any table into array row format */
|
|
33
|
-
function makeArrayRowTable(table) {
|
|
34
|
-
if (table.shape === 'array-row-table') {
|
|
35
|
-
return table;
|
|
36
|
-
}
|
|
37
|
-
const length = (0, table_accessors_1.getTableLength)(table);
|
|
38
|
-
const data = new Array(length);
|
|
39
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
40
|
-
data[rowIndex] = (0, table_accessors_1.getTableRowAsArray)(table, rowIndex);
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
shape: 'array-row-table',
|
|
44
|
-
schema: table.schema,
|
|
45
|
-
data
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
exports.makeArrayRowTable = makeArrayRowTable;
|
|
49
|
-
/** Convert any table into object row format */
|
|
50
|
-
function makeObjectRowTable(table) {
|
|
51
|
-
if (table.shape === 'object-row-table') {
|
|
52
|
-
return table;
|
|
53
|
-
}
|
|
54
|
-
const length = (0, table_accessors_1.getTableLength)(table);
|
|
55
|
-
const data = new Array(length);
|
|
56
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
57
|
-
data[rowIndex] = (0, table_accessors_1.getTableRowAsObject)(table, rowIndex);
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
shape: 'object-row-table',
|
|
61
|
-
schema: table.schema,
|
|
62
|
-
data
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
exports.makeObjectRowTable = makeObjectRowTable;
|