@loaders.gl/core 5.0.0-rc.2 → 5.0.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/dist/api.cjs +4129 -0
- package/dist/api.cjs.map +6 -0
- package/dist/api.d.ts +34 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +50 -0
- package/dist/api.js.map +1 -0
- package/dist/arrow-geometry/geometry-codecs.cjs +51 -50
- package/dist/arrow-geometry/geometry-codecs.cjs.map +3 -3
- package/dist/arrow-geometry/geometry-codecs.d.ts +1 -1
- package/dist/arrow-geometry/geometry-codecs.d.ts.map +1 -1
- package/dist/arrow-geometry/geometry-codecs.js +27 -60
- package/dist/arrow-geometry/geometry-codecs.js.map +1 -1
- package/dist/arrow-geometry/index.cjs +5 -2
- package/dist/arrow-geometry/index.cjs.map +2 -2
- package/dist/arrow-geometry/index.d.ts +1 -0
- package/dist/arrow-geometry/index.d.ts.map +1 -1
- package/dist/arrow-geometry/index.js +1 -0
- package/dist/arrow-geometry/index.js.map +1 -1
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.cjs +100 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.cjs.map +7 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.d.ts +15 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.d.ts.map +1 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.js +87 -0
- package/dist/arrow-geometry/triangulate-wkb-geometry-column.js.map +1 -0
- package/dist/arrow-geometry/triangulate-wkb.cjs +33 -118
- package/dist/arrow-geometry/triangulate-wkb.cjs.map +2 -2
- package/dist/arrow-geometry/triangulate-wkb.d.ts.map +1 -1
- package/dist/arrow-geometry/triangulate-wkb.js +39 -142
- package/dist/arrow-geometry/triangulate-wkb.js.map +1 -1
- package/dist/constants/index.cjs +2 -2
- package/dist/constants/index.d.ts +4 -4
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +2 -2
- package/dist/constants/index.js.map +1 -1
- package/dist/dist.dev.js +460 -541
- package/dist/dist.min.js +3 -3
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.cjs +15 -0
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.cjs.map +2 -2
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.js +19 -1
- package/dist/geoarrow/geoarrow-converter/convert-geoarrow-geometry.js.map +1 -1
- package/dist/geoarrow/geoarrow-converter/geoarrow-converter.d.ts +1 -1
- package/dist/geoarrow/geoarrow-converter/geoarrow-converter.d.ts.map +1 -1
- package/dist/geoarrow/get-geoarrow-vertex-count.cjs +6 -27
- package/dist/geoarrow/get-geoarrow-vertex-count.cjs.map +2 -2
- package/dist/geoarrow/get-geoarrow-vertex-count.d.ts.map +1 -1
- package/dist/geoarrow/get-geoarrow-vertex-count.js +9 -24
- package/dist/geoarrow/get-geoarrow-vertex-count.js.map +1 -1
- package/dist/geoarrow/index.cjs +1 -1
- package/dist/geoarrow/index.cjs.map +1 -1
- package/dist/geoarrow/index.d.ts +2 -2
- package/dist/geoarrow/index.d.ts.map +1 -1
- package/dist/geoarrow/index.js +1 -1
- package/dist/geoarrow/index.js.map +1 -1
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.cjs +3 -5
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.cjs.map +2 -2
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.d.ts +2 -24
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.d.ts.map +1 -1
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.js +6 -28
- package/dist/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.js.map +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs +21 -227
- package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs.map +2 -2
- package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts +2 -3
- package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts.map +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.js +24 -265
- package/dist/geoarrow/lib/kernels/decode-wkt-native.js.map +1 -1
- package/dist/index.cjs +67 -4114
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +1 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -46
- package/dist/index.js.map +1 -1
- package/dist/lib/api/encode-table.d.ts +4 -4
- package/dist/lib/api/encode-table.d.ts.map +1 -1
- package/dist/lib/api/encode-table.js +21 -3
- package/dist/lib/api/encode-table.js.map +1 -1
- package/dist/lib/api/encode.d.ts +6 -6
- package/dist/lib/api/encode.d.ts.map +1 -1
- package/dist/lib/api/encode.js +46 -7
- package/dist/lib/api/encode.js.map +1 -1
- package/dist/lib/init.js +1 -1
- package/dist/lib/init.js.map +1 -1
- package/dist/loader-utils/index.cjs +96 -239
- package/dist/loader-utils/index.cjs.map +3 -3
- package/dist/loader-utils/index.d.ts +1 -1
- package/dist/loader-utils/index.d.ts.map +1 -1
- package/dist/loader-utils/index.js +1 -1
- package/dist/loader-utils/index.js.map +1 -1
- package/dist/loader-utils/json-loader-metadata.cjs +85 -0
- package/dist/loader-utils/json-loader-metadata.cjs.map +6 -0
- package/dist/loader-utils/json-loader-metadata.d.ts +51 -0
- package/dist/loader-utils/json-loader-metadata.d.ts.map +1 -0
- package/dist/loader-utils/json-loader-metadata.js +31 -0
- package/dist/loader-utils/json-loader-metadata.js.map +1 -0
- package/dist/loader-utils/json-loader.cjs +80 -0
- package/dist/loader-utils/json-loader.cjs.map +6 -0
- package/dist/loader-utils/json-loader.d.ts +4 -4
- package/dist/loader-utils/json-loader.d.ts.map +1 -1
- package/dist/loader-utils/json-loader.js +3 -17
- package/dist/loader-utils/json-loader.js.map +1 -1
- package/dist/loader-utils/lib/log-utils/log.js +1 -1
- package/dist/loader-utils/lib/log-utils/log.js.map +1 -1
- package/dist/loader-utils/lib/request-utils/authentication.d.ts +2 -0
- package/dist/loader-utils/lib/request-utils/authentication.d.ts.map +1 -1
- package/dist/loader-utils/lib/request-utils/authentication.js +12 -0
- package/dist/loader-utils/lib/request-utils/authentication.js.map +1 -1
- package/dist/loader-utils/lib/scan-utils/columnar-predicate.d.ts +4 -52
- package/dist/loader-utils/lib/scan-utils/columnar-predicate.d.ts.map +1 -1
- package/dist/loader-utils/lib/scan-utils/columnar-predicate.js +16 -236
- package/dist/loader-utils/lib/scan-utils/columnar-predicate.js.map +1 -1
- package/dist/loader-utils/lib/scan-utils/relational-query.d.ts +2 -0
- package/dist/loader-utils/lib/scan-utils/relational-query.d.ts.map +1 -1
- package/dist/loader-utils/lib/scan-utils/relational-query.js.map +1 -1
- package/dist/loader-utils/lib/scan-utils/table-query.d.ts +1 -1
- package/dist/loader-utils/lib/scan-utils/table-query.d.ts.map +1 -1
- package/dist/loader-utils/lib/sources/data-source.d.ts +1 -1
- package/dist/loader-utils/lib/sources/data-source.d.ts.map +1 -1
- package/dist/loader-utils/lib/sources/raster-source.d.ts +4 -0
- package/dist/loader-utils/lib/sources/raster-source.d.ts.map +1 -1
- package/dist/loader-utils/lib/sources/utils/utils.d.ts +1 -1
- package/dist/loader-utils/lib/sources/utils/utils.d.ts.map +1 -1
- package/dist/loader-utils/tile-grid.d.ts +2 -1
- package/dist/loader-utils/tile-grid.d.ts.map +1 -1
- package/dist/loader-utils/tile-grid.js +1 -1
- package/dist/loader-utils/tile-grid.js.map +1 -1
- package/dist/loader-utils/writer-types.d.ts +2 -0
- package/dist/loader-utils/writer-types.d.ts.map +1 -1
- package/dist/null-loader-metadata.cjs +89 -0
- package/dist/null-loader-metadata.cjs.map +6 -0
- package/dist/null-loader-metadata.d.ts +48 -0
- package/dist/null-loader-metadata.d.ts.map +1 -0
- package/dist/null-loader-metadata.js +30 -0
- package/dist/null-loader-metadata.js.map +1 -0
- package/dist/null-loader.cjs +84 -0
- package/dist/null-loader.cjs.map +6 -0
- package/dist/null-loader.d.ts +6 -6
- package/dist/null-loader.d.ts.map +1 -1
- package/dist/null-loader.js +2 -15
- package/dist/null-loader.js.map +1 -1
- package/dist/null-worker-node.js +58 -28
- package/dist/null-worker.js +58 -28
- package/dist/scan/arrow-execution/expressions.cjs +9 -78
- package/dist/scan/arrow-execution/expressions.cjs.map +3 -3
- package/dist/scan/arrow-execution/expressions.d.ts +3 -9
- package/dist/scan/arrow-execution/expressions.d.ts.map +1 -1
- package/dist/scan/arrow-execution/expressions.js +2 -55
- package/dist/scan/arrow-execution/expressions.js.map +1 -1
- package/dist/scan/arrow-execution/filter-arrow-table.cjs +41 -179
- package/dist/scan/arrow-execution/filter-arrow-table.cjs.map +3 -3
- package/dist/scan/arrow-execution/filter-arrow-table.d.ts +1 -5
- package/dist/scan/arrow-execution/filter-arrow-table.d.ts.map +1 -1
- package/dist/scan/arrow-execution/filter-arrow-table.js +44 -190
- package/dist/scan/arrow-execution/filter-arrow-table.js.map +1 -1
- package/dist/scan/arrow-execution.cjs +2 -2
- package/dist/scan/arrow-execution.cjs.map +2 -2
- package/dist/scan/arrow-execution.d.ts +1 -1
- package/dist/scan/arrow-execution.d.ts.map +1 -1
- package/dist/scan/arrow-execution.js +1 -1
- package/dist/scan/arrow-execution.js.map +1 -1
- package/dist/scan/arrow-query.cjs +3 -3
- package/dist/scan/arrow-query.cjs.map +2 -2
- package/dist/scan/arrow-query.d.ts +2 -2
- package/dist/scan/arrow-query.d.ts.map +1 -1
- package/dist/scan/arrow-query.js +2 -2
- package/dist/scan/arrow-query.js.map +1 -1
- package/dist/scan/federated-table-scan-source.cjs +3 -3
- package/dist/scan/federated-table-scan-source.cjs.map +2 -2
- package/dist/scan/federated-table-scan-source.js +1 -1
- package/dist/scan/federated-table-scan-source.js.map +1 -1
- package/dist/scan/index.cjs +25 -53
- package/dist/scan/index.cjs.map +3 -3
- package/dist/scan/index.d.ts +7 -4
- package/dist/scan/index.d.ts.map +1 -1
- package/dist/scan/index.js +6 -4
- package/dist/scan/index.js.map +1 -1
- package/dist/scan/plan-arrow-table-query.cjs +271 -0
- package/dist/scan/plan-arrow-table-query.cjs.map +7 -0
- package/dist/scan/plan-arrow-table-query.d.ts +50 -0
- package/dist/scan/plan-arrow-table-query.d.ts.map +1 -0
- package/dist/scan/plan-arrow-table-query.js +257 -0
- package/dist/scan/plan-arrow-table-query.js.map +1 -0
- package/dist/scan/query-arrow-table-in-batches.cjs +7 -56
- package/dist/scan/query-arrow-table-in-batches.cjs.map +2 -2
- package/dist/scan/query-arrow-table-in-batches.d.ts +1 -1
- package/dist/scan/query-arrow-table-in-batches.d.ts.map +1 -1
- package/dist/scan/query-arrow-table-in-batches.js +7 -45
- package/dist/scan/query-arrow-table-in-batches.js.map +1 -1
- package/dist/scan/query-arrow-table.cjs +7 -443
- package/dist/scan/query-arrow-table.cjs.map +3 -3
- package/dist/scan/query-arrow-table.d.ts +6 -54
- package/dist/scan/query-arrow-table.d.ts.map +1 -1
- package/dist/scan/query-arrow-table.js +6 -475
- package/dist/scan/query-arrow-table.js.map +1 -1
- package/dist/scan/query-executor.cjs +202 -0
- package/dist/scan/query-executor.cjs.map +7 -0
- package/dist/scan/query-executor.d.ts +27 -0
- package/dist/scan/query-executor.d.ts.map +1 -0
- package/dist/scan/query-executor.js +203 -0
- package/dist/scan/query-executor.js.map +1 -0
- package/dist/scan/query-pushdown.cjs +3 -4
- package/dist/scan/query-pushdown.cjs.map +2 -2
- package/dist/scan/query-pushdown.js +4 -5
- package/dist/scan/query-pushdown.js.map +1 -1
- package/dist/scan/query.cjs +92 -204
- package/dist/scan/query.cjs.map +3 -3
- package/dist/scan/query.d.ts +5 -4
- package/dist/scan/query.d.ts.map +1 -1
- package/dist/scan/query.js +94 -229
- package/dist/scan/query.js.map +1 -1
- package/dist/scan/scan-engine.cjs +14 -7
- package/dist/scan/scan-engine.cjs.map +2 -2
- package/dist/scan/scan-engine.d.ts +1 -1
- package/dist/scan/scan-engine.d.ts.map +1 -1
- package/dist/scan/scan-engine.js +4 -9
- package/dist/scan/scan-engine.js.map +1 -1
- package/dist/scan/vector-table-scan-source.cjs +14 -3
- package/dist/scan/vector-table-scan-source.cjs.map +2 -2
- package/dist/scan/vector-table-scan-source.d.ts +1 -1
- package/dist/scan/vector-table-scan-source.d.ts.map +1 -1
- package/dist/scan/vector-table-scan-source.js +2 -1
- package/dist/scan/vector-table-scan-source.js.map +1 -1
- package/dist/schema-utils/index.cjs +193 -47
- package/dist/schema-utils/index.cjs.map +3 -3
- package/dist/schema-utils/index.d.ts +3 -0
- package/dist/schema-utils/index.d.ts.map +1 -1
- package/dist/schema-utils/index.js +3 -0
- package/dist/schema-utils/index.js.map +1 -1
- package/dist/schema-utils/lib/arrow/arrow-converter.d.ts +24 -0
- package/dist/schema-utils/lib/arrow/arrow-converter.d.ts.map +1 -0
- package/dist/schema-utils/lib/arrow/arrow-converter.js +43 -0
- package/dist/schema-utils/lib/arrow/arrow-converter.js.map +1 -0
- package/dist/schema-utils/lib/arrow/arrow-metadata.d.ts +2 -4
- package/dist/schema-utils/lib/arrow/arrow-metadata.d.ts.map +1 -1
- package/dist/schema-utils/lib/arrow/arrow-metadata.js +2 -43
- package/dist/schema-utils/lib/arrow/arrow-metadata.js.map +1 -1
- package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.d.ts +29 -0
- package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.d.ts.map +1 -0
- package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.js +89 -0
- package/dist/schema-utils/lib/arrow/convert-arrow-variable-width.js.map +1 -0
- package/dist/schema-utils/lib/arrow/convert-arrow.d.ts +17 -0
- package/dist/schema-utils/lib/arrow/convert-arrow.d.ts.map +1 -0
- package/dist/schema-utils/lib/arrow/convert-arrow.js +24 -0
- package/dist/schema-utils/lib/arrow/convert-arrow.js.map +1 -0
- package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.d.ts +4 -0
- package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.d.ts.map +1 -0
- package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.js +51 -0
- package/dist/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.js.map +1 -0
- package/dist/wkt/twkb/index.cjs +68 -5
- package/dist/wkt/twkb/index.cjs.map +3 -3
- package/dist/wkt/twkb/index.d.ts +10 -2
- package/dist/wkt/twkb/index.d.ts.map +1 -1
- package/dist/wkt/twkb/index.js +49 -2
- package/dist/wkt/twkb/index.js.map +1 -1
- package/dist/worker-utils/index.cjs +4 -4
- package/dist/worker-utils/index.cjs.map +1 -1
- package/dist/worker-utils/lib/env-utils/version.js +1 -1
- package/dist/worker-utils/lib/env-utils/version.js.map +1 -1
- package/package.json +49 -23
- package/src/api.ts +99 -0
- package/src/arrow-geometry/geometry-codecs.ts +35 -78
- package/src/arrow-geometry/index.ts +5 -0
- package/src/arrow-geometry/triangulate-wkb-geometry-column.ts +122 -0
- package/src/arrow-geometry/triangulate-wkb.ts +37 -169
- package/src/constants/index.ts +2 -2
- package/src/geoarrow/geoarrow-converter/convert-geoarrow-geometry.ts +22 -1
- package/src/geoarrow/get-geoarrow-vertex-count.ts +7 -32
- package/src/geoarrow/index.ts +2 -2
- package/src/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.ts +6 -30
- package/src/geoarrow/lib/kernels/decode-wkt-native.ts +24 -270
- package/src/index.ts +2 -94
- package/src/lib/api/encode-table.ts +31 -6
- package/src/lib/api/encode.ts +61 -11
- package/src/loader-utils/index.ts +1 -0
- package/src/loader-utils/json-loader-metadata.ts +35 -0
- package/src/loader-utils/json-loader.ts +3 -18
- package/src/loader-utils/lib/request-utils/authentication.ts +17 -0
- package/src/loader-utils/lib/scan-utils/columnar-predicate.ts +46 -363
- package/src/loader-utils/lib/scan-utils/relational-query.ts +7 -1
- package/src/loader-utils/lib/sources/raster-source.ts +4 -0
- package/src/loader-utils/tile-grid.ts +16 -1
- package/src/loader-utils/writer-types.ts +2 -0
- package/src/null-loader-metadata.ts +32 -0
- package/src/null-loader.ts +2 -17
- package/src/scan/arrow-execution/expressions.ts +2 -86
- package/src/scan/arrow-execution/filter-arrow-table.ts +54 -238
- package/src/scan/arrow-execution.ts +1 -1
- package/src/scan/arrow-query.ts +2 -2
- package/src/scan/federated-table-scan-source.ts +1 -1
- package/src/scan/index.ts +24 -4
- package/src/scan/plan-arrow-table-query.ts +367 -0
- package/src/scan/query-arrow-table-in-batches.ts +8 -54
- package/src/scan/query-arrow-table.ts +10 -626
- package/src/scan/query-executor.ts +286 -0
- package/src/scan/query-pushdown.ts +3 -4
- package/src/scan/query.ts +112 -293
- package/src/scan/scan-engine.ts +4 -11
- package/src/scan/vector-table-scan-source.ts +2 -1
- package/src/schema-utils/index.ts +14 -0
- package/src/schema-utils/lib/arrow/arrow-converter.ts +74 -0
- package/src/schema-utils/lib/arrow/arrow-metadata.ts +2 -50
- package/src/schema-utils/lib/arrow/convert-arrow-variable-width.ts +121 -0
- package/src/schema-utils/lib/arrow/convert-arrow.ts +52 -0
- package/src/schema-utils/lib/arrow/tighten-arrow-table-schema-nullability.ts +83 -0
- package/src/wkt/twkb/index.ts +63 -2
- package/dist/cluster-source.cjs +0 -6606
- package/dist/cluster-source.cjs.map +0 -6
- package/dist/cluster-source.d.ts +0 -2
- package/dist/cluster-source.d.ts.map +0 -1
- package/dist/cluster-source.js +0 -2
- package/dist/cluster-source.js.map +0 -1
- package/dist/federated-table-scan-source.cjs +0 -2303
- package/dist/federated-table-scan-source.cjs.map +0 -6
- package/dist/federated-table-scan-source.d.ts +0 -2
- package/dist/federated-table-scan-source.d.ts.map +0 -1
- package/dist/federated-table-scan-source.js +0 -2
- package/dist/federated-table-scan-source.js.map +0 -1
- package/dist/geoarrow/geoarrow-builder.cjs +0 -31
- package/dist/geoarrow/geoarrow-builder.cjs.map +0 -7
- package/dist/geoarrow/geoarrow-builder.d.ts +0 -3
- package/dist/geoarrow/geoarrow-builder.d.ts.map +0 -1
- package/dist/geoarrow/geoarrow-builder.js +0 -5
- package/dist/geoarrow/geoarrow-builder.js.map +0 -1
- package/dist/scan/arrow-execution/portable-predicate-compatibility.cjs +0 -41
- package/dist/scan/arrow-execution/portable-predicate-compatibility.cjs.map +0 -7
- package/dist/scan/arrow-execution/portable-predicate-compatibility.d.ts +0 -5
- package/dist/scan/arrow-execution/portable-predicate-compatibility.d.ts.map +0 -1
- package/dist/scan/arrow-execution/portable-predicate-compatibility.js +0 -23
- package/dist/scan/arrow-execution/portable-predicate-compatibility.js.map +0 -1
- package/dist/scan/arrow-execution/project-arrow-table.cjs +0 -70
- package/dist/scan/arrow-execution/project-arrow-table.cjs.map +0 -7
- package/dist/scan/arrow-execution/project-arrow-table.d.ts +0 -8
- package/dist/scan/arrow-execution/project-arrow-table.d.ts.map +0 -1
- package/dist/scan/arrow-execution/project-arrow-table.js +0 -39
- package/dist/scan/arrow-execution/project-arrow-table.js.map +0 -1
- package/dist/scan/query-arrow-table-math.cjs +0 -41
- package/dist/scan/query-arrow-table-math.cjs.map +0 -7
- package/dist/scan/query-arrow-table-math.d.ts +0 -5
- package/dist/scan/query-arrow-table-math.d.ts.map +0 -1
- package/dist/scan/query-arrow-table-math.js +0 -14
- package/dist/scan/query-arrow-table-math.js.map +0 -1
- package/dist/vector-table-scan-source.cjs +0 -1660
- package/dist/vector-table-scan-source.cjs.map +0 -6
- package/dist/vector-table-scan-source.d.ts +0 -2
- package/dist/vector-table-scan-source.d.ts.map +0 -1
- package/dist/vector-table-scan-source.js +0 -2
- package/dist/vector-table-scan-source.js.map +0 -1
- package/dist/wkt/twkb/convert-geometry-to-twkb.cjs +0 -211
- package/dist/wkt/twkb/convert-geometry-to-twkb.cjs.map +0 -7
- package/dist/wkt/twkb/convert-geometry-to-twkb.d.ts +0 -6
- package/dist/wkt/twkb/convert-geometry-to-twkb.d.ts.map +0 -1
- package/dist/wkt/twkb/convert-geometry-to-twkb.js +0 -204
- package/dist/wkt/twkb/convert-geometry-to-twkb.js.map +0 -1
- package/dist/wkt/twkb/convert-twkb-to-geometry.cjs +0 -251
- package/dist/wkt/twkb/convert-twkb-to-geometry.cjs.map +0 -7
- package/dist/wkt/twkb/convert-twkb-to-geometry.d.ts +0 -10
- package/dist/wkt/twkb/convert-twkb-to-geometry.d.ts.map +0 -1
- package/dist/wkt/twkb/convert-twkb-to-geometry.js +0 -261
- package/dist/wkt/twkb/convert-twkb-to-geometry.js.map +0 -1
- package/dist/wkt/twkb/twkb-io.cjs +0 -102
- package/dist/wkt/twkb/twkb-io.cjs.map +0 -7
- package/dist/wkt/twkb/twkb-io.d.ts +0 -33
- package/dist/wkt/twkb/twkb-io.d.ts.map +0 -1
- package/dist/wkt/twkb/twkb-io.js +0 -78
- package/dist/wkt/twkb/twkb-io.js.map +0 -1
- package/dist/wkt/twkb/twkb-types.cjs +0 -40
- package/dist/wkt/twkb/twkb-types.cjs.map +0 -7
- package/dist/wkt/twkb/twkb-types.d.ts +0 -11
- package/dist/wkt/twkb/twkb-types.d.ts.map +0 -1
- package/dist/wkt/twkb/twkb-types.js +0 -15
- package/dist/wkt/twkb/twkb-types.js.map +0 -1
- package/src/cluster-source.ts +0 -1
- package/src/federated-table-scan-source.ts +0 -1
- package/src/geoarrow/geoarrow-builder.ts +0 -21
- package/src/scan/arrow-execution/portable-predicate-compatibility.ts +0 -27
- package/src/scan/arrow-execution/project-arrow-table.ts +0 -53
- package/src/scan/query-arrow-table-math.ts +0 -23
- package/src/vector-table-scan-source.ts +0 -1
- package/src/wkt/twkb/convert-geometry-to-twkb.ts +0 -317
- package/src/wkt/twkb/convert-twkb-to-geometry.ts +0 -373
- package/src/wkt/twkb/twkb-io.ts +0 -85
- package/src/wkt/twkb/twkb-types.ts +0 -14
package/src/scan/query.ts
CHANGED
|
@@ -2,40 +2,44 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import * as arrow from 'apache-arrow';
|
|
5
|
+
import type * as arrow from 'apache-arrow';
|
|
6
|
+
import type {SQLQuery} from '@math.gl/sql/parser';
|
|
6
7
|
import type {
|
|
7
8
|
ProgressiveAggregateQuery,
|
|
8
9
|
ProgressiveQueryOptions,
|
|
9
10
|
ProgressiveQuerySnapshot
|
|
10
11
|
} from './query-progressive';
|
|
11
|
-
import type {SQLQuery} from '@math.gl/sql/parser';
|
|
12
|
-
import type {TableBatch, Schema} from '@loaders.gl/core/schema';
|
|
13
12
|
import {
|
|
14
|
-
normalizeTableQuery,
|
|
15
|
-
getColumnarPredicateColumns,
|
|
16
|
-
executeTableScanBatches,
|
|
17
|
-
planTableQuery,
|
|
18
13
|
emitQueryComplete,
|
|
19
14
|
type TableQuery,
|
|
20
15
|
type TableQueryExecutionOptions,
|
|
21
16
|
type TableQueryExecutionSummary,
|
|
22
17
|
type TableScanSource,
|
|
23
|
-
type TableScanReadOptions,
|
|
24
18
|
type LoaderOptions,
|
|
25
19
|
type DataSourceOptions,
|
|
26
|
-
type Loader
|
|
20
|
+
type Loader,
|
|
21
|
+
type DataSource
|
|
27
22
|
} from '@loaders.gl/core/loader-utils';
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
convertSchemaToArrow,
|
|
31
|
-
makeArrowMetadataBatch,
|
|
32
|
-
makeArrowTableFromBatches,
|
|
33
|
-
convertTableToArrow
|
|
34
|
-
} from '@loaders.gl/core/schema-utils';
|
|
35
|
-
import {projectArrowTable, filterArrowTable} from './arrow-execution';
|
|
36
|
-
import {filterArrowRows} from './arrow-execution/filter-arrow-table';
|
|
23
|
+
import {resolveQuerySource} from './resolve-query-source';
|
|
24
|
+
import {openQuerySource} from './query-open-source';
|
|
37
25
|
import type {SQLCatalogQuery} from './sql-catalog';
|
|
38
|
-
|
|
26
|
+
|
|
27
|
+
type QueryExecutor = typeof import('./query-executor');
|
|
28
|
+
let pendingExecutor: Promise<QueryExecutor> | undefined;
|
|
29
|
+
|
|
30
|
+
/** Shares the executor import across queries and explicit preload calls. */
|
|
31
|
+
function loadQueryExecutor(): Promise<QueryExecutor> {
|
|
32
|
+
pendingExecutor ??= import('./query-executor').catch(error => {
|
|
33
|
+
pendingExecutor = undefined;
|
|
34
|
+
throw error;
|
|
35
|
+
});
|
|
36
|
+
return pendingExecutor;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Loads the ordinary query executor without opening a source or reading data. */
|
|
40
|
+
export async function preloadQuery(): Promise<void> {
|
|
41
|
+
await loadQueryExecutor();
|
|
42
|
+
}
|
|
39
43
|
|
|
40
44
|
/** Logical table or metadata request. */
|
|
41
45
|
export type Query = TableQuery | SQLQuery | TypedTableQuery;
|
|
@@ -124,9 +128,17 @@ export async function query(
|
|
|
124
128
|
tableQuery: Query | string,
|
|
125
129
|
options: QueryOptions
|
|
126
130
|
): Promise<arrow.Table> {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
const results = runQuery(
|
|
132
|
+
tableQuery,
|
|
133
|
+
{...options, queryOutput: 'batches'},
|
|
134
|
+
async function* collect(executor, batches) {
|
|
135
|
+
const table = await executor.makeArrowTableFromBatches(batches);
|
|
136
|
+
if (table) yield table;
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
let result: arrow.Table | undefined;
|
|
140
|
+
for await (const table of results) result = table;
|
|
141
|
+
return result!;
|
|
130
142
|
}
|
|
131
143
|
|
|
132
144
|
/** Streams native Arrow batches or complete replacement snapshots. */
|
|
@@ -151,13 +163,7 @@ export async function* queryInBatches(
|
|
|
151
163
|
if (options.queryOutput !== undefined && options.queryOutput !== 'batches') {
|
|
152
164
|
throw new Error('Unsupported queryOutput.');
|
|
153
165
|
}
|
|
154
|
-
|
|
155
|
-
throw new Error('Aggregates require snapshots.');
|
|
156
|
-
}
|
|
157
|
-
for await (const table of queryAppendBatches(tableQuery as Query | string, options)) {
|
|
158
|
-
if (table.batches.length) yield* table.batches;
|
|
159
|
-
else yield makeArrowMetadataBatch(table.schema);
|
|
160
|
-
}
|
|
166
|
+
yield* runQuery(tableQuery as Query | string, options, (_executor, batches) => batches);
|
|
161
167
|
}
|
|
162
168
|
|
|
163
169
|
/** Streams complete aggregate snapshots and loads the grouped executor on demand. */
|
|
@@ -170,19 +176,27 @@ export async function* queryProgressive(
|
|
|
170
176
|
}
|
|
171
177
|
|
|
172
178
|
/** Executes one logical query with bounded batch buffering and cooperative cancellation. */
|
|
173
|
-
async function*
|
|
179
|
+
async function* runQuery<Result>(
|
|
174
180
|
tableQuery: Query | string,
|
|
175
|
-
options: QueryOptions
|
|
176
|
-
|
|
181
|
+
options: QueryOptions,
|
|
182
|
+
consume: (
|
|
183
|
+
executor: QueryExecutor,
|
|
184
|
+
batches: AsyncIterable<arrow.RecordBatch>
|
|
185
|
+
) => AsyncIterable<Result>
|
|
186
|
+
): AsyncGenerator<Result> {
|
|
187
|
+
if (typeof tableQuery === 'object' && tableQuery && 'aggregates' in tableQuery)
|
|
188
|
+
throw new Error('Aggregates require snapshots.');
|
|
177
189
|
const startedAt = Date.now();
|
|
178
190
|
let status: TableQueryExecutionSummary['status'] = 'early-terminated';
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
191
|
+
const metrics = {
|
|
192
|
+
rowsRead: 0,
|
|
193
|
+
rowsReturned: 0,
|
|
194
|
+
batchesRead: 0,
|
|
195
|
+
sourcesRead: 0,
|
|
196
|
+
earlyTerminationReason: undefined as TableQueryExecutionSummary['earlyTerminationReason']
|
|
197
|
+
};
|
|
183
198
|
let error: unknown;
|
|
184
199
|
let ownedSource: {close?: () => void | Promise<void>} | undefined;
|
|
185
|
-
let earlyTerminationReason: TableQueryExecutionSummary['earlyTerminationReason'];
|
|
186
200
|
try {
|
|
187
201
|
options.signal?.throwIfAborted();
|
|
188
202
|
const scan = options._scan;
|
|
@@ -194,6 +208,58 @@ async function* queryAppendBatches(
|
|
|
194
208
|
) {
|
|
195
209
|
throw new Error('Put offset and limit in the logical query, not the execution options.');
|
|
196
210
|
}
|
|
211
|
+
const executorImport = loadQueryExecutor();
|
|
212
|
+
|
|
213
|
+
const preparation = prepareSource();
|
|
214
|
+
const [executor, prepared] = await Promise.all([executorImport, preparation]).catch(
|
|
215
|
+
async failure => {
|
|
216
|
+
// Preparation can still be using an owned source when the executor import fails.
|
|
217
|
+
await preparation.catch(() => {});
|
|
218
|
+
throw failure;
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
options.signal?.throwIfAborted();
|
|
222
|
+
const batches = executor.executePreparedQuery(prepared, options, metrics);
|
|
223
|
+
yield* consume(executor, batches);
|
|
224
|
+
status = metrics.earlyTerminationReason ? 'early-terminated' : 'completed';
|
|
225
|
+
} catch (failure) {
|
|
226
|
+
error = failure;
|
|
227
|
+
status = options.signal?.aborted ? 'cancelled' : 'failed';
|
|
228
|
+
throw failure;
|
|
229
|
+
} finally {
|
|
230
|
+
if (status === 'early-terminated' && !metrics.earlyTerminationReason)
|
|
231
|
+
metrics.earlyTerminationReason = 'consumer-return';
|
|
232
|
+
try {
|
|
233
|
+
await ownedSource?.close?.();
|
|
234
|
+
} catch (failure) {
|
|
235
|
+
if (error === undefined) {
|
|
236
|
+
error = failure;
|
|
237
|
+
status = options.signal?.aborted ? 'cancelled' : 'failed';
|
|
238
|
+
metrics.earlyTerminationReason = undefined;
|
|
239
|
+
throw failure;
|
|
240
|
+
}
|
|
241
|
+
} finally {
|
|
242
|
+
emitQueryComplete(
|
|
243
|
+
options.onQueryComplete,
|
|
244
|
+
Object.freeze({
|
|
245
|
+
status,
|
|
246
|
+
sourcesPlanned: 1,
|
|
247
|
+
sourcesRead: metrics.sourcesRead,
|
|
248
|
+
batchesRead: metrics.batchesRead,
|
|
249
|
+
rowsRead: metrics.rowsRead,
|
|
250
|
+
rowsReturned: metrics.rowsReturned,
|
|
251
|
+
durationMilliseconds: Date.now() - startedAt,
|
|
252
|
+
...(metrics.earlyTerminationReason
|
|
253
|
+
? {earlyTerminationReason: metrics.earlyTerminationReason}
|
|
254
|
+
: {}),
|
|
255
|
+
...(error === undefined ? {} : {error})
|
|
256
|
+
})
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Resolves the query input and its schema without loading the Arrow executor. */
|
|
262
|
+
async function prepareSource() {
|
|
197
263
|
let parsedQuery: Query;
|
|
198
264
|
if (typeof tableQuery === 'string') {
|
|
199
265
|
const parser = await options.sqlParser;
|
|
@@ -220,14 +286,10 @@ async function* queryAppendBatches(
|
|
|
220
286
|
source =
|
|
221
287
|
logicalQuery.from === undefined
|
|
222
288
|
? options.source
|
|
223
|
-
: await (
|
|
224
|
-
logicalQuery.from,
|
|
225
|
-
options.sources,
|
|
226
|
-
options.signal
|
|
227
|
-
);
|
|
289
|
+
: await resolveQuerySource(logicalQuery.from, options.sources, options.signal);
|
|
228
290
|
}
|
|
229
291
|
if (logicalQuery.from === undefined && typeof source === 'string') {
|
|
230
|
-
const opened = await
|
|
292
|
+
const opened = await openQuerySource(options);
|
|
231
293
|
if (
|
|
232
294
|
opened &&
|
|
233
295
|
typeof opened === 'object' &&
|
|
@@ -267,235 +329,14 @@ async function* queryAppendBatches(
|
|
|
267
329
|
'Query source has a default offset or limit. Remove the source defaults and put offset and limit in the logical query.'
|
|
268
330
|
);
|
|
269
331
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
selection &&
|
|
278
|
-
typeof selection === 'object' &&
|
|
279
|
-
('expression' in selection || 'array' in selection)
|
|
280
|
-
);
|
|
281
|
-
const expressionFilter =
|
|
282
|
-
where && typeof where === 'object' && 'expression' in where ? where : undefined;
|
|
283
|
-
const portablePredicate = expressionFilter ? undefined : (where as TableQuery['where']);
|
|
284
|
-
const normalized = normalizeTableQuery(names, {
|
|
285
|
-
...controls,
|
|
286
|
-
select: computedProjection ? undefined : (select as TableQuery['select']),
|
|
287
|
-
where: castPredicate ? undefined : portablePredicate
|
|
288
|
-
});
|
|
289
|
-
const expressionTools =
|
|
290
|
-
computedProjection || expressionFilter || castPredicate
|
|
291
|
-
? await import('./arrow-execution/expressions')
|
|
292
|
-
: undefined;
|
|
293
|
-
const outputColumns = computedProjection
|
|
294
|
-
? expressionTools!.getProjectionColumns(select!)
|
|
295
|
-
: normalized.select.map(selection => selection.column);
|
|
296
|
-
const expressionColumns = expressionFilter
|
|
297
|
-
? expressionTools!.getExpressionColumns(expressionFilter.expression)
|
|
298
|
-
: castPredicate && portablePredicate
|
|
299
|
-
? getColumnarPredicateColumns(portablePredicate)
|
|
300
|
-
: [];
|
|
301
|
-
const required = [...new Set([...outputColumns, ...expressionColumns])];
|
|
302
|
-
const plan = planTableQuery(names, {
|
|
303
|
-
// A literal-only projection still needs a physical column to retain row counts.
|
|
304
|
-
columns: required.length ? required : names.slice(0, 1),
|
|
305
|
-
predicate: normalized.where
|
|
306
|
-
});
|
|
307
|
-
const requiredColumns = plan[0].kind === 'scan' ? plan[0].columns : names;
|
|
308
|
-
const capabilities = (metadata?.queryCapabilities ?? metadata?.capabilities)?.table;
|
|
309
|
-
// read() must perform exact filtering when it advertises pushdown+residual, not only pruning.
|
|
310
|
-
const delegatePredicate = Boolean(
|
|
311
|
-
normalized.where &&
|
|
312
|
-
capabilities &&
|
|
313
|
-
['pushdown', 'pushdown+residual'].includes(capabilities.predicate)
|
|
314
|
-
);
|
|
315
|
-
const residual = delegatePredicate ? undefined : normalized.where;
|
|
316
|
-
const canDelegateWindow = !residual && !expressionFilter && !castPredicate;
|
|
317
|
-
const delegateOffset = Boolean(
|
|
318
|
-
canDelegateWindow &&
|
|
319
|
-
normalized.offset !== undefined &&
|
|
320
|
-
capabilities &&
|
|
321
|
-
['pushdown', 'pushdown+residual'].includes(capabilities.offset ?? 'unsupported')
|
|
322
|
-
);
|
|
323
|
-
const requestedRows =
|
|
324
|
-
normalized.limit === undefined
|
|
325
|
-
? undefined
|
|
326
|
-
: (delegateOffset ? 0 : (normalized.offset ?? 0)) + normalized.limit;
|
|
327
|
-
const readOptions: TableScanReadOptions = {
|
|
328
|
-
signal: options.signal,
|
|
329
|
-
...(capabilities && capabilities.projection !== 'unsupported'
|
|
330
|
-
? {columns: requiredColumns}
|
|
331
|
-
: {}),
|
|
332
|
-
...(delegatePredicate ? {predicate: normalized.where} : {}),
|
|
333
|
-
...(delegateOffset ? {offset: normalized.offset} : {}),
|
|
334
|
-
...(canDelegateWindow &&
|
|
335
|
-
requestedRows !== undefined &&
|
|
336
|
-
Number.isSafeInteger(requestedRows) &&
|
|
337
|
-
capabilities &&
|
|
338
|
-
['pushdown', 'pushdown+residual'].includes(capabilities.limit)
|
|
339
|
-
? {limit: requestedRows}
|
|
340
|
-
: {})
|
|
332
|
+
return {
|
|
333
|
+
logicalQuery,
|
|
334
|
+
source,
|
|
335
|
+
inMemory,
|
|
336
|
+
metadata,
|
|
337
|
+
castPredicate,
|
|
338
|
+
catalogQuery: 'command' in parsedQuery
|
|
341
339
|
};
|
|
342
|
-
const inputSchema = readOptions.columns
|
|
343
|
-
? sourceSchema.select([...readOptions.columns])
|
|
344
|
-
: sourceSchema;
|
|
345
|
-
const readSchema = convertArrowToSchema(inputSchema);
|
|
346
|
-
const comparisonInputSchema = expressionTools ? convertSchemaToArrow(readSchema) : undefined;
|
|
347
|
-
const compiledFilter = expressionFilter
|
|
348
|
-
? expressionTools!.compileArrowExpression(expressionFilter.expression, {
|
|
349
|
-
inputSchema,
|
|
350
|
-
functions: options.functions
|
|
351
|
-
})
|
|
352
|
-
: castPredicate && portablePredicate
|
|
353
|
-
? expressionTools!.compileArrowPredicate(portablePredicate, {inputSchema})
|
|
354
|
-
: undefined;
|
|
355
|
-
if (compiledFilter && !arrow.DataType.isBool(compiledFilter.outputField.type))
|
|
356
|
-
throw new Error('SQL WHERE expression must return Boolean.');
|
|
357
|
-
const project = computedProjection
|
|
358
|
-
? expressionTools!.compileArrowProjection(
|
|
359
|
-
inputSchema,
|
|
360
|
-
select!,
|
|
361
|
-
options.signal,
|
|
362
|
-
options.functions
|
|
363
|
-
)
|
|
364
|
-
: (data: arrow.Table) => projectArrowTable(data, normalized.select);
|
|
365
|
-
const empty = project(new arrow.Table(inputSchema));
|
|
366
|
-
const comparisonSchema = convertSchemaToArrow(convertArrowToSchema(empty.schema));
|
|
367
|
-
const pushedPlan =
|
|
368
|
-
!inMemory &&
|
|
369
|
-
!options.functions?.length &&
|
|
370
|
-
!('command' in parsedQuery) &&
|
|
371
|
-
(source as TableScanSource).planQueryPushdown
|
|
372
|
-
? await (await import('./query-pushdown')).planQueryPushdown(
|
|
373
|
-
source as TableScanSource,
|
|
374
|
-
logicalQuery,
|
|
375
|
-
capabilities,
|
|
376
|
-
comparisonSchema,
|
|
377
|
-
Boolean(computedProjection || expressionFilter),
|
|
378
|
-
inputSchema,
|
|
379
|
-
options.signal
|
|
380
|
-
)
|
|
381
|
-
: null;
|
|
382
|
-
options.signal?.throwIfAborted();
|
|
383
|
-
let emitted = false;
|
|
384
|
-
/** Adapts physical batches without pulling ahead of the query consumer. */
|
|
385
|
-
async function* inputs(): AsyncIterable<arrow.Table> {
|
|
386
|
-
sourcesRead = 1;
|
|
387
|
-
const batches: AsyncIterable<unknown> = pushedPlan
|
|
388
|
-
? pushedPlan.read({signal: options.signal})
|
|
389
|
-
: inMemory
|
|
390
|
-
? memoryBatches(inMemory)
|
|
391
|
-
: (source as TableScanSource).read(readOptions);
|
|
392
|
-
for await (const value of batches) {
|
|
393
|
-
options.signal?.throwIfAborted();
|
|
394
|
-
let batch = normalizeBatch(value, pushedPlan?.schema ?? readSchema);
|
|
395
|
-
if (
|
|
396
|
-
!pushedPlan &&
|
|
397
|
-
comparisonInputSchema &&
|
|
398
|
-
!arrow.util.compareSchemas(
|
|
399
|
-
comparisonInputSchema,
|
|
400
|
-
convertSchemaToArrow(convertArrowToSchema(batch.schema))
|
|
401
|
-
)
|
|
402
|
-
) {
|
|
403
|
-
// A source may return a wider or differently ordered projection than requested.
|
|
404
|
-
batch = batch.select(inputSchema.names);
|
|
405
|
-
if (
|
|
406
|
-
!arrow.util.compareSchemas(
|
|
407
|
-
comparisonInputSchema,
|
|
408
|
-
convertSchemaToArrow(convertArrowToSchema(batch.schema))
|
|
409
|
-
)
|
|
410
|
-
)
|
|
411
|
-
throw new Error('Query input schema does not match source metadata.');
|
|
412
|
-
}
|
|
413
|
-
batchesRead++;
|
|
414
|
-
rowsRead += batch.numRows;
|
|
415
|
-
yield batch;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
for await (const value of executeTableScanBatches<arrow.Table>(
|
|
419
|
-
() => inputs(),
|
|
420
|
-
{
|
|
421
|
-
predicate: pushedPlan ? undefined : residual,
|
|
422
|
-
offset: pushedPlan || delegateOffset ? undefined : normalized.offset,
|
|
423
|
-
limit: normalized.limit,
|
|
424
|
-
skipEmptyBatches: true,
|
|
425
|
-
signal: options.signal
|
|
426
|
-
},
|
|
427
|
-
{
|
|
428
|
-
filter: (batch, predicate, signal) => {
|
|
429
|
-
if (pushedPlan) return batch;
|
|
430
|
-
if (compiledFilter) {
|
|
431
|
-
return filterArrowRows(
|
|
432
|
-
batch,
|
|
433
|
-
recordBatch => {
|
|
434
|
-
const matches = compiledFilter.evaluate(recordBatch, {signal});
|
|
435
|
-
return index => matches.get(index) === true;
|
|
436
|
-
},
|
|
437
|
-
{signal}
|
|
438
|
-
);
|
|
439
|
-
}
|
|
440
|
-
return predicate ? filterArrowTable(batch, predicate, {signal}) : batch;
|
|
441
|
-
},
|
|
442
|
-
project: batch => (pushedPlan || computedProjection ? batch : project(batch))
|
|
443
|
-
}
|
|
444
|
-
)) {
|
|
445
|
-
const finishProjection = pushedPlan
|
|
446
|
-
? pushedPlan.project
|
|
447
|
-
: computedProjection
|
|
448
|
-
? project
|
|
449
|
-
: undefined;
|
|
450
|
-
const batch = finishProjection ? finishProjection(value) : value;
|
|
451
|
-
if (
|
|
452
|
-
!arrow.util.compareSchemas(
|
|
453
|
-
comparisonSchema,
|
|
454
|
-
convertSchemaToArrow(convertArrowToSchema(batch.schema))
|
|
455
|
-
)
|
|
456
|
-
)
|
|
457
|
-
throw new Error('Query output schema does not match source metadata.');
|
|
458
|
-
emitted = true;
|
|
459
|
-
rowsReturned += batch.numRows;
|
|
460
|
-
yield batch;
|
|
461
|
-
}
|
|
462
|
-
// An empty schema-bearing batch makes collected and streaming empty results identical.
|
|
463
|
-
if (!emitted) yield empty;
|
|
464
|
-
if (normalized.limit !== undefined && rowsReturned >= normalized.limit)
|
|
465
|
-
earlyTerminationReason = 'limit';
|
|
466
|
-
status = earlyTerminationReason ? 'early-terminated' : 'completed';
|
|
467
|
-
} catch (failure) {
|
|
468
|
-
error = failure;
|
|
469
|
-
status = options.signal?.aborted ? 'cancelled' : 'failed';
|
|
470
|
-
throw failure;
|
|
471
|
-
} finally {
|
|
472
|
-
if (status === 'early-terminated' && !earlyTerminationReason)
|
|
473
|
-
earlyTerminationReason = 'consumer-return';
|
|
474
|
-
try {
|
|
475
|
-
await ownedSource?.close?.();
|
|
476
|
-
} catch (failure) {
|
|
477
|
-
if (error === undefined) {
|
|
478
|
-
error = failure;
|
|
479
|
-
status = options.signal?.aborted ? 'cancelled' : 'failed';
|
|
480
|
-
earlyTerminationReason = undefined;
|
|
481
|
-
throw failure;
|
|
482
|
-
}
|
|
483
|
-
} finally {
|
|
484
|
-
emitQueryComplete(
|
|
485
|
-
options.onQueryComplete,
|
|
486
|
-
Object.freeze({
|
|
487
|
-
status,
|
|
488
|
-
sourcesPlanned: 1,
|
|
489
|
-
sourcesRead,
|
|
490
|
-
batchesRead,
|
|
491
|
-
rowsRead,
|
|
492
|
-
rowsReturned,
|
|
493
|
-
durationMilliseconds: Date.now() - startedAt,
|
|
494
|
-
...(earlyTerminationReason ? {earlyTerminationReason} : {}),
|
|
495
|
-
...(error === undefined ? {} : {error})
|
|
496
|
-
})
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
340
|
}
|
|
500
341
|
}
|
|
501
342
|
|
|
@@ -511,28 +352,6 @@ async function normalizeTypedQuery(query: Query): Promise<SQLQuery | TableQuery>
|
|
|
511
352
|
return (await import('./arrow-execution/expressions')).normalizeTypedProjection(query);
|
|
512
353
|
}
|
|
513
354
|
|
|
514
|
-
/** Emits original Arrow RecordBatches without copying their buffers. */
|
|
515
|
-
async function* memoryBatches(data: arrow.Table): AsyncIterable<arrow.Table> {
|
|
516
|
-
for (const batch of data.batches) yield new arrow.Table(data.schema, [batch]);
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
/** Converts supported native table batches to Arrow while preserving their declared schema. */
|
|
520
|
-
function normalizeBatch(value: unknown, fallbackSchema: Schema): arrow.Table {
|
|
521
|
-
if (!value || typeof value !== 'object') throw new Error('Unsupported query batch.');
|
|
522
|
-
if ('numRows' in value) {
|
|
523
|
-
const batch = value as arrow.RecordBatch;
|
|
524
|
-
return new arrow.Table(batch.schema, [batch]);
|
|
525
|
-
}
|
|
526
|
-
if (!('shape' in value)) throw new Error('Unsupported query batch.');
|
|
527
|
-
const input = value as TableBatch;
|
|
528
|
-
const batch = {...input, schema: input.schema ?? fallbackSchema} as TableBatch;
|
|
529
|
-
if (!['object-row-table', 'array-row-table', 'columnar-table'].includes(batch.shape))
|
|
530
|
-
throw new Error(`Unsupported query batch shape: ${batch.shape}`);
|
|
531
|
-
return batch.length === 0 && batch.schema
|
|
532
|
-
? new arrow.Table(convertSchemaToArrow(batch.schema))
|
|
533
|
-
: convertTableToArrow(batch);
|
|
534
|
-
}
|
|
535
|
-
|
|
536
355
|
/** Checks predicate tree bounds and detects casts that require Arrow execution. */
|
|
537
356
|
function validatePredicateOperands(where: unknown): boolean {
|
|
538
357
|
if (where && typeof where === 'object' && 'expression' in where) {
|
package/src/scan/scan-engine.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {Table} from 'apache-arrow';
|
|
6
|
-
import {explainArrowTableQuery,
|
|
6
|
+
import {explainArrowTableQuery, type ArrowQueryOptions} from './plan-arrow-table-query';
|
|
7
7
|
import {type SQLPredicate} from './sql-predicate-types';
|
|
8
8
|
import type {TableQueryExplain} from '@loaders.gl/core/loader-utils';
|
|
9
9
|
|
|
@@ -39,18 +39,11 @@ export type ScanEngine = ScanBackend & {
|
|
|
39
39
|
|
|
40
40
|
const scanBackends = new Map<ScanBackendName, ScanBackend | ScanBackendLoader>();
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
query: queryArrowTable,
|
|
45
|
-
queryAsync: (sourceTable, options) =>
|
|
46
|
-
Promise.resolve().then(() => queryArrowTable(sourceTable, options)),
|
|
47
|
-
explain: explainArrowTableQuery
|
|
42
|
+
scanBackends.set('arrow', async () => {
|
|
43
|
+
const {queryArrowTable} = await import('./query-arrow-table');
|
|
44
|
+
return {name: 'arrow', query: queryArrowTable, explain: explainArrowTableQuery};
|
|
48
45
|
});
|
|
49
46
|
|
|
50
|
-
// Store the built-in backend directly. Apart from avoiding needless indirection, this keeps
|
|
51
|
-
// coverage stable when browser shards transform this shared module independently.
|
|
52
|
-
scanBackends.set('arrow', arrowScanBackend);
|
|
53
|
-
|
|
54
47
|
/**
|
|
55
48
|
* Registers a lazy scan backend without adding it to the default bundle.
|
|
56
49
|
*
|
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
} from '@loaders.gl/core/loader-utils';
|
|
19
19
|
import {createScanQueryMetadata} from '@loaders.gl/core/loader-utils';
|
|
20
20
|
import {ARROW_TABLE_QUERY_CAPABILITIES} from './table-query-capabilities';
|
|
21
|
-
import {explainArrowTableQuery,
|
|
21
|
+
import {explainArrowTableQuery, type ArrowQueryOptions} from './plan-arrow-table-query';
|
|
22
22
|
import {type SQLPredicate} from './sql-predicate-types';
|
|
23
23
|
|
|
24
24
|
/** Shared display and provenance options for an addressed vector-table scan. */
|
|
@@ -106,6 +106,7 @@ export abstract class AddressedVectorTableScanSource {
|
|
|
106
106
|
/** Applies the portable Arrow query to the addressed feature table. */
|
|
107
107
|
async query(options: ArrowQueryOptions = {}): Promise<Table> {
|
|
108
108
|
const table = await this.getTable(options.signal);
|
|
109
|
+
const {queryArrowTable} = await import('./query-arrow-table');
|
|
109
110
|
return queryArrowTable(table, options);
|
|
110
111
|
}
|
|
111
112
|
|
|
@@ -172,3 +172,17 @@ export {
|
|
|
172
172
|
export {refineArrowTableBatches} from './lib/arrow/arrow-metadata';
|
|
173
173
|
|
|
174
174
|
export {isArrowRecordBatch, isArrowTable} from '../lib/loader-utils/native-arrow';
|
|
175
|
+
|
|
176
|
+
export {
|
|
177
|
+
ARROW_CONVERTERS,
|
|
178
|
+
ArrowConverter,
|
|
179
|
+
convertArrow,
|
|
180
|
+
type ArrowConvertFromOptions,
|
|
181
|
+
type ArrowConvertToOptions
|
|
182
|
+
} from './lib/arrow/arrow-converter';
|
|
183
|
+
export {tightenArrowTableSchemaNullability} from './lib/arrow/tighten-arrow-table-schema-nullability';
|
|
184
|
+
export {
|
|
185
|
+
convertArrowTableVariableWidthTypes,
|
|
186
|
+
convertArrowVariableWidthVector,
|
|
187
|
+
type ConvertArrowVariableWidthOptions
|
|
188
|
+
} from './lib/arrow/convert-arrow-variable-width';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {Converter} from '../converters/types';
|
|
6
|
+
import {convertArrow, isApacheArrowTable} from './convert-arrow';
|
|
7
|
+
|
|
8
|
+
const convertArrowUnchecked = convertArrow as (
|
|
9
|
+
input: unknown,
|
|
10
|
+
targetShape:
|
|
11
|
+
| 'arrow'
|
|
12
|
+
| 'object-row-table'
|
|
13
|
+
| 'array-row-table'
|
|
14
|
+
| 'columnar-table'
|
|
15
|
+
| 'geojson-table',
|
|
16
|
+
options?: unknown
|
|
17
|
+
) => unknown;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Options shared by conversions from Apache Arrow tables to loaders.gl table shapes.
|
|
21
|
+
*/
|
|
22
|
+
export type ArrowConvertToOptions = {
|
|
23
|
+
batchSize?: number;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Options shared by conversions from loaders.gl tables to Apache Arrow tables.
|
|
28
|
+
*/
|
|
29
|
+
export type ArrowConvertFromOptions = {
|
|
30
|
+
batchSize?: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Leaf converter for Apache Arrow table interop.
|
|
35
|
+
*/
|
|
36
|
+
export const ArrowConverter: Converter<
|
|
37
|
+
'arrow' | 'object-row-table' | 'array-row-table' | 'columnar-table' | 'geojson-table',
|
|
38
|
+
ArrowConvertFromOptions | ArrowConvertToOptions
|
|
39
|
+
> = {
|
|
40
|
+
id: 'arrow',
|
|
41
|
+
from: ['arrow', 'object-row-table', 'array-row-table', 'columnar-table', 'geojson-table'],
|
|
42
|
+
to: ['arrow', 'object-row-table', 'array-row-table', 'columnar-table', 'geojson-table'],
|
|
43
|
+
canConvert(sourceShape, targetShape) {
|
|
44
|
+
const sourceIsArrow = sourceShape === 'arrow';
|
|
45
|
+
const targetIsArrow = targetShape === 'arrow';
|
|
46
|
+
return sourceIsArrow !== targetIsArrow;
|
|
47
|
+
},
|
|
48
|
+
detectInputShape(input) {
|
|
49
|
+
return isApacheArrowTable(input as any) ? 'arrow' : null;
|
|
50
|
+
},
|
|
51
|
+
convert(input, targetShape, options) {
|
|
52
|
+
switch (targetShape) {
|
|
53
|
+
case 'arrow':
|
|
54
|
+
return convertArrowUnchecked(input, 'arrow', options);
|
|
55
|
+
case 'object-row-table':
|
|
56
|
+
return convertArrowUnchecked(input, 'object-row-table', options);
|
|
57
|
+
case 'array-row-table':
|
|
58
|
+
return convertArrowUnchecked(input, 'array-row-table', options);
|
|
59
|
+
case 'columnar-table':
|
|
60
|
+
return convertArrowUnchecked(input, 'columnar-table', options);
|
|
61
|
+
case 'geojson-table':
|
|
62
|
+
return convertArrowUnchecked(input, 'geojson-table', options);
|
|
63
|
+
default:
|
|
64
|
+
throw new Error(`Unsupported Arrow conversion target: ${targetShape}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} as const;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Opt-in converter bundle for Apache Arrow conversions.
|
|
71
|
+
*/
|
|
72
|
+
export const ARROW_CONVERTERS = [ArrowConverter] as const;
|
|
73
|
+
|
|
74
|
+
export {convertArrow};
|
|
@@ -3,57 +3,9 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import * as arrow from 'apache-arrow';
|
|
6
|
-
import
|
|
7
|
-
import {serializeArrowSchema, deserializeArrowSchema} from '../schema/convert-arrow-schema';
|
|
6
|
+
import {mergeArrowSchemas, snapshotArrowSchema} from '@math.gl/core/arrow';
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
export function snapshotArrowSchema(schema: arrow.Schema): arrow.Schema {
|
|
11
|
-
return deserializeArrowSchema(serializeArrowSchema(schema));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** Merges compatible schema snapshots, with later metadata values taking precedence. */
|
|
15
|
-
export function mergeArrowSchemas(
|
|
16
|
-
previous: arrow.Schema | undefined,
|
|
17
|
-
next: arrow.Schema
|
|
18
|
-
): arrow.Schema {
|
|
19
|
-
if (!previous) return snapshotArrowSchema(next);
|
|
20
|
-
// Arrow validates names, order, nullability and types, but intentionally ignores metadata.
|
|
21
|
-
new arrow.Table(previous, [new arrow.RecordBatch(next, undefined)]);
|
|
22
|
-
const earlier = serializeArrowSchema(previous);
|
|
23
|
-
const later = serializeArrowSchema(next);
|
|
24
|
-
return deserializeArrowSchema({
|
|
25
|
-
...later,
|
|
26
|
-
fields: later.fields.map((field, index) => mergeFieldMetadata(earlier.fields[index], field)),
|
|
27
|
-
metadata: {...earlier.metadata, ...later.metadata}
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Merges metadata recursively without changing a field's structural definition. */
|
|
32
|
-
function mergeFieldMetadata(previous: Field, next: Field): Field {
|
|
33
|
-
return {
|
|
34
|
-
...next,
|
|
35
|
-
type: mergeTypeMetadata(previous.type, next.type),
|
|
36
|
-
metadata: {...previous.metadata, ...next.metadata}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Preserves nested field metadata, including fields inside dictionary values. */
|
|
41
|
-
function mergeTypeMetadata(previous: DataType, next: DataType): DataType {
|
|
42
|
-
if (typeof previous !== 'object' || typeof next !== 'object') return next;
|
|
43
|
-
if ('children' in previous && 'children' in next) {
|
|
44
|
-
const previousChildren = previous.children;
|
|
45
|
-
return {
|
|
46
|
-
...next,
|
|
47
|
-
children: next.children.map((field, index) =>
|
|
48
|
-
mergeFieldMetadata(previousChildren[index], field)
|
|
49
|
-
)
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
if (previous.type === 'dictionary' && next.type === 'dictionary') {
|
|
53
|
-
return {...next, dictionary: mergeTypeMetadata(previous.dictionary, next.dictionary)};
|
|
54
|
-
}
|
|
55
|
-
return next;
|
|
56
|
-
}
|
|
8
|
+
export {mergeArrowSchemas, snapshotArrowSchema};
|
|
57
9
|
|
|
58
10
|
/** Snapshots a batch's schema and metadata while retaining its data buffers and row count. */
|
|
59
11
|
function snapshotArrowBatch(batch: arrow.RecordBatch, schema: arrow.Schema): arrow.RecordBatch {
|