@loaders.gl/core 5.0.0-rc.1 → 5.0.0
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/SCAN-README.md +8 -8
- package/dist/arrow-geometry/binary-features.cjs +2 -2
- package/dist/arrow-geometry/binary-features.cjs.map +2 -2
- package/dist/arrow-geometry/binary-features.js +1 -1
- package/dist/arrow-geometry/binary-features.js.map +1 -1
- 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/legacy-binary/convert-flat-geojson-to-binary-features.cjs +2 -2
- package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.cjs.map +2 -2
- package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.js +1 -1
- package/dist/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.js.map +1 -1
- package/dist/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.cjs +2 -2
- package/dist/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.cjs.map +2 -2
- package/dist/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.js +1 -1
- package/dist/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.js.map +1 -1
- 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/cluster-source.cjs +128 -374
- package/dist/cluster-source.cjs.map +3 -3
- 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 +63 -15
- package/dist/dist.min.js +3 -3
- package/dist/federated-table-scan-source.cjs +174 -660
- package/dist/federated-table-scan-source.cjs.map +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/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/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.cjs +2 -2
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.cjs.map +2 -2
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.js +1 -1
- package/dist/geoarrow/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.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 +20 -226
- package/dist/geoarrow/lib/kernels/decode-wkt-native.cjs.map +2 -2
- package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts +1 -2
- package/dist/geoarrow/lib/kernels/decode-wkt-native.d.ts.map +1 -1
- package/dist/geoarrow/lib/kernels/decode-wkt-native.js +23 -264
- package/dist/geoarrow/lib/kernels/decode-wkt-native.js.map +1 -1
- package/dist/index.cjs +67 -19
- package/dist/index.cjs.map +1 -1
- package/dist/lib/api/load.js +36 -7
- package/dist/lib/api/load.js.map +1 -1
- package/dist/lib/api/parse.js +5 -2
- package/dist/lib/api/parse.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 +67 -229
- package/dist/loader-utils/index.cjs.map +2 -2
- package/dist/loader-utils/json-loader.js +1 -1
- 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/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/sources/tile-grid.d.ts +1 -1
- package/dist/loader-utils/lib/sources/tile-grid.d.ts.map +1 -1
- package/dist/loader-utils/lib/sources/tile-grid.js +1 -1
- package/dist/loader-utils/lib/sources/tile-grid.js.map +1 -1
- package/dist/loader-utils/lib/sources/tile-source-adapter.js +1 -1
- package/dist/loader-utils/lib/sources/tile-source-adapter.js.map +1 -1
- package/dist/loader-utils/lib/sources/tile-source.d.ts +1 -1
- package/dist/loader-utils/lib/sources/tile-source.d.ts.map +1 -1
- package/dist/loader-utils/loader-types.d.ts +6 -0
- package/dist/loader-utils/loader-types.d.ts.map +1 -1
- package/dist/loader-utils/loader-types.js.map +1 -1
- package/dist/loader-utils/tile-grid.cjs +5 -5
- package/dist/loader-utils/tile-grid.cjs.map +1 -1
- package/dist/null-loader.js +1 -1
- package/dist/null-loader.js.map +1 -1
- package/dist/null-worker-node.js +1 -1
- package/dist/null-worker.js +1 -1
- 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 +2 -8
- 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 +9 -49
- package/dist/scan/index.cjs.map +3 -3
- package/dist/scan/index.d.ts +2 -2
- package/dist/scan/index.d.ts.map +1 -1
- package/dist/scan/index.js +2 -2
- 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 +2 -39
- 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 +3 -26
- 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-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-scales.cjs +2 -1
- package/dist/scan/query-scales.cjs.map +2 -2
- package/dist/scan/query-scales.d.ts +2 -1
- package/dist/scan/query-scales.d.ts.map +1 -1
- package/dist/scan/query-scales.js +2 -1
- package/dist/scan/query-scales.js.map +1 -1
- package/dist/scan/query.cjs +10 -9
- package/dist/scan/query.cjs.map +2 -2
- package/dist/scan/query.d.ts.map +1 -1
- package/dist/scan/query.js +14 -5
- 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 +2 -2
- package/dist/scan/scan-engine.d.ts.map +1 -1
- package/dist/scan/scan-engine.js +5 -10
- package/dist/scan/scan-engine.js.map +1 -1
- package/dist/scan/sql-predicate-schema.cjs +10 -94
- package/dist/scan/sql-predicate-schema.cjs.map +3 -3
- package/dist/scan/sql-predicate-schema.d.ts +1 -1
- package/dist/scan/sql-predicate-schema.d.ts.map +1 -1
- package/dist/scan/sql-predicate-schema.js +9 -103
- package/dist/scan/sql-predicate-schema.js.map +1 -1
- package/dist/scan/sql-predicate-zod.cjs.map +1 -1
- package/dist/scan/sql-predicate-zod.d.ts +1 -1
- package/dist/scan/sql-predicate-zod.js +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 +11 -47
- package/dist/schema-utils/index.cjs.map +1 -1
- 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/vector-table-scan-source.cjs +905 -1453
- package/dist/vector-table-scan-source.cjs.map +3 -3
- 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 +33 -9
- 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/dist/worker-utils/lib/worker-api/process-on-worker.d.ts +4 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.d.ts.map +1 -1
- package/dist/worker-utils/lib/worker-api/process-on-worker.js +40 -6
- package/dist/worker-utils/lib/worker-api/process-on-worker.js.map +1 -1
- package/package.json +24 -104
- package/src/arrow-geometry/binary-features.ts +1 -1
- package/src/arrow-geometry/geometry-codecs.ts +35 -78
- package/src/arrow-geometry/legacy-binary/convert-flat-geojson-to-binary-features.ts +1 -1
- package/src/arrow-geometry/legacy-binary/convert-geojson-to-flat-geojson.ts +1 -1
- 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/lib/feature-collection-converters/convert-geometry-column-to-binary-feature-collection.ts +1 -1
- package/src/geoarrow/lib/geometry-converters/wkb/helpers/parse-wkb-header.ts +6 -30
- package/src/geoarrow/lib/kernels/decode-wkt-native.ts +23 -269
- package/src/lib/api/load.ts +36 -7
- package/src/lib/api/parse.ts +6 -2
- 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/tile-grid.ts +6 -2
- package/src/loader-utils/lib/sources/tile-source-adapter.ts +1 -1
- package/src/loader-utils/lib/sources/tile-source.ts +1 -1
- package/src/loader-utils/loader-types.ts +6 -0
- 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 +2 -2
- package/src/scan/plan-arrow-table-query.ts +367 -0
- package/src/scan/query-arrow-table-in-batches.ts +4 -33
- package/src/scan/query-arrow-table.ts +10 -626
- package/src/scan/query-pushdown.ts +3 -4
- package/src/scan/query-scales.ts +3 -4
- package/src/scan/query.ts +16 -10
- package/src/scan/scan-engine.ts +5 -12
- package/src/scan/sql-predicate-schema.ts +14 -125
- package/src/scan/sql-predicate-zod.ts +1 -1
- package/src/scan/vector-table-scan-source.ts +2 -1
- package/src/schema-utils/lib/arrow/arrow-metadata.ts +2 -50
- package/src/wkt/twkb/index.ts +63 -2
- package/src/worker-utils/lib/worker-api/process-on-worker.ts +39 -6
- 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/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/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/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
|
@@ -37,55 +37,11 @@ __export(federated_table_scan_source_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(federated_table_scan_source_exports);
|
|
38
38
|
|
|
39
39
|
// dist/scan/federated-table-scan-source.js
|
|
40
|
-
var
|
|
40
|
+
var arrow5 = __toESM(require("apache-arrow"), 1);
|
|
41
41
|
|
|
42
42
|
// src/loader-utils/lib/scan-utils/columnar-predicate.ts
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
function getColumnarPredicatePath(property) {
|
|
47
|
-
return typeof property.property === "string" ? [property.property] : [...property.property];
|
|
48
|
-
}
|
|
49
|
-
function getColumnarPredicatePaths(predicate) {
|
|
50
|
-
const paths = /* @__PURE__ */ new Map();
|
|
51
|
-
visitColumnarPredicate(predicate, (child) => {
|
|
52
|
-
if ("property" in child.args[0]) {
|
|
53
|
-
const path = getColumnarPredicatePath(child.args[0]);
|
|
54
|
-
paths.set(path.join("\0"), path);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
return [...paths.values()];
|
|
58
|
-
}
|
|
59
|
-
function validateColumnarPredicate(predicate, availableColumns) {
|
|
60
|
-
visitColumnarPredicate(predicate, (child) => {
|
|
61
|
-
if (child.op === "and" || child.op === "or") {
|
|
62
|
-
if (child.args.length < 2)
|
|
63
|
-
throw new Error(`Columnar predicate ${child.op} requires at least two child predicates`);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (child.op === "not") return;
|
|
67
|
-
const leaf = child;
|
|
68
|
-
const path = getColumnarPredicatePath(leaf.args[0]);
|
|
69
|
-
if (!path.length || path.some((component) => !component)) {
|
|
70
|
-
throw new Error("Columnar predicate property path must contain non-empty strings");
|
|
71
|
-
}
|
|
72
|
-
if (!availableColumns.has(path[0]))
|
|
73
|
-
throw new Error(`Columnar predicate column not found: ${path.join(".")}`);
|
|
74
|
-
if (leaf.op === "in" && leaf.args[1].length === 0) {
|
|
75
|
-
throw new Error("Columnar predicate in requires at least one value");
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
function isColumnarPredicateParameter(value) {
|
|
80
|
-
const parameterValue = value;
|
|
81
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 1 && Object.hasOwn(value, "parameter") && typeof parameterValue.parameter === "string" && parameterValue.parameter.length > 0;
|
|
82
|
-
}
|
|
83
|
-
function visitColumnarPredicate(predicate, visitor) {
|
|
84
|
-
visitor(predicate);
|
|
85
|
-
if (predicate.op === "and" || predicate.op === "or")
|
|
86
|
-
predicate.args.forEach((child) => visitColumnarPredicate(child, visitor));
|
|
87
|
-
else if (predicate.op === "not") visitColumnarPredicate(predicate.args[0], visitor);
|
|
88
|
-
}
|
|
43
|
+
var import_columnar_predicate = require("@math.gl/sql/columnar-predicate");
|
|
44
|
+
var import_columnar_predicate2 = require("@math.gl/sql/columnar-predicate");
|
|
89
45
|
|
|
90
46
|
// src/loader-utils/lib/scan-utils/scan-query-metadata.ts
|
|
91
47
|
var import_crs = require("@math.gl/geospatial/crs");
|
|
@@ -179,7 +135,7 @@ function getNonEmptyMetadataValue(metadata, key) {
|
|
|
179
135
|
function planTableQuery(sourceColumnNames, options = {}) {
|
|
180
136
|
validateTableQueryOptions(sourceColumnNames, options);
|
|
181
137
|
const outputColumnNames = options.columns ? [...options.columns] : [...sourceColumnNames];
|
|
182
|
-
const predicateColumnNames = options.predicate ? getColumnarPredicateColumns(options.predicate) : [];
|
|
138
|
+
const predicateColumnNames = options.predicate ? (0, import_columnar_predicate2.getColumnarPredicateColumns)(options.predicate) : [];
|
|
183
139
|
const requiredColumnNames = /* @__PURE__ */ new Set([...outputColumnNames, ...predicateColumnNames]);
|
|
184
140
|
const scanColumnNames = sourceColumnNames.filter(
|
|
185
141
|
(columnName) => requiredColumnNames.has(columnName)
|
|
@@ -211,7 +167,7 @@ function validateTableQueryOptions(sourceColumnNames, options) {
|
|
|
211
167
|
}
|
|
212
168
|
validateTableQueryLimit(options.limit);
|
|
213
169
|
if (options.predicate) {
|
|
214
|
-
validateColumnarPredicate(options.predicate, availableColumnNames);
|
|
170
|
+
(0, import_columnar_predicate2.validateColumnarPredicate)(options.predicate, availableColumnNames);
|
|
215
171
|
}
|
|
216
172
|
}
|
|
217
173
|
function validateTableQueryLimit(limit) {
|
|
@@ -314,7 +270,7 @@ function validateRelationalColumnReference(columnName, availableColumns) {
|
|
|
314
270
|
function explainTableQuery(sourceColumnNames, options, capabilities) {
|
|
315
271
|
const plan = planTableQuery(sourceColumnNames, options);
|
|
316
272
|
const outputColumns = options.columns ? [...options.columns] : [...sourceColumnNames];
|
|
317
|
-
const predicateColumns = options.predicate ? getColumnarPredicateColumns(options.predicate) : [];
|
|
273
|
+
const predicateColumns = options.predicate ? (0, import_columnar_predicate2.getColumnarPredicateColumns)(options.predicate) : [];
|
|
318
274
|
const requiredColumns = [...plan[0].kind === "scan" ? plan[0].columns : []];
|
|
319
275
|
return Object.freeze({
|
|
320
276
|
sourceColumns: Object.freeze([...sourceColumnNames]),
|
|
@@ -1033,47 +989,53 @@ var convertTableToArrow2 = ((...args) => convertTableToArrow(
|
|
|
1033
989
|
...args
|
|
1034
990
|
));
|
|
1035
991
|
|
|
1036
|
-
// dist/scan/
|
|
1037
|
-
var
|
|
1038
|
-
|
|
1039
|
-
// dist/scan/arrow-execution/project-arrow-table.js
|
|
1040
|
-
var arrow4 = __toESM(require("apache-arrow"), 1);
|
|
1041
|
-
function projectArrowTable(source, selections) {
|
|
1042
|
-
const outputNames = /* @__PURE__ */ new Set();
|
|
1043
|
-
const indices = [];
|
|
1044
|
-
const fields = selections.map((selection) => {
|
|
1045
|
-
const column = typeof selection === "string" ? selection : selection.column;
|
|
1046
|
-
const name = typeof selection === "string" ? selection : selection.as === void 0 ? column : selection.as;
|
|
1047
|
-
const index = source.schema.fields.findIndex((field) => field.name === column);
|
|
1048
|
-
if (index < 0)
|
|
1049
|
-
throw new Error(`Arrow projection column not found: ${column}`);
|
|
1050
|
-
if (typeof name !== "string" || typeof selection !== "string" && selection.as !== void 0 && !name.length || outputNames.has(name)) {
|
|
1051
|
-
throw new Error(`Invalid or duplicate Arrow projection output name: ${name}`);
|
|
1052
|
-
}
|
|
1053
|
-
outputNames.add(name);
|
|
1054
|
-
indices.push(index);
|
|
1055
|
-
return source.schema.fields[index].clone({ name });
|
|
1056
|
-
});
|
|
1057
|
-
const schema = new arrow4.Schema(fields, source.schema.metadata);
|
|
1058
|
-
const batches = source.batches.map((batch) => new arrow4.RecordBatch(schema, arrow4.makeData({
|
|
1059
|
-
type: new arrow4.Struct(fields),
|
|
1060
|
-
length: batch.numRows,
|
|
1061
|
-
children: indices.map((index) => batch.data.children[index])
|
|
1062
|
-
}), batch.metadata));
|
|
1063
|
-
return new arrow4.Table(schema, batches);
|
|
1064
|
-
}
|
|
992
|
+
// dist/scan/arrow-execution.js
|
|
993
|
+
var import_arrow2 = require("@math.gl/core/arrow");
|
|
1065
994
|
|
|
1066
995
|
// dist/scan/arrow-execution/filter-arrow-table.js
|
|
1067
|
-
var
|
|
996
|
+
var arrow4 = __toESM(require("apache-arrow"), 1);
|
|
1068
997
|
var import_arrow = require("@math.gl/core/arrow");
|
|
998
|
+
var import_columnar_predicate6 = require("@math.gl/sql/columnar-predicate");
|
|
1069
999
|
function filterArrowTable(source, predicate, options = {}) {
|
|
1070
|
-
validateColumnarPredicate(predicate, new Set(source.schema.fields.map((field) => field.name)));
|
|
1071
|
-
const
|
|
1000
|
+
(0, import_columnar_predicate2.validateColumnarPredicate)(predicate, new Set(source.schema.fields.map((field) => field.name)));
|
|
1001
|
+
const boundPredicate = normalizeArrowDatePredicate(predicate);
|
|
1072
1002
|
return filterArrowRows(source, (batch) => {
|
|
1073
|
-
const
|
|
1074
|
-
return (rowIndex) =>
|
|
1003
|
+
const evaluate = (0, import_columnar_predicate6.compileColumnarPredicate)(boundPredicate, (path) => bindPredicateColumn(batch, path));
|
|
1004
|
+
return (rowIndex) => evaluate(rowIndex) === true;
|
|
1075
1005
|
}, options);
|
|
1076
1006
|
}
|
|
1007
|
+
function bindPredicateColumn(batch, [name, ...properties]) {
|
|
1008
|
+
const column = batch.getChild(name);
|
|
1009
|
+
if (!column)
|
|
1010
|
+
throw new Error(`Arrow query column not found: ${name}`);
|
|
1011
|
+
return (rowIndex) => {
|
|
1012
|
+
let value = column.get(rowIndex);
|
|
1013
|
+
for (const property of properties) {
|
|
1014
|
+
if (value == null)
|
|
1015
|
+
return null;
|
|
1016
|
+
value = value[property];
|
|
1017
|
+
}
|
|
1018
|
+
return dateToMilliseconds(value);
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
function normalizeArrowDatePredicate(predicate) {
|
|
1022
|
+
switch (predicate.op) {
|
|
1023
|
+
case "and":
|
|
1024
|
+
case "or":
|
|
1025
|
+
return { ...predicate, args: predicate.args.map(normalizeArrowDatePredicate) };
|
|
1026
|
+
case "not":
|
|
1027
|
+
return { ...predicate, args: [normalizeArrowDatePredicate(predicate.args[0])] };
|
|
1028
|
+
case "isNull":
|
|
1029
|
+
return predicate;
|
|
1030
|
+
case "in":
|
|
1031
|
+
return { ...predicate, args: [predicate.args[0], predicate.args[1].map(dateToMilliseconds)] };
|
|
1032
|
+
default:
|
|
1033
|
+
return { ...predicate, args: [predicate.args[0], dateToMilliseconds(predicate.args[1])] };
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
function dateToMilliseconds(value) {
|
|
1037
|
+
return value instanceof Date ? value.getTime() : value;
|
|
1038
|
+
}
|
|
1077
1039
|
function filterArrowRows(source, selectBatch, options = {}) {
|
|
1078
1040
|
var _a, _b, _c;
|
|
1079
1041
|
let remaining = options.limit ?? Infinity;
|
|
@@ -1086,7 +1048,6 @@ function filterArrowRows(source, selectBatch, options = {}) {
|
|
|
1086
1048
|
if (remaining === 0)
|
|
1087
1049
|
break;
|
|
1088
1050
|
(_b = options.signal) == null ? void 0 : _b.throwIfAborted();
|
|
1089
|
-
const data = new arrow5.Table(source.schema, [batch]);
|
|
1090
1051
|
const selectRow = selectBatch(batch);
|
|
1091
1052
|
const indices = [];
|
|
1092
1053
|
for (let rowIndex = 0; rowIndex < batch.numRows && indices.length < remaining; rowIndex++) {
|
|
@@ -1095,283 +1056,25 @@ function filterArrowRows(source, selectBatch, options = {}) {
|
|
|
1095
1056
|
indices.push(rowIndex);
|
|
1096
1057
|
}
|
|
1097
1058
|
remaining -= indices.length;
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
batches.push(batch);
|
|
1102
|
-
continue;
|
|
1103
|
-
}
|
|
1104
|
-
if (indices[indices.length - 1] - indices[0] + 1 === indices.length) {
|
|
1105
|
-
batches.push(batch.slice(indices[0], indices[indices.length - 1] + 1));
|
|
1106
|
-
continue;
|
|
1107
|
-
}
|
|
1108
|
-
const gathered = (0, import_arrow.takeArrowTableRows)(data, Int32Array.from(indices));
|
|
1109
|
-
batches.push(...gathered.batches);
|
|
1110
|
-
}
|
|
1111
|
-
return new arrow5.Table(source.schema, batches);
|
|
1112
|
-
}
|
|
1113
|
-
function getPredicateColumns(sourceTable, columnNames) {
|
|
1114
|
-
const columns = {};
|
|
1115
|
-
for (const columnName of columnNames) {
|
|
1116
|
-
const column = sourceTable.getChild(columnName);
|
|
1117
|
-
if (!column) {
|
|
1118
|
-
throw new Error(`Arrow query column not found: ${columnName}`);
|
|
1119
|
-
}
|
|
1120
|
-
columns[columnName] = column;
|
|
1121
|
-
}
|
|
1122
|
-
return columns;
|
|
1123
|
-
}
|
|
1124
|
-
function evaluatePredicate(predicate, columns, rowIndex) {
|
|
1125
|
-
if (isLogicalPredicate(predicate)) {
|
|
1126
|
-
const values = predicate.args.map((child) => evaluatePredicate(child, columns, rowIndex));
|
|
1127
|
-
return predicate.op === "and" ? evaluateAnd(values) : evaluateOr(values);
|
|
1128
|
-
}
|
|
1129
|
-
if (isNotPredicate(predicate)) {
|
|
1130
|
-
const value2 = evaluatePredicate(predicate.args[0], columns, rowIndex);
|
|
1131
|
-
return value2 === null ? null : !value2;
|
|
1059
|
+
const selected = (0, import_arrow.selectArrowBatchRows)(batch, indices);
|
|
1060
|
+
if (selected)
|
|
1061
|
+
batches.push(selected);
|
|
1132
1062
|
}
|
|
1133
|
-
|
|
1134
|
-
if (isNullPredicate(predicate)) {
|
|
1135
|
-
return value === null || value === void 0;
|
|
1136
|
-
}
|
|
1137
|
-
if (isInPredicate(predicate)) {
|
|
1138
|
-
return evaluateIn(value, predicate.args[1]);
|
|
1139
|
-
}
|
|
1140
|
-
return evaluateComparison(value, predicate);
|
|
1141
|
-
}
|
|
1142
|
-
function getColumnValue(columns, columnName, rowIndex) {
|
|
1143
|
-
const path = typeof columnName === "string" ? [columnName] : columnName;
|
|
1144
|
-
const column = columns[path[0]];
|
|
1145
|
-
if (!column) {
|
|
1146
|
-
throw new Error(`Arrow query could not read predicate column "${columnName}".`);
|
|
1147
|
-
}
|
|
1148
|
-
let value = column.get(rowIndex);
|
|
1149
|
-
for (const property of path.slice(1)) {
|
|
1150
|
-
if (value === null || value === void 0)
|
|
1151
|
-
return null;
|
|
1152
|
-
value = value[property];
|
|
1153
|
-
}
|
|
1154
|
-
return value;
|
|
1155
|
-
}
|
|
1156
|
-
function evaluateAnd(values) {
|
|
1157
|
-
if (values.includes(false)) {
|
|
1158
|
-
return false;
|
|
1159
|
-
}
|
|
1160
|
-
return values.includes(null) ? null : true;
|
|
1161
|
-
}
|
|
1162
|
-
function evaluateOr(values) {
|
|
1163
|
-
if (values.includes(true)) {
|
|
1164
|
-
return true;
|
|
1165
|
-
}
|
|
1166
|
-
return values.includes(null) ? null : false;
|
|
1167
|
-
}
|
|
1168
|
-
function evaluateIn(value, candidates) {
|
|
1169
|
-
if (value === null || value === void 0) {
|
|
1170
|
-
return null;
|
|
1171
|
-
}
|
|
1172
|
-
for (const candidate of candidates) {
|
|
1173
|
-
if (compareValues(value, candidate) === 0) {
|
|
1174
|
-
return true;
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
return false;
|
|
1178
|
-
}
|
|
1179
|
-
function evaluateComparison(value, predicate) {
|
|
1180
|
-
if (value === null || value === void 0) {
|
|
1181
|
-
return null;
|
|
1182
|
-
}
|
|
1183
|
-
const comparison = compareValues(value, predicate.args[1]);
|
|
1184
|
-
switch (predicate.op) {
|
|
1185
|
-
case "=":
|
|
1186
|
-
return comparison === 0;
|
|
1187
|
-
case "<>":
|
|
1188
|
-
return comparison !== 0;
|
|
1189
|
-
case "<":
|
|
1190
|
-
return comparison < 0;
|
|
1191
|
-
case "<=":
|
|
1192
|
-
return comparison <= 0;
|
|
1193
|
-
case ">":
|
|
1194
|
-
return comparison > 0;
|
|
1195
|
-
case ">=":
|
|
1196
|
-
return comparison >= 0;
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
function compareValues(left, right) {
|
|
1200
|
-
if (isColumnarPredicateParameter(right)) {
|
|
1201
|
-
throw new Error(`Arrow query parameter ":${right.parameter}" must be bound before query execution.`);
|
|
1202
|
-
}
|
|
1203
|
-
if (left instanceof Date && right instanceof Date) {
|
|
1204
|
-
return compareArrowQueryNumbers(left.getTime(), right.getTime());
|
|
1205
|
-
}
|
|
1206
|
-
if (typeof left === "number" && right instanceof Date) {
|
|
1207
|
-
return compareArrowQueryNumbers(left, right.getTime());
|
|
1208
|
-
}
|
|
1209
|
-
if (left instanceof Uint8Array && right instanceof Uint8Array) {
|
|
1210
|
-
return compareBinary(left, right);
|
|
1211
|
-
}
|
|
1212
|
-
if (typeof left === "bigint" && typeof right === "bigint") {
|
|
1213
|
-
return left === right ? 0 : left < right ? -1 : 1;
|
|
1214
|
-
}
|
|
1215
|
-
if (typeof left === "bigint" && typeof right === "number" || typeof left === "number" && typeof right === "bigint") {
|
|
1216
|
-
const numericValue = typeof left === "number" ? left : right;
|
|
1217
|
-
if (!Number.isFinite(numericValue))
|
|
1218
|
-
throw new Error("Arrow query cannot compare non-finite numbers.");
|
|
1219
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
1220
|
-
}
|
|
1221
|
-
if (typeof left === "number" && typeof right === "number") {
|
|
1222
|
-
return compareArrowQueryNumbers(left, right);
|
|
1223
|
-
}
|
|
1224
|
-
if (typeof left === "string" && typeof right === "string") {
|
|
1225
|
-
return left === right ? 0 : left < right ? -1 : 1;
|
|
1226
|
-
}
|
|
1227
|
-
if (typeof left === "boolean" && typeof right === "boolean") {
|
|
1228
|
-
return Number(left) - Number(right);
|
|
1229
|
-
}
|
|
1230
|
-
throw new Error(`Arrow query cannot compare ${getArrowQueryValueType(left)} with ${getArrowQueryValueType(right)} values.`);
|
|
1231
|
-
}
|
|
1232
|
-
function compareArrowQueryNumbers(left, right) {
|
|
1233
|
-
if (!Number.isFinite(left) || !Number.isFinite(right)) {
|
|
1234
|
-
throw new Error("Arrow query cannot compare non-finite numbers.");
|
|
1235
|
-
}
|
|
1236
|
-
return left === right ? 0 : left < right ? -1 : 1;
|
|
1237
|
-
}
|
|
1238
|
-
function compareBinary(left, right) {
|
|
1239
|
-
const commonLength = Math.min(left.length, right.length);
|
|
1240
|
-
for (let index = 0; index < commonLength; index++) {
|
|
1241
|
-
if (left[index] !== right[index]) {
|
|
1242
|
-
return left[index] < right[index] ? -1 : 1;
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
return left.length === right.length ? 0 : left.length < right.length ? -1 : 1;
|
|
1246
|
-
}
|
|
1247
|
-
function getArrowQueryValueType(value) {
|
|
1248
|
-
if (value instanceof Date) {
|
|
1249
|
-
return "Date";
|
|
1250
|
-
}
|
|
1251
|
-
if (value instanceof Uint8Array) {
|
|
1252
|
-
return "Uint8Array";
|
|
1253
|
-
}
|
|
1254
|
-
return typeof value;
|
|
1255
|
-
}
|
|
1256
|
-
function isLogicalPredicate(predicate) {
|
|
1257
|
-
return predicate.op === "and" || predicate.op === "or";
|
|
1258
|
-
}
|
|
1259
|
-
function isNotPredicate(predicate) {
|
|
1260
|
-
return predicate.op === "not";
|
|
1261
|
-
}
|
|
1262
|
-
function isNullPredicate(predicate) {
|
|
1263
|
-
return predicate.op === "isNull";
|
|
1264
|
-
}
|
|
1265
|
-
function isInPredicate(predicate) {
|
|
1266
|
-
return predicate.op === "in";
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
// dist/scan/rows-to-arrow.js
|
|
1270
|
-
var arrow6 = __toESM(require("apache-arrow"), 1);
|
|
1271
|
-
function convertRowsToArrowTable(rows) {
|
|
1272
|
-
return arrow6.tableFromJSON(rows);
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
|
-
// dist/scan/sql-predicate-types.js
|
|
1276
|
-
function isSQLPredicateParameter(value) {
|
|
1277
|
-
return isColumnarPredicateParameter(value);
|
|
1063
|
+
return new arrow4.Table(source.schema, batches);
|
|
1278
1064
|
}
|
|
1279
1065
|
|
|
1280
1066
|
// dist/scan/sql-predicate-schema.js
|
|
1281
|
-
var
|
|
1282
|
-
var MAXIMUM_PREDICATE_NODES = 4096;
|
|
1067
|
+
var import_parser = require("@math.gl/sql/parser");
|
|
1283
1068
|
function validateSQLPredicate(value) {
|
|
1284
|
-
|
|
1285
|
-
|
|
1069
|
+
(0, import_parser.validateSQLPredicate)(value);
|
|
1070
|
+
rejectPredicateCasts(value, "$");
|
|
1286
1071
|
}
|
|
1287
|
-
function
|
|
1288
|
-
if (
|
|
1289
|
-
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
if (state.nodes > MAXIMUM_PREDICATE_NODES) {
|
|
1293
|
-
throw new Error("SQL predicate exceeds the maximum node count");
|
|
1294
|
-
}
|
|
1295
|
-
if (!isRecord(value) || !hasExactKeys(value, ["op", "args"])) {
|
|
1296
|
-
throw new Error(`SQL predicate ${path} must contain only op and args`);
|
|
1072
|
+
function rejectPredicateCasts(predicate, path) {
|
|
1073
|
+
if (predicate.op === "and" || predicate.op === "or" || predicate.op === "not") {
|
|
1074
|
+
predicate.args.forEach((child, index) => rejectPredicateCasts(child, path + ".args[" + index + "]"));
|
|
1075
|
+
} else if (Object.hasOwn(predicate.args[0], "casts")) {
|
|
1076
|
+
throw new Error("SQL predicate " + path + ".args[0] requires a non-empty property reference");
|
|
1297
1077
|
}
|
|
1298
|
-
if (typeof value.op !== "string" || !Array.isArray(value.args)) {
|
|
1299
|
-
throw new Error(`SQL predicate ${path} requires string op and array args`);
|
|
1300
|
-
}
|
|
1301
|
-
switch (value.op) {
|
|
1302
|
-
case "and":
|
|
1303
|
-
case "or":
|
|
1304
|
-
if (value.args.length < 2) {
|
|
1305
|
-
throw new Error(`SQL predicate ${path}.${value.op} requires at least two arguments`);
|
|
1306
|
-
}
|
|
1307
|
-
for (let index = 0; index < value.args.length; index++) {
|
|
1308
|
-
validatePredicateNode(value.args[index], `${path}.args[${index}]`, depth + 1, state);
|
|
1309
|
-
}
|
|
1310
|
-
return;
|
|
1311
|
-
case "not":
|
|
1312
|
-
if (value.args.length !== 1) {
|
|
1313
|
-
throw new Error(`SQL predicate ${path}.not requires exactly one argument`);
|
|
1314
|
-
}
|
|
1315
|
-
validatePredicateNode(value.args[0], `${path}.args[0]`, depth + 1, state);
|
|
1316
|
-
return;
|
|
1317
|
-
case "isNull":
|
|
1318
|
-
if (value.args.length !== 1) {
|
|
1319
|
-
throw new Error(`SQL predicate ${path}.isNull requires exactly one argument`);
|
|
1320
|
-
}
|
|
1321
|
-
validatePredicateProperty(value.args[0], `${path}.args[0]`);
|
|
1322
|
-
return;
|
|
1323
|
-
case "in":
|
|
1324
|
-
if (value.args.length !== 2 || !Array.isArray(value.args[1]) || value.args[1].length === 0) {
|
|
1325
|
-
throw new Error(`SQL predicate ${path}.in requires a property and non-empty value list`);
|
|
1326
|
-
}
|
|
1327
|
-
validatePredicateProperty(value.args[0], `${path}.args[0]`);
|
|
1328
|
-
value.args[1].forEach((item, index) => validatePredicateValue(item, `${path}.args[1][${index}]`));
|
|
1329
|
-
return;
|
|
1330
|
-
case "=":
|
|
1331
|
-
case "<>":
|
|
1332
|
-
case "<":
|
|
1333
|
-
case "<=":
|
|
1334
|
-
case ">":
|
|
1335
|
-
case ">=":
|
|
1336
|
-
if (value.args.length !== 2) {
|
|
1337
|
-
throw new Error(`SQL predicate ${path}.${value.op} requires exactly two arguments`);
|
|
1338
|
-
}
|
|
1339
|
-
validatePredicateProperty(value.args[0], `${path}.args[0]`);
|
|
1340
|
-
validatePredicateValue(value.args[1], `${path}.args[1]`);
|
|
1341
|
-
return;
|
|
1342
|
-
default:
|
|
1343
|
-
throw new Error(`SQL predicate ${path} has unsupported operator ${JSON.stringify(value.op)}`);
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
function validatePredicateProperty(value, path) {
|
|
1347
|
-
if (!isRecord(value) || !hasAllowedKeys(value, ["property", "quoted"]) || typeof value.property !== "string" || value.property.length === 0 || value.quoted !== void 0 && typeof value.quoted !== "boolean") {
|
|
1348
|
-
throw new Error(`SQL predicate ${path} requires a non-empty property reference`);
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
function validatePredicateValue(value, path) {
|
|
1352
|
-
if (isSQLPredicateParameter(value)) {
|
|
1353
|
-
return;
|
|
1354
|
-
}
|
|
1355
|
-
if (typeof value === "boolean" || typeof value === "bigint" || typeof value === "string" || value instanceof Uint8Array) {
|
|
1356
|
-
return;
|
|
1357
|
-
}
|
|
1358
|
-
if (typeof value === "number" && Number.isFinite(value)) {
|
|
1359
|
-
return;
|
|
1360
|
-
}
|
|
1361
|
-
if (value instanceof Date && Number.isFinite(value.getTime())) {
|
|
1362
|
-
return;
|
|
1363
|
-
}
|
|
1364
|
-
throw new Error(`SQL predicate ${path} contains an unsupported scalar value`);
|
|
1365
|
-
}
|
|
1366
|
-
function isRecord(value) {
|
|
1367
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1368
|
-
}
|
|
1369
|
-
function hasExactKeys(value, expectedKeys) {
|
|
1370
|
-
const keys = Object.keys(value);
|
|
1371
|
-
return keys.length === expectedKeys.length && expectedKeys.every((key) => keys.includes(key));
|
|
1372
|
-
}
|
|
1373
|
-
function hasAllowedKeys(value, allowedKeys) {
|
|
1374
|
-
return Object.keys(value).every((key) => allowedKeys.includes(key));
|
|
1375
1078
|
}
|
|
1376
1079
|
|
|
1377
1080
|
// dist/scan/table-query.js
|
|
@@ -1382,180 +1085,156 @@ function planTableQuery2(sourceColumnNames, options = {}) {
|
|
|
1382
1085
|
return planTableQuery(sourceColumnNames, options);
|
|
1383
1086
|
}
|
|
1384
1087
|
|
|
1385
|
-
// dist/scan/
|
|
1088
|
+
// dist/scan/plan-arrow-table-query.js
|
|
1386
1089
|
var executePortableArrowQuery = (table, { select, where, limit, signal }) => {
|
|
1387
1090
|
if (where)
|
|
1388
1091
|
table = filterArrowTable(table, where, { limit, signal });
|
|
1389
|
-
const projected = select ? projectArrowTable(table, select) : table;
|
|
1092
|
+
const projected = select ? (0, import_arrow2.projectArrowTable)(table, select) : table;
|
|
1390
1093
|
return projected.numRows === 0 || limit === void 0 ? projected : projected.slice(0, limit);
|
|
1391
1094
|
};
|
|
1392
|
-
function queryArrowTable(sourceTable, options = {},
|
|
1095
|
+
function queryArrowTable(sourceTable, options = {}, execute) {
|
|
1393
1096
|
throwIfAborted(options.signal);
|
|
1394
1097
|
if (options.select !== void 0) {
|
|
1395
1098
|
if (options.columns !== void 0 || hasRelationalOperators(options) || options.join) {
|
|
1396
1099
|
throw new Error("Arrow select cannot be combined with columns or relational operators.");
|
|
1397
1100
|
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
return projectArrowTable(result, select);
|
|
1405
|
-
}
|
|
1406
|
-
if (options.join) {
|
|
1407
|
-
validateArrowJoinQuery(sourceTable, options);
|
|
1408
|
-
}
|
|
1409
|
-
if (options.join && hasRelationalOperatorsExceptJoin(options)) {
|
|
1410
|
-
throw new Error("Arrow joins cannot yet be combined with other relational operators.");
|
|
1411
|
-
}
|
|
1412
|
-
if (options.join && !hasRelationalOperatorsExceptJoin(options)) {
|
|
1413
|
-
return queryArrowJoin(sourceTable, options);
|
|
1101
|
+
return (execute ?? executePortableArrowQuery)(sourceTable, {
|
|
1102
|
+
where: options.predicate,
|
|
1103
|
+
select: options.select,
|
|
1104
|
+
limit: options.limit,
|
|
1105
|
+
signal: options.signal
|
|
1106
|
+
});
|
|
1414
1107
|
}
|
|
1415
|
-
if (hasRelationalOperators(options)) {
|
|
1416
|
-
|
|
1108
|
+
if (options.join || hasRelationalOperators(options)) {
|
|
1109
|
+
if (options.join) {
|
|
1110
|
+
validateArrowJoinQuery(sourceTable, options);
|
|
1111
|
+
if (hasRelationalOperators(options)) {
|
|
1112
|
+
throw new Error("Arrow joins cannot yet be combined with other relational operators.");
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
if (!execute)
|
|
1116
|
+
throw new Error("Relational queries require the SQL executor.");
|
|
1117
|
+
return options.join ? queryArrowJoin(sourceTable, options, execute) : queryArrowTableRelational(sourceTable, options, execute);
|
|
1417
1118
|
}
|
|
1418
1119
|
const plan = planTableQuery2(sourceTable.schema.fields.map((field) => field.name), options);
|
|
1419
1120
|
const projection = plan.find((step) => step.kind === "project");
|
|
1420
|
-
return
|
|
1121
|
+
return (execute ?? executePortableArrowQuery)(sourceTable, {
|
|
1421
1122
|
where: options.predicate,
|
|
1422
1123
|
select: projection == null ? void 0 : projection.columns,
|
|
1423
1124
|
limit: options.limit,
|
|
1424
1125
|
signal: options.signal
|
|
1425
1126
|
});
|
|
1426
1127
|
}
|
|
1427
|
-
function queryArrowTableRelational(sourceTable, options) {
|
|
1428
|
-
var _a, _b, _c
|
|
1429
|
-
const
|
|
1430
|
-
const
|
|
1431
|
-
const
|
|
1432
|
-
const
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
const filteredTable = queryArrowTable(scannedTable, {
|
|
1438
|
-
predicate: options.predicate,
|
|
1439
|
-
columns: scanStep.columns,
|
|
1128
|
+
function queryArrowTableRelational(sourceTable, options, execute) {
|
|
1129
|
+
var _a, _b, _c;
|
|
1130
|
+
const sourceColumns = sourceTable.schema.fields.map((field) => field.name);
|
|
1131
|
+
const grouped = ((_a = options.groupBy) == null ? void 0 : _a.length) || ((_b = options.aggregates) == null ? void 0 : _b.length);
|
|
1132
|
+
const outputColumns = options.columns ?? (grouped ? [...options.groupBy ?? [], ...(options.aggregates ?? []).map((aggregate) => aggregate.name)] : sourceColumns);
|
|
1133
|
+
const plan = planRelationalQuery(sourceColumns, { ...options, columns: outputColumns });
|
|
1134
|
+
const scan = plan.tablePlan.find((step) => step.kind === "scan");
|
|
1135
|
+
let table = execute(sourceTable, {
|
|
1136
|
+
where: options.predicate,
|
|
1137
|
+
select: scan.columns,
|
|
1440
1138
|
signal: options.signal
|
|
1441
1139
|
});
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
const childResult = queryArrowTable(childTable, {
|
|
1448
|
-
...child.query || {},
|
|
1449
|
-
columns: getUnionChildColumns(sourceColumnNames, options),
|
|
1450
|
-
signal: options.signal
|
|
1140
|
+
if ((_c = options.union) == null ? void 0 : _c.length) {
|
|
1141
|
+
const childPlan = planRelationalQuery(sourceColumns, {
|
|
1142
|
+
...options,
|
|
1143
|
+
columns: outputColumns,
|
|
1144
|
+
predicate: void 0
|
|
1451
1145
|
});
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
}
|
|
1462
|
-
if ((_d = options.orderBy) == null ? void 0 : _d.length) {
|
|
1463
|
-
const orderBy = options.orderBy;
|
|
1464
|
-
rows = rows.map((row, index) => ({ row, index })).sort((left, right) => compareRows(left.row, right.row, orderBy) || left.index - right.index).map((entry) => entry.row);
|
|
1146
|
+
const columns = childPlan.tablePlan.find((step) => step.kind === "scan").columns;
|
|
1147
|
+
const union = options.union.map((child) => {
|
|
1148
|
+
var _a2;
|
|
1149
|
+
const input = (_a2 = options.tables) == null ? void 0 : _a2[child.source];
|
|
1150
|
+
if (!input)
|
|
1151
|
+
throw new Error("Arrow union source not found: " + child.source);
|
|
1152
|
+
return queryArrowTable(input, { ...child.query, columns, signal: options.signal }, execute);
|
|
1153
|
+
});
|
|
1154
|
+
table = execute((0, import_arrow2.projectArrowTable)(table, columns), { union, signal: options.signal });
|
|
1465
1155
|
}
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1156
|
+
for (const { name, expression } of options.expressions ?? []) {
|
|
1157
|
+
const select = [
|
|
1158
|
+
...table.schema.fields.map((field) => field.name),
|
|
1159
|
+
expression.op === "column" ? { column: expression.column, as: name } : { expression: toArrowExpression(expression), as: name }
|
|
1160
|
+
];
|
|
1161
|
+
table = execute(table, { select, signal: options.signal });
|
|
1162
|
+
}
|
|
1163
|
+
return execute(table, {
|
|
1164
|
+
select: outputColumns,
|
|
1165
|
+
groupBy: options.groupBy,
|
|
1166
|
+
aggregates: Object.fromEntries((options.aggregates ?? []).map((aggregate) => {
|
|
1167
|
+
const expression = aggregate.column === void 0 ? void 0 : identifier(aggregate.column);
|
|
1168
|
+
if (aggregate.function === "count")
|
|
1169
|
+
return [aggregate.name, { operation: "COUNT", expression }];
|
|
1170
|
+
const operations = { sum: "SUM", min: "MIN", max: "MAX", avg: "AVG" };
|
|
1171
|
+
return [
|
|
1172
|
+
aggregate.name,
|
|
1173
|
+
{ operation: operations[aggregate.function], expression }
|
|
1174
|
+
];
|
|
1175
|
+
})),
|
|
1176
|
+
orderBy: options.orderBy,
|
|
1177
|
+
limit: options.limit,
|
|
1178
|
+
signal: options.signal
|
|
1476
1179
|
});
|
|
1477
|
-
const limit = options.limit === void 0 ? outputRows.length : options.limit;
|
|
1478
|
-
const limitedRows = outputRows.slice(0, limit);
|
|
1479
|
-
return limitedRows.length ? convertRowsToArrowTable(limitedRows) : createEmptyRelationalResult(sourceData, outputColumns, options);
|
|
1480
1180
|
}
|
|
1481
|
-
function
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
requiredColumns.add(column);
|
|
1503
|
-
for (const aggregate of options.aggregates || []) {
|
|
1504
|
-
if (aggregate.column)
|
|
1505
|
-
requiredColumns.add(aggregate.column);
|
|
1506
|
-
}
|
|
1507
|
-
return sourceColumnNames.filter((column) => requiredColumns.has(column));
|
|
1181
|
+
function identifier(name) {
|
|
1182
|
+
return { type: "Identifier", name };
|
|
1183
|
+
}
|
|
1184
|
+
function toArrowExpression(expression) {
|
|
1185
|
+
if (expression.op === "literal")
|
|
1186
|
+
return literal(expression.value);
|
|
1187
|
+
const operators = { add: "+", subtract: "-", multiply: "*", divide: "/" };
|
|
1188
|
+
const binary = {
|
|
1189
|
+
type: "BinaryExpression",
|
|
1190
|
+
operator: operators[expression.op],
|
|
1191
|
+
left: identifier(expression.left),
|
|
1192
|
+
right: identifier(expression.right)
|
|
1193
|
+
};
|
|
1194
|
+
if (expression.op !== "divide")
|
|
1195
|
+
return binary;
|
|
1196
|
+
return {
|
|
1197
|
+
type: "ConditionalExpression",
|
|
1198
|
+
test: { ...binary, operator: "===", left: binary.right, right: literal(0) },
|
|
1199
|
+
consequent: literal(null),
|
|
1200
|
+
alternate: binary
|
|
1201
|
+
};
|
|
1508
1202
|
}
|
|
1509
|
-
function
|
|
1510
|
-
|
|
1511
|
-
return Boolean(((_a = options.expressions) == null ? void 0 : _a.length) || ((_b = options.orderBy) == null ? void 0 : _b.length) || ((_c = options.groupBy) == null ? void 0 : _c.length) || ((_d = options.aggregates) == null ? void 0 : _d.length) || ((_e = options.union) == null ? void 0 : _e.length) || options.join);
|
|
1203
|
+
function literal(value) {
|
|
1204
|
+
return { type: "Literal", value };
|
|
1512
1205
|
}
|
|
1513
|
-
function
|
|
1206
|
+
function hasRelationalOperators(options) {
|
|
1514
1207
|
var _a, _b, _c, _d, _e;
|
|
1515
1208
|
return Boolean(((_a = options.expressions) == null ? void 0 : _a.length) || ((_b = options.orderBy) == null ? void 0 : _b.length) || ((_c = options.groupBy) == null ? void 0 : _c.length) || ((_d = options.aggregates) == null ? void 0 : _d.length) || ((_e = options.union) == null ? void 0 : _e.length));
|
|
1516
1209
|
}
|
|
1517
|
-
function queryArrowJoin(sourceTable, options) {
|
|
1518
|
-
var _a;
|
|
1210
|
+
function queryArrowJoin(sourceTable, options, executeRelational) {
|
|
1211
|
+
var _a, _b, _c, _d;
|
|
1519
1212
|
const join = options.join;
|
|
1520
|
-
if (!join)
|
|
1521
|
-
throw new Error("Arrow join query is missing a join definition.");
|
|
1522
1213
|
const childTable = (_a = options.tables) == null ? void 0 : _a[join.child.source];
|
|
1523
1214
|
if (!childTable)
|
|
1524
1215
|
throw new Error(`Arrow join source not found: ${join.child.source}`);
|
|
1525
|
-
const
|
|
1526
|
-
|
|
1527
|
-
columns: void 0,
|
|
1216
|
+
const left = executeRelational(sourceTable, {
|
|
1217
|
+
where: options.predicate,
|
|
1528
1218
|
signal: options.signal
|
|
1529
1219
|
});
|
|
1530
|
-
const
|
|
1531
|
-
|
|
1220
|
+
const right = executeRelational(childTable, {
|
|
1221
|
+
where: (_b = join.child.query) == null ? void 0 : _b.predicate,
|
|
1222
|
+
select: (_c = join.child.query) == null ? void 0 : _c.columns,
|
|
1223
|
+
limit: (_d = join.child.query) == null ? void 0 : _d.limit,
|
|
1224
|
+
signal: options.signal
|
|
1225
|
+
});
|
|
1226
|
+
return executeRelational(left, {
|
|
1227
|
+
join: {
|
|
1228
|
+
table: right,
|
|
1229
|
+
type: join.type,
|
|
1230
|
+
left: join.left,
|
|
1231
|
+
right: join.right,
|
|
1232
|
+
rightPrefix: `${join.child.source}.`
|
|
1233
|
+
},
|
|
1234
|
+
select: options.columns,
|
|
1235
|
+
limit: options.limit,
|
|
1532
1236
|
signal: options.signal
|
|
1533
1237
|
});
|
|
1534
|
-
const leftRows = arrowTableToRows(leftResult);
|
|
1535
|
-
const rightRows = arrowTableToRows(rightResult);
|
|
1536
|
-
const rightPrefix = `${join.child.source}.`;
|
|
1537
|
-
const defaultOutputColumns = [
|
|
1538
|
-
...sourceTable.schema.fields.map((field) => field.name),
|
|
1539
|
-
...rightResult.schema.fields.map((field) => `${rightPrefix}${field.name}`)
|
|
1540
|
-
];
|
|
1541
|
-
const rows = [];
|
|
1542
|
-
for (const leftRow of leftRows) {
|
|
1543
|
-
for (const rightRow of rightRows) {
|
|
1544
|
-
if (leftRow[join.left] !== null && leftRow[join.left] !== void 0 && rightRow[join.right] !== null && rightRow[join.right] !== void 0 && compareSortValues(leftRow[join.left], rightRow[join.right]) === 0) {
|
|
1545
|
-
rows.push({
|
|
1546
|
-
...leftRow,
|
|
1547
|
-
...Object.fromEntries(Object.entries(rightRow).map(([key, value]) => [`${rightPrefix}${key}`, value]))
|
|
1548
|
-
});
|
|
1549
|
-
}
|
|
1550
|
-
}
|
|
1551
|
-
}
|
|
1552
|
-
const outputColumns = options.columns || defaultOutputColumns;
|
|
1553
|
-
const outputRows = rows.map((row) => Object.fromEntries(outputColumns.map((column) => [column, row[column]])));
|
|
1554
|
-
const limitedRows = outputRows.slice(0, options.limit);
|
|
1555
|
-
return limitedRows.length ? convertRowsToArrowTable(limitedRows) : createEmptyRelationalResult(sourceTable, outputColumns, options, new Map(rightResult.schema.fields.map((field) => [
|
|
1556
|
-
`${rightPrefix}${field.name}`,
|
|
1557
|
-
new arrow7.Field(`${rightPrefix}${field.name}`, field.type, field.nullable, field.metadata)
|
|
1558
|
-
])));
|
|
1559
1238
|
}
|
|
1560
1239
|
function validateArrowJoinQuery(sourceTable, options) {
|
|
1561
1240
|
var _a, _b, _c;
|
|
@@ -1603,171 +1282,6 @@ function validateArrowJoinQuery(sourceTable, options) {
|
|
|
1603
1282
|
}
|
|
1604
1283
|
}
|
|
1605
1284
|
}
|
|
1606
|
-
function arrowTableToRows(data) {
|
|
1607
|
-
const columns = data.schema.fields.map((field) => ({
|
|
1608
|
-
name: field.name,
|
|
1609
|
-
vector: data.getChild(field.name)
|
|
1610
|
-
}));
|
|
1611
|
-
return Array.from({ length: data.numRows }, (_, rowIndex) => {
|
|
1612
|
-
const row = {};
|
|
1613
|
-
for (const column of columns) {
|
|
1614
|
-
if (!column.vector)
|
|
1615
|
-
throw new Error(`Arrow relational query could not read ${column.name}`);
|
|
1616
|
-
row[column.name] = column.vector.get(rowIndex);
|
|
1617
|
-
}
|
|
1618
|
-
return row;
|
|
1619
|
-
});
|
|
1620
|
-
}
|
|
1621
|
-
function evaluateRelationalExpression(expression, row) {
|
|
1622
|
-
const definition = expression.expression;
|
|
1623
|
-
if (definition.op === "literal")
|
|
1624
|
-
return definition.value;
|
|
1625
|
-
if (definition.op === "column")
|
|
1626
|
-
return row[definition.column];
|
|
1627
|
-
const left = row[definition.left];
|
|
1628
|
-
const right = row[definition.right];
|
|
1629
|
-
if (left === null || left === void 0 || right === null || right === void 0)
|
|
1630
|
-
return null;
|
|
1631
|
-
if (typeof left !== "number" || typeof right !== "number") {
|
|
1632
|
-
throw new Error(`Arrow relational expression ${expression.name} requires numeric operands.`);
|
|
1633
|
-
}
|
|
1634
|
-
switch (definition.op) {
|
|
1635
|
-
case "add":
|
|
1636
|
-
return left + right;
|
|
1637
|
-
case "subtract":
|
|
1638
|
-
return left - right;
|
|
1639
|
-
case "multiply":
|
|
1640
|
-
return left * right;
|
|
1641
|
-
case "divide":
|
|
1642
|
-
return right === 0 ? null : left / right;
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
function compareRows(left, right, orderBy) {
|
|
1646
|
-
for (const key of orderBy) {
|
|
1647
|
-
const leftValue = left[key.column];
|
|
1648
|
-
const rightValue = right[key.column];
|
|
1649
|
-
const nulls = key.nulls || "last";
|
|
1650
|
-
if (leftValue === null || leftValue === void 0 || rightValue === null || rightValue === void 0) {
|
|
1651
|
-
if (leftValue === rightValue)
|
|
1652
|
-
continue;
|
|
1653
|
-
const nullResult = leftValue === null || leftValue === void 0 ? -1 : 1;
|
|
1654
|
-
return nulls === "first" ? nullResult : -nullResult;
|
|
1655
|
-
}
|
|
1656
|
-
const result = compareSortValues(leftValue, rightValue);
|
|
1657
|
-
if (result)
|
|
1658
|
-
return (key.direction === "desc" ? -1 : 1) * result;
|
|
1659
|
-
}
|
|
1660
|
-
return 0;
|
|
1661
|
-
}
|
|
1662
|
-
function compareSortValues(left, right) {
|
|
1663
|
-
if (left instanceof Date && right instanceof Date)
|
|
1664
|
-
return compareArrowQueryNumbers(left.getTime(), right.getTime());
|
|
1665
|
-
if (typeof left === "bigint" && typeof right === "bigint")
|
|
1666
|
-
return left === right ? 0 : left < right ? -1 : 1;
|
|
1667
|
-
if (typeof left === "number" && typeof right === "number")
|
|
1668
|
-
return compareArrowQueryNumbers(left, right);
|
|
1669
|
-
if (typeof left === "string" && typeof right === "string")
|
|
1670
|
-
return left === right ? 0 : left < right ? -1 : 1;
|
|
1671
|
-
if (typeof left === "boolean" && typeof right === "boolean")
|
|
1672
|
-
return Number(left) - Number(right);
|
|
1673
|
-
throw new Error(`Arrow relational order cannot compare ${getArrowQueryValueType(left)} with ${getArrowQueryValueType(right)}.`);
|
|
1674
|
-
}
|
|
1675
|
-
function aggregateRows(rows, groupBy, aggregates) {
|
|
1676
|
-
const groups = /* @__PURE__ */ new Map();
|
|
1677
|
-
for (const row of rows) {
|
|
1678
|
-
const key = serializeGroupKey(groupBy.map((column) => row[column]));
|
|
1679
|
-
const group = groups.get(key) || [];
|
|
1680
|
-
group.push(row);
|
|
1681
|
-
groups.set(key, group);
|
|
1682
|
-
}
|
|
1683
|
-
if (!groupBy.length && !rows.length)
|
|
1684
|
-
groups.set("[]", []);
|
|
1685
|
-
return [...groups.values()].map((group) => {
|
|
1686
|
-
var _a;
|
|
1687
|
-
const output = {};
|
|
1688
|
-
for (const column of groupBy)
|
|
1689
|
-
output[column] = ((_a = group[0]) == null ? void 0 : _a[column]) ?? null;
|
|
1690
|
-
for (const aggregate of aggregates)
|
|
1691
|
-
output[aggregate.name] = evaluateAggregate(aggregate, group);
|
|
1692
|
-
return output;
|
|
1693
|
-
});
|
|
1694
|
-
}
|
|
1695
|
-
function serializeGroupKey(values) {
|
|
1696
|
-
return values.map((value) => {
|
|
1697
|
-
if (value === null || value === void 0)
|
|
1698
|
-
return "null:";
|
|
1699
|
-
if (value instanceof Date)
|
|
1700
|
-
return `date:${value.getTime()}`;
|
|
1701
|
-
if (value instanceof Uint8Array)
|
|
1702
|
-
return `bytes:${Array.from(value).join(".")}`;
|
|
1703
|
-
return `${typeof value}:${String(value)}`;
|
|
1704
|
-
}).join("");
|
|
1705
|
-
}
|
|
1706
|
-
function createEmptyRelationalResult(sourceData, outputColumns, options, additionalFields) {
|
|
1707
|
-
const sourceFields = new Map(sourceData.schema.fields.map((field) => [field.name, field]));
|
|
1708
|
-
const expressions = new Map((options.expressions || []).map((expression) => [expression.name, expression]));
|
|
1709
|
-
const aggregates = new Map((options.aggregates || []).map((aggregate) => [aggregate.name, aggregate]));
|
|
1710
|
-
const fields = outputColumns.map((columnName) => {
|
|
1711
|
-
const sourceField = sourceFields.get(columnName);
|
|
1712
|
-
if (sourceField)
|
|
1713
|
-
return sourceField;
|
|
1714
|
-
const additionalField = additionalFields == null ? void 0 : additionalFields.get(columnName);
|
|
1715
|
-
if (additionalField)
|
|
1716
|
-
return additionalField;
|
|
1717
|
-
const expression = expressions.get(columnName);
|
|
1718
|
-
if (expression)
|
|
1719
|
-
return new arrow7.Field(columnName, getExpressionType(expression, sourceFields), true);
|
|
1720
|
-
const aggregate = aggregates.get(columnName);
|
|
1721
|
-
if (aggregate)
|
|
1722
|
-
return new arrow7.Field(columnName, getAggregateType(aggregate, sourceFields), true);
|
|
1723
|
-
return new arrow7.Field(columnName, new arrow7.Utf8(), true);
|
|
1724
|
-
});
|
|
1725
|
-
const columns = {};
|
|
1726
|
-
for (const field of fields)
|
|
1727
|
-
columns[field.name] = arrow7.vectorFromArray([], field.type);
|
|
1728
|
-
return new arrow7.Table(new arrow7.Schema(fields), columns);
|
|
1729
|
-
}
|
|
1730
|
-
function getExpressionType(expression, sourceFields) {
|
|
1731
|
-
var _a;
|
|
1732
|
-
if (expression.expression.op === "literal") {
|
|
1733
|
-
const value = expression.expression.value;
|
|
1734
|
-
if (typeof value === "boolean")
|
|
1735
|
-
return new arrow7.Bool();
|
|
1736
|
-
if (typeof value === "number")
|
|
1737
|
-
return new arrow7.Float64();
|
|
1738
|
-
return new arrow7.Utf8();
|
|
1739
|
-
}
|
|
1740
|
-
if (expression.expression.op === "column") {
|
|
1741
|
-
return ((_a = sourceFields.get(expression.expression.column)) == null ? void 0 : _a.type) || new arrow7.Utf8();
|
|
1742
|
-
}
|
|
1743
|
-
return new arrow7.Float64();
|
|
1744
|
-
}
|
|
1745
|
-
function getAggregateType(aggregate, sourceFields) {
|
|
1746
|
-
var _a;
|
|
1747
|
-
if (aggregate.function === "count")
|
|
1748
|
-
return new arrow7.Int32();
|
|
1749
|
-
return aggregate.column ? ((_a = sourceFields.get(aggregate.column)) == null ? void 0 : _a.type) || new arrow7.Float64() : new arrow7.Float64();
|
|
1750
|
-
}
|
|
1751
|
-
function evaluateAggregate(aggregate, rows) {
|
|
1752
|
-
if (aggregate.function === "count")
|
|
1753
|
-
return aggregate.column ? rows.filter((row) => row[aggregate.column] != null).length : rows.length;
|
|
1754
|
-
const values = rows.map((row) => row[aggregate.column]).filter((value) => value != null);
|
|
1755
|
-
if (!values.length)
|
|
1756
|
-
return null;
|
|
1757
|
-
if (!values.every((value) => typeof value === "number"))
|
|
1758
|
-
throw new Error(`Arrow aggregate ${aggregate.function} requires numeric values.`);
|
|
1759
|
-
const numericValues = values;
|
|
1760
|
-
switch (aggregate.function) {
|
|
1761
|
-
case "sum":
|
|
1762
|
-
return numericValues.reduce((sum, value) => sum + value, 0);
|
|
1763
|
-
case "avg":
|
|
1764
|
-
return numericValues.reduce((sum, value) => sum + value, 0) / numericValues.length;
|
|
1765
|
-
case "min":
|
|
1766
|
-
return Math.min(...numericValues);
|
|
1767
|
-
case "max":
|
|
1768
|
-
return Math.max(...numericValues);
|
|
1769
|
-
}
|
|
1770
|
-
}
|
|
1771
1285
|
function throwIfAborted(signal) {
|
|
1772
1286
|
if (signal == null ? void 0 : signal.aborted) {
|
|
1773
1287
|
const error = new Error("Arrow query was aborted.");
|
|
@@ -1930,7 +1444,7 @@ var FederatedTableScanSource = class {
|
|
|
1930
1444
|
sourceRowsRead += batchLength;
|
|
1931
1445
|
if (batchLength <= 0)
|
|
1932
1446
|
continue;
|
|
1933
|
-
const physicalTable = native ? new
|
|
1447
|
+
const physicalTable = native ? new arrow5.Table(input.schema, [input]) : convertTableToArrow2(input.schema ? input : { ...input, schema: resolvedSource.metadata.schema });
|
|
1934
1448
|
const sourceResult = queryArrowTable(physicalTable, {
|
|
1935
1449
|
predicate: sourceResidualPredicate,
|
|
1936
1450
|
limit: Number.isFinite(sourceRemaining) ? sourceRemaining : void 0,
|
|
@@ -1969,7 +1483,7 @@ var FederatedTableScanSource = class {
|
|
|
1969
1483
|
for (const recordBatch of result.batches) {
|
|
1970
1484
|
const metadata = new Map(native && resultLength === batchLength ? input.metadata : void 0);
|
|
1971
1485
|
metadata.set("loaders.gl.federation", JSON.stringify(provenance));
|
|
1972
|
-
yield new
|
|
1486
|
+
yield new arrow5.RecordBatch(recordBatch.schema, recordBatch.data, metadata);
|
|
1973
1487
|
}
|
|
1974
1488
|
remaining -= resultLength;
|
|
1975
1489
|
}
|
|
@@ -2174,7 +1688,7 @@ function createSourceReadOptions(source, requiredOutputColumns, remaining, optio
|
|
|
2174
1688
|
const sourceResidualPredicate = getSourceResidualPredicate(source);
|
|
2175
1689
|
const requiredSourceColumns = requiredOutputColumns.map((outputName) => source.sourceNameByOutputName.get(outputName)).filter((sourceName) => Boolean(sourceName));
|
|
2176
1690
|
if (sourceResidualPredicate) {
|
|
2177
|
-
requiredSourceColumns.push(...getColumnarPredicateColumns(sourceResidualPredicate));
|
|
1691
|
+
requiredSourceColumns.push(...(0, import_columnar_predicate2.getColumnarPredicateColumns)(sourceResidualPredicate));
|
|
2178
1692
|
}
|
|
2179
1693
|
if (!requiredSourceColumns.length) {
|
|
2180
1694
|
requiredSourceColumns.push(source.fields[0].sourceName);
|
|
@@ -2202,9 +1716,9 @@ function createCanonicalArrowTable(schema, source, physicalTable) {
|
|
|
2202
1716
|
const sourceName = source.sourceNameByOutputName.get(field.name);
|
|
2203
1717
|
const vector = sourceName ? physicalTable.getChild(sourceName) : null;
|
|
2204
1718
|
const mappedField = source.fields.find((sourceField) => sourceField.outputName === field.name);
|
|
2205
|
-
columns[field.name] = vector ? mappedField && !areDataTypesEqual(mappedField.field.type, schema.fields.find((schemaField) => schemaField.name === field.name).type) ?
|
|
1719
|
+
columns[field.name] = vector ? mappedField && !areDataTypesEqual(mappedField.field.type, schema.fields.find((schemaField) => schemaField.name === field.name).type) ? arrow5.vectorFromArray(Array.from(vector), field.type) : vector : arrow5.vectorFromArray(Array.from({ length: physicalTable.numRows }, () => null), field.type);
|
|
2206
1720
|
}
|
|
2207
|
-
return new
|
|
1721
|
+
return new arrow5.Table(arrowSchema, columns);
|
|
2208
1722
|
}
|
|
2209
1723
|
function createSourceTelemetry(options) {
|
|
2210
1724
|
var _a;
|