@loaders.gl/schema-utils 4.4.0-alpha.1
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/LICENSE +41 -0
- package/README.md +9 -0
- package/dist/dist.dev.js +14269 -0
- package/dist/dist.min.js +18 -0
- package/dist/index.cjs +2436 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/lib/arrow-utils/arrow-fixed-size-list-utils.d.ts +11 -0
- package/dist/lib/arrow-utils/arrow-fixed-size-list-utils.d.ts.map +1 -0
- package/dist/lib/arrow-utils/arrow-fixed-size-list-utils.js +40 -0
- package/dist/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.d.ts +11 -0
- package/dist/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.d.ts.map +1 -0
- package/dist/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.js +32 -0
- package/dist/lib/mesh/convert-mesh-to-table.d.ts +18 -0
- package/dist/lib/mesh/convert-mesh-to-table.d.ts.map +1 -0
- package/dist/lib/mesh/convert-mesh-to-table.js +60 -0
- package/dist/lib/mesh/convert-table-to-mesh.d.ts +7 -0
- package/dist/lib/mesh/convert-table-to-mesh.d.ts.map +1 -0
- package/dist/lib/mesh/convert-table-to-mesh.js +40 -0
- package/dist/lib/mesh/deduce-mesh-schema.d.ts +23 -0
- package/dist/lib/mesh/deduce-mesh-schema.d.ts.map +1 -0
- package/dist/lib/mesh/deduce-mesh-schema.js +62 -0
- package/dist/lib/mesh/mesh-utils.d.ts +23 -0
- package/dist/lib/mesh/mesh-utils.d.ts.map +1 -0
- package/dist/lib/mesh/mesh-utils.js +46 -0
- package/dist/lib/schema/convert-arrow-schema.d.ts +23 -0
- package/dist/lib/schema/convert-arrow-schema.d.ts.map +1 -0
- package/dist/lib/schema/convert-arrow-schema.js +280 -0
- package/dist/lib/schema/data-type.d.ts +16 -0
- package/dist/lib/schema/data-type.d.ts.map +1 -0
- package/dist/lib/schema/data-type.js +88 -0
- package/dist/lib/schema/deduce-table-schema.d.ts +14 -0
- package/dist/lib/schema/deduce-table-schema.d.ts.map +1 -0
- package/dist/lib/schema/deduce-table-schema.js +100 -0
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts +19 -0
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-field.js +36 -0
- package/dist/lib/table/arrow-api/arrow-like-interface.d.ts +43 -0
- package/dist/lib/table/arrow-api/arrow-like-interface.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-interface.js +4 -0
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts +12 -0
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-schema.js +81 -0
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts +28 -0
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-table.js +63 -0
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts +177 -0
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-type.js +442 -0
- package/dist/lib/table/arrow-api/enum.d.ts +92 -0
- package/dist/lib/table/arrow-api/enum.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/enum.js +97 -0
- package/dist/lib/table/arrow-api/get-type-info.d.ts +13 -0
- package/dist/lib/table/arrow-api/get-type-info.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/get-type-info.js +27 -0
- package/dist/lib/table/arrow-api/index.d.ts +5 -0
- package/dist/lib/table/arrow-api/index.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/index.js +7 -0
- package/dist/lib/table/batch-builder/arrow-table-batch-aggregator.d.ts +10 -0
- package/dist/lib/table/batch-builder/arrow-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/arrow-table-batch-aggregator.js +67 -0
- package/dist/lib/table/batch-builder/arrow-table-builder.d.ts +25 -0
- package/dist/lib/table/batch-builder/arrow-table-builder.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/arrow-table-builder.js +99 -0
- package/dist/lib/table/batch-builder/base-table-batch-aggregator.d.ts +19 -0
- package/dist/lib/table/batch-builder/base-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/base-table-batch-aggregator.js +63 -0
- package/dist/lib/table/batch-builder/columnar-table-batch-aggregator.d.ts +20 -0
- package/dist/lib/table/batch-builder/columnar-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/columnar-table-batch-aggregator.js +83 -0
- package/dist/lib/table/batch-builder/row-table-batch-aggregator.d.ts +21 -0
- package/dist/lib/table/batch-builder/row-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/row-table-batch-aggregator.js +85 -0
- package/dist/lib/table/batch-builder/table-batch-aggregator.d.ts +24 -0
- package/dist/lib/table/batch-builder/table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/table-batch-aggregator.js +4 -0
- package/dist/lib/table/batch-builder/table-batch-builder.d.ts +52 -0
- package/dist/lib/table/batch-builder/table-batch-builder.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/table-batch-builder.js +148 -0
- package/dist/lib/table/batches/convert-batches.d.ts +10 -0
- package/dist/lib/table/batches/convert-batches.d.ts.map +1 -0
- package/dist/lib/table/batches/convert-batches.js +45 -0
- package/dist/lib/table/batches/make-arrow-batch-iterator.d.ts +17 -0
- package/dist/lib/table/batches/make-arrow-batch-iterator.d.ts.map +1 -0
- package/dist/lib/table/batches/make-arrow-batch-iterator.js +57 -0
- package/dist/lib/table/batches/make-table-batch-iterator.d.ts +15 -0
- package/dist/lib/table/batches/make-table-batch-iterator.d.ts.map +1 -0
- package/dist/lib/table/batches/make-table-batch-iterator.js +21 -0
- package/dist/lib/table/batches/make-table-from-batches.d.ts +9 -0
- package/dist/lib/table/batches/make-table-from-batches.d.ts.map +1 -0
- package/dist/lib/table/batches/make-table-from-batches.js +62 -0
- package/dist/lib/table/tables/convert-arrow-table.d.ts +24 -0
- package/dist/lib/table/tables/convert-arrow-table.d.ts.map +1 -0
- package/dist/lib/table/tables/convert-arrow-table.js +150 -0
- package/dist/lib/table/tables/convert-table.d.ts +43 -0
- package/dist/lib/table/tables/convert-table.d.ts.map +1 -0
- package/dist/lib/table/tables/convert-table.js +120 -0
- package/dist/lib/table/tables/make-table.d.ts +67 -0
- package/dist/lib/table/tables/make-table.d.ts.map +1 -0
- package/dist/lib/table/tables/make-table.js +101 -0
- package/dist/lib/table/tables/row-utils.d.ts +15 -0
- package/dist/lib/table/tables/row-utils.d.ts.map +1 -0
- package/dist/lib/table/tables/row-utils.js +49 -0
- package/dist/lib/table/tables/table-accessors.d.ts +68 -0
- package/dist/lib/table/tables/table-accessors.d.ts.map +1 -0
- package/dist/lib/table/tables/table-accessors.js +350 -0
- package/dist/lib/table/tables/table-column.d.ts +7 -0
- package/dist/lib/table/tables/table-column.d.ts.map +1 -0
- package/dist/lib/table/tables/table-column.js +39 -0
- package/dist/lib/table/tables/table-types.d.ts +12 -0
- package/dist/lib/table/tables/table-types.d.ts.map +1 -0
- package/dist/lib/table/tables/table-types.js +23 -0
- package/dist/lib/utils/assert.d.ts +2 -0
- package/dist/lib/utils/assert.d.ts.map +1 -0
- package/dist/lib/utils/assert.js +8 -0
- package/dist/lib/utils/async-queue.d.ts +18 -0
- package/dist/lib/utils/async-queue.d.ts.map +1 -0
- package/dist/lib/utils/async-queue.js +90 -0
- package/dist/types/types.d.ts +15 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +4 -0
- package/package.json +52 -0
- package/src/index.ts +134 -0
- package/src/lib/arrow-utils/arrow-fixed-size-list-utils.ts +63 -0
- package/src/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.ts +48 -0
- package/src/lib/mesh/convert-mesh-to-table.ts +77 -0
- package/src/lib/mesh/convert-table-to-mesh.ts +49 -0
- package/src/lib/mesh/deduce-mesh-schema.ts +75 -0
- package/src/lib/mesh/mesh-utils.ts +64 -0
- package/src/lib/schema/convert-arrow-schema.ts +301 -0
- package/src/lib/schema/data-type.ts +103 -0
- package/src/lib/schema/deduce-table-schema.ts +119 -0
- package/src/lib/table/arrow-api/arrow-like-field.ts +53 -0
- package/src/lib/table/arrow-api/arrow-like-interface.ts +84 -0
- package/src/lib/table/arrow-api/arrow-like-schema.ts +101 -0
- package/src/lib/table/arrow-api/arrow-like-table.ts +85 -0
- package/src/lib/table/arrow-api/arrow-like-type.ts +502 -0
- package/src/lib/table/arrow-api/enum.ts +99 -0
- package/src/lib/table/arrow-api/get-type-info.ts +38 -0
- package/src/lib/table/arrow-api/index.ts +8 -0
- package/src/lib/table/batch-builder/arrow-table-batch-aggregator-builders.ts.disabled +190 -0
- package/src/lib/table/batch-builder/arrow-table-batch-aggregator.ts +82 -0
- package/src/lib/table/batch-builder/arrow-table-builder.ts +112 -0
- package/src/lib/table/batch-builder/base-table-batch-aggregator.ts +82 -0
- package/src/lib/table/batch-builder/columnar-table-batch-aggregator.ts +99 -0
- package/src/lib/table/batch-builder/row-table-batch-aggregator.ts +108 -0
- package/src/lib/table/batch-builder/table-batch-aggregator.ts +28 -0
- package/src/lib/table/batch-builder/table-batch-builder.ts +185 -0
- package/src/lib/table/batches/convert-batches.ts +83 -0
- package/src/lib/table/batches/make-arrow-batch-iterator.ts +75 -0
- package/src/lib/table/batches/make-table-batch-iterator.ts +25 -0
- package/src/lib/table/batches/make-table-from-batches.ts +84 -0
- package/src/lib/table/tables/convert-arrow-table.ts +198 -0
- package/src/lib/table/tables/convert-table.ts +151 -0
- package/src/lib/table/tables/make-table.ts +127 -0
- package/src/lib/table/tables/row-utils.ts +59 -0
- package/src/lib/table/tables/table-accessors.ts +417 -0
- package/src/lib/table/tables/table-column.ts +49 -0
- package/src/lib/table/tables/table-types.ts +37 -0
- package/src/lib/utils/assert.ts +8 -0
- package/src/lib/utils/async-queue.ts +104 -0
- package/src/types/types.ts +45 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import * as arrow from 'apache-arrow';
|
|
5
|
+
import { getDataTypeFromArray } from "../schema/data-type.js";
|
|
6
|
+
import { deserializeArrowType } from "../schema/convert-arrow-schema.js";
|
|
7
|
+
export function isListFixedSizeList(vector) {
|
|
8
|
+
return vector.type instanceof arrow.FixedSizeList;
|
|
9
|
+
}
|
|
10
|
+
export function getListFixedSizeListSize(vector) {
|
|
11
|
+
return vector.type instanceof arrow.FixedSizeList ? vector.type.listSize : 1;
|
|
12
|
+
}
|
|
13
|
+
/** Get Arrow FixedSizeList vector from a typed array */
|
|
14
|
+
export function getListFixedSizeListVector(indexes, typedArray, stride) {
|
|
15
|
+
const data = getFixedSizeListData(typedArray, stride);
|
|
16
|
+
return new arrow.Vector([data]);
|
|
17
|
+
}
|
|
18
|
+
/** Get Arrow FixedSizeList vector from a typed array */
|
|
19
|
+
export function getFixedSizeListData(typedArray, stride) {
|
|
20
|
+
const listType = getFixedSizeListType(typedArray, stride);
|
|
21
|
+
const data = new arrow.Data(listType, 0, typedArray.length / stride, 0, [
|
|
22
|
+
typedArray
|
|
23
|
+
]);
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
/** Get Arrow FixedSizeList vector from a typed array */
|
|
27
|
+
export function getFixedSizeListType(typedArray, stride) {
|
|
28
|
+
const { type } = getDataTypeFromArray(typedArray);
|
|
29
|
+
const arrowType = deserializeArrowType(type);
|
|
30
|
+
const listType = new arrow.FixedSizeList(stride, new arrow.Field('value', arrowType));
|
|
31
|
+
return listType;
|
|
32
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Mesh, ArrowTable, ColumnarTable } from '@loaders.gl/schema';
|
|
2
|
+
export declare function convertMeshToTable(mesh: Mesh, shape: 'columnar-table'): ColumnarTable;
|
|
3
|
+
export declare function convertMeshToTable(mesh: Mesh, shape: 'arrow-table'): ArrowTable;
|
|
4
|
+
/**
|
|
5
|
+
* Convert a loaders.gl Mesh to a Columnar Table
|
|
6
|
+
* @param mesh
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function convertMeshToColumnarTable(mesh: Mesh): ColumnarTable;
|
|
10
|
+
/**
|
|
11
|
+
* * Convert a loaders.gl Mesh to an Apache Arrow Table
|
|
12
|
+
* @param mesh
|
|
13
|
+
* @param metadata
|
|
14
|
+
* @param batchSize
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare function convertMeshToArrowTable(mesh: Mesh, batchSize?: number): ArrowTable;
|
|
18
|
+
//# sourceMappingURL=convert-mesh-to-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-mesh-to-table.d.ts","sourceRoot":"","sources":["../../../src/lib/mesh/convert-mesh-to-table.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,IAAI,EAAE,UAAU,EAAE,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAKxE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,gBAAgB,GAAG,aAAa,CAAC;AACvF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,aAAa,GAAG,UAAU,CAAC;AAmBjF;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,CAYpE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,UAAU,CAqBlF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import * as arrow from 'apache-arrow';
|
|
5
|
+
import { getFixedSizeListData } from "../arrow-utils/arrow-fixed-size-list-utils.js";
|
|
6
|
+
import { deserializeArrowSchema } from "../schema/convert-arrow-schema.js";
|
|
7
|
+
/**
|
|
8
|
+
* Convert a mesh to a specific shape
|
|
9
|
+
*/
|
|
10
|
+
export function convertMeshToTable(mesh, shape) {
|
|
11
|
+
switch (shape) {
|
|
12
|
+
case 'columnar-table':
|
|
13
|
+
return convertMeshToColumnarTable(mesh);
|
|
14
|
+
case 'arrow-table':
|
|
15
|
+
return convertMeshToArrowTable(mesh);
|
|
16
|
+
default:
|
|
17
|
+
throw new Error(shape);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Convert a loaders.gl Mesh to a Columnar Table
|
|
22
|
+
* @param mesh
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export function convertMeshToColumnarTable(mesh) {
|
|
26
|
+
const columns = {};
|
|
27
|
+
for (const [columnName, attribute] of Object.entries(mesh.attributes)) {
|
|
28
|
+
columns[columnName] = attribute.value;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
shape: 'columnar-table',
|
|
32
|
+
schema: mesh.schema,
|
|
33
|
+
data: columns
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* * Convert a loaders.gl Mesh to an Apache Arrow Table
|
|
38
|
+
* @param mesh
|
|
39
|
+
* @param metadata
|
|
40
|
+
* @param batchSize
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
export function convertMeshToArrowTable(mesh, batchSize) {
|
|
44
|
+
const { schema } = mesh;
|
|
45
|
+
const arrowSchema = deserializeArrowSchema(schema);
|
|
46
|
+
const arrowDatas = [];
|
|
47
|
+
for (const attributeKey in mesh.attributes) {
|
|
48
|
+
const attribute = mesh.attributes[attributeKey];
|
|
49
|
+
const { value, size = 1 } = attribute;
|
|
50
|
+
const listData = getFixedSizeListData(value, size);
|
|
51
|
+
arrowDatas.push(listData);
|
|
52
|
+
// fields.push(field);
|
|
53
|
+
}
|
|
54
|
+
const structField = new arrow.Struct(arrowSchema.fields);
|
|
55
|
+
const length = arrowDatas[0].length;
|
|
56
|
+
const structData = new arrow.Data(structField, 0, length, 0, undefined, arrowDatas);
|
|
57
|
+
const recordBatch = new arrow.RecordBatch(arrowSchema, structData);
|
|
58
|
+
const table = new arrow.Table([recordBatch]);
|
|
59
|
+
return { shape: 'arrow-table', schema, data: table };
|
|
60
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Mesh, ColumnarTable, ArrowTable } from '@loaders.gl/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Convert a mesh to a specific shape
|
|
4
|
+
*/
|
|
5
|
+
export declare function convertTableToMesh(table: ColumnarTable | ArrowTable): Mesh;
|
|
6
|
+
export declare function convertArrowTableToMesh(table: ArrowTable): Mesh;
|
|
7
|
+
//# sourceMappingURL=convert-table-to-mesh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-table-to-mesh.d.ts","sourceRoot":"","sources":["../../../src/lib/mesh/convert-table-to-mesh.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,IAAI,EAAE,aAAa,EAAE,UAAU,EAAS,MAAM,oBAAoB,CAAC;AAKhF;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,GAAG,UAAU,GAAG,IAAI,CAS1E;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAmB/D"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { getFixedSizeListSize } from "../arrow-utils/arrow-fixed-size-list-utils.js";
|
|
5
|
+
import { serializeArrowSchema } from "../schema/convert-arrow-schema.js";
|
|
6
|
+
// import {makeMeshAttributeMetadata} from './deduce-mesh-schema';
|
|
7
|
+
/**
|
|
8
|
+
* Convert a mesh to a specific shape
|
|
9
|
+
*/
|
|
10
|
+
export function convertTableToMesh(table) {
|
|
11
|
+
switch (table.shape) {
|
|
12
|
+
// case 'columnar-table':
|
|
13
|
+
// return convertColumnarTableToMesh(table);
|
|
14
|
+
case 'arrow-table':
|
|
15
|
+
return convertArrowTableToMesh(table);
|
|
16
|
+
default:
|
|
17
|
+
throw new Error(table.shape);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function convertArrowTableToMesh(table) {
|
|
21
|
+
const arrowTable = table.data;
|
|
22
|
+
const schema = serializeArrowSchema(arrowTable.schema);
|
|
23
|
+
const fields = schema.fields;
|
|
24
|
+
const attributes = {};
|
|
25
|
+
for (const field of fields) {
|
|
26
|
+
const { name } = field;
|
|
27
|
+
const attributeData = arrowTable.getChild(name);
|
|
28
|
+
const size = getFixedSizeListSize(attributeData);
|
|
29
|
+
const typedArray = attributeData?.toArray();
|
|
30
|
+
attributes[name] = { value: typedArray, size };
|
|
31
|
+
}
|
|
32
|
+
fixMetadata(schema);
|
|
33
|
+
const topology = schema.metadata.topology;
|
|
34
|
+
return { schema, attributes, topology, mode: 0 };
|
|
35
|
+
}
|
|
36
|
+
function fixMetadata(schema) {
|
|
37
|
+
schema.metadata ||= {};
|
|
38
|
+
schema.metadata.topology ||= 'point-list';
|
|
39
|
+
schema.metadata.mode ||= '0';
|
|
40
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MeshAttribute, MeshAttributes, Schema, Field } from '@loaders.gl/schema';
|
|
2
|
+
/**
|
|
3
|
+
* Create a schema for mesh attributes data
|
|
4
|
+
* @param attributes
|
|
5
|
+
* @param metadata
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function deduceMeshSchema(attributes: MeshAttributes, metadata?: Record<string, string>): Schema;
|
|
9
|
+
/**
|
|
10
|
+
* Create arrow-like schema field for mesh attribute
|
|
11
|
+
* @param attributeName
|
|
12
|
+
* @param attribute
|
|
13
|
+
* @param optionalMetadata
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare function deduceMeshField(name: string, attribute: MeshAttribute, optionalMetadata?: Record<string, string>): Field;
|
|
17
|
+
/**
|
|
18
|
+
* Make metadata by mesh attribute properties
|
|
19
|
+
* @param attribute
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export declare function makeMeshAttributeMetadata(attribute: MeshAttribute): Record<string, string>;
|
|
23
|
+
//# sourceMappingURL=deduce-mesh-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deduce-mesh-schema.d.ts","sourceRoot":"","sources":["../../../src/lib/mesh/deduce-mesh-schema.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,aAAa,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAC,MAAM,oBAAoB,CAAC;AAGhF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,cAAc,EAC1B,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACpC,MAAM,CAGR;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,aAAa,EACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACxC,KAAK,CASP;AAgBD;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAY1F"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { getDataTypeFromTypedArray } from "../schema/data-type.js";
|
|
5
|
+
/**
|
|
6
|
+
* Create a schema for mesh attributes data
|
|
7
|
+
* @param attributes
|
|
8
|
+
* @param metadata
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export function deduceMeshSchema(attributes, metadata = {}) {
|
|
12
|
+
const fields = deduceMeshFields(attributes);
|
|
13
|
+
return { fields, metadata };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create arrow-like schema field for mesh attribute
|
|
17
|
+
* @param attributeName
|
|
18
|
+
* @param attribute
|
|
19
|
+
* @param optionalMetadata
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export function deduceMeshField(name, attribute, optionalMetadata) {
|
|
23
|
+
const type = getDataTypeFromTypedArray(attribute.value);
|
|
24
|
+
const metadata = optionalMetadata ? optionalMetadata : makeMeshAttributeMetadata(attribute);
|
|
25
|
+
return {
|
|
26
|
+
name,
|
|
27
|
+
type: { type: 'fixed-size-list', listSize: attribute.size, children: [{ name: 'value', type }] },
|
|
28
|
+
nullable: false,
|
|
29
|
+
metadata
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create fields array for mesh attributes
|
|
34
|
+
* @param attributes
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
function deduceMeshFields(attributes) {
|
|
38
|
+
const fields = [];
|
|
39
|
+
for (const attributeName in attributes) {
|
|
40
|
+
const attribute = attributes[attributeName];
|
|
41
|
+
fields.push(deduceMeshField(attributeName, attribute));
|
|
42
|
+
}
|
|
43
|
+
return fields;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Make metadata by mesh attribute properties
|
|
47
|
+
* @param attribute
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
export function makeMeshAttributeMetadata(attribute) {
|
|
51
|
+
const result = {};
|
|
52
|
+
if ('byteOffset' in attribute) {
|
|
53
|
+
result.byteOffset = attribute.byteOffset.toString(10);
|
|
54
|
+
}
|
|
55
|
+
if ('byteStride' in attribute) {
|
|
56
|
+
result.byteStride = attribute.byteStride.toString(10);
|
|
57
|
+
}
|
|
58
|
+
if ('normalized' in attribute) {
|
|
59
|
+
result.normalized = attribute.normalized.toString();
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MeshAttributes } from '@loaders.gl/schema';
|
|
2
|
+
import { TypedArray } from "../../types/types.js";
|
|
3
|
+
type TypedArrays = {
|
|
4
|
+
[key: string]: TypedArray;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Holds an axis aligned bounding box
|
|
8
|
+
* TODO - make sure AxisAlignedBoundingBox in math.gl/culling understands this format (or change this format)
|
|
9
|
+
*/
|
|
10
|
+
type BoundingBox = [[number, number, number], [number, number, number]];
|
|
11
|
+
/**
|
|
12
|
+
* Get number of vertices in mesh
|
|
13
|
+
* @param attributes
|
|
14
|
+
*/
|
|
15
|
+
export declare function getMeshSize(attributes: TypedArrays): number;
|
|
16
|
+
/**
|
|
17
|
+
* Get the (axis aligned) bounding box of a mesh
|
|
18
|
+
* @param attributes
|
|
19
|
+
* @returns array of two vectors representing the axis aligned bounding box
|
|
20
|
+
*/
|
|
21
|
+
export declare function getMeshBoundingBox(attributes: MeshAttributes): BoundingBox;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=mesh-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/mesh/mesh-utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAC,UAAU,EAAC,6BAA0B;AAE7C,KAAK,WAAW,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAC,CAAC;AAE/C;;;GAGG;AACH,KAAK,WAAW,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAExE;;;GAGG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,WAAW,GAAG,MAAM,CAU3D;AAED;;;;GAIG;AAEH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,cAAc,GAAG,WAAW,CA4B1E"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get number of vertices in mesh
|
|
3
|
+
* @param attributes
|
|
4
|
+
*/
|
|
5
|
+
export function getMeshSize(attributes) {
|
|
6
|
+
let size = 0;
|
|
7
|
+
for (const attributeName in attributes) {
|
|
8
|
+
const attribute = attributes[attributeName];
|
|
9
|
+
if (ArrayBuffer.isView(attribute)) {
|
|
10
|
+
// @ts-ignore DataView doesn't have BYTES_PER_ELEMENT
|
|
11
|
+
size += attribute.byteLength * attribute.BYTES_PER_ELEMENT;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return size;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get the (axis aligned) bounding box of a mesh
|
|
18
|
+
* @param attributes
|
|
19
|
+
* @returns array of two vectors representing the axis aligned bounding box
|
|
20
|
+
*/
|
|
21
|
+
// eslint-disable-next-line complexity
|
|
22
|
+
export function getMeshBoundingBox(attributes) {
|
|
23
|
+
let minX = Infinity;
|
|
24
|
+
let minY = Infinity;
|
|
25
|
+
let minZ = Infinity;
|
|
26
|
+
let maxX = -Infinity;
|
|
27
|
+
let maxY = -Infinity;
|
|
28
|
+
let maxZ = -Infinity;
|
|
29
|
+
const positions = attributes.POSITION ? attributes.POSITION.value : [];
|
|
30
|
+
const len = positions && positions.length;
|
|
31
|
+
for (let i = 0; i < len; i += 3) {
|
|
32
|
+
const x = positions[i];
|
|
33
|
+
const y = positions[i + 1];
|
|
34
|
+
const z = positions[i + 2];
|
|
35
|
+
minX = x < minX ? x : minX;
|
|
36
|
+
minY = y < minY ? y : minY;
|
|
37
|
+
minZ = z < minZ ? z : minZ;
|
|
38
|
+
maxX = x > maxX ? x : maxX;
|
|
39
|
+
maxY = y > maxY ? y : maxY;
|
|
40
|
+
maxZ = z > maxZ ? z : maxZ;
|
|
41
|
+
}
|
|
42
|
+
return [
|
|
43
|
+
[minX, minY, minZ],
|
|
44
|
+
[maxX, maxY, maxZ]
|
|
45
|
+
];
|
|
46
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DataType, Field, Schema, SchemaMetadata } from '@loaders.gl/schema';
|
|
2
|
+
import * as arrow from 'apache-arrow';
|
|
3
|
+
/** Convert Apache Arrow Schema (class instance) to a serialized Schema (plain data) */
|
|
4
|
+
export declare function convertArrowToSchema(arrowSchema: arrow.Schema): Schema;
|
|
5
|
+
/** Convert Apache Arrow Schema (class instance) to a serialized Schema (plain data) */
|
|
6
|
+
export declare function convertSchemaToArrow(schema: Schema): arrow.Schema;
|
|
7
|
+
/** Convert Apache Arrow Schema (class instance) to a serialized Schema (plain data) */
|
|
8
|
+
export declare function serializeArrowSchema(arrowSchema: arrow.Schema): Schema;
|
|
9
|
+
/** Convert a serialized Schema (plain data) to an Apache Arrow Schema (class instance) */
|
|
10
|
+
export declare function deserializeArrowSchema(schema: Schema): arrow.Schema;
|
|
11
|
+
/** Convert Apache Arrow Schema metadata (Map<string, string>) to serialized metadata (Record<string, string> */
|
|
12
|
+
export declare function serializeArrowMetadata(arrowMetadata: Map<string, string>): SchemaMetadata;
|
|
13
|
+
/** Convert serialized metadata (Record<string, string> to Apache Arrow Schema metadata (Map<string, string>) to */
|
|
14
|
+
export declare function deserializeArrowMetadata(metadata?: SchemaMetadata): Map<string, string>;
|
|
15
|
+
/** Convert Apache Arrow Field (class instance) to serialized Field (plain data) */
|
|
16
|
+
export declare function serializeArrowField(field: arrow.Field): Field;
|
|
17
|
+
/** Convert a serialized Field (plain data) to an Apache Arrow Field (class instance)*/
|
|
18
|
+
export declare function deserializeArrowField(field: Field): arrow.Field;
|
|
19
|
+
/** Converts a serializable loaders.gl data type to hydrated arrow data type */
|
|
20
|
+
export declare function serializeArrowType(arrowType: arrow.DataType): DataType;
|
|
21
|
+
/** Converts a serializable loaders.gl data type to hydrated arrow data type */
|
|
22
|
+
export declare function deserializeArrowType(dataType: DataType): arrow.DataType;
|
|
23
|
+
//# sourceMappingURL=convert-arrow-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-arrow-schema.d.ts","sourceRoot":"","sources":["../../../src/lib/schema/convert-arrow-schema.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,uFAAuF;AACvF,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAEtE;AAED,uFAAuF;AACvF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAEjE;AAED,uFAAuF;AACvF,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAKtE;AAED,0FAA0F;AAC1F,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAKnE;AAED,gHAAgH;AAChH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,cAAc,CAEzF;AAED,mHAAmH;AACnH,wBAAgB,wBAAwB,CAAC,QAAQ,CAAC,EAAE,cAAc,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAEvF;AAED,mFAAmF;AACnF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,KAAK,CAO7D;AAED,uFAAuF;AACvF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAAC,KAAK,CAO/D;AAED,+EAA+E;AAE/E,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAuJtE;AAED,+EAA+E;AAE/E,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAgFvE"}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import * as arrow from 'apache-arrow';
|
|
5
|
+
/** Convert Apache Arrow Schema (class instance) to a serialized Schema (plain data) */
|
|
6
|
+
export function convertArrowToSchema(arrowSchema) {
|
|
7
|
+
return serializeArrowSchema(arrowSchema);
|
|
8
|
+
}
|
|
9
|
+
/** Convert Apache Arrow Schema (class instance) to a serialized Schema (plain data) */
|
|
10
|
+
export function convertSchemaToArrow(schema) {
|
|
11
|
+
return deserializeArrowSchema(schema);
|
|
12
|
+
}
|
|
13
|
+
/** Convert Apache Arrow Schema (class instance) to a serialized Schema (plain data) */
|
|
14
|
+
export function serializeArrowSchema(arrowSchema) {
|
|
15
|
+
return {
|
|
16
|
+
fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
|
|
17
|
+
metadata: serializeArrowMetadata(arrowSchema.metadata)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Convert a serialized Schema (plain data) to an Apache Arrow Schema (class instance) */
|
|
21
|
+
export function deserializeArrowSchema(schema) {
|
|
22
|
+
return new arrow.Schema(schema.fields.map((field) => deserializeArrowField(field)), deserializeArrowMetadata(schema.metadata));
|
|
23
|
+
}
|
|
24
|
+
/** Convert Apache Arrow Schema metadata (Map<string, string>) to serialized metadata (Record<string, string> */
|
|
25
|
+
export function serializeArrowMetadata(arrowMetadata) {
|
|
26
|
+
return Object.fromEntries(arrowMetadata);
|
|
27
|
+
}
|
|
28
|
+
/** Convert serialized metadata (Record<string, string> to Apache Arrow Schema metadata (Map<string, string>) to */
|
|
29
|
+
export function deserializeArrowMetadata(metadata) {
|
|
30
|
+
return metadata ? new Map(Object.entries(metadata)) : new Map();
|
|
31
|
+
}
|
|
32
|
+
/** Convert Apache Arrow Field (class instance) to serialized Field (plain data) */
|
|
33
|
+
export function serializeArrowField(field) {
|
|
34
|
+
return {
|
|
35
|
+
name: field.name,
|
|
36
|
+
type: serializeArrowType(field.type),
|
|
37
|
+
nullable: field.nullable,
|
|
38
|
+
metadata: serializeArrowMetadata(field.metadata)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Convert a serialized Field (plain data) to an Apache Arrow Field (class instance)*/
|
|
42
|
+
export function deserializeArrowField(field) {
|
|
43
|
+
return new arrow.Field(field.name, deserializeArrowType(field.type), field.nullable, deserializeArrowMetadata(field.metadata));
|
|
44
|
+
}
|
|
45
|
+
/** Converts a serializable loaders.gl data type to hydrated arrow data type */
|
|
46
|
+
// eslint-disable-next-line complexity
|
|
47
|
+
export function serializeArrowType(arrowType) {
|
|
48
|
+
switch (arrowType.constructor) {
|
|
49
|
+
case arrow.Null:
|
|
50
|
+
return 'null';
|
|
51
|
+
case arrow.Binary:
|
|
52
|
+
return 'binary';
|
|
53
|
+
case arrow.Bool:
|
|
54
|
+
return 'bool';
|
|
55
|
+
case arrow.Int:
|
|
56
|
+
const intType = arrowType;
|
|
57
|
+
return `${intType.isSigned ? 'u' : ''}int${intType.bitWidth}`;
|
|
58
|
+
case arrow.Int8:
|
|
59
|
+
return 'int8';
|
|
60
|
+
case arrow.Int16:
|
|
61
|
+
return 'int16';
|
|
62
|
+
case arrow.Int32:
|
|
63
|
+
return 'int32';
|
|
64
|
+
case arrow.Int64:
|
|
65
|
+
return 'int64';
|
|
66
|
+
case arrow.Uint8:
|
|
67
|
+
return 'uint8';
|
|
68
|
+
case arrow.Uint16:
|
|
69
|
+
return 'uint16';
|
|
70
|
+
case arrow.Uint32:
|
|
71
|
+
return 'uint32';
|
|
72
|
+
case arrow.Uint64:
|
|
73
|
+
return 'uint64';
|
|
74
|
+
case arrow.Float:
|
|
75
|
+
const precision = arrowType.precision;
|
|
76
|
+
// return `float(precision + 1) * 16`;
|
|
77
|
+
switch (precision) {
|
|
78
|
+
case arrow.Precision.HALF:
|
|
79
|
+
return 'float16';
|
|
80
|
+
case arrow.Precision.SINGLE:
|
|
81
|
+
return 'float32';
|
|
82
|
+
case arrow.Precision.DOUBLE:
|
|
83
|
+
return 'float64';
|
|
84
|
+
default:
|
|
85
|
+
return 'float16';
|
|
86
|
+
}
|
|
87
|
+
case arrow.Float16:
|
|
88
|
+
return 'float16';
|
|
89
|
+
case arrow.Float32:
|
|
90
|
+
return 'float32';
|
|
91
|
+
case arrow.Float64:
|
|
92
|
+
return 'float64';
|
|
93
|
+
case arrow.Utf8:
|
|
94
|
+
return 'utf8';
|
|
95
|
+
case arrow.Decimal:
|
|
96
|
+
const decimal = arrowType;
|
|
97
|
+
return {
|
|
98
|
+
type: 'decimal',
|
|
99
|
+
bitWidth: decimal.bitWidth,
|
|
100
|
+
precision: decimal.precision,
|
|
101
|
+
scale: decimal.scale
|
|
102
|
+
};
|
|
103
|
+
case arrow.Date_:
|
|
104
|
+
const dateUnit = arrowType.unit;
|
|
105
|
+
return dateUnit === arrow.DateUnit.DAY ? 'date-day' : 'date-millisecond';
|
|
106
|
+
case arrow.DateDay:
|
|
107
|
+
return 'date-day';
|
|
108
|
+
case arrow.DateMillisecond:
|
|
109
|
+
return 'date-millisecond';
|
|
110
|
+
case arrow.Time:
|
|
111
|
+
const timeUnit = arrowType.unit;
|
|
112
|
+
switch (timeUnit) {
|
|
113
|
+
case arrow.TimeUnit.SECOND:
|
|
114
|
+
return 'time-second';
|
|
115
|
+
case arrow.TimeUnit.MILLISECOND:
|
|
116
|
+
return 'time-millisecond';
|
|
117
|
+
case arrow.TimeUnit.MICROSECOND:
|
|
118
|
+
return 'time-microsecond';
|
|
119
|
+
case arrow.TimeUnit.NANOSECOND:
|
|
120
|
+
return 'time-nanosecond';
|
|
121
|
+
default:
|
|
122
|
+
return 'time-second';
|
|
123
|
+
}
|
|
124
|
+
case arrow.TimeMillisecond:
|
|
125
|
+
return 'time-millisecond';
|
|
126
|
+
case arrow.TimeSecond:
|
|
127
|
+
return 'time-second';
|
|
128
|
+
case arrow.TimeMicrosecond:
|
|
129
|
+
return 'time-microsecond';
|
|
130
|
+
case arrow.TimeNanosecond:
|
|
131
|
+
return 'time-nanosecond';
|
|
132
|
+
case arrow.Timestamp:
|
|
133
|
+
const timeStampUnit = arrowType.unit;
|
|
134
|
+
switch (timeStampUnit) {
|
|
135
|
+
case arrow.TimeUnit.SECOND:
|
|
136
|
+
return 'timestamp-second';
|
|
137
|
+
case arrow.TimeUnit.MILLISECOND:
|
|
138
|
+
return 'timestamp-millisecond';
|
|
139
|
+
case arrow.TimeUnit.MICROSECOND:
|
|
140
|
+
return 'timestamp-microsecond';
|
|
141
|
+
case arrow.TimeUnit.NANOSECOND:
|
|
142
|
+
return 'timestamp-nanosecond';
|
|
143
|
+
default:
|
|
144
|
+
return 'timestamp-second';
|
|
145
|
+
}
|
|
146
|
+
case arrow.TimestampSecond:
|
|
147
|
+
return 'timestamp-second';
|
|
148
|
+
case arrow.TimestampMillisecond:
|
|
149
|
+
return 'timestamp-millisecond';
|
|
150
|
+
case arrow.TimestampMicrosecond:
|
|
151
|
+
return 'timestamp-microsecond';
|
|
152
|
+
case arrow.TimestampNanosecond:
|
|
153
|
+
return 'timestamp-nanosecond';
|
|
154
|
+
case arrow.Interval:
|
|
155
|
+
const intervalUnit = arrowType.unit;
|
|
156
|
+
switch (intervalUnit) {
|
|
157
|
+
case arrow.IntervalUnit.DAY_TIME:
|
|
158
|
+
return 'interval-daytime';
|
|
159
|
+
case arrow.IntervalUnit.YEAR_MONTH:
|
|
160
|
+
return 'interval-yearmonth';
|
|
161
|
+
default:
|
|
162
|
+
return 'interval-daytime';
|
|
163
|
+
}
|
|
164
|
+
case arrow.IntervalDayTime:
|
|
165
|
+
return 'interval-daytime';
|
|
166
|
+
case arrow.IntervalYearMonth:
|
|
167
|
+
return 'interval-yearmonth';
|
|
168
|
+
case arrow.Map_:
|
|
169
|
+
const mapType = arrowType;
|
|
170
|
+
return {
|
|
171
|
+
type: 'map',
|
|
172
|
+
keysSorted: mapType.keysSorted,
|
|
173
|
+
children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
|
|
174
|
+
};
|
|
175
|
+
case arrow.List:
|
|
176
|
+
const listType = arrowType;
|
|
177
|
+
const listField = listType.valueField;
|
|
178
|
+
return {
|
|
179
|
+
type: 'list',
|
|
180
|
+
children: [serializeArrowField(listField)]
|
|
181
|
+
};
|
|
182
|
+
case arrow.FixedSizeList:
|
|
183
|
+
const fixedSizeList = arrowType;
|
|
184
|
+
return {
|
|
185
|
+
type: 'fixed-size-list',
|
|
186
|
+
listSize: fixedSizeList.listSize,
|
|
187
|
+
children: [serializeArrowField(fixedSizeList.children[0])]
|
|
188
|
+
};
|
|
189
|
+
case arrow.Struct:
|
|
190
|
+
const structType = arrowType;
|
|
191
|
+
return {
|
|
192
|
+
type: 'struct',
|
|
193
|
+
children: structType.children.map((arrowField) => serializeArrowField(arrowField))
|
|
194
|
+
};
|
|
195
|
+
default:
|
|
196
|
+
throw new Error(`arrow type not supported: ${arrowType.constructor.name}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/** Converts a serializable loaders.gl data type to hydrated arrow data type */
|
|
200
|
+
// eslint-disable-next-line complexity
|
|
201
|
+
export function deserializeArrowType(dataType) {
|
|
202
|
+
if (typeof dataType === 'object') {
|
|
203
|
+
switch (dataType.type) {
|
|
204
|
+
case 'decimal':
|
|
205
|
+
return new arrow.Decimal(dataType.precision, dataType.scale, dataType.bitWidth);
|
|
206
|
+
case 'map':
|
|
207
|
+
let children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
|
|
208
|
+
return new arrow.Map_(children, dataType.keysSorted);
|
|
209
|
+
case 'list':
|
|
210
|
+
const field = deserializeArrowField(dataType.children[0]);
|
|
211
|
+
return new arrow.List(field);
|
|
212
|
+
case 'fixed-size-list':
|
|
213
|
+
const child = deserializeArrowField(dataType.children[0]);
|
|
214
|
+
return new arrow.FixedSizeList(dataType.listSize, child);
|
|
215
|
+
case 'struct':
|
|
216
|
+
children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
|
|
217
|
+
return new arrow.Struct(children);
|
|
218
|
+
default:
|
|
219
|
+
throw new Error('array type not supported');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
switch (dataType) {
|
|
223
|
+
case 'null':
|
|
224
|
+
return new arrow.Null();
|
|
225
|
+
case 'binary':
|
|
226
|
+
return new arrow.Binary();
|
|
227
|
+
case 'bool':
|
|
228
|
+
return new arrow.Bool();
|
|
229
|
+
case 'int8':
|
|
230
|
+
return new arrow.Int8();
|
|
231
|
+
case 'int16':
|
|
232
|
+
return new arrow.Int16();
|
|
233
|
+
case 'int32':
|
|
234
|
+
return new arrow.Int32();
|
|
235
|
+
case 'int64':
|
|
236
|
+
return new arrow.Int64();
|
|
237
|
+
case 'uint8':
|
|
238
|
+
return new arrow.Uint8();
|
|
239
|
+
case 'uint16':
|
|
240
|
+
return new arrow.Uint16();
|
|
241
|
+
case 'uint32':
|
|
242
|
+
return new arrow.Uint32();
|
|
243
|
+
case 'uint64':
|
|
244
|
+
return new arrow.Uint64();
|
|
245
|
+
case 'float16':
|
|
246
|
+
return new arrow.Float16();
|
|
247
|
+
case 'float32':
|
|
248
|
+
return new arrow.Float32();
|
|
249
|
+
case 'float64':
|
|
250
|
+
return new arrow.Float64();
|
|
251
|
+
case 'utf8':
|
|
252
|
+
return new arrow.Utf8();
|
|
253
|
+
case 'date-day':
|
|
254
|
+
return new arrow.DateDay();
|
|
255
|
+
case 'date-millisecond':
|
|
256
|
+
return new arrow.DateMillisecond();
|
|
257
|
+
case 'time-second':
|
|
258
|
+
return new arrow.TimeSecond();
|
|
259
|
+
case 'time-millisecond':
|
|
260
|
+
return new arrow.TimeMillisecond();
|
|
261
|
+
case 'time-microsecond':
|
|
262
|
+
return new arrow.TimeMicrosecond();
|
|
263
|
+
case 'time-nanosecond':
|
|
264
|
+
return new arrow.TimeNanosecond();
|
|
265
|
+
case 'timestamp-second':
|
|
266
|
+
return new arrow.TimestampSecond();
|
|
267
|
+
case 'timestamp-millisecond':
|
|
268
|
+
return new arrow.TimestampMillisecond();
|
|
269
|
+
case 'timestamp-microsecond':
|
|
270
|
+
return new arrow.TimestampMicrosecond();
|
|
271
|
+
case 'timestamp-nanosecond':
|
|
272
|
+
return new arrow.TimestampNanosecond();
|
|
273
|
+
case 'interval-daytime':
|
|
274
|
+
return new arrow.IntervalDayTime();
|
|
275
|
+
case 'interval-yearmonth':
|
|
276
|
+
return new arrow.IntervalYearMonth();
|
|
277
|
+
default:
|
|
278
|
+
throw new Error('array type not supported');
|
|
279
|
+
}
|
|
280
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DataType, TypedArray, TypedArrayConstructor, ArrayType } from '@loaders.gl/schema';
|
|
2
|
+
/** Deduce column types from values */
|
|
3
|
+
export declare function getDataTypeFromValue(value: unknown, defaultNumberType?: 'float32'): DataType;
|
|
4
|
+
/**
|
|
5
|
+
* Deduces a simple data type "descriptor from a typed array instance
|
|
6
|
+
*/
|
|
7
|
+
export declare function getDataTypeFromArray(array: ArrayType): {
|
|
8
|
+
type: DataType;
|
|
9
|
+
nullable: boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Deduces a simple data type "descriptor from a typed array instance
|
|
13
|
+
*/
|
|
14
|
+
export declare function getDataTypeFromTypedArray(array: TypedArray): DataType;
|
|
15
|
+
export declare function getArrayTypeFromDataType(type: DataType, nullable: boolean | undefined): TypedArrayConstructor | ArrayConstructor;
|
|
16
|
+
//# sourceMappingURL=data-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-type.d.ts","sourceRoot":"","sources":["../../../src/lib/schema/data-type.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAE,qBAAqB,EAAE,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAE1F,sCAAsC;AACtC,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,iBAAiB,GAAE,SAAqB,GACvC,QAAQ,CAcV;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,GAAG;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAC,CAW1F;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAsBrE;AAED,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,QAAQ,EACd,QAAQ,EAAE,OAAO,GAAG,SAAS,GAC5B,qBAAqB,GAAG,gBAAgB,CA8B1C"}
|