@loaders.gl/schema 4.1.0-alpha.1 → 4.1.0-alpha.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 +35 -18
- package/dist/index.cjs +36 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/mesh/convert-mesh.d.ts.map +1 -1
- package/dist/lib/mesh/convert-mesh.js.map +1 -1
- package/dist/lib/mesh/deduce-mesh-schema.d.ts.map +1 -1
- package/dist/lib/mesh/deduce-mesh-schema.js.map +1 -1
- package/dist/lib/mesh/mesh-to-arrow-table.js.map +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.map +1 -1
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts.map +1 -1
- package/dist/lib/table/arrow-api/arrow-like-schema.js.map +1 -1
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts.map +1 -1
- package/dist/lib/table/arrow-api/arrow-like-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/arrow-api/get-type-info.d.ts.map +1 -1
- package/dist/lib/table/arrow-api/get-type-info.js.map +1 -1
- package/dist/lib/table/arrow-api/index.d.ts.map +1 -1
- package/dist/lib/table/arrow-api/index.js.map +1 -1
- package/dist/lib/table/batches/base-table-batch-aggregator.d.ts +1 -0
- package/dist/lib/table/batches/base-table-batch-aggregator.d.ts.map +1 -1
- package/dist/lib/table/batches/base-table-batch-aggregator.js +4 -1
- package/dist/lib/table/batches/base-table-batch-aggregator.js.map +1 -1
- package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts.map +1 -1
- package/dist/lib/table/batches/columnar-table-batch-aggregator.js.map +1 -1
- package/dist/lib/table/batches/row-table-batch-aggregator.d.ts +2 -2
- package/dist/lib/table/batches/row-table-batch-aggregator.d.ts.map +1 -1
- package/dist/lib/table/batches/row-table-batch-aggregator.js +5 -3
- package/dist/lib/table/batches/row-table-batch-aggregator.js.map +1 -1
- package/dist/lib/table/batches/table-batch-aggregator.d.ts.map +1 -1
- package/dist/lib/table/batches/table-batch-aggregator.js.map +1 -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 +2 -4
- package/dist/lib/table/batches/table-batch-builder.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.map +1 -1
- package/dist/lib/table/simple-table/data-type.d.ts.map +1 -1
- package/dist/lib/table/simple-table/data-type.js.map +1 -1
- package/dist/lib/table/simple-table/make-table-from-batches.d.ts.map +1 -1
- package/dist/lib/table/simple-table/make-table-from-batches.js.map +1 -1
- 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 +10 -4
- package/dist/lib/table/simple-table/row-utils.d.ts.map +1 -1
- package/dist/lib/table/simple-table/row-utils.js +26 -11
- package/dist/lib/table/simple-table/row-utils.js.map +1 -1
- package/dist/lib/table/simple-table/table-accessors.d.ts.map +1 -1
- package/dist/lib/table/simple-table/table-accessors.js.map +1 -1
- package/dist/lib/table/simple-table/table-column.d.ts.map +1 -1
- package/dist/lib/table/simple-table/table-column.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.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/category-mesh.d.ts.map +1 -1
- package/dist/types/category-mesh.js.map +1 -1
- package/dist/types/category-table.d.ts.map +1 -1
- package/dist/types/category-table.js.map +1 -1
- package/dist/types/category-texture.d.ts.map +1 -1
- package/dist/types/category-texture.js.map +1 -1
- package/dist/types/flat-geometries.d.ts.map +1 -1
- package/dist/types/flat-geometries.js.map +1 -1
- 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 +2 -1
- package/src/lib/mesh/convert-mesh.ts +2 -1
- package/src/lib/mesh/deduce-mesh-schema.ts +2 -1
- package/src/lib/mesh/mesh-to-arrow-table.ts +2 -1
- package/src/lib/table/arrow-api/arrow-like-field.ts +2 -1
- package/src/lib/table/arrow-api/arrow-like-schema.ts +2 -1
- package/src/lib/table/arrow-api/arrow-like-table.ts +2 -1
- package/src/lib/table/arrow-api/arrow-like-type.ts +2 -1
- package/src/lib/table/arrow-api/enum.ts +2 -1
- package/src/lib/table/arrow-api/get-type-info.ts +2 -1
- package/src/lib/table/arrow-api/index.ts +2 -1
- package/src/lib/table/batches/base-table-batch-aggregator.ts +8 -2
- package/src/lib/table/batches/columnar-table-batch-aggregator.ts +2 -1
- package/src/lib/table/batches/row-table-batch-aggregator.ts +19 -7
- package/src/lib/table/batches/table-batch-aggregator.ts +2 -1
- package/src/lib/table/batches/table-batch-builder.ts +7 -8
- package/src/lib/table/simple-table/convert-table.ts +2 -1
- package/src/lib/table/simple-table/data-type.ts +2 -1
- package/src/lib/table/simple-table/make-table-from-batches.ts +2 -1
- package/src/lib/table/simple-table/make-table.ts +2 -1
- package/src/lib/table/simple-table/row-utils.ts +40 -19
- package/src/lib/table/simple-table/table-accessors.ts +2 -1
- package/src/lib/table/simple-table/table-column.ts +2 -1
- package/src/lib/table/simple-table/table-schema.ts +2 -1
- package/src/types/batch.ts +2 -1
- package/src/types/binary-geometries.ts +2 -1
- package/src/types/category-gis.ts +2 -1
- package/src/types/category-image.ts +2 -1
- package/src/types/category-mesh.ts +2 -1
- package/src/types/category-table.ts +2 -1
- package/src/types/category-texture.ts +2 -1
- package/src/types/flat-geometries.ts +2 -1
- package/src/types/schema.ts +2 -1
- package/src/types/types.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/types/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/types/schema.ts"],"names":[],"mappings":"AAIA,0BAA0B;AAC1B,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEjF,+BAA+B;AAC/B,MAAM,MAAM,QAAQ,GAChB,MAAM,GAEN,MAAM,GACN,KAAK,GACL,MAAM,GACN,OAAO,GACP,OAAO,GACP,OAAO,GACP,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,SAAS,GACT,SAAS,GACT,SAAS,GACT,QAAQ,GACR,MAAM,GACN,UAAU,GACV,kBAAkB,GAClB,aAAa,GACb,kBAAkB,GAClB,kBAAkB,GAClB,iBAAiB,GACjB,kBAAkB,GAClB,uBAAuB,GACvB,uBAAuB,GACvB,sBAAsB,GACtB,kBAAkB,GAClB,oBAAoB,GAEpB;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,GACrE;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,KAAK,EAAE,CAAA;CAAC,GACjC;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,KAAK,EAAE,CAAA;CAAC,GACnC;IACE,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,UAAU,CAAC;IACpB,QAAQ,EAAE,KAAK,EAAE,CAAC;IAClB,kBAAkB,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAC;CAC7C,GACD;IACE,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,UAAU,CAAC;IACpB,QAAQ,EAAE,KAAK,EAAE,CAAC;IAClB,kBAAkB,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAC;CAC7C,GACD;IAAC,IAAI,EAAE,mBAAmB,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAC,GAC9C;IAAC,IAAI,EAAE,iBAAiB,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,KAAK,EAAE,CAAA;CAAC,GAC9D;IAAC,IAAI,EAAE,KAAK,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,KAAK,EAAE,CAAA;CAAC,GACrD;IAAC,IAAI,EAAE,YAAY,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,QAAQ,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAC,CAAC;AAGjG;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACpD,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEnD,MAAM,MAAM,KAAK,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,QAAQ,EAAE,cAAc,CAAC;CAC1B,CAAC"}
|
package/dist/types/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":[],"sources":["../../src/types/schema.ts"],"sourcesContent":["// loaders.gl
|
|
1
|
+
{"version":3,"file":"schema.js","names":[],"sources":["../../src/types/schema.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n/** For dictionary type */\nexport type KeyType = 'int8' | 'int16' | 'int32' | 'uint8' | 'uint16' | 'uint32';\n\n/** ArrowLike DataType class */\nexport type DataType =\n | 'null'\n // Primitive types\n | 'bool'\n | 'int'\n | 'int8'\n | 'int16'\n | 'int32'\n | 'int64'\n | 'uint8'\n | 'uint16'\n | 'uint32'\n | 'uint64'\n | 'float'\n | 'float16'\n | 'float32'\n | 'float64'\n | 'binary'\n | 'utf8'\n | 'date-day'\n | 'date-millisecond'\n | 'time-second'\n | 'time-millisecond'\n | 'time-microsecond'\n | 'time-nanosecond'\n | 'timestamp-second'\n | 'timestamp-millisecond'\n | 'timestamp-microsecond'\n | 'timestamp-nanosecond'\n | 'interval-daytime'\n | 'interval-yearmonth'\n // Composite types\n | {type: 'decimal'; bitWidth: number; precision: number; scale: number}\n | {type: 'list'; children: Field[]} // one child only\n | {type: 'struct'; children: Field[]}\n | {\n type: 'sparse-union';\n typeIds: Int32Array;\n children: Field[];\n typeIdToChildIndex: {[key: number]: number};\n }\n | {\n type: 'dense-union';\n typeIds: Int32Array;\n children: Field[];\n typeIdToChildIndex: {[key: number]: number};\n }\n | {type: 'fixed-size-binary'; byteWidth: number}\n | {type: 'fixed-size-list'; listSize: number; children: Field[]}\n | {type: 'map'; keysSorted: boolean; children: Field[]} // Field is \"struct\"\n | {type: 'dictionary'; id: number; indices: KeyType; dictionary: DataType; isOrdered: boolean};\n// TODO - unions etc\n\n/**\n * SchemaMetadata\n */\nexport type SchemaMetadata = Record<string, string>;\nexport type FieldMetadata = Record<string, string>;\n\nexport type Field = {\n name: string;\n type: DataType;\n nullable?: boolean;\n metadata?: FieldMetadata;\n};\n\n/**\n * `Schema` type that that can hold all data required by an Arrow Schema\n * but is fully serializable. Helper functions make it easy to convert to and from arrow schemas\n * https://loaders.gl/arrowjs/docs/api-reference/schema\n */\nexport type Schema = {\n fields: Field[];\n metadata: SchemaMetadata;\n};\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAIA,sBAAsB;AACtB,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,UAAU,GACV,UAAU,GACV,WAAW,GACX,UAAU,GACV,WAAW,GACX,iBAAiB,GACjB,YAAY,GACZ,YAAY,CAAC;AAEjB,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,aAAa,GAAG,cAAc,CAAC;AAExE,MAAM,MAAM,qBAAqB,GAC7B,oBAAoB,GACpB,qBAAqB,GACrB,qBAAqB,GACrB,sBAAsB,GACtB,qBAAqB,GACrB,sBAAsB,GACtB,uBAAuB,GACvB,uBAAuB,CAAC;AAE5B,MAAM,MAAM,wBAAwB,GAChC,qBAAqB,GACrB,wBAAwB,GACxB,yBAAyB,CAAC;AAE9B,mDAAmD;AACnD,MAAM,MAAM,WAAW,GAAG,MAAM,EAAE,GAAG,UAAU,CAAC;AAEhD,MAAM,MAAM,YAAY,GAAG,MAAM,EAAE,GAAG,UAAU,CAAC;AAEjD,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;CAChB;AAED,mDAAmD;AACnD,MAAM,MAAM,QAAQ,GAAG,GAAG,EAAE,GAAG,UAAU,CAAC"}
|
package/dist/types/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/types/types.ts"],"sourcesContent":["// loaders.gl
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/types/types.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n/** Any typed array */\nexport type TypedArray =\n | Int8Array\n | Uint8Array\n | Int16Array\n | Uint16Array\n | Int32Array\n | Uint32Array\n | Uint8ClampedArray\n | Float32Array\n | Float64Array;\n\nexport type BigTypedArray = TypedArray | BigInt64Array | BigUint64Array;\n\nexport type TypedArrayConstructor =\n | Int8ArrayConstructor\n | Uint8ArrayConstructor\n | Int16ArrayConstructor\n | Uint16ArrayConstructor\n | Int32ArrayConstructor\n | Uint32ArrayConstructor\n | Float32ArrayConstructor\n | Float64ArrayConstructor;\n\nexport type BigTypedArrayConstructor =\n | TypedArrayConstructor\n | BigInt64ArrayConstructor\n | BigUint64ArrayConstructor;\n\n/** Any numeric array: typed array or `number[]` */\nexport type NumberArray = number[] | TypedArray;\n\nexport type NumericArray = number[] | TypedArray;\n\nexport interface ArrayType<T = unknown> {\n readonly length: number;\n [n: number]: T;\n}\n\n/** Any array: typed array or js array (`any[]`) */\nexport type AnyArray = any[] | TypedArray;\n"],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/schema",
|
|
3
|
-
"version": "4.1.0-alpha.
|
|
3
|
+
"version": "4.1.0-alpha.3",
|
|
4
4
|
"description": "Table format APIs for JSON, CSV, etc...",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@types/geojson": "^7946.0.7"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "b78075a7cb8d4ecd4aac84805ce74b8ceb400cf7"
|
|
46
46
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import type {Schema} from '../../../types/schema';
|
|
@@ -11,6 +12,7 @@ export class BaseTableBatchAggregator implements TableBatchAggregator {
|
|
|
11
12
|
schema: Schema;
|
|
12
13
|
options: TableBatchOptions;
|
|
13
14
|
|
|
15
|
+
shape?: 'array-row-table' | 'object-row-table';
|
|
14
16
|
length: number = 0;
|
|
15
17
|
rows: any[] | null = null;
|
|
16
18
|
cursor: number = 0;
|
|
@@ -39,6 +41,8 @@ export class BaseTableBatchAggregator implements TableBatchAggregator {
|
|
|
39
41
|
this.cursor = cursor as number;
|
|
40
42
|
}
|
|
41
43
|
|
|
44
|
+
this.shape = 'array-row-table';
|
|
45
|
+
|
|
42
46
|
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
43
47
|
this.rows[this.length] = row;
|
|
44
48
|
this.length++;
|
|
@@ -49,6 +53,8 @@ export class BaseTableBatchAggregator implements TableBatchAggregator {
|
|
|
49
53
|
this.cursor = cursor as number;
|
|
50
54
|
}
|
|
51
55
|
|
|
56
|
+
this.shape = 'object-row-table';
|
|
57
|
+
|
|
52
58
|
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
53
59
|
this.rows[this.length] = row;
|
|
54
60
|
this.length++;
|
|
@@ -64,7 +70,7 @@ export class BaseTableBatchAggregator implements TableBatchAggregator {
|
|
|
64
70
|
this.rows = null;
|
|
65
71
|
|
|
66
72
|
const batch: TableBatch = {
|
|
67
|
-
shape: this.
|
|
73
|
+
shape: this.shape || 'array-row-table',
|
|
68
74
|
batchType: 'data',
|
|
69
75
|
data: rows,
|
|
70
76
|
length: this.length,
|
|
@@ -1,31 +1,36 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import type {Schema} from '../../../types/schema';
|
|
5
6
|
import type {TableBatch} from '../../../types/category-table';
|
|
6
|
-
// import type {ArrayRowTableBatch, ObjectRowTableBatch} from '../../category/table';
|
|
7
|
-
import {convertToArrayRow, convertToObjectRow} from '../simple-table/row-utils';
|
|
8
7
|
import {TableBatchAggregator, TableBatchOptions} from './table-batch-aggregator';
|
|
8
|
+
import {
|
|
9
|
+
convertToArrayRow,
|
|
10
|
+
convertToObjectRow,
|
|
11
|
+
inferHeadersFromArrayRow,
|
|
12
|
+
inferHeadersFromObjectRow
|
|
13
|
+
} from '../simple-table/row-utils';
|
|
9
14
|
|
|
10
15
|
const DEFAULT_ROW_COUNT = 100;
|
|
11
16
|
|
|
12
17
|
export class RowTableBatchAggregator implements TableBatchAggregator {
|
|
13
|
-
schema: Schema;
|
|
18
|
+
schema: Schema | null;
|
|
14
19
|
options: TableBatchOptions;
|
|
15
20
|
|
|
16
21
|
length: number = 0;
|
|
17
22
|
objectRows: {[columnName: string]: unknown}[] | null = null;
|
|
18
23
|
arrayRows: unknown[][] | null = null;
|
|
19
24
|
cursor: number = 0;
|
|
20
|
-
private _headers: string[] =
|
|
25
|
+
private _headers: string[] | null = null;
|
|
21
26
|
|
|
22
|
-
constructor(schema: Schema, options: TableBatchOptions) {
|
|
27
|
+
constructor(schema: Schema | null, options: TableBatchOptions) {
|
|
23
28
|
this.options = options;
|
|
24
29
|
this.schema = schema;
|
|
25
30
|
|
|
26
31
|
// schema is an array if there're no headers
|
|
27
32
|
// object if there are headers
|
|
28
|
-
if (
|
|
33
|
+
if (schema) {
|
|
29
34
|
this._headers = [];
|
|
30
35
|
for (const key in schema) {
|
|
31
36
|
this._headers[schema[key].index] = schema[key].name;
|
|
@@ -42,6 +47,9 @@ export class RowTableBatchAggregator implements TableBatchAggregator {
|
|
|
42
47
|
this.cursor = cursor as number;
|
|
43
48
|
}
|
|
44
49
|
|
|
50
|
+
// TODO - infer schema at a higher level, instead of hacking headers here?
|
|
51
|
+
this._headers ||= inferHeadersFromArrayRow(row);
|
|
52
|
+
|
|
45
53
|
// eslint-disable-next-line default-case
|
|
46
54
|
switch (this.options.shape) {
|
|
47
55
|
case 'object-row-table':
|
|
@@ -61,6 +69,9 @@ export class RowTableBatchAggregator implements TableBatchAggregator {
|
|
|
61
69
|
this.cursor = cursor as number;
|
|
62
70
|
}
|
|
63
71
|
|
|
72
|
+
// TODO - infer schema at a higher level, instead of hacking headers here?
|
|
73
|
+
this._headers ||= inferHeadersFromObjectRow(row);
|
|
74
|
+
|
|
64
75
|
// eslint-disable-next-line default-case
|
|
65
76
|
switch (this.options.shape) {
|
|
66
77
|
case 'array-row-table':
|
|
@@ -90,6 +101,7 @@ export class RowTableBatchAggregator implements TableBatchAggregator {
|
|
|
90
101
|
batchType: 'data',
|
|
91
102
|
data: rows,
|
|
92
103
|
length: this.length,
|
|
104
|
+
// @ts-expect-error we should infer a schema
|
|
93
105
|
schema: this.schema,
|
|
94
106
|
cursor: this.cursor
|
|
95
107
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import type {Schema} from '../../../types/schema';
|
|
@@ -10,11 +11,11 @@ import {ColumnarTableBatchAggregator} from './columnar-table-batch-aggregator';
|
|
|
10
11
|
|
|
11
12
|
// TODO define interface instead
|
|
12
13
|
type TableBatchBuilderOptions = {
|
|
13
|
-
shape
|
|
14
|
+
shape?: 'array-row-table' | 'object-row-table' | 'columnar-table' | 'arrow-table';
|
|
14
15
|
batchSize?: number | 'auto';
|
|
15
16
|
batchDebounceMs?: number;
|
|
16
|
-
limit
|
|
17
|
-
_limitMB
|
|
17
|
+
limit?: number;
|
|
18
|
+
_limitMB?: number;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
type GetBatchOptions = {
|
|
@@ -23,7 +24,7 @@ type GetBatchOptions = {
|
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
const DEFAULT_OPTIONS: Required<TableBatchBuilderOptions> = {
|
|
26
|
-
shape:
|
|
27
|
+
shape: undefined!,
|
|
27
28
|
batchSize: 'auto',
|
|
28
29
|
batchDebounceMs: 0,
|
|
29
30
|
limit: 0,
|
|
@@ -172,8 +173,6 @@ export class TableBatchBuilder {
|
|
|
172
173
|
|
|
173
174
|
private _getTableBatchType(): TableBatchConstructor {
|
|
174
175
|
switch (this.options.shape) {
|
|
175
|
-
case 'row-table':
|
|
176
|
-
return BaseTableBatchAggregator;
|
|
177
176
|
case 'array-row-table':
|
|
178
177
|
case 'object-row-table':
|
|
179
178
|
return RowTableBatchAggregator;
|
|
@@ -185,7 +184,7 @@ export class TableBatchBuilder {
|
|
|
185
184
|
}
|
|
186
185
|
return TableBatchBuilder.ArrowBatch;
|
|
187
186
|
default:
|
|
188
|
-
|
|
187
|
+
return BaseTableBatchAggregator;
|
|
189
188
|
}
|
|
190
189
|
}
|
|
191
190
|
}
|
|
@@ -1,38 +1,59 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
/** Convert an object row to an array row */
|
|
5
6
|
export function convertToObjectRow(
|
|
6
|
-
arrayRow:
|
|
7
|
-
headers: string[]
|
|
8
|
-
): {[columnName: string]:
|
|
7
|
+
arrayRow: unknown[],
|
|
8
|
+
headers: string[] | null
|
|
9
|
+
): {[columnName: string]: unknown} {
|
|
9
10
|
if (!arrayRow) {
|
|
10
11
|
throw new Error('null row');
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
}
|
|
18
23
|
}
|
|
19
24
|
return objectRow;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
/** Convert an object row to an array row */
|
|
23
28
|
export function convertToArrayRow(
|
|
24
|
-
objectRow: {[columnName: string]:
|
|
25
|
-
headers: string[]
|
|
26
|
-
):
|
|
29
|
+
objectRow: {[columnName: string]: unknown},
|
|
30
|
+
headers: string[] | null
|
|
31
|
+
): unknown[] {
|
|
27
32
|
if (!objectRow) {
|
|
28
33
|
throw new Error('null row');
|
|
29
34
|
}
|
|
30
|
-
|
|
31
|
-
|
|
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;
|
|
32
42
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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);
|
|
36
52
|
}
|
|
37
|
-
return
|
|
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);
|
|
38
59
|
}
|
package/src/types/batch.ts
CHANGED
package/src/types/schema.ts
CHANGED
package/src/types/types.ts
CHANGED