@loaders.gl/schema 3.4.10 → 3.4.12

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.
Files changed (32) hide show
  1. package/package.json +2 -2
  2. package/dist/bundle.js +0 -5
  3. package/dist/category/common.js +0 -10
  4. package/dist/category/gis.js +0 -2
  5. package/dist/category/image/image.js +0 -2
  6. package/dist/category/mesh/convert-mesh.js +0 -40
  7. package/dist/category/mesh/deduce-mesh-schema.js +0 -62
  8. package/dist/category/mesh/mesh-to-arrow-table.js +0 -34
  9. package/dist/category/mesh/mesh-types.js +0 -2
  10. package/dist/category/mesh/mesh-utils.js +0 -51
  11. package/dist/category/table/deduce-table-schema.js +0 -106
  12. package/dist/category/table/table-types.js +0 -2
  13. package/dist/category/texture/texture.js +0 -2
  14. package/dist/index.js +0 -75
  15. package/dist/lib/arrow/arrow-like-type-utils.js +0 -27
  16. package/dist/lib/arrow/arrow-type-utils.js +0 -50
  17. package/dist/lib/arrow/get-type-info.js +0 -28
  18. package/dist/lib/batches/base-table-batch-aggregator.js +0 -58
  19. package/dist/lib/batches/columnar-table-batch-aggregator.js +0 -90
  20. package/dist/lib/batches/row-table-batch-aggregator.js +0 -79
  21. package/dist/lib/batches/table-batch-aggregator.js +0 -2
  22. package/dist/lib/batches/table-batch-builder.js +0 -153
  23. package/dist/lib/schema/impl/enum.js +0 -97
  24. package/dist/lib/schema/impl/field.js +0 -32
  25. package/dist/lib/schema/impl/schema.js +0 -83
  26. package/dist/lib/schema/impl/type.js +0 -462
  27. package/dist/lib/schema/schema.js +0 -90
  28. package/dist/lib/schema-utils/deduce-column-type.js +0 -92
  29. package/dist/lib/utils/assert.js +0 -12
  30. package/dist/lib/utils/async-queue.js +0 -92
  31. package/dist/lib/utils/row-utils.js +0 -33
  32. package/dist/types.js +0 -2
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const DEFAULT_ROW_COUNT = 100;
4
- class ColumnarTableBatchAggregator {
5
- constructor(schema, options) {
6
- this.length = 0;
7
- this.allocated = 0;
8
- this.columns = {};
9
- this.schema = schema;
10
- this._reallocateColumns();
11
- }
12
- rowCount() {
13
- return this.length;
14
- }
15
- addArrayRow(row) {
16
- // If user keeps pushing rows beyond batch size, reallocate
17
- this._reallocateColumns();
18
- let i = 0;
19
- // TODO what if no csv header, columns not populated?
20
- for (const fieldName in this.columns) {
21
- this.columns[fieldName][this.length] = row[i++];
22
- }
23
- this.length++;
24
- }
25
- addObjectRow(row) {
26
- // If user keeps pushing rows beyond batch size, reallocate
27
- this._reallocateColumns();
28
- for (const fieldName in row) {
29
- this.columns[fieldName][this.length] = row[fieldName];
30
- }
31
- this.length++;
32
- }
33
- getBatch() {
34
- this._pruneColumns();
35
- const columns = Array.isArray(this.schema) ? this.columns : {};
36
- // schema is an array if there're no headers
37
- // object if there are headers
38
- // columns should match schema format
39
- if (!Array.isArray(this.schema)) {
40
- for (const fieldName in this.schema) {
41
- const field = this.schema[fieldName];
42
- columns[field.name] = this.columns[field.index];
43
- }
44
- }
45
- this.columns = {};
46
- const batch = {
47
- shape: 'columnar-table',
48
- batchType: 'data',
49
- data: columns,
50
- schema: this.schema,
51
- length: this.length
52
- };
53
- return batch;
54
- }
55
- // HELPERS
56
- _reallocateColumns() {
57
- if (this.length < this.allocated) {
58
- return;
59
- }
60
- // @ts-ignore TODO
61
- this.allocated = this.allocated > 0 ? (this.allocated *= 2) : DEFAULT_ROW_COUNT;
62
- this.columns = {};
63
- for (const fieldName in this.schema) {
64
- const field = this.schema[fieldName];
65
- const ArrayType = field.type || Float32Array;
66
- const oldColumn = this.columns[field.index];
67
- if (oldColumn && ArrayBuffer.isView(oldColumn)) {
68
- // Copy the old data to the new array
69
- const typedArray = new ArrayType(this.allocated);
70
- typedArray.set(oldColumn);
71
- this.columns[field.index] = typedArray;
72
- }
73
- else if (oldColumn) {
74
- // Plain array
75
- oldColumn.length = this.allocated;
76
- this.columns[field.index] = oldColumn;
77
- }
78
- else {
79
- // Create new
80
- this.columns[field.index] = new ArrayType(this.allocated);
81
- }
82
- }
83
- }
84
- _pruneColumns() {
85
- for (const [columnName, column] of Object.entries(this.columns)) {
86
- this.columns[columnName] = column.slice(0, this.length);
87
- }
88
- }
89
- }
90
- exports.default = ColumnarTableBatchAggregator;
@@ -1,79 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // import type {ArrayRowTableBatch, ObjectRowTableBatch} from '../../category/table';
4
- const row_utils_1 = require("../utils/row-utils");
5
- const DEFAULT_ROW_COUNT = 100;
6
- class RowTableBatchAggregator {
7
- constructor(schema, options) {
8
- this.length = 0;
9
- this.objectRows = null;
10
- this.arrayRows = null;
11
- this.cursor = 0;
12
- this._headers = [];
13
- this.options = options;
14
- this.schema = schema;
15
- // schema is an array if there're no headers
16
- // object if there are headers
17
- if (!Array.isArray(schema)) {
18
- this._headers = [];
19
- for (const key in schema) {
20
- this._headers[schema[key].index] = schema[key].name;
21
- }
22
- }
23
- }
24
- rowCount() {
25
- return this.length;
26
- }
27
- addArrayRow(row, cursor) {
28
- if (Number.isFinite(cursor)) {
29
- this.cursor = cursor;
30
- }
31
- // eslint-disable-next-line default-case
32
- switch (this.options.shape) {
33
- case 'object-row-table':
34
- const rowObject = (0, row_utils_1.convertToObjectRow)(row, this._headers);
35
- this.addObjectRow(rowObject, cursor);
36
- break;
37
- case 'array-row-table':
38
- this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT);
39
- this.arrayRows[this.length] = row;
40
- this.length++;
41
- break;
42
- }
43
- }
44
- addObjectRow(row, cursor) {
45
- if (Number.isFinite(cursor)) {
46
- this.cursor = cursor;
47
- }
48
- // eslint-disable-next-line default-case
49
- switch (this.options.shape) {
50
- case 'array-row-table':
51
- const rowArray = (0, row_utils_1.convertToArrayRow)(row, this._headers);
52
- this.addArrayRow(rowArray, cursor);
53
- break;
54
- case 'object-row-table':
55
- this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT);
56
- this.objectRows[this.length] = row;
57
- this.length++;
58
- break;
59
- }
60
- }
61
- getBatch() {
62
- let rows = this.arrayRows || this.objectRows;
63
- if (!rows) {
64
- return null;
65
- }
66
- rows = rows.slice(0, this.length);
67
- this.arrayRows = null;
68
- this.objectRows = null;
69
- return {
70
- shape: this.options.shape,
71
- batchType: 'data',
72
- data: rows,
73
- length: this.length,
74
- schema: this.schema,
75
- cursor: this.cursor
76
- };
77
- }
78
- }
79
- exports.default = RowTableBatchAggregator;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,153 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const base_table_batch_aggregator_1 = __importDefault(require("./base-table-batch-aggregator"));
7
- const row_table_batch_aggregator_1 = __importDefault(require("./row-table-batch-aggregator"));
8
- const columnar_table_batch_aggregator_1 = __importDefault(require("./columnar-table-batch-aggregator"));
9
- const DEFAULT_OPTIONS = {
10
- shape: 'array-row-table',
11
- batchSize: 'auto',
12
- batchDebounceMs: 0,
13
- limit: 0,
14
- _limitMB: 0
15
- };
16
- const ERR_MESSAGE = 'TableBatchBuilder';
17
- /** Incrementally builds batches from a stream of rows */
18
- class TableBatchBuilder {
19
- constructor(schema, options) {
20
- this.aggregator = null;
21
- this.batchCount = 0;
22
- this.bytesUsed = 0;
23
- this.isChunkComplete = false;
24
- this.lastBatchEmittedMs = Date.now();
25
- this.totalLength = 0;
26
- this.totalBytes = 0;
27
- this.rowBytes = 0;
28
- this.schema = schema;
29
- this.options = { ...DEFAULT_OPTIONS, ...options };
30
- }
31
- limitReached() {
32
- if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {
33
- return true;
34
- }
35
- if (Boolean(this.options?._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {
36
- return true;
37
- }
38
- return false;
39
- }
40
- /** @deprecated Use addArrayRow or addObjectRow */
41
- addRow(row) {
42
- if (this.limitReached()) {
43
- return;
44
- }
45
- this.totalLength++;
46
- this.rowBytes = this.rowBytes || this._estimateRowMB(row);
47
- this.totalBytes += this.rowBytes;
48
- if (Array.isArray(row)) {
49
- this.addArrayRow(row);
50
- }
51
- else {
52
- this.addObjectRow(row);
53
- }
54
- }
55
- /** Add one row to the batch */
56
- addArrayRow(row) {
57
- if (!this.aggregator) {
58
- const TableBatchType = this._getTableBatchType();
59
- this.aggregator = new TableBatchType(this.schema, this.options);
60
- }
61
- this.aggregator.addArrayRow(row);
62
- }
63
- /** Add one row to the batch */
64
- addObjectRow(row) {
65
- if (!this.aggregator) {
66
- const TableBatchType = this._getTableBatchType();
67
- this.aggregator = new TableBatchType(this.schema, this.options);
68
- }
69
- this.aggregator.addObjectRow(row);
70
- }
71
- /** Mark an incoming raw memory chunk has completed */
72
- chunkComplete(chunk) {
73
- if (chunk instanceof ArrayBuffer) {
74
- this.bytesUsed += chunk.byteLength;
75
- }
76
- if (typeof chunk === 'string') {
77
- this.bytesUsed += chunk.length;
78
- }
79
- this.isChunkComplete = true;
80
- }
81
- getFullBatch(options) {
82
- return this._isFull() ? this._getBatch(options) : null;
83
- }
84
- getFinalBatch(options) {
85
- return this._getBatch(options);
86
- }
87
- // INTERNAL
88
- _estimateRowMB(row) {
89
- return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
90
- }
91
- _isFull() {
92
- // No batch, not ready
93
- if (!this.aggregator || this.aggregator.rowCount() === 0) {
94
- return false;
95
- }
96
- // if batchSize === 'auto' we wait for chunk to complete
97
- // if batchSize === number, ensure we have enough rows
98
- if (this.options.batchSize === 'auto') {
99
- if (!this.isChunkComplete) {
100
- return false;
101
- }
102
- }
103
- else if (this.options.batchSize > this.aggregator.rowCount()) {
104
- return false;
105
- }
106
- // Debounce batches
107
- if (this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs) {
108
- return false;
109
- }
110
- // Emit batch
111
- this.isChunkComplete = false;
112
- this.lastBatchEmittedMs = Date.now();
113
- return true;
114
- }
115
- /**
116
- * bytesUsed can be set via chunkComplete or via getBatch*
117
- */
118
- _getBatch(options) {
119
- if (!this.aggregator) {
120
- return null;
121
- }
122
- // TODO - this can overly increment bytes used?
123
- if (options?.bytesUsed) {
124
- this.bytesUsed = options.bytesUsed;
125
- }
126
- const normalizedBatch = this.aggregator.getBatch();
127
- normalizedBatch.count = this.batchCount;
128
- normalizedBatch.bytesUsed = this.bytesUsed;
129
- Object.assign(normalizedBatch, options);
130
- this.batchCount++;
131
- this.aggregator = null;
132
- return normalizedBatch;
133
- }
134
- _getTableBatchType() {
135
- switch (this.options.shape) {
136
- case 'row-table':
137
- return base_table_batch_aggregator_1.default;
138
- case 'array-row-table':
139
- case 'object-row-table':
140
- return row_table_batch_aggregator_1.default;
141
- case 'columnar-table':
142
- return columnar_table_batch_aggregator_1.default;
143
- case 'arrow-table':
144
- if (!TableBatchBuilder.ArrowBatch) {
145
- throw new Error(ERR_MESSAGE);
146
- }
147
- return TableBatchBuilder.ArrowBatch;
148
- default:
149
- throw new Error(ERR_MESSAGE);
150
- }
151
- }
152
- }
153
- exports.default = TableBatchBuilder;
@@ -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 || (exports.Type = {}));
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * ArrowJS `Field` API-compatible class for row-based tables
5
- * https://loaders.gl/arrowjs/docs/api-reference/field
6
- * A field holds name, nullable, and metadata information about a table "column"
7
- * A Schema is essentially a list of fields
8
- */
9
- class Field {
10
- constructor(name, type, nullable = false, metadata = new Map()) {
11
- this.name = name;
12
- this.type = type;
13
- this.nullable = nullable;
14
- this.metadata = metadata;
15
- }
16
- get typeId() {
17
- return this.type && this.type.typeId;
18
- }
19
- clone() {
20
- return new Field(this.name, this.type, this.nullable, this.metadata);
21
- }
22
- compareTo(other) {
23
- return (this.name === other.name &&
24
- this.type === other.type &&
25
- this.nullable === other.nullable &&
26
- this.metadata === other.metadata);
27
- }
28
- toString() {
29
- return `${this.type}${this.nullable ? ', nullable' : ''}${this.metadata ? `, metadata: ${this.metadata}` : ''}`;
30
- }
31
- }
32
- exports.default = Field;
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert_1 = require("../../utils/assert");
4
- /**
5
- * ArrowJS `Schema` API-compatible class for row-based tables (returned from `DataTable`)
6
- * https://loaders.gl/arrowjs/docs/api-reference/schema
7
- */
8
- class Schema {
9
- constructor(fields, metadata) {
10
- (0, assert_1.assert)(Array.isArray(fields));
11
- checkNames(fields);
12
- // For kepler fields, create arrow compatible `Fields` that have kepler fields as `metadata`
13
- this.fields = fields;
14
- this.metadata = metadata || new Map();
15
- }
16
- // TODO - arrow only seems to compare fields, not metadata
17
- compareTo(other) {
18
- if (this.metadata !== other.metadata) {
19
- return false;
20
- }
21
- if (this.fields.length !== other.fields.length) {
22
- return false;
23
- }
24
- for (let i = 0; i < this.fields.length; ++i) {
25
- if (!this.fields[i].compareTo(other.fields[i])) {
26
- return false;
27
- }
28
- }
29
- return true;
30
- }
31
- select(...columnNames) {
32
- // Ensure column names reference valid fields
33
- const nameMap = Object.create(null);
34
- for (const name of columnNames) {
35
- nameMap[name] = true;
36
- }
37
- const selectedFields = this.fields.filter((field) => nameMap[field.name]);
38
- return new Schema(selectedFields, this.metadata);
39
- }
40
- selectAt(...columnIndices) {
41
- // Ensure column indices reference valid fields
42
- const selectedFields = columnIndices.map((index) => this.fields[index]).filter(Boolean);
43
- return new Schema(selectedFields, this.metadata);
44
- }
45
- assign(schemaOrFields) {
46
- let fields;
47
- let metadata = this.metadata;
48
- if (schemaOrFields instanceof Schema) {
49
- const otherSchema = schemaOrFields;
50
- fields = otherSchema.fields;
51
- metadata = mergeMaps(mergeMaps(new Map(), this.metadata), otherSchema.metadata);
52
- }
53
- else {
54
- fields = schemaOrFields;
55
- }
56
- // Create a merged list of fields, overwrite fields in place, new fields at end
57
- const fieldMap = Object.create(null);
58
- for (const field of this.fields) {
59
- fieldMap[field.name] = field;
60
- }
61
- for (const field of fields) {
62
- fieldMap[field.name] = field;
63
- }
64
- const mergedFields = Object.values(fieldMap);
65
- return new Schema(mergedFields, metadata);
66
- }
67
- }
68
- exports.default = Schema;
69
- // Warn if any duplicated field names
70
- function checkNames(fields) {
71
- const usedNames = {};
72
- for (const field of fields) {
73
- if (usedNames[field.name]) {
74
- // eslint-disable-next-line
75
- console.warn('Schema: duplicated field name', field.name, field);
76
- }
77
- usedNames[field.name] = true;
78
- }
79
- }
80
- function mergeMaps(m1, m2) {
81
- // @ts-ignore
82
- return new Map([...(m1 || new Map()), ...(m2 || new Map())]);
83
- }