@loaders.gl/schema 4.0.1 → 4.0.3
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 +93 -1
- package/dist/index.cjs +78 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/mesh/mesh-to-arrow-table.js.map +1 -1
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts.map +1 -1
- package/dist/lib/table/arrow-api/arrow-like-type.js.map +1 -1
- package/dist/lib/table/arrow-api/enum.d.ts.map +1 -1
- package/dist/lib/table/arrow-api/enum.js.map +1 -1
- package/dist/lib/table/simple-table/convert-table.d.ts.map +1 -1
- package/dist/lib/table/simple-table/convert-table.js +2 -2
- package/dist/lib/table/simple-table/convert-table.js.map +1 -1
- package/dist/lib/table/simple-table/make-table-from-batches.d.ts +22 -0
- package/dist/lib/table/simple-table/make-table-from-batches.d.ts.map +1 -0
- package/dist/lib/table/simple-table/make-table-from-batches.js +76 -0
- package/dist/lib/table/simple-table/make-table-from-batches.js.map +1 -0
- package/dist/lib/table/simple-table/make-table.d.ts.map +1 -1
- package/dist/lib/table/simple-table/make-table.js.map +1 -1
- package/dist/lib/table/simple-table/row-utils.d.ts.map +1 -1
- package/dist/lib/table/simple-table/row-utils.js.map +1 -1
- package/dist/lib/table/simple-table/table-accessors.d.ts +1 -0
- package/dist/lib/table/simple-table/table-accessors.d.ts.map +1 -1
- package/dist/lib/table/simple-table/table-accessors.js +17 -0
- package/dist/lib/table/simple-table/table-accessors.js.map +1 -1
- package/dist/lib/table/simple-table/table-schema.d.ts.map +1 -1
- package/dist/lib/table/simple-table/table-schema.js.map +1 -1
- package/dist/types/batch.d.ts +1 -1
- package/dist/types/batch.d.ts.map +1 -1
- package/dist/types/batch.js.map +1 -1
- package/dist/types/binary-geometries.d.ts.map +1 -1
- package/dist/types/binary-geometries.js.map +1 -1
- package/dist/types/category-gis.d.ts.map +1 -1
- package/dist/types/category-gis.js.map +1 -1
- package/dist/types/category-image.d.ts.map +1 -1
- package/dist/types/category-image.js.map +1 -1
- package/dist/types/schema.d.ts +5 -0
- package/dist/types/schema.d.ts.map +1 -1
- package/dist/types/schema.js.map +1 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +8 -0
- package/src/lib/mesh/mesh-to-arrow-table.ts +3 -0
- package/src/lib/table/arrow-api/arrow-like-type.ts +3 -0
- package/src/lib/table/arrow-api/enum.ts +3 -0
- package/src/lib/table/simple-table/convert-table.ts +2 -1
- package/src/lib/table/simple-table/make-table-from-batches.ts +102 -0
- package/src/lib/table/simple-table/make-table.ts +1 -0
- package/src/lib/table/simple-table/row-utils.ts +3 -0
- package/src/lib/table/simple-table/table-accessors.ts +21 -0
- package/src/lib/table/simple-table/table-schema.ts +3 -0
- package/src/types/batch.ts +1 -1
- package/src/types/binary-geometries.ts +3 -0
- package/src/types/category-gis.ts +3 -0
- package/src/types/category-image.ts +3 -0
- package/src/types/schema.ts +1 -0
- package/src/types/types.ts +3 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
// Copyright (c) vis.gl contributors
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
TableBatch,
|
|
6
|
+
Table,
|
|
7
|
+
Schema,
|
|
8
|
+
ObjectRowTable,
|
|
9
|
+
ArrayRowTable,
|
|
10
|
+
Feature
|
|
11
|
+
} from '@loaders.gl/schema';
|
|
12
|
+
import {getTableLength} from '@loaders.gl/schema';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns an iterator that yields a single table as a sequence of batches.
|
|
16
|
+
* @note Currently only a single batch is yielded.
|
|
17
|
+
* @note All batches will have the same shape and schema as the original table.
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export function* makeBatchesFromTable(table: Table): IterableIterator<TableBatch> {
|
|
21
|
+
yield makeBatchFromTable(table);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns a table packaged as a single table batch
|
|
26
|
+
* @note The batch will have the same shape and schema as the original table.
|
|
27
|
+
* @returns `null` if no batches are yielded by the async iterator
|
|
28
|
+
*/
|
|
29
|
+
export function makeBatchFromTable(table: Table): TableBatch {
|
|
30
|
+
return {...table, length: getTableLength(table), batchType: 'data'};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Assembles all batches from an async iterator into a single table.
|
|
35
|
+
* @note All batches must have the same shape and schema
|
|
36
|
+
* @param batchIterator
|
|
37
|
+
* @returns `null` if no batches are yielded by the async iterator
|
|
38
|
+
*/
|
|
39
|
+
// eslint-disable-next-line complexity
|
|
40
|
+
export async function makeTableFromBatches(
|
|
41
|
+
batchIterator: AsyncIterable<TableBatch> | Iterable<TableBatch>
|
|
42
|
+
): Promise<Table | null> {
|
|
43
|
+
let arrayRows: ArrayRowTable['data'];
|
|
44
|
+
let objectRows: ObjectRowTable['data'];
|
|
45
|
+
let features: Feature[];
|
|
46
|
+
let shape: Table['shape'] | null = null;
|
|
47
|
+
let schema: Schema | undefined;
|
|
48
|
+
|
|
49
|
+
for await (const batch of batchIterator) {
|
|
50
|
+
shape = shape || batch.shape;
|
|
51
|
+
schema = schema || batch.schema;
|
|
52
|
+
|
|
53
|
+
switch (batch.shape) {
|
|
54
|
+
case 'array-row-table':
|
|
55
|
+
arrayRows = arrayRows! || [];
|
|
56
|
+
for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
|
|
57
|
+
const row = batch.data[rowIndex];
|
|
58
|
+
arrayRows.push(row);
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
|
|
62
|
+
case 'object-row-table':
|
|
63
|
+
objectRows = objectRows! || [];
|
|
64
|
+
for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
|
|
65
|
+
const row = batch.data[rowIndex];
|
|
66
|
+
objectRows.push(row);
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
|
|
70
|
+
case 'geojson-table':
|
|
71
|
+
features = features! || [];
|
|
72
|
+
for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
|
|
73
|
+
const row = batch.features[rowIndex];
|
|
74
|
+
features.push(row);
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
|
|
78
|
+
case 'columnar-table':
|
|
79
|
+
case 'arrow-table':
|
|
80
|
+
default:
|
|
81
|
+
throw new Error('shape');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!shape) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
switch (shape) {
|
|
90
|
+
case 'array-row-table':
|
|
91
|
+
return {shape: 'array-row-table', data: arrayRows!, schema};
|
|
92
|
+
|
|
93
|
+
case 'object-row-table':
|
|
94
|
+
return {shape: 'object-row-table', data: objectRows!, schema};
|
|
95
|
+
|
|
96
|
+
case 'geojson-table':
|
|
97
|
+
return {shape: 'geojson-table', type: 'FeatureCollection', features: features!, schema};
|
|
98
|
+
|
|
99
|
+
default:
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -5,6 +5,27 @@
|
|
|
5
5
|
|
|
6
6
|
import {Table, ArrayRowTable, ObjectRowTable} from '../../../types/category-table';
|
|
7
7
|
|
|
8
|
+
export function isTable(table: any): table is Table {
|
|
9
|
+
const shape = typeof table === 'object' && table?.shape;
|
|
10
|
+
switch (shape) {
|
|
11
|
+
case 'array-row-table':
|
|
12
|
+
case 'object-row-table':
|
|
13
|
+
return Array.isArray(table.data);
|
|
14
|
+
|
|
15
|
+
case 'geojson-table':
|
|
16
|
+
return Array.isArray(table.features);
|
|
17
|
+
|
|
18
|
+
case 'columnar-table':
|
|
19
|
+
return table.data && typeof table.data === 'object';
|
|
20
|
+
|
|
21
|
+
case 'arrow-table':
|
|
22
|
+
return Boolean(table?.data?.numRows !== undefined);
|
|
23
|
+
|
|
24
|
+
default:
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
8
29
|
/**
|
|
9
30
|
* Returns the length of the table (i.e. the number of rows)
|
|
10
31
|
*/
|
package/src/types/batch.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type Batch = {
|
|
|
19
19
|
/** Schema of the data in this batch */
|
|
20
20
|
schema?: Schema;
|
|
21
21
|
/** Data in this batch */
|
|
22
|
-
data
|
|
22
|
+
data?: unknown;
|
|
23
23
|
/** If this is an arrow table. @deprecated Use `data` */
|
|
24
24
|
recordBatch?: ApacheRecordBatch;
|
|
25
25
|
/** Length of data in this batch */
|
package/src/types/schema.ts
CHANGED
|
@@ -37,6 +37,7 @@ export type DataType =
|
|
|
37
37
|
| 'interval-daytime'
|
|
38
38
|
| 'interval-yearmonth'
|
|
39
39
|
// Composite types
|
|
40
|
+
| {type: 'decimal'; bitWidth: number; precision: number; scale: number}
|
|
40
41
|
| {type: 'list'; children: Field[]} // one child only
|
|
41
42
|
| {type: 'struct'; children: Field[]}
|
|
42
43
|
| {
|