@loaders.gl/schema 4.0.0-alpha.22 → 4.0.0-alpha.24
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 +517 -927
- package/dist/es5/index.js +7 -0
- package/dist/es5/index.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/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/esm/index.js +1 -0
- package/dist/esm/index.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/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/index.d.ts +3 -2
- package/dist/index.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/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 -11
- package/dist/types/category-table.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +8 -4
- package/src/lib/table/simple-table/convert-table.ts +73 -1
- package/src/types/binary-geometries.ts +10 -7
- package/src/types/category-gis.ts +5 -4
- package/src/types/category-table.ts +26 -11
- 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,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;
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// loaders.gl, MIT license
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.getArrayTypeFromDataType = exports.getDataTypeFromTypedArray = exports.getDataTypeFromArray = exports.getDataTypeFromValue = void 0;
|
|
5
|
-
/** Deduce column types from values */
|
|
6
|
-
function getDataTypeFromValue(value, defaultNumberType = 'float32') {
|
|
7
|
-
if (value instanceof Date) {
|
|
8
|
-
return 'date-millisecond';
|
|
9
|
-
}
|
|
10
|
-
if (value instanceof Number) {
|
|
11
|
-
return defaultNumberType;
|
|
12
|
-
}
|
|
13
|
-
if (typeof value === 'string') {
|
|
14
|
-
return 'utf8';
|
|
15
|
-
}
|
|
16
|
-
if (value === null || value === 'undefined') {
|
|
17
|
-
return 'null';
|
|
18
|
-
}
|
|
19
|
-
return 'null';
|
|
20
|
-
}
|
|
21
|
-
exports.getDataTypeFromValue = getDataTypeFromValue;
|
|
22
|
-
/**
|
|
23
|
-
* Deduces a simple data type "descriptor from a typed array instance
|
|
24
|
-
*/
|
|
25
|
-
function getDataTypeFromArray(array) {
|
|
26
|
-
let type = getDataTypeFromTypedArray(array);
|
|
27
|
-
if (type !== 'null') {
|
|
28
|
-
return { type, nullable: false };
|
|
29
|
-
}
|
|
30
|
-
if (array.length > 0) {
|
|
31
|
-
type = getDataTypeFromValue(array[0]);
|
|
32
|
-
return { type, nullable: true };
|
|
33
|
-
}
|
|
34
|
-
return { type: 'null', nullable: true };
|
|
35
|
-
}
|
|
36
|
-
exports.getDataTypeFromArray = getDataTypeFromArray;
|
|
37
|
-
/**
|
|
38
|
-
* Deduces a simple data type "descriptor from a typed array instance
|
|
39
|
-
*/
|
|
40
|
-
function getDataTypeFromTypedArray(array) {
|
|
41
|
-
switch (array.constructor) {
|
|
42
|
-
case Int8Array:
|
|
43
|
-
return 'int8';
|
|
44
|
-
case Uint8Array:
|
|
45
|
-
case Uint8ClampedArray:
|
|
46
|
-
return 'uint8';
|
|
47
|
-
case Int16Array:
|
|
48
|
-
return 'int16';
|
|
49
|
-
case Uint16Array:
|
|
50
|
-
return 'uint16';
|
|
51
|
-
case Int32Array:
|
|
52
|
-
return 'int32';
|
|
53
|
-
case Uint32Array:
|
|
54
|
-
return 'uint32';
|
|
55
|
-
case Float32Array:
|
|
56
|
-
return 'float32';
|
|
57
|
-
case Float64Array:
|
|
58
|
-
return 'float64';
|
|
59
|
-
default:
|
|
60
|
-
return 'null';
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.getDataTypeFromTypedArray = getDataTypeFromTypedArray;
|
|
64
|
-
function getArrayTypeFromDataType(type, nullable) {
|
|
65
|
-
if (!nullable) {
|
|
66
|
-
switch (type) {
|
|
67
|
-
case 'int8':
|
|
68
|
-
return Int8Array;
|
|
69
|
-
case 'uint8':
|
|
70
|
-
return Uint8Array;
|
|
71
|
-
case 'int16':
|
|
72
|
-
return Int16Array;
|
|
73
|
-
case 'uint16':
|
|
74
|
-
return Uint16Array;
|
|
75
|
-
case 'int32':
|
|
76
|
-
return Int32Array;
|
|
77
|
-
case 'uint32':
|
|
78
|
-
return Uint32Array;
|
|
79
|
-
case 'float32':
|
|
80
|
-
return Float32Array;
|
|
81
|
-
case 'float64':
|
|
82
|
-
return Float64Array;
|
|
83
|
-
default:
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// if (typeof BigInt64Array !== 'undefined') {
|
|
88
|
-
// TYPED_ARRAY_TO_TYPE.BigInt64Array = new Int64();
|
|
89
|
-
// TYPED_ARRAY_TO_TYPE.BigUint64Array = new Uint64();
|
|
90
|
-
// }
|
|
91
|
-
return Array;
|
|
92
|
-
}
|
|
93
|
-
exports.getArrayTypeFromDataType = getArrayTypeFromDataType;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeTableFromData = void 0;
|
|
4
|
-
const table_schema_1 = require("./table-schema");
|
|
5
|
-
function makeTableFromData(data) {
|
|
6
|
-
let table;
|
|
7
|
-
switch (getTableShapeFromData(data)) {
|
|
8
|
-
case 'array-row-table':
|
|
9
|
-
table = { shape: 'array-row-table', data: data };
|
|
10
|
-
break;
|
|
11
|
-
case 'object-row-table':
|
|
12
|
-
table = { shape: 'object-row-table', data: data };
|
|
13
|
-
break;
|
|
14
|
-
case 'columnar-table':
|
|
15
|
-
table = { shape: 'columnar-table', data: data };
|
|
16
|
-
break;
|
|
17
|
-
default:
|
|
18
|
-
throw new Error('table');
|
|
19
|
-
}
|
|
20
|
-
const schema = (0, table_schema_1.deduceTableSchema)(table);
|
|
21
|
-
return { ...table, schema };
|
|
22
|
-
}
|
|
23
|
-
exports.makeTableFromData = makeTableFromData;
|
|
24
|
-
/** Helper function to get shape of data */
|
|
25
|
-
function getTableShapeFromData(data) {
|
|
26
|
-
if (Array.isArray(data)) {
|
|
27
|
-
if (data.length === 0) {
|
|
28
|
-
throw new Error('cannot deduce type of empty table');
|
|
29
|
-
}
|
|
30
|
-
// Deduce the table shape from the first row
|
|
31
|
-
const firstRow = data[0];
|
|
32
|
-
if (Array.isArray(firstRow)) {
|
|
33
|
-
return 'array-row-table';
|
|
34
|
-
}
|
|
35
|
-
if (firstRow && typeof firstRow === 'object') {
|
|
36
|
-
return 'object-row-table';
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (data && typeof data === 'object') {
|
|
40
|
-
return 'columnar-table';
|
|
41
|
-
}
|
|
42
|
-
throw new Error('invalid table');
|
|
43
|
-
}
|
|
44
|
-
/** Convert any table into object row format *
|
|
45
|
-
export function makeColumnarTable(table: Table): ColumnarTable {
|
|
46
|
-
if (table.shape === 'columnar-table') {
|
|
47
|
-
return table;
|
|
48
|
-
}
|
|
49
|
-
const length = getTableLength(table);
|
|
50
|
-
const data = new Array<{[key: string]: unknown}>(length);
|
|
51
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
52
|
-
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
shape: 'columnar-table',
|
|
56
|
-
schema: table.schema,
|
|
57
|
-
data
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
/** Convert any table into array row format *
|
|
63
|
-
export function makeArrayRowTable(table: TableLike): ArrayRowTable {
|
|
64
|
-
if (table.shape === 'array-row-table') {
|
|
65
|
-
return table;
|
|
66
|
-
}
|
|
67
|
-
const length = getTableLength(table);
|
|
68
|
-
const data = new Array<unknown[]>(length);
|
|
69
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
70
|
-
data[rowIndex] = getTableRowAsArray(table, rowIndex);
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
shape: 'array-row-table',
|
|
74
|
-
schema: table.schema,
|
|
75
|
-
data
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Convert any table into object row format *
|
|
80
|
-
export function makeObjectRowTable(table: Table): ObjectRowTable {
|
|
81
|
-
if (table.shape === 'object-row-table') {
|
|
82
|
-
return table;
|
|
83
|
-
}
|
|
84
|
-
const length = getTableLength(table);
|
|
85
|
-
const data = new Array<{[key: string]: unknown}>(length);
|
|
86
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
87
|
-
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
shape: 'object-row-table',
|
|
91
|
-
schema: table.schema,
|
|
92
|
-
data
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
*/
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertToArrayRow = exports.convertToObjectRow = void 0;
|
|
4
|
-
/** Convert an object row to an array row */
|
|
5
|
-
function convertToObjectRow(arrayRow, headers) {
|
|
6
|
-
if (!arrayRow) {
|
|
7
|
-
throw new Error('null row');
|
|
8
|
-
}
|
|
9
|
-
if (!headers) {
|
|
10
|
-
throw new Error('no headers');
|
|
11
|
-
}
|
|
12
|
-
const objectRow = {};
|
|
13
|
-
for (let i = 0; i < headers.length; i++) {
|
|
14
|
-
objectRow[headers[i]] = arrayRow[i];
|
|
15
|
-
}
|
|
16
|
-
return objectRow;
|
|
17
|
-
}
|
|
18
|
-
exports.convertToObjectRow = convertToObjectRow;
|
|
19
|
-
/** Convert an object row to an array row */
|
|
20
|
-
function convertToArrayRow(objectRow, headers) {
|
|
21
|
-
if (!objectRow) {
|
|
22
|
-
throw new Error('null row');
|
|
23
|
-
}
|
|
24
|
-
if (!headers) {
|
|
25
|
-
throw new Error('no headers');
|
|
26
|
-
}
|
|
27
|
-
const arrayRow = new Array(headers.length);
|
|
28
|
-
for (let i = 0; i < headers.length; i++) {
|
|
29
|
-
arrayRow[i] = objectRow[headers[i]];
|
|
30
|
-
}
|
|
31
|
-
return arrayRow;
|
|
32
|
-
}
|
|
33
|
-
exports.convertToArrayRow = convertToArrayRow;
|