@loaders.gl/schema 3.1.0-alpha.4 → 3.1.0-beta.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/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +1289 -0
- package/dist/category/common.d.ts +20 -0
- package/dist/category/common.d.ts.map +1 -0
- package/dist/category/common.js +10 -0
- package/dist/category/gis.d.ts +50 -0
- package/dist/category/gis.d.ts.map +1 -0
- package/dist/category/gis.js +2 -0
- package/dist/category/mesh/convert-mesh.d.ts +15 -0
- package/dist/category/mesh/convert-mesh.d.ts.map +1 -0
- package/dist/category/mesh/convert-mesh.js +39 -0
- package/dist/category/mesh/deduce-mesh-schema.d.ts +24 -0
- package/dist/category/mesh/deduce-mesh-schema.d.ts.map +1 -0
- package/dist/category/mesh/deduce-mesh-schema.js +62 -0
- package/dist/category/mesh/mesh-to-arrow-table.d.ts +1 -0
- package/dist/category/mesh/mesh-to-arrow-table.d.ts.map +1 -0
- package/dist/category/mesh/mesh-to-arrow-table.js +44 -0
- package/dist/category/mesh/mesh-types.d.ts +50 -0
- package/dist/category/mesh/mesh-types.d.ts.map +1 -0
- package/dist/category/mesh/mesh-types.js +2 -0
- package/dist/category/mesh/mesh-utils.d.ts +23 -0
- package/dist/category/mesh/mesh-utils.d.ts.map +1 -0
- package/dist/category/mesh/mesh-utils.js +51 -0
- package/dist/category/table/deduce-table-schema.d.ts +9 -0
- package/dist/category/table/deduce-table-schema.d.ts.map +1 -0
- package/dist/category/table/deduce-table-schema.js +106 -0
- package/dist/category/table/table-types.d.ts +78 -0
- package/dist/category/table/table-types.d.ts.map +1 -0
- package/dist/category/table/table-types.js +2 -0
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/category/mesh/convert-mesh.js +2 -18
- package/dist/es5/category/mesh/convert-mesh.js.map +1 -1
- package/dist/es5/category/mesh/deduce-mesh-schema.js +9 -9
- package/dist/es5/category/mesh/deduce-mesh-schema.js.map +1 -1
- package/dist/es5/category/mesh/mesh-to-arrow-table.js +0 -38
- package/dist/es5/category/mesh/mesh-to-arrow-table.js.map +1 -1
- package/dist/es5/category/mesh/mesh-utils.js +16 -16
- package/dist/es5/category/mesh/mesh-utils.js.map +1 -1
- package/dist/es5/category/table/deduce-table-schema.js +9 -9
- package/dist/es5/category/table/deduce-table-schema.js.map +1 -1
- package/dist/es5/index.js +53 -53
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/arrow/arrow-like-type-utils.js +1 -1
- package/dist/es5/lib/arrow/arrow-like-type-utils.js.map +1 -1
- package/dist/es5/lib/arrow/arrow-type-utils.js +0 -70
- package/dist/es5/lib/arrow/arrow-type-utils.js.map +1 -1
- package/dist/es5/lib/arrow/get-type-info.js +4 -4
- package/dist/es5/lib/arrow/get-type-info.js.map +1 -1
- package/dist/es5/lib/batches/base-table-batch-aggregator.js +42 -53
- package/dist/es5/lib/batches/base-table-batch-aggregator.js.map +1 -1
- package/dist/es5/lib/batches/columnar-table-batch-aggregator.js +71 -90
- package/dist/es5/lib/batches/columnar-table-batch-aggregator.js.map +1 -1
- package/dist/es5/lib/batches/row-table-batch-aggregator.js +59 -70
- package/dist/es5/lib/batches/row-table-batch-aggregator.js.map +1 -1
- package/dist/es5/lib/batches/table-batch-builder.js +113 -133
- package/dist/es5/lib/batches/table-batch-builder.js.map +1 -1
- package/dist/es5/lib/schema/impl/enum.js +1 -1
- package/dist/es5/lib/schema/impl/field.js +19 -32
- package/dist/es5/lib/schema/impl/field.js.map +1 -1
- package/dist/es5/lib/schema/impl/schema.js +54 -119
- package/dist/es5/lib/schema/impl/schema.js.map +1 -1
- package/dist/es5/lib/schema/impl/type.js +395 -728
- package/dist/es5/lib/schema/impl/type.js.map +1 -1
- package/dist/es5/lib/schema/{index.js → schema.js} +38 -38
- package/dist/es5/lib/schema/schema.js.map +1 -0
- package/dist/es5/lib/schema-utils/deduce-column-type.js.map +1 -1
- package/dist/es5/lib/utils/async-queue.js +81 -164
- package/dist/es5/lib/utils/async-queue.js.map +1 -1
- package/dist/es5/lib/utils/row-utils.js +4 -4
- package/dist/es5/lib/utils/row-utils.js.map +1 -1
- package/dist/esm/category/mesh/convert-mesh.js +1 -8
- package/dist/esm/category/mesh/convert-mesh.js.map +1 -1
- package/dist/esm/category/mesh/deduce-mesh-schema.js +1 -1
- package/dist/esm/category/mesh/deduce-mesh-schema.js.map +1 -1
- package/dist/esm/category/mesh/mesh-to-arrow-table.js +0 -29
- package/dist/esm/category/mesh/mesh-to-arrow-table.js.map +1 -1
- package/dist/esm/category/table/deduce-table-schema.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/arrow/arrow-like-type-utils.js +1 -1
- package/dist/esm/lib/arrow/arrow-like-type-utils.js.map +1 -1
- package/dist/esm/lib/arrow/arrow-type-utils.js +0 -60
- package/dist/esm/lib/arrow/arrow-type-utils.js.map +1 -1
- package/dist/esm/lib/arrow/get-type-info.js +1 -1
- package/dist/esm/lib/arrow/get-type-info.js.map +1 -1
- package/dist/esm/lib/batches/base-table-batch-aggregator.js.map +1 -1
- package/dist/esm/lib/batches/columnar-table-batch-aggregator.js.map +1 -1
- package/dist/esm/lib/batches/row-table-batch-aggregator.js.map +1 -1
- package/dist/esm/lib/batches/table-batch-builder.js.map +1 -1
- package/dist/esm/lib/schema/impl/field.js +1 -1
- package/dist/esm/lib/schema/impl/field.js.map +1 -1
- package/dist/esm/lib/schema/impl/schema.js.map +1 -1
- package/dist/esm/lib/schema/impl/type.js +8 -8
- package/dist/esm/lib/schema/impl/type.js.map +1 -1
- package/dist/esm/lib/schema/{index.js → schema.js} +1 -1
- package/dist/esm/lib/schema/schema.js.map +1 -0
- package/dist/esm/lib/schema-utils/deduce-column-type.js.map +1 -1
- package/dist/esm/lib/utils/async-queue.js.map +1 -1
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +75 -0
- package/dist/lib/arrow/arrow-like-type-utils.d.ts +4 -0
- package/dist/lib/arrow/arrow-like-type-utils.d.ts.map +1 -0
- package/dist/lib/arrow/arrow-like-type-utils.js +27 -0
- package/dist/lib/arrow/arrow-type-utils.d.ts +1 -0
- package/dist/lib/arrow/arrow-type-utils.d.ts.map +1 -0
- package/dist/lib/arrow/arrow-type-utils.js +70 -0
- package/dist/lib/arrow/get-type-info.d.ts +14 -0
- package/dist/lib/arrow/get-type-info.d.ts.map +1 -0
- package/dist/lib/arrow/get-type-info.js +28 -0
- package/dist/lib/batches/base-table-batch-aggregator.d.ts +19 -0
- package/dist/lib/batches/base-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/batches/base-table-batch-aggregator.js +58 -0
- package/dist/lib/batches/columnar-table-batch-aggregator.d.ts +23 -0
- package/dist/lib/batches/columnar-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/batches/columnar-table-batch-aggregator.js +90 -0
- package/dist/lib/batches/row-table-batch-aggregator.d.ts +22 -0
- package/dist/lib/batches/row-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/batches/row-table-batch-aggregator.js +79 -0
- package/dist/lib/batches/table-batch-aggregator.d.ts +25 -0
- package/dist/lib/batches/table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/batches/table-batch-aggregator.js +2 -0
- package/dist/lib/batches/table-batch-builder.d.ts +53 -0
- package/dist/lib/batches/table-batch-builder.d.ts.map +1 -0
- package/dist/lib/batches/table-batch-builder.js +153 -0
- package/dist/lib/schema/impl/enum.d.ts +92 -0
- package/dist/lib/schema/impl/enum.d.ts.map +1 -0
- package/dist/lib/schema/impl/enum.js +97 -0
- package/dist/lib/schema/impl/field.d.ts +19 -0
- package/dist/lib/schema/impl/field.d.ts.map +1 -0
- package/dist/lib/schema/impl/field.js +32 -0
- package/dist/lib/schema/impl/schema.d.ts +16 -0
- package/dist/lib/schema/impl/schema.d.ts.map +1 -0
- package/dist/lib/schema/impl/schema.js +83 -0
- package/dist/lib/schema/impl/type.d.ts +176 -0
- package/dist/lib/schema/impl/type.d.ts.map +1 -0
- package/dist/lib/schema/impl/type.js +462 -0
- package/dist/lib/schema/schema.d.ts +5 -0
- package/dist/lib/schema/schema.d.ts.map +1 -0
- package/dist/lib/schema/schema.js +90 -0
- package/dist/lib/schema-utils/deduce-column-type.d.ts +3 -0
- package/dist/lib/schema-utils/deduce-column-type.d.ts.map +1 -0
- package/dist/lib/schema-utils/deduce-column-type.js +92 -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 +12 -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 +92 -0
- package/dist/lib/utils/row-utils.d.ts +9 -0
- package/dist/lib/utils/row-utils.d.ts.map +1 -0
- package/dist/lib/utils/row-utils.js +33 -0
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/package.json +5 -7
- package/src/category/common.ts +2 -1
- package/src/category/mesh/convert-mesh.ts +6 -6
- package/src/category/mesh/deduce-mesh-schema.ts +1 -1
- package/src/category/mesh/mesh-to-arrow-table.ts +4 -2
- package/src/category/mesh/mesh-types.ts +1 -1
- package/src/category/table/deduce-table-schema.ts +1 -1
- package/src/category/table/table-types.ts +5 -2
- package/src/index.ts +1 -1
- package/src/lib/arrow/arrow-like-type-utils.ts +11 -1
- package/src/lib/arrow/arrow-type-utils.ts +2 -0
- package/src/lib/arrow/get-type-info.ts +1 -1
- package/src/lib/batches/base-table-batch-aggregator.ts +1 -1
- package/src/lib/batches/columnar-table-batch-aggregator.ts +1 -1
- package/src/lib/batches/row-table-batch-aggregator.ts +1 -1
- package/src/lib/batches/table-batch-aggregator.ts +1 -1
- package/src/lib/batches/table-batch-builder.ts +2 -2
- package/src/lib/schema/impl/schema.ts +2 -2
- package/src/lib/schema/impl/type.ts +2 -2
- package/src/lib/schema/{index.ts → schema.ts} +0 -0
- package/src/lib/schema-utils/deduce-column-type.ts +6 -2
- package/src/lib/utils/async-queue.ts +7 -4
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/es5/lib/schema/index.js.map +0 -1
- package/dist/esm/lib/schema/index.js.map +0 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare type RecordBatch = any;
|
|
2
|
+
export declare type Field = any;
|
|
3
|
+
export declare type Schema = {
|
|
4
|
+
[key: string]: Field;
|
|
5
|
+
};
|
|
6
|
+
export declare type Batch = {
|
|
7
|
+
batchType: 'data' | 'metadata' | 'partial-result' | 'final-result';
|
|
8
|
+
mimeType?: string;
|
|
9
|
+
shape: string;
|
|
10
|
+
data: any;
|
|
11
|
+
recordBatch?: RecordBatch;
|
|
12
|
+
length: number;
|
|
13
|
+
schema?: Schema;
|
|
14
|
+
bytesUsed?: number;
|
|
15
|
+
count?: number;
|
|
16
|
+
cursor?: number;
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/category/common.ts"],"names":[],"mappings":"AACA,aAAK,WAAW,GAAG,GAAG,CAAC;AAEvB,oBAAY,KAAK,GAAG,GAAG,CAAC;AAExB,oBAAY,MAAM,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAAC;CACtB,CAAC;AAEF,oBAAY,KAAK,GAAG;IAClB,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,gBAAgB,GAAG,cAAc,CAAC;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,GAAG,CAAC;IACV,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { TypedArray } from '../types';
|
|
2
|
+
export type { GeoJSON, Feature, Geometry, Position, GeoJsonProperties } from 'geojson';
|
|
3
|
+
export type { Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon } from 'geojson';
|
|
4
|
+
export declare type BinaryAttribute = {
|
|
5
|
+
value: TypedArray;
|
|
6
|
+
size: number;
|
|
7
|
+
};
|
|
8
|
+
export declare type BinaryGeometryType = 'Point' | 'LineString' | 'Polygon';
|
|
9
|
+
declare type NumericProps = {
|
|
10
|
+
[key: string]: BinaryAttribute;
|
|
11
|
+
};
|
|
12
|
+
declare type Properties = object[];
|
|
13
|
+
/**
|
|
14
|
+
* Represent a single Geometry, similar to a GeoJSON Geometry
|
|
15
|
+
*/
|
|
16
|
+
export declare type BinaryGeometry = BinaryPointGeometry | BinaryLineGeometry | BinaryPolygonGeometry;
|
|
17
|
+
export declare type BinaryPointGeometry = {
|
|
18
|
+
type: 'Point';
|
|
19
|
+
positions: BinaryAttribute;
|
|
20
|
+
};
|
|
21
|
+
export declare type BinaryLineGeometry = {
|
|
22
|
+
type: 'LineString';
|
|
23
|
+
positions: BinaryAttribute;
|
|
24
|
+
pathIndices: BinaryAttribute;
|
|
25
|
+
};
|
|
26
|
+
export declare type BinaryPolygonGeometry = {
|
|
27
|
+
type: 'Polygon';
|
|
28
|
+
positions: BinaryAttribute;
|
|
29
|
+
polygonIndices: BinaryAttribute;
|
|
30
|
+
primitivePolygonIndices: BinaryAttribute;
|
|
31
|
+
};
|
|
32
|
+
export declare type BinaryProperties = {
|
|
33
|
+
featureIds: BinaryAttribute;
|
|
34
|
+
globalFeatureIds: BinaryAttribute;
|
|
35
|
+
numericProps: NumericProps;
|
|
36
|
+
properties: Properties;
|
|
37
|
+
fields?: Properties;
|
|
38
|
+
};
|
|
39
|
+
export declare type BinaryPointFeatures = BinaryPointGeometry & BinaryProperties;
|
|
40
|
+
export declare type BinaryLineFeatures = BinaryLineGeometry & BinaryProperties;
|
|
41
|
+
export declare type BinaryPolygonFeatures = BinaryPolygonGeometry & BinaryProperties;
|
|
42
|
+
/**
|
|
43
|
+
* Represent a collection of Features, similar to a GeoJSON FeatureCollection
|
|
44
|
+
*/
|
|
45
|
+
export declare type BinaryFeatures = {
|
|
46
|
+
points?: BinaryPointFeatures;
|
|
47
|
+
lines?: BinaryLineFeatures;
|
|
48
|
+
polygons?: BinaryPolygonFeatures;
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=gis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gis.d.ts","sourceRoot":"","sources":["../../src/category/gis.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAKzC,YAAY,EAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAC,MAAM,SAAS,CAAC;AAErF,YAAY,EAAC,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,OAAO,EAAE,YAAY,EAAC,MAAM,SAAS,CAAC;AAInG,oBAAY,eAAe,GAAG;IAAC,KAAK,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,CAAC;AAChE,oBAAY,kBAAkB,GAAG,OAAO,GAAG,YAAY,GAAG,SAAS,CAAC;AAEpE,aAAK,YAAY,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAA;CAAC,CAAC;AACrD,aAAK,UAAU,GAAG,MAAM,EAAE,CAAC;AAE3B;;GAEG;AACH,oBAAY,cAAc,GAAG,mBAAmB,GAAG,kBAAkB,GAAG,qBAAqB,CAAC;AAE9F,oBAAY,mBAAmB,GAAG;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,eAAe,CAAC;CAC5B,CAAC;AAEF,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,EAAE,eAAe,CAAC;IAC3B,WAAW,EAAE,eAAe,CAAC;CAC9B,CAAC;AAEF,oBAAY,qBAAqB,GAAG;IAClC,IAAI,EAAE,SAAS,CAAC;IAChB,SAAS,EAAE,eAAe,CAAC;IAC3B,cAAc,EAAE,eAAe,CAAC;IAChC,uBAAuB,EAAE,eAAe,CAAC;CAC1C,CAAC;AAEF,oBAAY,gBAAgB,GAAG;IAC7B,UAAU,EAAE,eAAe,CAAC;IAC5B,gBAAgB,EAAE,eAAe,CAAC;IAClC,YAAY,EAAE,YAAY,CAAC;IAC3B,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB,CAAC;AAEF,oBAAY,mBAAmB,GAAG,mBAAmB,GAAG,gBAAgB,CAAC;AACzE,oBAAY,kBAAkB,GAAG,kBAAkB,GAAG,gBAAgB,CAAC;AACvE,oBAAY,qBAAqB,GAAG,qBAAqB,GAAG,gBAAgB,CAAC;AAE7E;;GAEG;AACH,oBAAY,cAAc,GAAG;IAC3B,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B,QAAQ,CAAC,EAAE,qBAAqB,CAAC;CAClC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Mesh } from './mesh-types';
|
|
2
|
+
import type { ColumnarTable, ArrowTable } from '../table/table-types';
|
|
3
|
+
declare type TargetShape = 'mesh' | 'columnar-table' | 'arrow-table';
|
|
4
|
+
/**
|
|
5
|
+
* Convert a mesh to a specific shape
|
|
6
|
+
*/
|
|
7
|
+
export declare function convertMesh(mesh: Mesh, shape: TargetShape, options?: any): Mesh | ColumnarTable | ArrowTable;
|
|
8
|
+
/**
|
|
9
|
+
* Convert a loaders.gl Mesh to a Columnar Table
|
|
10
|
+
* @param mesh
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function convertMeshToColumnarTable(mesh: Mesh): ColumnarTable;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=convert-mesh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert-mesh.d.ts","sourceRoot":"","sources":["../../../src/category/mesh/convert-mesh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAC,aAAa,EAAE,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAGpE,aAAK,WAAW,GAAG,MAAM,GAAG,gBAAgB,GAAG,aAAa,CAAC;AAE7D;;GAEG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,WAAW,EAClB,OAAO,CAAC,EAAE,GAAG,GACZ,IAAI,GAAG,aAAa,GAAG,UAAU,CAcnC;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,CAYpE"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertMeshToColumnarTable = exports.convertMesh = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Convert a mesh to a specific shape
|
|
6
|
+
*/
|
|
7
|
+
function convertMesh(mesh, shape, options) {
|
|
8
|
+
switch (shape || 'mesh') {
|
|
9
|
+
case 'mesh':
|
|
10
|
+
return mesh;
|
|
11
|
+
case 'columnar-table':
|
|
12
|
+
return convertMeshToColumnarTable(mesh);
|
|
13
|
+
// case 'arrow-table':
|
|
14
|
+
// return {
|
|
15
|
+
// shape: 'arrow-table',
|
|
16
|
+
// data: convertMeshToArrowTable(mesh)
|
|
17
|
+
// };
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`Unsupported shape ${options?.shape}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.convertMesh = convertMesh;
|
|
23
|
+
/**
|
|
24
|
+
* Convert a loaders.gl Mesh to a Columnar Table
|
|
25
|
+
* @param mesh
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
function convertMeshToColumnarTable(mesh) {
|
|
29
|
+
const columns = {};
|
|
30
|
+
for (const [columnName, attribute] of Object.entries(mesh.attributes)) {
|
|
31
|
+
columns[columnName] = attribute.value;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
shape: 'columnar-table',
|
|
35
|
+
schema: mesh.schema,
|
|
36
|
+
data: columns
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.convertMeshToColumnarTable = convertMeshToColumnarTable;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MeshAttribute, MeshAttributes } from './mesh-types';
|
|
2
|
+
import { Schema, Field } from '../../lib/schema/schema';
|
|
3
|
+
/**
|
|
4
|
+
* Create a schema for mesh attributes data
|
|
5
|
+
* @param attributes
|
|
6
|
+
* @param metadata
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function deduceMeshSchema(attributes: MeshAttributes, metadata?: Map<string, string>): Schema;
|
|
10
|
+
/**
|
|
11
|
+
* Create arrow-like schema field for mesh attribute
|
|
12
|
+
* @param attributeName
|
|
13
|
+
* @param attribute
|
|
14
|
+
* @param optionalMetadata
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare function deduceMeshField(attributeName: string, attribute: MeshAttribute, optionalMetadata?: Map<string, string>): Field;
|
|
18
|
+
/**
|
|
19
|
+
* Make metadata by mesh attribute properties
|
|
20
|
+
* @param attribute
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export declare function makeMeshAttributeMetadata(attribute: MeshAttribute): Map<string, string>;
|
|
24
|
+
//# sourceMappingURL=deduce-mesh-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deduce-mesh-schema.d.ts","sourceRoot":"","sources":["../../../src/category/mesh/deduce-mesh-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAC,MAAM,EAAE,KAAK,EAAgB,MAAM,yBAAyB,CAAC;AAGrE;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,cAAc,EAC1B,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,MAAM,CAGR;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,aAAa,EACxB,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACrC,KAAK,CAUP;AAgBD;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,aAAa,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAYvF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeMeshAttributeMetadata = exports.deduceMeshField = exports.deduceMeshSchema = void 0;
|
|
4
|
+
const schema_1 = require("../../lib/schema/schema");
|
|
5
|
+
const arrow_like_type_utils_1 = require("../../lib/arrow/arrow-like-type-utils");
|
|
6
|
+
/**
|
|
7
|
+
* Create a schema for mesh attributes data
|
|
8
|
+
* @param attributes
|
|
9
|
+
* @param metadata
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
function deduceMeshSchema(attributes, metadata) {
|
|
13
|
+
const fields = deduceMeshFields(attributes);
|
|
14
|
+
return new schema_1.Schema(fields, metadata);
|
|
15
|
+
}
|
|
16
|
+
exports.deduceMeshSchema = deduceMeshSchema;
|
|
17
|
+
/**
|
|
18
|
+
* Create arrow-like schema field for mesh attribute
|
|
19
|
+
* @param attributeName
|
|
20
|
+
* @param attribute
|
|
21
|
+
* @param optionalMetadata
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
function deduceMeshField(attributeName, attribute, optionalMetadata) {
|
|
25
|
+
const type = (0, arrow_like_type_utils_1.getArrowTypeFromTypedArray)(attribute.value);
|
|
26
|
+
const metadata = optionalMetadata ? optionalMetadata : makeMeshAttributeMetadata(attribute);
|
|
27
|
+
const field = new schema_1.Field(attributeName, new schema_1.FixedSizeList(attribute.size, new schema_1.Field('value', type)), false, metadata);
|
|
28
|
+
return field;
|
|
29
|
+
}
|
|
30
|
+
exports.deduceMeshField = deduceMeshField;
|
|
31
|
+
/**
|
|
32
|
+
* Create fields array for mesh attributes
|
|
33
|
+
* @param attributes
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
function deduceMeshFields(attributes) {
|
|
37
|
+
const fields = [];
|
|
38
|
+
for (const attributeName in attributes) {
|
|
39
|
+
const attribute = attributes[attributeName];
|
|
40
|
+
fields.push(deduceMeshField(attributeName, attribute));
|
|
41
|
+
}
|
|
42
|
+
return fields;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Make metadata by mesh attribute properties
|
|
46
|
+
* @param attribute
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
function makeMeshAttributeMetadata(attribute) {
|
|
50
|
+
const result = new Map();
|
|
51
|
+
if ('byteOffset' in attribute) {
|
|
52
|
+
result.set('byteOffset', attribute.byteOffset.toString(10));
|
|
53
|
+
}
|
|
54
|
+
if ('byteStride' in attribute) {
|
|
55
|
+
result.set('byteStride', attribute.byteStride.toString(10));
|
|
56
|
+
}
|
|
57
|
+
if ('normalized' in attribute) {
|
|
58
|
+
result.set('normalized', attribute.normalized.toString());
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
exports.makeMeshAttributeMetadata = makeMeshAttributeMetadata;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=mesh-to-arrow-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh-to-arrow-table.d.ts","sourceRoot":"","sources":["../../../src/category/mesh/mesh-to-arrow-table.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
import {
|
|
4
|
+
Table,
|
|
5
|
+
Schema,
|
|
6
|
+
RecordBatch,
|
|
7
|
+
FixedSizeList,
|
|
8
|
+
Field,
|
|
9
|
+
Data,
|
|
10
|
+
FixedSizeListVector
|
|
11
|
+
} from 'apache-arrow';
|
|
12
|
+
import {AbstractVector} from 'apache-arrow/vector';
|
|
13
|
+
import {getArrowType, getArrowVector} from '../../lib/arrow/arrow-type-utils';
|
|
14
|
+
import type {Mesh} from './mesh-types';
|
|
15
|
+
import {makeMeshAttributeMetadata} from './deduce-mesh-schema';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* * Convert a loaders.gl Mesh to an Apache Arrow Table
|
|
19
|
+
* @param mesh
|
|
20
|
+
* @param metadata
|
|
21
|
+
* @param batchSize
|
|
22
|
+
* @returns
|
|
23
|
+
*
|
|
24
|
+
export function convertMeshToArrowTable(mesh: Mesh, batchSize?: number): Table {
|
|
25
|
+
const vectors: AbstractVector[] = [];
|
|
26
|
+
const fields: Field[] = [];
|
|
27
|
+
for (const attributeKey in mesh.attributes) {
|
|
28
|
+
const attribute = mesh.attributes[attributeKey];
|
|
29
|
+
const {value, size = 1} = attribute;
|
|
30
|
+
const type = getArrowType(value);
|
|
31
|
+
const vector = getArrowVector(value);
|
|
32
|
+
const listType = new FixedSizeList(size, new Field('value', type));
|
|
33
|
+
const field = new Field(attributeKey, listType, false, makeMeshAttributeMetadata(attribute));
|
|
34
|
+
const data = new Data(listType, 0, value.length / size, 0, undefined, [vector]);
|
|
35
|
+
const listVector = new FixedSizeListVector(data);
|
|
36
|
+
vectors.push(listVector);
|
|
37
|
+
fields.push(field);
|
|
38
|
+
}
|
|
39
|
+
const schema = new Schema(fields, mesh?.schema?.metadata || new Map<string, string>());
|
|
40
|
+
const recordBatch = new RecordBatch(schema, vectors[0].length, vectors);
|
|
41
|
+
const table = new Table(schema, recordBatch);
|
|
42
|
+
return table;
|
|
43
|
+
}
|
|
44
|
+
*/
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Schema } from '../../lib/schema/schema';
|
|
2
|
+
import type { TypedArray } from '../../types';
|
|
3
|
+
import type { ColumnarTable, ArrowTable } from '../table/table-types';
|
|
4
|
+
/** Mesh as columnar table */
|
|
5
|
+
export interface MeshTable extends ColumnarTable {
|
|
6
|
+
topology: 'point-list' | 'triangle-list' | 'triangle-strip';
|
|
7
|
+
indices?: MeshAttribute;
|
|
8
|
+
}
|
|
9
|
+
/** Mesh as arrow table */
|
|
10
|
+
export interface MeshArrowTable extends ArrowTable {
|
|
11
|
+
topology: 'point-list' | 'triangle-list' | 'triangle-strip';
|
|
12
|
+
indices?: MeshAttribute;
|
|
13
|
+
}
|
|
14
|
+
/** Geometry part of a Mesh (compatible with a standard luma.gl "mesh") */
|
|
15
|
+
export declare type MeshGeometry = {
|
|
16
|
+
attributes: {
|
|
17
|
+
[attributeName: string]: MeshAttribute;
|
|
18
|
+
};
|
|
19
|
+
indices?: MeshAttribute;
|
|
20
|
+
topology: 'point-list' | 'triangle-list' | 'triangle-strip';
|
|
21
|
+
mode: number;
|
|
22
|
+
};
|
|
23
|
+
/** Geometry and metadata for a Mesh (compatible with a standard luma.gl "mesh") */
|
|
24
|
+
export declare type Mesh = MeshGeometry & {
|
|
25
|
+
loader?: string;
|
|
26
|
+
loaderData?: {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
};
|
|
29
|
+
header?: {
|
|
30
|
+
vertexCount: number;
|
|
31
|
+
boundingBox?: [number[], number[]];
|
|
32
|
+
};
|
|
33
|
+
schema: Schema;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* luma.gl compatible attribute descriptors
|
|
37
|
+
* Can be mapped to any WebGL framework
|
|
38
|
+
*/
|
|
39
|
+
export declare type MeshAttribute = {
|
|
40
|
+
value: TypedArray;
|
|
41
|
+
size: number;
|
|
42
|
+
byteOffset?: number;
|
|
43
|
+
byteStride?: number;
|
|
44
|
+
normalized?: boolean;
|
|
45
|
+
};
|
|
46
|
+
/** A map of mesh attributes keyed by attribute names */
|
|
47
|
+
export declare type MeshAttributes = {
|
|
48
|
+
[attributeName: string]: MeshAttribute;
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=mesh-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh-types.d.ts","sourceRoot":"","sources":["../../../src/category/mesh/mesh-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAC,aAAa,EAAE,UAAU,EAAC,MAAM,sBAAsB,CAAC;AAEpE,6BAA6B;AAC7B,MAAM,WAAW,SAAU,SAAQ,aAAa;IAE9C,QAAQ,EAAE,YAAY,GAAG,eAAe,GAAG,gBAAgB,CAAC;IAC5D,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAED,0BAA0B;AAC1B,MAAM,WAAW,cAAe,SAAQ,UAAU;IAEhD,QAAQ,EAAE,YAAY,GAAG,eAAe,GAAG,gBAAgB,CAAC;IAC5D,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAED,0EAA0E;AAC1E,oBAAY,YAAY,GAAG;IACzB,UAAU,EAAE;QAAC,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,CAAA;KAAC,CAAC;IACrD,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,QAAQ,EAAE,YAAY,GAAG,eAAe,GAAG,gBAAgB,CAAC;IAC5D,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,mFAAmF;AACnF,oBAAY,IAAI,GAAG,YAAY,GAAG;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAAC;IAClC,MAAM,CAAC,EAAE;QACP,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;KACpC,CAAC;IACF,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,oBAAY,aAAa,GAAG;IAC1B,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,wDAAwD;AACxD,oBAAY,cAAc,GAAG;IAAC,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,CAAA;CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TypedArray } from '../../types';
|
|
2
|
+
import { MeshAttributes } from './mesh-types';
|
|
3
|
+
declare 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
|
+
declare 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/category/mesh/mesh-utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AACvC,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AAE5C,aAAK,WAAW,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAC,CAAC;AAE/C;;;GAGG;AACH,aAAK,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,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMeshBoundingBox = exports.getMeshSize = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Get number of vertices in mesh
|
|
6
|
+
* @param attributes
|
|
7
|
+
*/
|
|
8
|
+
function getMeshSize(attributes) {
|
|
9
|
+
let size = 0;
|
|
10
|
+
for (const attributeName in attributes) {
|
|
11
|
+
const attribute = attributes[attributeName];
|
|
12
|
+
if (ArrayBuffer.isView(attribute)) {
|
|
13
|
+
// @ts-ignore DataView doesn't have BYTES_PER_ELEMENT
|
|
14
|
+
size += attribute.byteLength * attribute.BYTES_PER_ELEMENT;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return size;
|
|
18
|
+
}
|
|
19
|
+
exports.getMeshSize = getMeshSize;
|
|
20
|
+
/**
|
|
21
|
+
* Get the (axis aligned) bounding box of a mesh
|
|
22
|
+
* @param attributes
|
|
23
|
+
* @returns array of two vectors representing the axis aligned bounding box
|
|
24
|
+
*/
|
|
25
|
+
// eslint-disable-next-line complexity
|
|
26
|
+
function getMeshBoundingBox(attributes) {
|
|
27
|
+
let minX = Infinity;
|
|
28
|
+
let minY = Infinity;
|
|
29
|
+
let minZ = Infinity;
|
|
30
|
+
let maxX = -Infinity;
|
|
31
|
+
let maxY = -Infinity;
|
|
32
|
+
let maxZ = -Infinity;
|
|
33
|
+
const positions = attributes.POSITION ? attributes.POSITION.value : [];
|
|
34
|
+
const len = positions && positions.length;
|
|
35
|
+
for (let i = 0; i < len; i += 3) {
|
|
36
|
+
const x = positions[i];
|
|
37
|
+
const y = positions[i + 1];
|
|
38
|
+
const z = positions[i + 2];
|
|
39
|
+
minX = x < minX ? x : minX;
|
|
40
|
+
minY = y < minY ? y : minY;
|
|
41
|
+
minZ = z < minZ ? z : minZ;
|
|
42
|
+
maxX = x > maxX ? x : maxX;
|
|
43
|
+
maxY = y > maxY ? y : maxY;
|
|
44
|
+
maxZ = z > maxZ ? z : maxZ;
|
|
45
|
+
}
|
|
46
|
+
return [
|
|
47
|
+
[minX, minY, minZ],
|
|
48
|
+
[maxX, maxY, maxZ]
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
exports.getMeshBoundingBox = getMeshBoundingBox;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Schema } from '../../lib/schema/schema';
|
|
2
|
+
/**
|
|
3
|
+
* SCHEMA SUPPORT - AUTODEDUCTION
|
|
4
|
+
* @param {*} table
|
|
5
|
+
* @param {*} schema
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function deduceTableSchema(table: any, schema?: Schema): Schema;
|
|
9
|
+
//# sourceMappingURL=deduce-table-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deduce-table-schema.d.ts","sourceRoot":"","sources":["../../../src/category/table/deduce-table-schema.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EAcP,MAAM,yBAAyB,CAAC;AAmBjC;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,KAAA,EAAE,MAAM,CAAC,EAAE,MAAM,UAMvD"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deduceTableSchema = void 0;
|
|
4
|
+
// const TYPED_ARRAY_TO_TYPE = {
|
|
5
|
+
// Int8Array: new Int8(),
|
|
6
|
+
// Int16Array: new Int16(),
|
|
7
|
+
// Int32Array: new Int32(),
|
|
8
|
+
// Uint8Array: new Uint8(),
|
|
9
|
+
// Uint8ClampedArray: new Uint8(),
|
|
10
|
+
// Uint16Array: new Uint16(),
|
|
11
|
+
// Uint32Array: new Uint32(),
|
|
12
|
+
// Float32Array: new Float32(),
|
|
13
|
+
// Float64Array: new Float64()
|
|
14
|
+
// };
|
|
15
|
+
// if (typeof BigInt64Array !== 'undefined') {
|
|
16
|
+
// TYPED_ARRAY_TO_TYPE.BigInt64Array = new Int64();
|
|
17
|
+
// TYPED_ARRAY_TO_TYPE.BigUint64Array = new Uint64();
|
|
18
|
+
// }
|
|
19
|
+
/**
|
|
20
|
+
* SCHEMA SUPPORT - AUTODEDUCTION
|
|
21
|
+
* @param {*} table
|
|
22
|
+
* @param {*} schema
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
function deduceTableSchema(table, schema) {
|
|
26
|
+
const deducedSchema = Array.isArray(table)
|
|
27
|
+
? deduceSchemaForRowTable(table)
|
|
28
|
+
: deduceSchemaForColumnarTable(table);
|
|
29
|
+
// Deduced schema will fill in missing info from partial options.schema, if provided
|
|
30
|
+
return Object.assign(deducedSchema, schema);
|
|
31
|
+
}
|
|
32
|
+
exports.deduceTableSchema = deduceTableSchema;
|
|
33
|
+
function deduceSchemaForColumnarTable(columnarTable) {
|
|
34
|
+
const schema = {};
|
|
35
|
+
for (const field in columnarTable) {
|
|
36
|
+
const column = columnarTable[field];
|
|
37
|
+
// Check if column is typed, if so we are done
|
|
38
|
+
if (ArrayBuffer.isView(column)) {
|
|
39
|
+
schema[field] = column.constructor;
|
|
40
|
+
// else we need data
|
|
41
|
+
}
|
|
42
|
+
else if (column.length) {
|
|
43
|
+
const value = column[0];
|
|
44
|
+
schema[field] = deduceTypeFromValue(value);
|
|
45
|
+
// TODO - support nested schemas?
|
|
46
|
+
}
|
|
47
|
+
// else we mark as present but unknow
|
|
48
|
+
schema[field] = schema[field] || null;
|
|
49
|
+
}
|
|
50
|
+
return schema;
|
|
51
|
+
}
|
|
52
|
+
function deduceSchemaForRowTable(rowTable) {
|
|
53
|
+
const schema = {};
|
|
54
|
+
if (rowTable.length) {
|
|
55
|
+
const row = rowTable[0];
|
|
56
|
+
// TODO - Could look at additional rows if nulls in first row
|
|
57
|
+
for (const field in row) {
|
|
58
|
+
const value = row[field];
|
|
59
|
+
schema[field] = deduceTypeFromValue(value);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return schema;
|
|
63
|
+
}
|
|
64
|
+
function deduceTypeFromValue(value) {
|
|
65
|
+
if (value instanceof Date) {
|
|
66
|
+
return Date;
|
|
67
|
+
}
|
|
68
|
+
else if (value instanceof Number) {
|
|
69
|
+
return Float32Array;
|
|
70
|
+
}
|
|
71
|
+
else if (typeof value === 'string') {
|
|
72
|
+
return String;
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
/*
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
78
|
+
function deduceSchema(rows) {
|
|
79
|
+
const row = rows[0];
|
|
80
|
+
|
|
81
|
+
const schema = {};
|
|
82
|
+
let i = 0;
|
|
83
|
+
for (const columnName in row) {
|
|
84
|
+
const value = row[columnName];
|
|
85
|
+
switch (typeof value) {
|
|
86
|
+
case 'number':
|
|
87
|
+
case 'boolean':
|
|
88
|
+
// TODO - booleans could be handled differently...
|
|
89
|
+
schema[columnName] = {name: String(columnName), index: i, type: Float32Array};
|
|
90
|
+
break;
|
|
91
|
+
|
|
92
|
+
case 'object':
|
|
93
|
+
schema[columnName] = {name: String(columnName), index: i, type: Array};
|
|
94
|
+
break;
|
|
95
|
+
|
|
96
|
+
case 'string':
|
|
97
|
+
default:
|
|
98
|
+
schema[columnName] = {name: String(columnName), index: i, type: Array};
|
|
99
|
+
// We currently only handle numeric rows
|
|
100
|
+
// TODO we could offer a function to map strings to numbers?
|
|
101
|
+
}
|
|
102
|
+
i++;
|
|
103
|
+
}
|
|
104
|
+
return schema;
|
|
105
|
+
}
|
|
106
|
+
*/
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Schema } from '../../lib/schema/schema';
|
|
2
|
+
import type { AnyArray } from '../../types';
|
|
3
|
+
import type { Batch } from '../common';
|
|
4
|
+
declare type ApacheArrowTable = any;
|
|
5
|
+
declare type RecordBatch = any;
|
|
6
|
+
/** A general table */
|
|
7
|
+
export interface Table {
|
|
8
|
+
shape: 'row-table' | 'array-row-table' | 'object-row-table' | 'columnar-table' | 'arrow-table';
|
|
9
|
+
schema?: Schema;
|
|
10
|
+
schemaType?: 'explicit' | 'deduced';
|
|
11
|
+
}
|
|
12
|
+
/** A table organized as an array of rows */
|
|
13
|
+
export interface RowTable extends Table {
|
|
14
|
+
shape: 'row-table' | 'array-row-table' | 'object-row-table';
|
|
15
|
+
data: any[];
|
|
16
|
+
}
|
|
17
|
+
/** A table organized as an array of rows, each row is an array of values */
|
|
18
|
+
export interface ArrayRowTable extends RowTable {
|
|
19
|
+
shape: 'array-row-table';
|
|
20
|
+
data: any[][];
|
|
21
|
+
}
|
|
22
|
+
/** A table organized as an array of rows, each row is an object mapping columns to values */
|
|
23
|
+
export interface ObjectRowTable extends RowTable {
|
|
24
|
+
shape: 'object-row-table';
|
|
25
|
+
data: {
|
|
26
|
+
[columnName: string]: any;
|
|
27
|
+
}[];
|
|
28
|
+
}
|
|
29
|
+
/** A table organized as a map of columns, each column is an array of value */
|
|
30
|
+
export interface ColumnarTable extends Table {
|
|
31
|
+
shape: 'columnar-table';
|
|
32
|
+
data: {
|
|
33
|
+
[columnName: string]: AnyArray;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** A table organized as an Apache Arrow table */
|
|
37
|
+
export interface ArrowTable extends Table {
|
|
38
|
+
shape: 'arrow-table';
|
|
39
|
+
data: ApacheArrowTable;
|
|
40
|
+
}
|
|
41
|
+
/** Batch for a general table */
|
|
42
|
+
export declare type TableBatch = Batch & {
|
|
43
|
+
data: any;
|
|
44
|
+
length: number;
|
|
45
|
+
schema?: Schema;
|
|
46
|
+
schemaType?: 'explicit' | 'deduced';
|
|
47
|
+
};
|
|
48
|
+
/** Batch for a table organized as an array of rows */
|
|
49
|
+
export declare type RowTableBatch = TableBatch & {
|
|
50
|
+
shape: 'row-table';
|
|
51
|
+
data: any[];
|
|
52
|
+
};
|
|
53
|
+
/** Batch for a table organized as an array of rows, each row is an array of values */
|
|
54
|
+
export declare type RowArrayTableBatch = RowTableBatch & {
|
|
55
|
+
shape: 'array-row-table';
|
|
56
|
+
data: any[][];
|
|
57
|
+
};
|
|
58
|
+
/** Batch for a table organized as an array of rows, each row is an object mapping columns to values */
|
|
59
|
+
export declare type RowObjectTableBatch = RowTableBatch & {
|
|
60
|
+
shape: 'object-row-table';
|
|
61
|
+
data: {
|
|
62
|
+
[columnName: string]: any;
|
|
63
|
+
}[];
|
|
64
|
+
};
|
|
65
|
+
/** Batch for a table organized as a map of columns, each column is an array of value */
|
|
66
|
+
export declare type ColumnarTableBatch = TableBatch & {
|
|
67
|
+
shape: 'columnar-table';
|
|
68
|
+
data: {
|
|
69
|
+
[columnName: string]: AnyArray;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
/** Batch for a table organized as an Apache Arrow table */
|
|
73
|
+
export declare type ArrowTableBatch = TableBatch & {
|
|
74
|
+
shape: 'arrow-table';
|
|
75
|
+
data: RecordBatch;
|
|
76
|
+
};
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=table-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-types.d.ts","sourceRoot":"","sources":["../../../src/category/table/table-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,WAAW,CAAC;AAGrC,aAAK,gBAAgB,GAAG,GAAG,CAAC;AAC5B,aAAK,WAAW,GAAG,GAAG,CAAC;AAEvB,sBAAsB;AACtB,MAAM,WAAW,KAAK;IACpB,KAAK,EAAE,WAAW,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,aAAa,CAAC;IAC/F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CACrC;AAED,4CAA4C;AAC5C,MAAM,WAAW,QAAS,SAAQ,KAAK;IACrC,KAAK,EAAE,WAAW,GAAG,iBAAiB,GAAG,kBAAkB,CAAC;IAC5D,IAAI,EAAE,GAAG,EAAE,CAAC;CACb;AAED,4EAA4E;AAC5E,MAAM,WAAW,aAAc,SAAQ,QAAQ;IAC7C,KAAK,EAAE,iBAAiB,CAAC;IACzB,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;CACf;AAED,6FAA6F;AAC7F,MAAM,WAAW,cAAe,SAAQ,QAAQ;IAC9C,KAAK,EAAE,kBAAkB,CAAC;IAC1B,IAAI,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,EAAE,CAAC;CACrC;AAED,8EAA8E;AAC9E,MAAM,WAAW,aAAc,SAAQ,KAAK;IAC1C,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,CAAA;KAAC,CAAC;CACxC;AAED,iDAAiD;AACjD,MAAM,WAAW,UAAW,SAAQ,KAAK;IACvC,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,EAAE,gBAAgB,CAAC;CACxB;AAID,gCAAgC;AAChC,oBAAY,UAAU,GAAG,KAAK,GAAG;IAC/B,IAAI,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CACrC,CAAC;AAEF,sDAAsD;AACtD,oBAAY,aAAa,GAAG,UAAU,GAAG;IACvC,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,GAAG,EAAE,CAAC;CACb,CAAC;AAEF,sFAAsF;AACtF,oBAAY,kBAAkB,GAAG,aAAa,GAAG;IAC/C,KAAK,EAAE,iBAAiB,CAAC;IACzB,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;CACf,CAAC;AAEF,uGAAuG;AACvG,oBAAY,mBAAmB,GAAG,aAAa,GAAG;IAChD,KAAK,EAAE,kBAAkB,CAAC;IAC1B,IAAI,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,EAAE,CAAC;CACrC,CAAC;AAEF,wFAAwF;AACxF,oBAAY,kBAAkB,GAAG,UAAU,GAAG;IAC5C,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,CAAA;KAAC,CAAC;CACxC,CAAC;AAEF,2DAA2D;AAC3D,oBAAY,eAAe,GAAG,UAAU,GAAG;IACzC,KAAK,EAAE,aAAa,CAAC;IACrB,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC"}
|