@loaders.gl/schema 4.0.0-alpha.4 → 4.0.0-alpha.6
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 +2 -2
- package/dist/dist.min.js +13589 -0
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +406 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/mesh/convert-mesh.js +34 -0
- package/dist/es5/lib/mesh/convert-mesh.js.map +1 -0
- package/dist/es5/lib/mesh/deduce-mesh-schema.js +56 -0
- package/dist/es5/lib/mesh/deduce-mesh-schema.js.map +1 -0
- package/dist/es5/lib/mesh/mesh-to-arrow-table.js +2 -0
- package/dist/es5/lib/mesh/mesh-to-arrow-table.js.map +1 -0
- package/dist/es5/lib/mesh/mesh-utils.js +40 -0
- package/dist/es5/lib/mesh/mesh-utils.js.map +1 -0
- package/dist/es5/lib/table/arrow/arrow-type-utils.js +30 -0
- package/dist/es5/lib/table/arrow/arrow-type-utils.js.map +1 -0
- package/dist/es5/lib/table/arrow/convert-schema-arrow.js +179 -0
- package/dist/es5/lib/table/arrow/convert-schema-arrow.js.map +1 -0
- package/dist/es5/lib/table/arrow/convert-table-to-arrow.js +2 -0
- package/dist/es5/lib/table/arrow/convert-table-to-arrow.js.map +1 -0
- package/dist/es5/lib/table/arrow-api/arrow-like-field.js +49 -0
- package/dist/es5/lib/table/arrow-api/arrow-like-field.js.map +1 -0
- package/dist/es5/lib/table/arrow-api/arrow-like-schema.js +118 -0
- package/dist/es5/lib/table/arrow-api/arrow-like-schema.js.map +1 -0
- package/dist/es5/lib/table/arrow-api/arrow-like-table.js +80 -0
- package/dist/es5/lib/table/arrow-api/arrow-like-table.js.map +1 -0
- package/dist/es5/lib/table/arrow-api/arrow-like-type.js +740 -0
- package/dist/es5/lib/table/arrow-api/arrow-like-type.js.map +1 -0
- package/dist/es5/lib/table/arrow-api/enum.js +55 -0
- package/dist/es5/lib/table/arrow-api/enum.js.map +1 -0
- package/dist/es5/lib/table/arrow-api/get-type-info.js +27 -0
- package/dist/es5/lib/table/arrow-api/get-type-info.js.map +1 -0
- package/dist/es5/lib/table/arrow-api/index.js +44 -0
- package/dist/es5/lib/table/arrow-api/index.js.map +1 -0
- package/dist/es5/lib/table/batches/base-table-batch-aggregator.js +78 -0
- package/dist/es5/lib/table/batches/base-table-batch-aggregator.js.map +1 -0
- package/dist/es5/lib/table/batches/columnar-table-batch-aggregator.js +106 -0
- package/dist/es5/lib/table/batches/columnar-table-batch-aggregator.js.map +1 -0
- package/dist/es5/lib/table/batches/row-table-batch-aggregator.js +96 -0
- package/dist/es5/lib/table/batches/row-table-batch-aggregator.js.map +1 -0
- package/dist/es5/lib/table/batches/table-batch-aggregator.js +2 -0
- package/dist/es5/lib/table/batches/table-batch-aggregator.js.map +1 -0
- package/dist/es5/lib/table/batches/table-batch-builder.js +173 -0
- package/dist/es5/lib/table/batches/table-batch-builder.js.map +1 -0
- package/dist/es5/lib/table/simple-table/convert-table.js +82 -0
- package/dist/es5/lib/table/simple-table/convert-table.js.map +1 -0
- package/dist/es5/lib/table/simple-table/data-type.js +94 -0
- package/dist/es5/lib/table/simple-table/data-type.js.map +1 -0
- package/dist/es5/lib/table/simple-table/make-table.js +60 -0
- package/dist/es5/lib/table/simple-table/make-table.js.map +1 -0
- package/dist/es5/lib/table/simple-table/row-utils.js +34 -0
- package/dist/es5/lib/table/simple-table/row-utils.js.map +1 -0
- package/dist/es5/lib/table/simple-table/table-accessors.js +343 -0
- package/dist/es5/lib/table/simple-table/table-accessors.js.map +1 -0
- package/dist/es5/lib/table/simple-table/table-column.js +12 -0
- package/dist/es5/lib/table/simple-table/table-column.js.map +1 -0
- package/dist/es5/lib/table/simple-table/table-schema.js +85 -0
- package/dist/es5/lib/table/simple-table/table-schema.js.map +1 -0
- package/dist/es5/lib/utils/assert.js +12 -0
- package/dist/es5/lib/utils/assert.js.map +1 -0
- package/dist/es5/lib/utils/async-queue.js +169 -0
- package/dist/es5/lib/utils/async-queue.js.map +1 -0
- package/dist/es5/types/category-gis.js +2 -0
- package/dist/es5/types/category-gis.js.map +1 -0
- package/dist/es5/types/category-image.js +2 -0
- package/dist/es5/types/category-image.js.map +1 -0
- package/dist/es5/types/category-mesh.js +2 -0
- package/dist/es5/types/category-mesh.js.map +1 -0
- package/dist/es5/types/category-table.js +2 -0
- package/dist/es5/types/category-table.js.map +1 -0
- package/dist/es5/types/category-texture.js +2 -0
- package/dist/es5/types/category-texture.js.map +1 -0
- package/dist/es5/types/schema.js +2 -0
- package/dist/es5/types/schema.js.map +1 -0
- package/dist/es5/types/types.js +2 -0
- package/dist/es5/types/types.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/{category → esm/lib}/mesh/convert-mesh.js +0 -11
- package/dist/esm/lib/mesh/convert-mesh.js.map +1 -0
- package/dist/esm/lib/mesh/deduce-mesh-schema.js +48 -0
- package/dist/esm/lib/mesh/deduce-mesh-schema.js.map +1 -0
- package/dist/esm/lib/mesh/mesh-to-arrow-table.js +2 -0
- package/dist/esm/lib/mesh/mesh-to-arrow-table.js.map +1 -0
- package/dist/{category → esm/lib}/mesh/mesh-utils.js +0 -5
- package/dist/esm/lib/mesh/mesh-utils.js.map +1 -0
- package/dist/{lib/arrow/arrow-like-type-utils.js → esm/lib/table/arrow/arrow-type-utils.js} +3 -11
- package/dist/esm/lib/table/arrow/arrow-type-utils.js.map +1 -0
- package/dist/esm/lib/table/arrow/convert-schema-arrow.js +158 -0
- package/dist/esm/lib/table/arrow/convert-schema-arrow.js.map +1 -0
- package/dist/esm/lib/table/arrow/convert-table-to-arrow.js +2 -0
- package/dist/esm/lib/table/arrow/convert-table-to-arrow.js.map +1 -0
- package/dist/{lib/schema/impl/field.js → esm/lib/table/arrow-api/arrow-like-field.js} +6 -13
- package/dist/esm/lib/table/arrow-api/arrow-like-field.js.map +1 -0
- package/dist/{lib/schema/impl/schema.js → esm/lib/table/arrow-api/arrow-like-schema.js} +22 -47
- package/dist/esm/lib/table/arrow-api/arrow-like-schema.js.map +1 -0
- package/dist/esm/lib/table/arrow-api/arrow-like-table.js +51 -0
- package/dist/esm/lib/table/arrow-api/arrow-like-table.js.map +1 -0
- package/dist/{lib/schema/impl/type.js → esm/lib/table/arrow-api/arrow-like-type.js} +11 -116
- package/dist/esm/lib/table/arrow-api/arrow-like-type.js.map +1 -0
- package/dist/{lib/schema/impl → esm/lib/table/arrow-api}/enum.js +3 -4
- package/dist/esm/lib/table/arrow-api/enum.js.map +1 -0
- package/dist/{lib/arrow → esm/lib/table/arrow-api}/get-type-info.js +1 -4
- package/dist/esm/lib/table/arrow-api/get-type-info.js.map +1 -0
- package/dist/esm/lib/table/arrow-api/index.js +5 -0
- package/dist/esm/lib/table/arrow-api/index.js.map +1 -0
- package/dist/{lib → esm/lib/table}/batches/base-table-batch-aggregator.js +1 -18
- package/dist/esm/lib/table/batches/base-table-batch-aggregator.js.map +1 -0
- package/dist/{lib → esm/lib/table}/batches/columnar-table-batch-aggregator.js +1 -24
- package/dist/esm/lib/table/batches/columnar-table-batch-aggregator.js.map +1 -0
- package/dist/{lib → esm/lib/table}/batches/row-table-batch-aggregator.js +2 -22
- package/dist/esm/lib/table/batches/row-table-batch-aggregator.js.map +1 -0
- package/dist/esm/lib/table/batches/table-batch-aggregator.js.map +1 -0
- package/dist/{lib → esm/lib/table}/batches/table-batch-builder.js +6 -49
- package/dist/esm/lib/table/batches/table-batch-builder.js.map +1 -0
- package/dist/esm/lib/table/simple-table/convert-table.js +59 -0
- package/dist/esm/lib/table/simple-table/convert-table.js.map +1 -0
- package/dist/esm/lib/table/simple-table/data-type.js +85 -0
- package/dist/esm/lib/table/simple-table/data-type.js.map +1 -0
- package/dist/esm/lib/table/simple-table/make-table.js +50 -0
- package/dist/esm/lib/table/simple-table/make-table.js.map +1 -0
- package/dist/{lib/utils → esm/lib/table/simple-table}/row-utils.js +0 -8
- package/dist/esm/lib/table/simple-table/row-utils.js.map +1 -0
- package/dist/esm/lib/table/simple-table/table-accessors.js +262 -0
- package/dist/esm/lib/table/simple-table/table-accessors.js.map +1 -0
- package/dist/esm/lib/table/simple-table/table-column.js +6 -0
- package/dist/esm/lib/table/simple-table/table-column.js.map +1 -0
- package/dist/esm/lib/table/simple-table/table-schema.js +70 -0
- package/dist/esm/lib/table/simple-table/table-schema.js.map +1 -0
- package/dist/esm/lib/utils/assert.js +6 -0
- package/dist/esm/lib/utils/assert.js.map +1 -0
- package/dist/esm/lib/utils/async-queue.js +94 -0
- package/dist/esm/lib/utils/async-queue.js.map +1 -0
- package/dist/esm/types/category-gis.js +2 -0
- package/dist/esm/types/category-gis.js.map +1 -0
- package/dist/esm/types/category-image.js +2 -0
- package/dist/esm/types/category-image.js.map +1 -0
- package/dist/esm/types/category-mesh.js +2 -0
- package/dist/esm/types/category-mesh.js.map +1 -0
- package/dist/esm/types/category-table.js +2 -0
- package/dist/esm/types/category-table.js.map +1 -0
- package/dist/esm/types/category-texture.js +2 -0
- package/dist/esm/types/category-texture.js.map +1 -0
- package/dist/esm/types/schema.js +2 -0
- package/dist/esm/types/schema.js.map +1 -0
- package/dist/esm/types/types.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +92 -13
- package/dist/lib/mesh/convert-mesh.d.ts +15 -0
- package/dist/lib/mesh/convert-mesh.d.ts.map +1 -0
- package/dist/lib/mesh/convert-mesh.js +40 -0
- package/dist/lib/mesh/deduce-mesh-schema.d.ts +24 -0
- package/dist/lib/mesh/deduce-mesh-schema.d.ts.map +1 -0
- package/dist/lib/mesh/deduce-mesh-schema.js +66 -0
- package/dist/lib/mesh/mesh-to-arrow-table.d.ts +1 -0
- package/dist/lib/mesh/mesh-to-arrow-table.d.ts.map +1 -0
- package/dist/lib/mesh/mesh-to-arrow-table.js +44 -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 +51 -0
- package/dist/lib/table/arrow/arrow-type-utils.d.ts +4 -0
- package/dist/lib/table/arrow/arrow-type-utils.d.ts.map +1 -0
- package/dist/lib/table/arrow/arrow-type-utils.js +53 -0
- package/dist/lib/table/arrow/convert-schema-arrow.d.ts +13 -0
- package/dist/lib/table/arrow/convert-schema-arrow.d.ts.map +1 -0
- package/dist/lib/table/arrow/convert-schema-arrow.js +187 -0
- package/dist/lib/table/arrow/convert-table-to-arrow.d.ts +42 -0
- package/dist/lib/table/arrow/convert-table-to-arrow.d.ts.map +1 -0
- package/dist/lib/table/arrow/convert-table-to-arrow.js +57 -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 +34 -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 +53 -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 +463 -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 +29 -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 +25 -0
- package/dist/lib/table/batches/base-table-batch-aggregator.d.ts +19 -0
- package/dist/lib/table/batches/base-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batches/base-table-batch-aggregator.js +60 -0
- package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts +23 -0
- package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batches/columnar-table-batch-aggregator.js +92 -0
- package/dist/lib/table/batches/row-table-batch-aggregator.d.ts +22 -0
- package/dist/lib/table/batches/row-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batches/row-table-batch-aggregator.js +81 -0
- package/dist/lib/table/batches/table-batch-aggregator.d.ts +25 -0
- package/dist/lib/table/batches/table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batches/table-batch-aggregator.js +3 -0
- package/dist/lib/table/batches/table-batch-builder.d.ts +53 -0
- package/dist/lib/table/batches/table-batch-builder.d.ts.map +1 -0
- package/dist/lib/table/batches/table-batch-builder.js +152 -0
- package/dist/lib/table/simple-table/convert-table.d.ts +8 -0
- package/dist/lib/table/simple-table/convert-table.d.ts.map +1 -0
- package/dist/lib/table/simple-table/convert-table.js +65 -0
- package/dist/lib/table/simple-table/data-type.d.ts +17 -0
- package/dist/lib/table/simple-table/data-type.d.ts.map +1 -0
- package/dist/lib/table/simple-table/data-type.js +93 -0
- package/dist/lib/table/simple-table/make-table.d.ts +65 -0
- package/dist/lib/table/simple-table/make-table.d.ts.map +1 -0
- package/dist/lib/table/simple-table/make-table.js +95 -0
- package/dist/lib/table/simple-table/row-utils.d.ts +9 -0
- package/dist/lib/table/simple-table/row-utils.d.ts.map +1 -0
- package/dist/lib/table/simple-table/row-utils.js +33 -0
- package/dist/lib/table/simple-table/table-accessors.d.ts +67 -0
- package/dist/lib/table/simple-table/table-accessors.d.ts.map +1 -0
- package/dist/lib/table/simple-table/table-accessors.js +319 -0
- package/dist/lib/table/simple-table/table-column.d.ts +7 -0
- package/dist/lib/table/simple-table/table-column.d.ts.map +1 -0
- package/dist/lib/table/simple-table/table-column.js +41 -0
- package/dist/lib/table/simple-table/table-schema.d.ts +15 -0
- package/dist/lib/table/simple-table/table-schema.d.ts.map +1 -0
- package/dist/lib/table/simple-table/table-schema.js +85 -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 +11 -5
- 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 +82 -109
- package/dist/types/category-gis.d.ts +99 -0
- package/dist/types/category-gis.d.ts.map +1 -0
- package/dist/types/category-gis.js +2 -0
- package/dist/types/category-image.d.ts +18 -0
- package/dist/types/category-image.d.ts.map +1 -0
- package/dist/types/category-image.js +2 -0
- package/dist/types/category-mesh.d.ts +48 -0
- package/dist/types/category-mesh.d.ts.map +1 -0
- package/dist/types/category-mesh.js +3 -0
- package/dist/types/category-table.d.ts +86 -0
- package/dist/types/category-table.d.ts.map +1 -0
- package/dist/types/category-table.js +3 -0
- package/dist/types/category-texture.d.ts +18 -0
- package/dist/types/category-texture.d.ts.map +1 -0
- package/dist/types/category-texture.js +3 -0
- package/dist/types/schema.d.ts +77 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/schema.js +3 -0
- package/dist/types/types.d.ts +15 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +2 -0
- package/package.json +7 -8
- package/src/index.ts +82 -29
- package/src/{category → lib}/mesh/convert-mesh.ts +10 -8
- package/src/{category → lib}/mesh/deduce-mesh-schema.ts +20 -19
- package/src/{category → lib}/mesh/mesh-to-arrow-table.ts +5 -3
- package/src/{category → lib}/mesh/mesh-utils.ts +2 -2
- package/src/lib/{arrow → table/arrow}/arrow-type-utils.ts +16 -12
- package/src/lib/table/arrow/convert-schema-arrow.ts +232 -0
- package/src/lib/table/arrow/convert-table-to-arrow.ts +59 -0
- package/src/lib/{schema/impl/field.ts → table/arrow-api/arrow-like-field.ts} +6 -4
- package/src/lib/table/arrow-api/arrow-like-schema.ts +99 -0
- package/src/lib/table/arrow-api/arrow-like-table.ts +83 -0
- package/src/lib/{schema/impl/type.ts → table/arrow-api/arrow-like-type.ts} +2 -1
- package/src/lib/{arrow → table/arrow-api}/get-type-info.ts +4 -3
- package/src/lib/table/arrow-api/index.ts +6 -0
- package/src/lib/{batches → table/batches}/base-table-batch-aggregator.ts +5 -3
- package/src/lib/{batches → table/batches}/columnar-table-batch-aggregator.ts +5 -3
- package/src/lib/{batches → table/batches}/row-table-batch-aggregator.ts +6 -4
- package/src/lib/{batches → table/batches}/table-batch-aggregator.ts +4 -2
- package/src/lib/{batches → table/batches}/table-batch-builder.ts +8 -6
- package/src/lib/table/simple-table/convert-table.ts +72 -0
- package/src/lib/table/simple-table/data-type.ts +102 -0
- package/src/lib/table/simple-table/make-table.ts +108 -0
- package/src/lib/table/simple-table/table-accessors.ts +360 -0
- package/src/lib/table/simple-table/table-column.ts +47 -0
- package/src/lib/table/simple-table/table-schema.ts +97 -0
- package/src/types/category-gis.ts +136 -0
- package/src/types/category-image.ts +19 -0
- package/src/{category/mesh/mesh-types.ts → types/category-mesh.ts} +6 -4
- package/src/types/category-table.ts +104 -0
- package/src/types/category-texture.ts +30 -0
- package/src/types/schema.ts +97 -0
- package/src/types/types.ts +43 -0
- package/dist/bundle.js.map +0 -1
- package/dist/category/common.js +0 -2
- package/dist/category/common.js.map +0 -1
- package/dist/category/gis.js +0 -2
- package/dist/category/gis.js.map +0 -1
- package/dist/category/mesh/convert-mesh.js.map +0 -1
- package/dist/category/mesh/deduce-mesh-schema.js +0 -42
- package/dist/category/mesh/deduce-mesh-schema.js.map +0 -1
- package/dist/category/mesh/mesh-to-arrow-table.js +0 -31
- package/dist/category/mesh/mesh-to-arrow-table.js.map +0 -1
- package/dist/category/mesh/mesh-types.js +0 -2
- package/dist/category/mesh/mesh-types.js.map +0 -1
- package/dist/category/mesh/mesh-utils.js.map +0 -1
- package/dist/category/table/deduce-table-schema.js +0 -51
- package/dist/category/table/deduce-table-schema.js.map +0 -1
- package/dist/category/table/table-types.js +0 -2
- package/dist/category/table/table-types.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/arrow/arrow-like-type-utils.js.map +0 -1
- package/dist/lib/arrow/arrow-type-utils.js +0 -62
- package/dist/lib/arrow/arrow-type-utils.js.map +0 -1
- package/dist/lib/arrow/get-type-info.js.map +0 -1
- package/dist/lib/batches/base-table-batch-aggregator.js.map +0 -1
- package/dist/lib/batches/columnar-table-batch-aggregator.js.map +0 -1
- package/dist/lib/batches/row-table-batch-aggregator.js.map +0 -1
- package/dist/lib/batches/table-batch-aggregator.js.map +0 -1
- package/dist/lib/batches/table-batch-builder.js.map +0 -1
- package/dist/lib/schema/impl/enum.js.map +0 -1
- package/dist/lib/schema/impl/field.js.map +0 -1
- package/dist/lib/schema/impl/schema.js.map +0 -1
- package/dist/lib/schema/impl/type.js.map +0 -1
- package/dist/lib/schema/index.js +0 -5
- package/dist/lib/schema/index.js.map +0 -1
- package/dist/lib/schema-utils/deduce-column-type.js +0 -23
- package/dist/lib/schema-utils/deduce-column-type.js.map +0 -1
- package/dist/lib/utils/assert.js.map +0 -1
- package/dist/lib/utils/async-queue.js.map +0 -1
- package/dist/lib/utils/row-utils.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/src/category/common.ts +0 -30
- package/src/category/gis.ts +0 -61
- package/src/category/table/deduce-table-schema.ts +0 -123
- package/src/category/table/table-types.ts +0 -81
- package/src/lib/arrow/arrow-like-type-utils.ts +0 -25
- package/src/lib/schema/impl/schema.ts +0 -99
- package/src/lib/schema/index.ts +0 -82
- package/src/lib/schema-utils/deduce-column-type.ts +0 -92
- package/src/types.ts +0 -19
- /package/dist/{lib → esm/lib/table}/batches/table-batch-aggregator.js +0 -0
- /package/dist/{types.js → esm/types/types.js} +0 -0
- /package/src/lib/{schema/impl → table/arrow-api}/enum.ts +0 -0
- /package/src/lib/{utils → table/simple-table}/row-utils.ts +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
import {Table, ArrayRowTable, ObjectRowTable, ColumnarTable} from '../../../types/category-table';
|
|
3
|
+
import {deduceTableSchema} from './table-schema';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Makes a typed table from data.
|
|
7
|
+
* @throws Row tables must contain at least one row. Columnar tables must contain empty arrays
|
|
8
|
+
*/
|
|
9
|
+
export function makeTableFromData(data: unknown[][]): ArrayRowTable;
|
|
10
|
+
export function makeTableFromData(data: {[column: string]: unknown}[]): ObjectRowTable;
|
|
11
|
+
export function makeTableFromData(data: {[column: string]: ArrayLike<unknown>}): ColumnarTable;
|
|
12
|
+
export function makeTableFromData(data: unknown): Table {
|
|
13
|
+
let table: Table;
|
|
14
|
+
switch (getTableShapeFromData(data)) {
|
|
15
|
+
case 'array-row-table':
|
|
16
|
+
table = {shape: 'array-row-table', data: data as unknown[][]};
|
|
17
|
+
break;
|
|
18
|
+
case 'object-row-table':
|
|
19
|
+
table = {shape: 'object-row-table', data: data as {[key: string]: unknown}[]};
|
|
20
|
+
break;
|
|
21
|
+
case 'columnar-table':
|
|
22
|
+
table = {shape: 'columnar-table', data: data as {[column: string]: ArrayLike<unknown>}};
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
throw new Error('table');
|
|
26
|
+
}
|
|
27
|
+
const schema = deduceTableSchema(table);
|
|
28
|
+
return {...table, schema};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Helper function to get shape of data */
|
|
32
|
+
function getTableShapeFromData(data) {
|
|
33
|
+
if (Array.isArray(data)) {
|
|
34
|
+
if (data.length === 0) {
|
|
35
|
+
throw new Error('cannot deduce type of empty table');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Deduce the table shape from the first row
|
|
39
|
+
const firstRow = data[0];
|
|
40
|
+
|
|
41
|
+
if (Array.isArray(firstRow)) {
|
|
42
|
+
return 'array-row-table';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (firstRow && typeof firstRow === 'object') {
|
|
46
|
+
return 'object-row-table';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (data && typeof data === 'object') {
|
|
51
|
+
return 'columnar-table';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
throw new Error('invalid table');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Convert any table into object row format *
|
|
58
|
+
export function makeColumnarTable(table: Table): ColumnarTable {
|
|
59
|
+
if (table.shape === 'columnar-table') {
|
|
60
|
+
return table;
|
|
61
|
+
}
|
|
62
|
+
const length = getTableLength(table);
|
|
63
|
+
const data = new Array<{[key: string]: unknown}>(length);
|
|
64
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
65
|
+
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
shape: 'columnar-table',
|
|
69
|
+
schema: table.schema,
|
|
70
|
+
data
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
/** Convert any table into array row format *
|
|
76
|
+
export function makeArrayRowTable(table: TableLike): ArrayRowTable {
|
|
77
|
+
if (table.shape === 'array-row-table') {
|
|
78
|
+
return table;
|
|
79
|
+
}
|
|
80
|
+
const length = getTableLength(table);
|
|
81
|
+
const data = new Array<unknown[]>(length);
|
|
82
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
83
|
+
data[rowIndex] = getTableRowAsArray(table, rowIndex);
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
shape: 'array-row-table',
|
|
87
|
+
schema: table.schema,
|
|
88
|
+
data
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Convert any table into object row format *
|
|
93
|
+
export function makeObjectRowTable(table: Table): ObjectRowTable {
|
|
94
|
+
if (table.shape === 'object-row-table') {
|
|
95
|
+
return table;
|
|
96
|
+
}
|
|
97
|
+
const length = getTableLength(table);
|
|
98
|
+
const data = new Array<{[key: string]: unknown}>(length);
|
|
99
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
100
|
+
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
shape: 'object-row-table',
|
|
104
|
+
schema: table.schema,
|
|
105
|
+
data
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
*/
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-else-return */
|
|
4
|
+
|
|
5
|
+
import {Table, ArrayRowTable, ObjectRowTable} from '../../../types/category-table';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns the length of the table (i.e. the number of rows)
|
|
9
|
+
*/
|
|
10
|
+
export function getTableLength(table: Table): number {
|
|
11
|
+
switch (table.shape) {
|
|
12
|
+
case 'array-row-table':
|
|
13
|
+
case 'object-row-table':
|
|
14
|
+
case 'geojson-row-table':
|
|
15
|
+
return table.data.length;
|
|
16
|
+
|
|
17
|
+
case 'arrow-table':
|
|
18
|
+
return table.data.numRows;
|
|
19
|
+
|
|
20
|
+
case 'columnar-table':
|
|
21
|
+
for (const column of Object.values(table.data)) {
|
|
22
|
+
return column.length || 0;
|
|
23
|
+
}
|
|
24
|
+
return 0;
|
|
25
|
+
default:
|
|
26
|
+
throw new Error('table');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns the number of columns in the table
|
|
32
|
+
* @throws Fails to deduce number of columns if the table has no schema and is empty
|
|
33
|
+
*/
|
|
34
|
+
export function getTableNumCols(table: Table): number {
|
|
35
|
+
if (table.schema) {
|
|
36
|
+
return table.schema.fields.length;
|
|
37
|
+
}
|
|
38
|
+
if (getTableLength(table) === 0) {
|
|
39
|
+
throw new Error('empty table');
|
|
40
|
+
}
|
|
41
|
+
switch (table.shape) {
|
|
42
|
+
case 'array-row-table':
|
|
43
|
+
return table.data[0].length;
|
|
44
|
+
case 'object-row-table':
|
|
45
|
+
case 'geojson-row-table':
|
|
46
|
+
return Object.keys(table.data[0]).length;
|
|
47
|
+
|
|
48
|
+
case 'columnar-table':
|
|
49
|
+
return Object.keys(table.data).length;
|
|
50
|
+
|
|
51
|
+
case 'arrow-table':
|
|
52
|
+
return table.data.numCols;
|
|
53
|
+
default:
|
|
54
|
+
throw new Error('table');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Get a table cell value at row index and column name */
|
|
59
|
+
export function getTableCell(table: Table, rowIndex: number, columnName: string): unknown {
|
|
60
|
+
switch (table.shape) {
|
|
61
|
+
case 'array-row-table':
|
|
62
|
+
const columnIndex = getTableColumnIndex(table, columnName);
|
|
63
|
+
return table.data[rowIndex][columnIndex];
|
|
64
|
+
|
|
65
|
+
case 'object-row-table':
|
|
66
|
+
case 'geojson-row-table':
|
|
67
|
+
return table.data[rowIndex][columnName];
|
|
68
|
+
|
|
69
|
+
case 'columnar-table':
|
|
70
|
+
const column = table.data[columnName];
|
|
71
|
+
return column[rowIndex];
|
|
72
|
+
|
|
73
|
+
case 'arrow-table':
|
|
74
|
+
const arrowColumnIndex = table.data.schema.fields.findIndex(
|
|
75
|
+
(field) => field.name === columnName
|
|
76
|
+
);
|
|
77
|
+
return table.data.getChildAt(arrowColumnIndex)?.get(rowIndex);
|
|
78
|
+
|
|
79
|
+
default:
|
|
80
|
+
throw new Error('todo');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Get a table cell value at row index and column name */
|
|
85
|
+
export function getTableCellAt(table: Table, rowIndex: number, columnIndex: number): unknown {
|
|
86
|
+
switch (table.shape) {
|
|
87
|
+
case 'array-row-table':
|
|
88
|
+
return table.data[rowIndex][columnIndex];
|
|
89
|
+
|
|
90
|
+
case 'object-row-table':
|
|
91
|
+
case 'geojson-row-table':
|
|
92
|
+
let columnName = getTableColumnName(table, columnIndex);
|
|
93
|
+
return table.data[rowIndex][columnName];
|
|
94
|
+
|
|
95
|
+
case 'columnar-table':
|
|
96
|
+
columnName = getTableColumnName(table, columnIndex);
|
|
97
|
+
const column = table.data[columnName];
|
|
98
|
+
return column[rowIndex];
|
|
99
|
+
|
|
100
|
+
case 'arrow-table':
|
|
101
|
+
return table.data.getChildAt(columnIndex)?.get(rowIndex);
|
|
102
|
+
|
|
103
|
+
default:
|
|
104
|
+
throw new Error('todo');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Deduce the table row shape */
|
|
109
|
+
export function getTableRowShape(table: Table): 'array-row-table' | 'object-row-table' {
|
|
110
|
+
switch (table.shape) {
|
|
111
|
+
case 'array-row-table':
|
|
112
|
+
case 'object-row-table':
|
|
113
|
+
return table.shape;
|
|
114
|
+
|
|
115
|
+
case 'geojson-row-table':
|
|
116
|
+
return 'object-row-table';
|
|
117
|
+
|
|
118
|
+
case 'columnar-table':
|
|
119
|
+
default:
|
|
120
|
+
throw new Error('Not a row table');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Get the index of a named table column. Requires the table to have a schema */
|
|
125
|
+
export function getTableColumnIndex(table: Table, columnName: string): number {
|
|
126
|
+
const columnIndex = table.schema?.fields.findIndex((field) => field.name === columnName);
|
|
127
|
+
if (columnIndex === undefined) {
|
|
128
|
+
throw new Error(columnName);
|
|
129
|
+
}
|
|
130
|
+
return columnIndex;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Get the name of a table column by index. Requires the table to have a schema */
|
|
134
|
+
export function getTableColumnName(table: Table, columnIndex: number): string {
|
|
135
|
+
const columnName = table.schema?.fields[columnIndex]?.name;
|
|
136
|
+
if (!columnName) {
|
|
137
|
+
throw new Error(`${columnIndex}`);
|
|
138
|
+
}
|
|
139
|
+
return columnName;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Returns one row of the table in object format.
|
|
144
|
+
* @param target Optional parameter will be used if needed to store the row. Can be reused between calls to improve performance
|
|
145
|
+
* @returns an array representing the row. May be the original array in the row, a new object, or the target parameter
|
|
146
|
+
*/
|
|
147
|
+
// eslint-disable-next-line complexity
|
|
148
|
+
export function getTableRowAsObject(
|
|
149
|
+
table: Table,
|
|
150
|
+
rowIndex: number,
|
|
151
|
+
target?: {[columnName: string]: unknown},
|
|
152
|
+
copy?: 'copy'
|
|
153
|
+
): {[columnName: string]: unknown} {
|
|
154
|
+
switch (table.shape) {
|
|
155
|
+
case 'object-row-table':
|
|
156
|
+
return copy ? Object.fromEntries(Object.entries(table.data[rowIndex])) : table.data[rowIndex];
|
|
157
|
+
|
|
158
|
+
case 'array-row-table':
|
|
159
|
+
case 'geojson-row-table':
|
|
160
|
+
if (table.schema) {
|
|
161
|
+
const objectRow: {[columnName: string]: unknown} = target || {};
|
|
162
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
163
|
+
objectRow[table.schema.fields[i].name] = table.data[rowIndex][i];
|
|
164
|
+
}
|
|
165
|
+
return objectRow;
|
|
166
|
+
}
|
|
167
|
+
throw new Error('no schema');
|
|
168
|
+
|
|
169
|
+
case 'columnar-table':
|
|
170
|
+
if (table.schema) {
|
|
171
|
+
const objectRow: {[columnName: string]: unknown} = target || {};
|
|
172
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
173
|
+
objectRow[table.schema.fields[i].name] =
|
|
174
|
+
table.data[table.schema.fields[i].name][rowIndex];
|
|
175
|
+
}
|
|
176
|
+
return objectRow;
|
|
177
|
+
} else {
|
|
178
|
+
// eslint-disable-line no-else-return
|
|
179
|
+
const objectRow: {[columnName: string]: unknown} = target || {};
|
|
180
|
+
for (const [name, column] of Object.entries(table.data)) {
|
|
181
|
+
objectRow[name] = column[rowIndex];
|
|
182
|
+
}
|
|
183
|
+
return objectRow;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
case 'arrow-table':
|
|
187
|
+
const objectRow: {[columnName: string]: unknown} = target || {};
|
|
188
|
+
const row = table.data.get(rowIndex);
|
|
189
|
+
const schema = table.data.schema;
|
|
190
|
+
for (let i = 0; i < schema.fields.length; i++) {
|
|
191
|
+
objectRow[schema.fields[i].name] = row?.[schema.fields[i].name];
|
|
192
|
+
}
|
|
193
|
+
return objectRow;
|
|
194
|
+
|
|
195
|
+
default:
|
|
196
|
+
throw new Error('shape');
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Returns one row of the table in array format.
|
|
202
|
+
* @param target Optional parameter will be used if needed to store the row. Can be reused between calls to improve performance.
|
|
203
|
+
* @returns an array representing the row. May be the original array in the row, a new object, or the target parameter
|
|
204
|
+
*/
|
|
205
|
+
// eslint-disable-next-line complexity
|
|
206
|
+
export function getTableRowAsArray(
|
|
207
|
+
table: Table,
|
|
208
|
+
rowIndex: number,
|
|
209
|
+
target?: unknown[],
|
|
210
|
+
copy?: 'copy'
|
|
211
|
+
): unknown[] {
|
|
212
|
+
switch (table.shape) {
|
|
213
|
+
case 'array-row-table':
|
|
214
|
+
return copy ? Array.from(table.data[rowIndex]) : table.data[rowIndex];
|
|
215
|
+
|
|
216
|
+
case 'object-row-table':
|
|
217
|
+
case 'geojson-row-table':
|
|
218
|
+
if (table.schema) {
|
|
219
|
+
const arrayRow: unknown[] = target || [];
|
|
220
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
221
|
+
arrayRow[i] = table.data[rowIndex][table.schema.fields[i].name];
|
|
222
|
+
}
|
|
223
|
+
return arrayRow;
|
|
224
|
+
}
|
|
225
|
+
// Warning: just slap on the values, this risks mismatches between rows
|
|
226
|
+
return Object.values(table.data[rowIndex]);
|
|
227
|
+
|
|
228
|
+
case 'columnar-table':
|
|
229
|
+
if (table.schema) {
|
|
230
|
+
const arrayRow: unknown[] = target || [];
|
|
231
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
232
|
+
arrayRow[i] = table.data[table.schema.fields[i].name][rowIndex];
|
|
233
|
+
}
|
|
234
|
+
return arrayRow;
|
|
235
|
+
} else {
|
|
236
|
+
// eslint-disable-line no-else-return
|
|
237
|
+
const arrayRow: unknown[] = target || [];
|
|
238
|
+
let i = 0;
|
|
239
|
+
for (const column of Object.values(table.data)) {
|
|
240
|
+
arrayRow[i] = column[rowIndex];
|
|
241
|
+
i++;
|
|
242
|
+
}
|
|
243
|
+
return arrayRow;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
case 'arrow-table':
|
|
247
|
+
const arrayRow: unknown[] = target || [];
|
|
248
|
+
const row = table.data.get(rowIndex);
|
|
249
|
+
const schema = table.data.schema;
|
|
250
|
+
for (let i = 0; i < schema.fields.length; i++) {
|
|
251
|
+
arrayRow[i] = row?.[schema.fields[i].name];
|
|
252
|
+
}
|
|
253
|
+
return arrayRow;
|
|
254
|
+
|
|
255
|
+
default:
|
|
256
|
+
throw new Error('shape');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Convert any table into array row format */
|
|
261
|
+
export function makeArrayRowTable(table: Table): ArrayRowTable {
|
|
262
|
+
if (table.shape === 'array-row-table') {
|
|
263
|
+
return table;
|
|
264
|
+
}
|
|
265
|
+
const length = getTableLength(table);
|
|
266
|
+
const data = new Array<unknown[]>(length);
|
|
267
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
268
|
+
data[rowIndex] = getTableRowAsArray(table, rowIndex);
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
shape: 'array-row-table',
|
|
272
|
+
schema: table.schema,
|
|
273
|
+
data
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Convert any table into object row format */
|
|
278
|
+
export function makeObjectRowTable(table: Table): ObjectRowTable {
|
|
279
|
+
if (table.shape === 'object-row-table') {
|
|
280
|
+
return table;
|
|
281
|
+
}
|
|
282
|
+
const length = getTableLength(table);
|
|
283
|
+
const data = new Array<{[key: string]: unknown}>(length);
|
|
284
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
285
|
+
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
shape: 'object-row-table',
|
|
289
|
+
schema: table.schema,
|
|
290
|
+
data
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Convert any table into object row format */
|
|
295
|
+
export function makeColumnarTable(table: Table): ObjectRowTable {
|
|
296
|
+
if (table.shape === 'object-row-table') {
|
|
297
|
+
return table;
|
|
298
|
+
}
|
|
299
|
+
const length = getTableLength(table);
|
|
300
|
+
const data = new Array<{[key: string]: unknown}>(length);
|
|
301
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
302
|
+
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
shape: 'object-row-table',
|
|
306
|
+
schema: table.schema,
|
|
307
|
+
data
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Row Iterators
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Iterate over table rows
|
|
315
|
+
* @param table
|
|
316
|
+
* @param shape
|
|
317
|
+
*/
|
|
318
|
+
export function* makeRowIterator(
|
|
319
|
+
table: Table,
|
|
320
|
+
shape: 'object-row-table' | 'array-row-table'
|
|
321
|
+
): Iterable<unknown[] | {[key: string]: unknown}> {
|
|
322
|
+
switch (shape) {
|
|
323
|
+
case 'array-row-table':
|
|
324
|
+
yield* makeArrayRowIterator(table);
|
|
325
|
+
break;
|
|
326
|
+
case 'object-row-table':
|
|
327
|
+
yield* makeObjectRowIterator(table);
|
|
328
|
+
break;
|
|
329
|
+
|
|
330
|
+
default:
|
|
331
|
+
throw new Error(`Unknown row type ${shape}`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Streaming processing: Iterate over table, yielding array rows
|
|
337
|
+
* @param table
|
|
338
|
+
* @param shape
|
|
339
|
+
*/
|
|
340
|
+
export function* makeArrayRowIterator(table: Table, target: unknown[] = []): Iterable<unknown[]> {
|
|
341
|
+
const length = getTableLength(table);
|
|
342
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
343
|
+
yield getTableRowAsArray(table, rowIndex, target);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Streaming processing: Iterate over table, yielding object rows
|
|
349
|
+
* @param table
|
|
350
|
+
* @param shape
|
|
351
|
+
*/
|
|
352
|
+
export function* makeObjectRowIterator(
|
|
353
|
+
table: Table,
|
|
354
|
+
target: {[key: string]: unknown} = {}
|
|
355
|
+
): Iterable<{[key: string]: unknown}> {
|
|
356
|
+
const length = getTableLength(table);
|
|
357
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
358
|
+
yield getTableRowAsObject(table, rowIndex, target);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
// import type {TypedArray,} from '../../../types/types';
|
|
4
|
+
import {Field} from '../../../types/schema';
|
|
5
|
+
import {getArrayTypeFromDataType} from './data-type';
|
|
6
|
+
|
|
7
|
+
export interface ArrayType<T = unknown> {
|
|
8
|
+
readonly length: number;
|
|
9
|
+
[n: number]: T;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function makeColumnFromField(field: Field, length: number): ArrayType {
|
|
13
|
+
const ArrayType = getArrayTypeFromDataType(field.type, field.nullable);
|
|
14
|
+
return new ArrayType(length);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
+
function deduceSchema(rows) {
|
|
20
|
+
const row = rows[0];
|
|
21
|
+
|
|
22
|
+
const schema = {};
|
|
23
|
+
let i = 0;
|
|
24
|
+
for (const columnName in row) {
|
|
25
|
+
const value = row[columnName];
|
|
26
|
+
switch (typeof value) {
|
|
27
|
+
case 'number':
|
|
28
|
+
case 'boolean':
|
|
29
|
+
// TODO - booleans could be handled differently...
|
|
30
|
+
schema[columnName] = {name: String(columnName), index: i, type: Float32Array};
|
|
31
|
+
break;
|
|
32
|
+
|
|
33
|
+
case 'object':
|
|
34
|
+
schema[columnName] = {name: String(columnName), index: i, type: Array};
|
|
35
|
+
break;
|
|
36
|
+
|
|
37
|
+
case 'string':
|
|
38
|
+
default:
|
|
39
|
+
schema[columnName] = {name: String(columnName), index: i, type: Array};
|
|
40
|
+
// We currently only handle numeric rows
|
|
41
|
+
// TODO we could offer a function to map strings to numbers?
|
|
42
|
+
}
|
|
43
|
+
i++;
|
|
44
|
+
}
|
|
45
|
+
return schema;
|
|
46
|
+
}
|
|
47
|
+
*/
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Type deduction
|
|
2
|
+
import {Schema, Field} from '../../../types/schema';
|
|
3
|
+
import {ArrayType} from '../../../types/types';
|
|
4
|
+
import {Table} from '../../../types/category-table';
|
|
5
|
+
import {getDataTypeFromArray, getDataTypeFromValue} from './data-type';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* SCHEMA SUPPORT - AUTODEDUCTION
|
|
9
|
+
* @param {*} table
|
|
10
|
+
* @param {*} schema
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export function deduceTableSchema(table: Table): Schema {
|
|
14
|
+
switch (table.shape) {
|
|
15
|
+
case 'array-row-table':
|
|
16
|
+
case 'object-row-table':
|
|
17
|
+
return deduceSchemaFromRows(table.data);
|
|
18
|
+
|
|
19
|
+
case 'columnar-table':
|
|
20
|
+
return deduceSchemaFromColumns(table.data);
|
|
21
|
+
|
|
22
|
+
case 'arrow-table':
|
|
23
|
+
default:
|
|
24
|
+
throw new Error('Deduce schema');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function deduceSchema(
|
|
29
|
+
data: unknown[][] | {[key: string]: unknown}[] | {[key: string]: unknown[]}
|
|
30
|
+
): Schema {
|
|
31
|
+
return Array.isArray(data) ? deduceSchemaFromRows(data) : deduceSchemaFromColumns(data);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Given an object with columnar arrays, try to deduce a schema */
|
|
35
|
+
function deduceSchemaFromColumns(columnarTable: {[key: string]: ArrayType}): Schema {
|
|
36
|
+
const fields: Field[] = [];
|
|
37
|
+
for (const [columnName, column] of Object.entries(columnarTable)) {
|
|
38
|
+
const field = deduceFieldFromColumn(column, columnName);
|
|
39
|
+
fields.push(field);
|
|
40
|
+
}
|
|
41
|
+
return {fields, metadata: {}};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Given an array of rows, try to deduce a schema */
|
|
45
|
+
function deduceSchemaFromRows(rowTable: unknown[][] | {[key: string]: unknown}[]): Schema {
|
|
46
|
+
if (!rowTable.length) {
|
|
47
|
+
throw new Error('deduce from empty table');
|
|
48
|
+
}
|
|
49
|
+
const fields: Field[] = [];
|
|
50
|
+
const row0 = rowTable[0];
|
|
51
|
+
// TODO - fields can be nullable, false detection...
|
|
52
|
+
// Could look at additional rows if nulls in first row
|
|
53
|
+
// TODO - if array, column names will be numbers
|
|
54
|
+
for (const [columnName, value] of Object.entries(row0)) {
|
|
55
|
+
fields.push(deduceFieldFromValue(value, columnName));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {fields, metadata: {}};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Given a column (i.e. array), attempt to deduce an appropriate `Field` */
|
|
62
|
+
function deduceFieldFromColumn(column: ArrayType, name: string): Field {
|
|
63
|
+
if (ArrayBuffer.isView(column)) {
|
|
64
|
+
const type = getDataTypeFromArray(column);
|
|
65
|
+
return {
|
|
66
|
+
name,
|
|
67
|
+
type: type.type || 'null',
|
|
68
|
+
nullable: type.nullable
|
|
69
|
+
// metadata: {}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (Array.isArray(column) && column.length > 0) {
|
|
74
|
+
const value = column[0];
|
|
75
|
+
const type = getDataTypeFromValue(value);
|
|
76
|
+
// TODO - support nested schemas?
|
|
77
|
+
return {
|
|
78
|
+
name,
|
|
79
|
+
type,
|
|
80
|
+
nullable: true
|
|
81
|
+
// metadata: {},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
throw new Error('empty table');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Given a value, attempt to deduce an appropriate `Field` */
|
|
89
|
+
function deduceFieldFromValue(value: unknown, name: string): Field {
|
|
90
|
+
const type = getDataTypeFromValue(value);
|
|
91
|
+
return {
|
|
92
|
+
name,
|
|
93
|
+
type,
|
|
94
|
+
nullable: true
|
|
95
|
+
// metadata: {}
|
|
96
|
+
};
|
|
97
|
+
}
|