@loaders.gl/schema 4.2.0-alpha.3 → 4.2.0-alpha.5
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 +190 -161
- package/dist/dist.min.js +9 -0
- package/dist/index.cjs +64 -73
- 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 +30 -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 +69 -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 +53 -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 +357 -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 +53 -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 +81 -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 +74 -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 +128 -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 +76 -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/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,306 +1,350 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
1
4
|
export function isTable(table) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
5
|
+
const shape = typeof table === 'object' && table?.shape;
|
|
6
|
+
switch (shape) {
|
|
7
|
+
case 'array-row-table':
|
|
8
|
+
case 'object-row-table':
|
|
9
|
+
return Array.isArray(table.data);
|
|
10
|
+
case 'geojson-table':
|
|
11
|
+
return Array.isArray(table.features);
|
|
12
|
+
case 'columnar-table':
|
|
13
|
+
return table.data && typeof table.data === 'object';
|
|
14
|
+
case 'arrow-table':
|
|
15
|
+
return Boolean(table?.data?.numRows !== undefined);
|
|
16
|
+
default:
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
17
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Returns the length of the table (i.e. the number of rows)
|
|
22
|
+
*/
|
|
18
23
|
export function getTableLength(table) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
switch (table.shape) {
|
|
25
|
+
case 'array-row-table':
|
|
26
|
+
case 'object-row-table':
|
|
27
|
+
return table.data.length;
|
|
28
|
+
case 'geojson-table':
|
|
29
|
+
return table.features.length;
|
|
30
|
+
case 'arrow-table':
|
|
31
|
+
const arrowTable = table.data;
|
|
32
|
+
return arrowTable.numRows;
|
|
33
|
+
case 'columnar-table':
|
|
34
|
+
for (const column of Object.values(table.data)) {
|
|
35
|
+
return column.length || 0;
|
|
36
|
+
}
|
|
37
|
+
return 0;
|
|
38
|
+
default:
|
|
39
|
+
throw new Error('table');
|
|
40
|
+
}
|
|
36
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns the number of columns in the table
|
|
44
|
+
* @throws Fails to deduce number of columns if the table has no schema and is empty
|
|
45
|
+
*/
|
|
37
46
|
export function getTableNumCols(table) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
if (table.schema) {
|
|
48
|
+
return table.schema.fields.length;
|
|
49
|
+
}
|
|
50
|
+
if (getTableLength(table) === 0) {
|
|
51
|
+
throw new Error('empty table');
|
|
52
|
+
}
|
|
53
|
+
switch (table.shape) {
|
|
54
|
+
case 'array-row-table':
|
|
55
|
+
return table.data[0].length;
|
|
56
|
+
case 'object-row-table':
|
|
57
|
+
return Object.keys(table.data[0]).length;
|
|
58
|
+
case 'geojson-table':
|
|
59
|
+
return Object.keys(table.features[0]).length;
|
|
60
|
+
case 'columnar-table':
|
|
61
|
+
return Object.keys(table.data).length;
|
|
62
|
+
case 'arrow-table':
|
|
63
|
+
const arrowTable = table.data;
|
|
64
|
+
return arrowTable.numCols;
|
|
65
|
+
default:
|
|
66
|
+
throw new Error('table');
|
|
67
|
+
}
|
|
59
68
|
}
|
|
69
|
+
/** Get a table cell value at row index and column name */
|
|
60
70
|
export function getTableCell(table, rowIndex, columnName) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
71
|
+
switch (table.shape) {
|
|
72
|
+
case 'array-row-table':
|
|
73
|
+
const columnIndex = getTableColumnIndex(table, columnName);
|
|
74
|
+
return table.data[rowIndex][columnIndex];
|
|
75
|
+
case 'object-row-table':
|
|
76
|
+
return table.data[rowIndex][columnName];
|
|
77
|
+
case 'geojson-table':
|
|
78
|
+
return table.features[rowIndex][columnName];
|
|
79
|
+
case 'columnar-table':
|
|
80
|
+
const column = table.data[columnName];
|
|
81
|
+
return column[rowIndex];
|
|
82
|
+
case 'arrow-table':
|
|
83
|
+
const arrowTable = table.data;
|
|
84
|
+
const arrowColumnIndex = arrowTable.schema.fields.findIndex((field) => field.name === columnName);
|
|
85
|
+
return arrowTable.getChildAt(arrowColumnIndex)?.get(rowIndex);
|
|
86
|
+
default:
|
|
87
|
+
throw new Error('todo');
|
|
88
|
+
}
|
|
80
89
|
}
|
|
90
|
+
/** Get a table cell value at row index and column name */
|
|
81
91
|
export function getTableCellAt(table, rowIndex, columnIndex) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
92
|
+
switch (table.shape) {
|
|
93
|
+
case 'array-row-table':
|
|
94
|
+
return table.data[rowIndex][columnIndex];
|
|
95
|
+
case 'object-row-table':
|
|
96
|
+
const columnName1 = getTableColumnName(table, columnIndex);
|
|
97
|
+
return table.data[rowIndex][columnName1];
|
|
98
|
+
case 'geojson-table':
|
|
99
|
+
const columnName2 = getTableColumnName(table, columnIndex);
|
|
100
|
+
return table.features[rowIndex][columnName2];
|
|
101
|
+
case 'columnar-table':
|
|
102
|
+
const columnName3 = getTableColumnName(table, columnIndex);
|
|
103
|
+
const column = table.data[columnName3];
|
|
104
|
+
return column[rowIndex];
|
|
105
|
+
case 'arrow-table':
|
|
106
|
+
const arrowTable = table.data;
|
|
107
|
+
return arrowTable.getChildAt(columnIndex)?.get(rowIndex);
|
|
108
|
+
default:
|
|
109
|
+
throw new Error('todo');
|
|
110
|
+
}
|
|
102
111
|
}
|
|
112
|
+
/** Deduce the table row shape */
|
|
103
113
|
export function getTableRowShape(table) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
switch (table.shape) {
|
|
115
|
+
case 'array-row-table':
|
|
116
|
+
case 'object-row-table':
|
|
117
|
+
return table.shape;
|
|
118
|
+
case 'geojson-table':
|
|
119
|
+
// TODO - this is not correct, geojson-table is not a row table
|
|
120
|
+
return 'object-row-table';
|
|
121
|
+
case 'columnar-table':
|
|
122
|
+
default:
|
|
123
|
+
throw new Error('Not a row table');
|
|
124
|
+
}
|
|
114
125
|
}
|
|
126
|
+
/** Get the index of a named table column. Requires the table to have a schema */
|
|
115
127
|
export function getTableColumnIndex(table, columnName) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return columnIndex;
|
|
128
|
+
const columnIndex = table.schema?.fields.findIndex((field) => field.name === columnName);
|
|
129
|
+
if (columnIndex === undefined) {
|
|
130
|
+
throw new Error(columnName);
|
|
131
|
+
}
|
|
132
|
+
return columnIndex;
|
|
122
133
|
}
|
|
134
|
+
/** Get the name of a table column by index. Requires the table to have a schema */
|
|
123
135
|
export function getTableColumnName(table, columnIndex) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return columnName;
|
|
136
|
+
const columnName = table.schema?.fields[columnIndex]?.name;
|
|
137
|
+
if (!columnName) {
|
|
138
|
+
throw new Error(`${columnIndex}`);
|
|
139
|
+
}
|
|
140
|
+
return columnName;
|
|
130
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Returns one row of the table in object format.
|
|
144
|
+
* @param target Optional parameter will be used if needed to store the row. Can be reused between calls to improve performance
|
|
145
|
+
* @returns an array representing the row. May be the original array in the row, a new object, or the target parameter
|
|
146
|
+
*/
|
|
147
|
+
// eslint-disable-next-line complexity
|
|
131
148
|
export function getTableRowAsObject(table, rowIndex, target, copy) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
149
|
+
switch (table.shape) {
|
|
150
|
+
case 'object-row-table':
|
|
151
|
+
return copy ? Object.fromEntries(Object.entries(table.data[rowIndex])) : table.data[rowIndex];
|
|
152
|
+
case 'array-row-table':
|
|
153
|
+
if (table.schema) {
|
|
154
|
+
const objectRow = target || {};
|
|
155
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
156
|
+
objectRow[table.schema.fields[i].name] = table.data[rowIndex][i];
|
|
157
|
+
}
|
|
158
|
+
return objectRow;
|
|
159
|
+
}
|
|
160
|
+
throw new Error('no schema');
|
|
161
|
+
case 'geojson-table':
|
|
162
|
+
if (table.schema) {
|
|
163
|
+
const objectRow = target || {};
|
|
164
|
+
// TODO - should lift properties to top level
|
|
165
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
166
|
+
objectRow[table.schema.fields[i].name] = table.features[rowIndex][i];
|
|
167
|
+
}
|
|
168
|
+
return objectRow;
|
|
169
|
+
}
|
|
170
|
+
throw new Error('no schema');
|
|
171
|
+
case 'columnar-table':
|
|
172
|
+
if (table.schema) {
|
|
173
|
+
const objectRow = target || {};
|
|
174
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
175
|
+
objectRow[table.schema.fields[i].name] =
|
|
176
|
+
table.data[table.schema.fields[i].name][rowIndex];
|
|
177
|
+
}
|
|
178
|
+
return objectRow;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
// eslint-disable-line no-else-return
|
|
182
|
+
const objectRow = target || {};
|
|
183
|
+
for (const [name, column] of Object.entries(table.data)) {
|
|
184
|
+
objectRow[name] = column[rowIndex];
|
|
185
|
+
}
|
|
186
|
+
return objectRow;
|
|
187
|
+
}
|
|
188
|
+
case 'arrow-table':
|
|
189
|
+
const arrowTable = table.data;
|
|
190
|
+
const objectRow = target || {};
|
|
191
|
+
const row = arrowTable.get(rowIndex);
|
|
192
|
+
const schema = arrowTable.schema;
|
|
193
|
+
for (let i = 0; i < schema.fields.length; i++) {
|
|
194
|
+
objectRow[schema.fields[i].name] = row?.[schema.fields[i].name];
|
|
195
|
+
}
|
|
196
|
+
return objectRow;
|
|
197
|
+
default:
|
|
198
|
+
throw new Error('shape');
|
|
199
|
+
}
|
|
179
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Returns one row of the table in array format.
|
|
203
|
+
* @param target Optional parameter will be used if needed to store the row. Can be reused between calls to improve performance.
|
|
204
|
+
* @returns an array representing the row. May be the original array in the row, a new object, or the target parameter
|
|
205
|
+
*/
|
|
206
|
+
// eslint-disable-next-line complexity
|
|
180
207
|
export function getTableRowAsArray(table, rowIndex, target, copy) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
208
|
+
switch (table.shape) {
|
|
209
|
+
case 'array-row-table':
|
|
210
|
+
return copy ? Array.from(table.data[rowIndex]) : table.data[rowIndex];
|
|
211
|
+
case 'object-row-table':
|
|
212
|
+
if (table.schema) {
|
|
213
|
+
const arrayRow = target || [];
|
|
214
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
215
|
+
arrayRow[i] = table.data[rowIndex][table.schema.fields[i].name];
|
|
216
|
+
}
|
|
217
|
+
return arrayRow;
|
|
218
|
+
}
|
|
219
|
+
// Warning: just slap on the values, this risks mismatches between rows
|
|
220
|
+
return Object.values(table.data[rowIndex]);
|
|
221
|
+
case 'geojson-table':
|
|
222
|
+
if (table.schema) {
|
|
223
|
+
const arrayRow = target || [];
|
|
224
|
+
// TODO - should lift properties to top level
|
|
225
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
226
|
+
arrayRow[i] = table.features[rowIndex][table.schema.fields[i].name];
|
|
227
|
+
}
|
|
228
|
+
return arrayRow;
|
|
229
|
+
}
|
|
230
|
+
// Warning: just slap on the values, this risks mismatches between rows
|
|
231
|
+
return Object.values(table.features[rowIndex]);
|
|
232
|
+
case 'columnar-table':
|
|
233
|
+
if (table.schema) {
|
|
234
|
+
const arrayRow = target || [];
|
|
235
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
236
|
+
arrayRow[i] = table.data[table.schema.fields[i].name][rowIndex];
|
|
237
|
+
}
|
|
238
|
+
return arrayRow;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
// eslint-disable-line no-else-return
|
|
242
|
+
const arrayRow = target || [];
|
|
243
|
+
let i = 0;
|
|
244
|
+
for (const column of Object.values(table.data)) {
|
|
245
|
+
arrayRow[i] = column[rowIndex];
|
|
246
|
+
i++;
|
|
247
|
+
}
|
|
248
|
+
return arrayRow;
|
|
249
|
+
}
|
|
250
|
+
case 'arrow-table':
|
|
251
|
+
const arrowTable = table.data;
|
|
252
|
+
const arrayRow = target || [];
|
|
253
|
+
const row = arrowTable.get(rowIndex);
|
|
254
|
+
const schema = arrowTable.schema;
|
|
255
|
+
for (let i = 0; i < schema.fields.length; i++) {
|
|
256
|
+
arrayRow[i] = row?.[schema.fields[i].name];
|
|
257
|
+
}
|
|
258
|
+
return arrayRow;
|
|
259
|
+
default:
|
|
260
|
+
throw new Error('shape');
|
|
261
|
+
}
|
|
230
262
|
}
|
|
263
|
+
/** Convert any table into array row format */
|
|
231
264
|
export function makeArrayRowTable(table) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
265
|
+
if (table.shape === 'array-row-table') {
|
|
266
|
+
return table;
|
|
267
|
+
}
|
|
268
|
+
const length = getTableLength(table);
|
|
269
|
+
const data = new Array(length);
|
|
270
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
271
|
+
data[rowIndex] = getTableRowAsArray(table, rowIndex);
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
shape: 'array-row-table',
|
|
275
|
+
schema: table.schema,
|
|
276
|
+
data
|
|
277
|
+
};
|
|
245
278
|
}
|
|
279
|
+
/** Convert any table into object row format */
|
|
246
280
|
export function makeObjectRowTable(table) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
281
|
+
if (table.shape === 'object-row-table') {
|
|
282
|
+
return table;
|
|
283
|
+
}
|
|
284
|
+
const length = getTableLength(table);
|
|
285
|
+
const data = new Array(length);
|
|
286
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
287
|
+
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
shape: 'object-row-table',
|
|
291
|
+
schema: table.schema,
|
|
292
|
+
data
|
|
293
|
+
};
|
|
260
294
|
}
|
|
295
|
+
/** Convert any table into object row format */
|
|
261
296
|
export function makeColumnarTable(table) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
297
|
+
if (table.shape === 'object-row-table') {
|
|
298
|
+
return table;
|
|
299
|
+
}
|
|
300
|
+
const length = getTableLength(table);
|
|
301
|
+
const data = new Array(length);
|
|
302
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
303
|
+
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
shape: 'object-row-table',
|
|
307
|
+
schema: table.schema,
|
|
308
|
+
data
|
|
309
|
+
};
|
|
275
310
|
}
|
|
311
|
+
// Row Iterators
|
|
312
|
+
/**
|
|
313
|
+
* Iterate over table rows
|
|
314
|
+
* @param table
|
|
315
|
+
* @param shape
|
|
316
|
+
*/
|
|
276
317
|
export function* makeRowIterator(table, shape) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
318
|
+
switch (shape) {
|
|
319
|
+
case 'array-row-table':
|
|
320
|
+
yield* makeArrayRowIterator(table);
|
|
321
|
+
break;
|
|
322
|
+
case 'object-row-table':
|
|
323
|
+
yield* makeObjectRowIterator(table);
|
|
324
|
+
break;
|
|
325
|
+
default:
|
|
326
|
+
throw new Error(`Unknown row type ${shape}`);
|
|
327
|
+
}
|
|
287
328
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
329
|
+
/**
|
|
330
|
+
* Streaming processing: Iterate over table, yielding array rows
|
|
331
|
+
* @param table
|
|
332
|
+
* @param shape
|
|
333
|
+
*/
|
|
334
|
+
export function* makeArrayRowIterator(table, target = []) {
|
|
291
335
|
const length = getTableLength(table);
|
|
292
336
|
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
293
|
-
|
|
337
|
+
yield getTableRowAsArray(table, rowIndex, target);
|
|
294
338
|
}
|
|
295
|
-
}();
|
|
296
339
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
340
|
+
/**
|
|
341
|
+
* Streaming processing: Iterate over table, yielding object rows
|
|
342
|
+
* @param table
|
|
343
|
+
* @param shape
|
|
344
|
+
*/
|
|
345
|
+
export function* makeObjectRowIterator(table, target = {}) {
|
|
300
346
|
const length = getTableLength(table);
|
|
301
347
|
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
302
|
-
|
|
348
|
+
yield getTableRowAsObject(table, rowIndex, target);
|
|
303
349
|
}
|
|
304
|
-
}();
|
|
305
350
|
}
|
|
306
|
-
//# sourceMappingURL=table-accessors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-column.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/simple-table/table-column.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,KAAK,EAAC,
|
|
1
|
+
{"version":3,"file":"table-column.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/simple-table/table-column.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,KAAK,EAAC,iCAA8B;AAG5C,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;CAChB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAG3E"}
|