@loaders.gl/schema 4.3.2 → 4.4.0-alpha.2
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/categories/category-gis.d.ts +6 -0
- package/dist/categories/category-gis.d.ts.map +1 -0
- package/dist/categories/category-image.d.ts.map +1 -0
- package/dist/{types → categories}/category-mesh.d.ts +2 -2
- package/dist/categories/category-mesh.d.ts.map +1 -0
- package/dist/{types → categories}/category-table.d.ts +14 -14
- package/dist/categories/category-table.d.ts.map +1 -0
- package/dist/categories/category-texture.d.ts.map +1 -0
- package/dist/{lib/mesh → deprecated}/mesh-utils.d.ts +4 -2
- package/dist/deprecated/mesh-utils.d.ts.map +1 -0
- package/dist/{lib/mesh → deprecated}/mesh-utils.js +2 -0
- package/dist/dist.dev.js +0 -1836
- package/dist/dist.min.js +1 -1
- package/dist/geometry/binary-features.d.ts +30 -0
- package/dist/geometry/binary-features.d.ts.map +1 -0
- package/dist/geometry/binary-geometries.d.ts +33 -0
- package/dist/geometry/binary-geometries.d.ts.map +1 -0
- package/dist/geometry/flat-geometries.d.ts +61 -0
- package/dist/geometry/flat-geometries.d.ts.map +1 -0
- package/dist/index.cjs +2 -1792
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +10 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -23
- package/dist/types/batch.d.ts +3 -1
- package/dist/types/batch.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/{types → categories}/category-gis.ts +7 -18
- package/src/{types → categories}/category-mesh.ts +2 -2
- package/src/{types → categories}/category-table.ts +14 -17
- package/src/{lib/mesh → deprecated}/mesh-utils.ts +4 -2
- package/src/geometry/binary-features.ts +43 -0
- package/src/geometry/binary-geometries.ts +45 -0
- package/src/{types → geometry}/flat-geometries.ts +44 -14
- package/src/index.ts +15 -101
- package/src/types/batch.ts +3 -1
- package/dist/lib/mesh/convert-mesh.d.ts +0 -15
- package/dist/lib/mesh/convert-mesh.d.ts.map +0 -1
- package/dist/lib/mesh/convert-mesh.js +0 -37
- package/dist/lib/mesh/deduce-mesh-schema.d.ts +0 -24
- package/dist/lib/mesh/deduce-mesh-schema.d.ts.map +0 -1
- package/dist/lib/mesh/deduce-mesh-schema.js +0 -62
- package/dist/lib/mesh/mesh-to-arrow-table.d.ts +0 -1
- package/dist/lib/mesh/mesh-to-arrow-table.d.ts.map +0 -1
- package/dist/lib/mesh/mesh-to-arrow-table.js +0 -47
- package/dist/lib/mesh/mesh-utils.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts +0 -19
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-field.js +0 -36
- package/dist/lib/table/arrow-api/arrow-like-interface.d.ts +0 -43
- package/dist/lib/table/arrow-api/arrow-like-interface.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts +0 -12
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-schema.js +0 -81
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts +0 -24
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-table.js +0 -63
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts +0 -177
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-type.js +0 -442
- package/dist/lib/table/arrow-api/enum.d.ts +0 -92
- package/dist/lib/table/arrow-api/enum.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/enum.js +0 -97
- package/dist/lib/table/arrow-api/get-type-info.d.ts +0 -13
- package/dist/lib/table/arrow-api/get-type-info.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/get-type-info.js +0 -27
- package/dist/lib/table/arrow-api/index.d.ts +0 -5
- package/dist/lib/table/arrow-api/index.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/index.js +0 -7
- package/dist/lib/table/batches/base-table-batch-aggregator.d.ts +0 -20
- package/dist/lib/table/batches/base-table-batch-aggregator.d.ts.map +0 -1
- package/dist/lib/table/batches/base-table-batch-aggregator.js +0 -63
- package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts +0 -23
- package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts.map +0 -1
- package/dist/lib/table/batches/columnar-table-batch-aggregator.js +0 -91
- package/dist/lib/table/batches/row-table-batch-aggregator.d.ts +0 -22
- package/dist/lib/table/batches/row-table-batch-aggregator.d.ts.map +0 -1
- package/dist/lib/table/batches/row-table-batch-aggregator.js +0 -85
- package/dist/lib/table/batches/table-batch-aggregator.d.ts +0 -25
- package/dist/lib/table/batches/table-batch-aggregator.d.ts.map +0 -1
- package/dist/lib/table/batches/table-batch-aggregator.js +0 -4
- package/dist/lib/table/batches/table-batch-builder.d.ts +0 -53
- package/dist/lib/table/batches/table-batch-builder.d.ts.map +0 -1
- package/dist/lib/table/batches/table-batch-builder.js +0 -151
- package/dist/lib/table/simple-table/convert-table.d.ts +0 -43
- package/dist/lib/table/simple-table/convert-table.d.ts.map +0 -1
- package/dist/lib/table/simple-table/convert-table.js +0 -118
- package/dist/lib/table/simple-table/data-type.d.ts +0 -17
- package/dist/lib/table/simple-table/data-type.d.ts.map +0 -1
- package/dist/lib/table/simple-table/data-type.js +0 -88
- package/dist/lib/table/simple-table/make-table-from-batches.d.ts +0 -22
- package/dist/lib/table/simple-table/make-table-from-batches.d.ts.map +0 -1
- package/dist/lib/table/simple-table/make-table-from-batches.js +0 -79
- package/dist/lib/table/simple-table/make-table.d.ts +0 -65
- package/dist/lib/table/simple-table/make-table.d.ts.map +0 -1
- package/dist/lib/table/simple-table/make-table.js +0 -94
- package/dist/lib/table/simple-table/row-utils.d.ts +0 -15
- package/dist/lib/table/simple-table/row-utils.d.ts.map +0 -1
- package/dist/lib/table/simple-table/row-utils.js +0 -49
- package/dist/lib/table/simple-table/table-accessors.d.ts +0 -68
- package/dist/lib/table/simple-table/table-accessors.d.ts.map +0 -1
- package/dist/lib/table/simple-table/table-accessors.js +0 -350
- package/dist/lib/table/simple-table/table-column.d.ts +0 -7
- package/dist/lib/table/simple-table/table-column.d.ts.map +0 -1
- package/dist/lib/table/simple-table/table-column.js +0 -39
- package/dist/lib/table/simple-table/table-schema.d.ts +0 -15
- package/dist/lib/table/simple-table/table-schema.d.ts.map +0 -1
- package/dist/lib/table/simple-table/table-schema.js +0 -100
- package/dist/lib/utils/assert.d.ts +0 -2
- package/dist/lib/utils/assert.d.ts.map +0 -1
- package/dist/lib/utils/assert.js +0 -8
- package/dist/lib/utils/async-queue.d.ts +0 -18
- package/dist/lib/utils/async-queue.d.ts.map +0 -1
- package/dist/lib/utils/async-queue.js +0 -90
- package/dist/types/binary-geometries.d.ts +0 -57
- package/dist/types/binary-geometries.d.ts.map +0 -1
- package/dist/types/category-gis.d.ts +0 -18
- package/dist/types/category-gis.d.ts.map +0 -1
- package/dist/types/category-image.d.ts.map +0 -1
- package/dist/types/category-mesh.d.ts.map +0 -1
- package/dist/types/category-table.d.ts.map +0 -1
- package/dist/types/category-texture.d.ts.map +0 -1
- package/dist/types/flat-geometries.d.ts +0 -30
- package/dist/types/flat-geometries.d.ts.map +0 -1
- package/src/lib/mesh/convert-mesh.ts +0 -51
- package/src/lib/mesh/deduce-mesh-schema.ts +0 -76
- package/src/lib/mesh/mesh-to-arrow-table.ts +0 -47
- package/src/lib/table/arrow-api/arrow-like-field.ts +0 -53
- package/src/lib/table/arrow-api/arrow-like-interface.ts +0 -84
- package/src/lib/table/arrow-api/arrow-like-schema.ts +0 -101
- package/src/lib/table/arrow-api/arrow-like-table.ts +0 -86
- package/src/lib/table/arrow-api/arrow-like-type.ts +0 -502
- package/src/lib/table/arrow-api/enum.ts +0 -99
- package/src/lib/table/arrow-api/get-type-info.ts +0 -38
- package/src/lib/table/arrow-api/index.ts +0 -8
- package/src/lib/table/batches/base-table-batch-aggregator.ts +0 -83
- package/src/lib/table/batches/columnar-table-batch-aggregator.ts +0 -112
- package/src/lib/table/batches/row-table-batch-aggregator.ts +0 -109
- package/src/lib/table/batches/table-batch-aggregator.ts +0 -29
- package/src/lib/table/batches/table-batch-builder.ts +0 -190
- package/src/lib/table/simple-table/convert-table.ts +0 -149
- package/src/lib/table/simple-table/data-type.ts +0 -104
- package/src/lib/table/simple-table/make-table-from-batches.ts +0 -98
- package/src/lib/table/simple-table/make-table.ts +0 -111
- package/src/lib/table/simple-table/row-utils.ts +0 -59
- package/src/lib/table/simple-table/table-accessors.ts +0 -417
- package/src/lib/table/simple-table/table-column.ts +0 -49
- package/src/lib/table/simple-table/table-schema.ts +0 -121
- package/src/lib/utils/assert.ts +0 -8
- package/src/lib/utils/async-queue.ts +0 -104
- package/src/types/binary-geometries.ts +0 -67
- /package/dist/{types → categories}/category-gis.js +0 -0
- /package/dist/{types → categories}/category-image.d.ts +0 -0
- /package/dist/{types → categories}/category-image.js +0 -0
- /package/dist/{types → categories}/category-mesh.js +0 -0
- /package/dist/{types → categories}/category-table.js +0 -0
- /package/dist/{types → categories}/category-texture.d.ts +0 -0
- /package/dist/{types → categories}/category-texture.js +0 -0
- /package/dist/{lib/table/arrow-api/arrow-like-interface.js → geometry/binary-features.js} +0 -0
- /package/dist/{types → geometry}/binary-geometries.js +0 -0
- /package/dist/{types → geometry}/flat-geometries.js +0 -0
- /package/src/{types → categories}/category-image.ts +0 -0
- /package/src/{types → categories}/category-texture.ts +0 -0
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {DataType} from '../../../types/schema';
|
|
6
|
-
import {TypedArray, TypedArrayConstructor, ArrayType} from '../../../types/types';
|
|
7
|
-
|
|
8
|
-
/** Deduce column types from values */
|
|
9
|
-
export function getDataTypeFromValue(
|
|
10
|
-
value: unknown,
|
|
11
|
-
defaultNumberType: 'float32' = 'float32'
|
|
12
|
-
): DataType {
|
|
13
|
-
if (value instanceof Date) {
|
|
14
|
-
return 'date-millisecond';
|
|
15
|
-
}
|
|
16
|
-
if (value instanceof Number) {
|
|
17
|
-
return defaultNumberType;
|
|
18
|
-
}
|
|
19
|
-
if (typeof value === 'string') {
|
|
20
|
-
return 'utf8';
|
|
21
|
-
}
|
|
22
|
-
if (value === null || value === 'undefined') {
|
|
23
|
-
return 'null';
|
|
24
|
-
}
|
|
25
|
-
return 'null';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Deduces a simple data type "descriptor from a typed array instance
|
|
30
|
-
*/
|
|
31
|
-
export function getDataTypeFromArray(array: ArrayType): {type: DataType; nullable: boolean} {
|
|
32
|
-
let type = getDataTypeFromTypedArray(array as TypedArray);
|
|
33
|
-
if (type !== 'null') {
|
|
34
|
-
return {type, nullable: false};
|
|
35
|
-
}
|
|
36
|
-
if (array.length > 0) {
|
|
37
|
-
type = getDataTypeFromValue(array[0]);
|
|
38
|
-
return {type, nullable: true};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return {type: 'null', nullable: true};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Deduces a simple data type "descriptor from a typed array instance
|
|
46
|
-
*/
|
|
47
|
-
export function getDataTypeFromTypedArray(array: TypedArray): DataType {
|
|
48
|
-
switch (array.constructor) {
|
|
49
|
-
case Int8Array:
|
|
50
|
-
return 'int8';
|
|
51
|
-
case Uint8Array:
|
|
52
|
-
case Uint8ClampedArray:
|
|
53
|
-
return 'uint8';
|
|
54
|
-
case Int16Array:
|
|
55
|
-
return 'int16';
|
|
56
|
-
case Uint16Array:
|
|
57
|
-
return 'uint16';
|
|
58
|
-
case Int32Array:
|
|
59
|
-
return 'int32';
|
|
60
|
-
case Uint32Array:
|
|
61
|
-
return 'uint32';
|
|
62
|
-
case Float32Array:
|
|
63
|
-
return 'float32';
|
|
64
|
-
case Float64Array:
|
|
65
|
-
return 'float64';
|
|
66
|
-
default:
|
|
67
|
-
return 'null';
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function getArrayTypeFromDataType(
|
|
72
|
-
type: DataType,
|
|
73
|
-
nullable: boolean | undefined
|
|
74
|
-
): TypedArrayConstructor | ArrayConstructor {
|
|
75
|
-
if (!nullable) {
|
|
76
|
-
switch (type) {
|
|
77
|
-
case 'int8':
|
|
78
|
-
return Int8Array;
|
|
79
|
-
case 'uint8':
|
|
80
|
-
return Uint8Array;
|
|
81
|
-
case 'int16':
|
|
82
|
-
return Int16Array;
|
|
83
|
-
case 'uint16':
|
|
84
|
-
return Uint16Array;
|
|
85
|
-
case 'int32':
|
|
86
|
-
return Int32Array;
|
|
87
|
-
case 'uint32':
|
|
88
|
-
return Uint32Array;
|
|
89
|
-
case 'float32':
|
|
90
|
-
return Float32Array;
|
|
91
|
-
case 'float64':
|
|
92
|
-
return Float64Array;
|
|
93
|
-
default:
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// if (typeof BigInt64Array !== 'undefined') {
|
|
99
|
-
// TYPED_ARRAY_TO_TYPE.BigInt64Array = new Int64();
|
|
100
|
-
// TYPED_ARRAY_TO_TYPE.BigUint64Array = new Uint64();
|
|
101
|
-
// }
|
|
102
|
-
|
|
103
|
-
return Array;
|
|
104
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {Schema} from '../../../types/schema';
|
|
6
|
-
import type {TableBatch, Table, ObjectRowTable, ArrayRowTable} from '../../../types/category-table';
|
|
7
|
-
import type {Feature} from '../../../types/category-gis';
|
|
8
|
-
import {getTableLength} from './table-accessors';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Returns an iterator that yields a single table as a sequence of batches.
|
|
12
|
-
* @note Currently only a single batch is yielded.
|
|
13
|
-
* @note All batches will have the same shape and schema as the original table.
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
export function* makeBatchesFromTable(table: Table): IterableIterator<TableBatch> {
|
|
17
|
-
yield makeBatchFromTable(table);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Returns a table packaged as a single table batch
|
|
22
|
-
* @note The batch will have the same shape and schema as the original table.
|
|
23
|
-
* @returns `null` if no batches are yielded by the async iterator
|
|
24
|
-
*/
|
|
25
|
-
export function makeBatchFromTable(table: Table): TableBatch {
|
|
26
|
-
return {...table, length: getTableLength(table), batchType: 'data'};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Assembles all batches from an async iterator into a single table.
|
|
31
|
-
* @note All batches must have the same shape and schema
|
|
32
|
-
* @param batchIterator
|
|
33
|
-
* @returns `null` if no batches are yielded by the async iterator
|
|
34
|
-
*/
|
|
35
|
-
// eslint-disable-next-line complexity
|
|
36
|
-
export async function makeTableFromBatches(
|
|
37
|
-
batchIterator: AsyncIterable<TableBatch> | Iterable<TableBatch>
|
|
38
|
-
): Promise<Table | null> {
|
|
39
|
-
let arrayRows: ArrayRowTable['data'];
|
|
40
|
-
let objectRows: ObjectRowTable['data'];
|
|
41
|
-
let features: Feature[];
|
|
42
|
-
let shape: Table['shape'] | null = null;
|
|
43
|
-
let schema: Schema | undefined;
|
|
44
|
-
|
|
45
|
-
for await (const batch of batchIterator) {
|
|
46
|
-
shape = shape || batch.shape;
|
|
47
|
-
schema = schema || batch.schema;
|
|
48
|
-
|
|
49
|
-
switch (batch.shape) {
|
|
50
|
-
case 'array-row-table':
|
|
51
|
-
arrayRows = arrayRows! || [];
|
|
52
|
-
for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
|
|
53
|
-
const row = batch.data[rowIndex];
|
|
54
|
-
arrayRows.push(row);
|
|
55
|
-
}
|
|
56
|
-
break;
|
|
57
|
-
|
|
58
|
-
case 'object-row-table':
|
|
59
|
-
objectRows = objectRows! || [];
|
|
60
|
-
for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
|
|
61
|
-
const row = batch.data[rowIndex];
|
|
62
|
-
objectRows.push(row);
|
|
63
|
-
}
|
|
64
|
-
break;
|
|
65
|
-
|
|
66
|
-
case 'geojson-table':
|
|
67
|
-
features = features! || [];
|
|
68
|
-
for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
|
|
69
|
-
const row = batch.features[rowIndex];
|
|
70
|
-
features.push(row);
|
|
71
|
-
}
|
|
72
|
-
break;
|
|
73
|
-
|
|
74
|
-
case 'columnar-table':
|
|
75
|
-
case 'arrow-table':
|
|
76
|
-
default:
|
|
77
|
-
throw new Error('shape');
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (!shape) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
switch (shape) {
|
|
86
|
-
case 'array-row-table':
|
|
87
|
-
return {shape: 'array-row-table', data: arrayRows!, schema};
|
|
88
|
-
|
|
89
|
-
case 'object-row-table':
|
|
90
|
-
return {shape: 'object-row-table', data: objectRows!, schema};
|
|
91
|
-
|
|
92
|
-
case 'geojson-table':
|
|
93
|
-
return {shape: 'geojson-table', type: 'FeatureCollection', features: features!, schema};
|
|
94
|
-
|
|
95
|
-
default:
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {Table, ArrayRowTable, ObjectRowTable, ColumnarTable} from '../../../types/category-table';
|
|
6
|
-
import {deduceTableSchema} from './table-schema';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Makes a typed table from data.
|
|
10
|
-
* @throws Row tables must contain at least one row. Columnar tables must contain empty arrays
|
|
11
|
-
*/
|
|
12
|
-
export function makeTableFromData(data: unknown[][]): ArrayRowTable;
|
|
13
|
-
export function makeTableFromData(data: {[column: string]: unknown}[]): ObjectRowTable;
|
|
14
|
-
export function makeTableFromData(data: {[column: string]: ArrayLike<unknown>}): ColumnarTable;
|
|
15
|
-
export function makeTableFromData(data: unknown): Table {
|
|
16
|
-
let table: Table;
|
|
17
|
-
switch (getTableShapeFromData(data)) {
|
|
18
|
-
case 'array-row-table':
|
|
19
|
-
table = {shape: 'array-row-table', data: data as unknown[][]};
|
|
20
|
-
break;
|
|
21
|
-
case 'object-row-table':
|
|
22
|
-
table = {shape: 'object-row-table', data: data as {[key: string]: unknown}[]};
|
|
23
|
-
break;
|
|
24
|
-
case 'columnar-table':
|
|
25
|
-
table = {shape: 'columnar-table', data: data as {[column: string]: ArrayLike<unknown>}};
|
|
26
|
-
break;
|
|
27
|
-
default:
|
|
28
|
-
throw new Error('table');
|
|
29
|
-
}
|
|
30
|
-
const schema = deduceTableSchema(table);
|
|
31
|
-
return {...table, schema};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Helper function to get shape of data */
|
|
35
|
-
function getTableShapeFromData(data) {
|
|
36
|
-
if (Array.isArray(data)) {
|
|
37
|
-
if (data.length === 0) {
|
|
38
|
-
throw new Error('cannot deduce type of empty table');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Deduce the table shape from the first row
|
|
42
|
-
const firstRow = data[0];
|
|
43
|
-
|
|
44
|
-
if (Array.isArray(firstRow)) {
|
|
45
|
-
return 'array-row-table';
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (firstRow && typeof firstRow === 'object') {
|
|
49
|
-
return 'object-row-table';
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (data && typeof data === 'object') {
|
|
54
|
-
return 'columnar-table';
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
throw new Error('invalid table');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Convert any table into object row format *
|
|
61
|
-
export function makeColumnarTable(table: Table): ColumnarTable {
|
|
62
|
-
if (table.shape === 'columnar-table') {
|
|
63
|
-
return table;
|
|
64
|
-
}
|
|
65
|
-
const length = getTableLength(table);
|
|
66
|
-
const data = new Array<{[key: string]: unknown}>(length);
|
|
67
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
68
|
-
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
shape: 'columnar-table',
|
|
72
|
-
schema: table.schema,
|
|
73
|
-
data
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
/** Convert any table into array row format *
|
|
79
|
-
export function makeArrayRowTable(table: TableLike): ArrayRowTable {
|
|
80
|
-
if (table.shape === 'array-row-table') {
|
|
81
|
-
return table;
|
|
82
|
-
}
|
|
83
|
-
const length = getTableLength(table);
|
|
84
|
-
const data = new Array<unknown[]>(length);
|
|
85
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
86
|
-
data[rowIndex] = getTableRowAsArray(table, rowIndex);
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
shape: 'array-row-table',
|
|
90
|
-
schema: table.schema,
|
|
91
|
-
data
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** Convert any table into object row format *
|
|
96
|
-
export function makeObjectRowTable(table: Table): ObjectRowTable {
|
|
97
|
-
if (table.shape === 'object-row-table') {
|
|
98
|
-
return table;
|
|
99
|
-
}
|
|
100
|
-
const length = getTableLength(table);
|
|
101
|
-
const data = new Array<{[key: string]: unknown}>(length);
|
|
102
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
103
|
-
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
104
|
-
}
|
|
105
|
-
return {
|
|
106
|
-
shape: 'object-row-table',
|
|
107
|
-
schema: table.schema,
|
|
108
|
-
data
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
*/
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
/** Convert an object row to an array row */
|
|
6
|
-
export function convertToObjectRow(
|
|
7
|
-
arrayRow: unknown[],
|
|
8
|
-
headers: string[] | null
|
|
9
|
-
): {[columnName: string]: unknown} {
|
|
10
|
-
if (!arrayRow) {
|
|
11
|
-
throw new Error('null row');
|
|
12
|
-
}
|
|
13
|
-
const objectRow: {[columnName: string]: unknown} = {};
|
|
14
|
-
if (headers) {
|
|
15
|
-
for (let i = 0; i < headers.length; i++) {
|
|
16
|
-
objectRow[headers[i]] = arrayRow[i];
|
|
17
|
-
}
|
|
18
|
-
} else {
|
|
19
|
-
for (let i = 0; i < arrayRow.length; i++) {
|
|
20
|
-
const columnName = `column-${i}`;
|
|
21
|
-
objectRow[columnName] = arrayRow[i];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return objectRow;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Convert an object row to an array row */
|
|
28
|
-
export function convertToArrayRow(
|
|
29
|
-
objectRow: {[columnName: string]: unknown},
|
|
30
|
-
headers: string[] | null
|
|
31
|
-
): unknown[] {
|
|
32
|
-
if (!objectRow) {
|
|
33
|
-
throw new Error('null row');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (headers) {
|
|
37
|
-
const arrayRow = new Array(headers.length);
|
|
38
|
-
for (let i = 0; i < headers.length; i++) {
|
|
39
|
-
arrayRow[i] = objectRow[headers[i]];
|
|
40
|
-
}
|
|
41
|
-
return arrayRow;
|
|
42
|
-
}
|
|
43
|
-
return Object.values(objectRow);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Get headers from a sample array row */
|
|
47
|
-
export function inferHeadersFromArrayRow(arrayRow: unknown[]) {
|
|
48
|
-
const headers: string[] = [];
|
|
49
|
-
for (let i = 0; i < arrayRow.length; i++) {
|
|
50
|
-
const columnName = `column-${i}`;
|
|
51
|
-
headers.push(columnName);
|
|
52
|
-
}
|
|
53
|
-
return headers;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Get headers from a smaple object row */
|
|
57
|
-
export function inferHeadersFromObjectRow(row: {[columnName: string]: unknown}) {
|
|
58
|
-
return Object.keys(row);
|
|
59
|
-
}
|