@loaders.gl/core 5.0.0-rc.2 → 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/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/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 +124 -370
- 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 +2 -2
- package/dist/dist.min.js +2 -2
- package/dist/federated-table-scan-source.cjs +166 -564
- 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/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 +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/lib/init.js +1 -1
- package/dist/lib/init.js.map +1 -1
- package/dist/loader-utils/index.cjs +31 -217
- 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/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.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 +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 +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 +854 -1314
- 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 +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 +7 -7
- package/src/arrow-geometry/geometry-codecs.ts +35 -78
- 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/geometry-converters/wkb/helpers/parse-wkb-header.ts +6 -30
- package/src/geoarrow/lib/kernels/decode-wkt-native.ts +23 -269
- 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/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.ts +16 -10
- package/src/scan/scan-engine.ts +4 -11
- 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/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,181 +1056,11 @@ 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;
|
|
1132
|
-
}
|
|
1133
|
-
const value = getColumnValue(columns, predicate.args[0].property, rowIndex);
|
|
1134
|
-
if (isNullPredicate(predicate)) {
|
|
1135
|
-
return value === null || value === void 0;
|
|
1059
|
+
const selected = (0, import_arrow.selectArrowBatchRows)(batch, indices);
|
|
1060
|
+
if (selected)
|
|
1061
|
+
batches.push(selected);
|
|
1136
1062
|
}
|
|
1137
|
-
|
|
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);
|
|
1063
|
+
return new arrow4.Table(source.schema, batches);
|
|
1273
1064
|
}
|
|
1274
1065
|
|
|
1275
1066
|
// dist/scan/sql-predicate-schema.js
|
|
@@ -1294,180 +1085,156 @@ function planTableQuery2(sourceColumnNames, options = {}) {
|
|
|
1294
1085
|
return planTableQuery(sourceColumnNames, options);
|
|
1295
1086
|
}
|
|
1296
1087
|
|
|
1297
|
-
// dist/scan/
|
|
1088
|
+
// dist/scan/plan-arrow-table-query.js
|
|
1298
1089
|
var executePortableArrowQuery = (table, { select, where, limit, signal }) => {
|
|
1299
1090
|
if (where)
|
|
1300
1091
|
table = filterArrowTable(table, where, { limit, signal });
|
|
1301
|
-
const projected = select ? projectArrowTable(table, select) : table;
|
|
1092
|
+
const projected = select ? (0, import_arrow2.projectArrowTable)(table, select) : table;
|
|
1302
1093
|
return projected.numRows === 0 || limit === void 0 ? projected : projected.slice(0, limit);
|
|
1303
1094
|
};
|
|
1304
|
-
function queryArrowTable(sourceTable, options = {},
|
|
1095
|
+
function queryArrowTable(sourceTable, options = {}, execute) {
|
|
1305
1096
|
throwIfAborted(options.signal);
|
|
1306
1097
|
if (options.select !== void 0) {
|
|
1307
1098
|
if (options.columns !== void 0 || hasRelationalOperators(options) || options.join) {
|
|
1308
1099
|
throw new Error("Arrow select cannot be combined with columns or relational operators.");
|
|
1309
1100
|
}
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
return projectArrowTable(result, select);
|
|
1317
|
-
}
|
|
1318
|
-
if (options.join) {
|
|
1319
|
-
validateArrowJoinQuery(sourceTable, options);
|
|
1320
|
-
}
|
|
1321
|
-
if (options.join && hasRelationalOperatorsExceptJoin(options)) {
|
|
1322
|
-
throw new Error("Arrow joins cannot yet be combined with other relational operators.");
|
|
1323
|
-
}
|
|
1324
|
-
if (options.join && !hasRelationalOperatorsExceptJoin(options)) {
|
|
1325
|
-
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
|
+
});
|
|
1326
1107
|
}
|
|
1327
|
-
if (hasRelationalOperators(options)) {
|
|
1328
|
-
|
|
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);
|
|
1329
1118
|
}
|
|
1330
1119
|
const plan = planTableQuery2(sourceTable.schema.fields.map((field) => field.name), options);
|
|
1331
1120
|
const projection = plan.find((step) => step.kind === "project");
|
|
1332
|
-
return
|
|
1121
|
+
return (execute ?? executePortableArrowQuery)(sourceTable, {
|
|
1333
1122
|
where: options.predicate,
|
|
1334
1123
|
select: projection == null ? void 0 : projection.columns,
|
|
1335
1124
|
limit: options.limit,
|
|
1336
1125
|
signal: options.signal
|
|
1337
1126
|
});
|
|
1338
1127
|
}
|
|
1339
|
-
function queryArrowTableRelational(sourceTable, options) {
|
|
1340
|
-
var _a, _b, _c
|
|
1341
|
-
const
|
|
1342
|
-
const
|
|
1343
|
-
const
|
|
1344
|
-
const
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
const filteredTable = queryArrowTable(scannedTable, {
|
|
1350
|
-
predicate: options.predicate,
|
|
1351
|
-
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,
|
|
1352
1138
|
signal: options.signal
|
|
1353
1139
|
});
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
const childResult = queryArrowTable(childTable, {
|
|
1360
|
-
...child.query || {},
|
|
1361
|
-
columns: getUnionChildColumns(sourceColumnNames, options),
|
|
1362
|
-
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
|
|
1363
1145
|
});
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
}
|
|
1374
|
-
if ((_d = options.orderBy) == null ? void 0 : _d.length) {
|
|
1375
|
-
const orderBy = options.orderBy;
|
|
1376
|
-
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 });
|
|
1377
1155
|
}
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
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
|
|
1388
1179
|
});
|
|
1389
|
-
const limit = options.limit === void 0 ? outputRows.length : options.limit;
|
|
1390
|
-
const limitedRows = outputRows.slice(0, limit);
|
|
1391
|
-
return limitedRows.length ? convertRowsToArrowTable(limitedRows) : createEmptyRelationalResult(sourceData, outputColumns, options);
|
|
1392
1180
|
}
|
|
1393
|
-
function
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
requiredColumns.add(column);
|
|
1415
|
-
for (const aggregate of options.aggregates || []) {
|
|
1416
|
-
if (aggregate.column)
|
|
1417
|
-
requiredColumns.add(aggregate.column);
|
|
1418
|
-
}
|
|
1419
|
-
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
|
+
};
|
|
1420
1202
|
}
|
|
1421
|
-
function
|
|
1422
|
-
|
|
1423
|
-
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 };
|
|
1424
1205
|
}
|
|
1425
|
-
function
|
|
1206
|
+
function hasRelationalOperators(options) {
|
|
1426
1207
|
var _a, _b, _c, _d, _e;
|
|
1427
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));
|
|
1428
1209
|
}
|
|
1429
|
-
function queryArrowJoin(sourceTable, options) {
|
|
1430
|
-
var _a;
|
|
1210
|
+
function queryArrowJoin(sourceTable, options, executeRelational) {
|
|
1211
|
+
var _a, _b, _c, _d;
|
|
1431
1212
|
const join = options.join;
|
|
1432
|
-
if (!join)
|
|
1433
|
-
throw new Error("Arrow join query is missing a join definition.");
|
|
1434
1213
|
const childTable = (_a = options.tables) == null ? void 0 : _a[join.child.source];
|
|
1435
1214
|
if (!childTable)
|
|
1436
1215
|
throw new Error(`Arrow join source not found: ${join.child.source}`);
|
|
1437
|
-
const
|
|
1438
|
-
|
|
1439
|
-
columns: void 0,
|
|
1216
|
+
const left = executeRelational(sourceTable, {
|
|
1217
|
+
where: options.predicate,
|
|
1440
1218
|
signal: options.signal
|
|
1441
1219
|
});
|
|
1442
|
-
const
|
|
1443
|
-
|
|
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,
|
|
1444
1236
|
signal: options.signal
|
|
1445
1237
|
});
|
|
1446
|
-
const leftRows = arrowTableToRows(leftResult);
|
|
1447
|
-
const rightRows = arrowTableToRows(rightResult);
|
|
1448
|
-
const rightPrefix = `${join.child.source}.`;
|
|
1449
|
-
const defaultOutputColumns = [
|
|
1450
|
-
...sourceTable.schema.fields.map((field) => field.name),
|
|
1451
|
-
...rightResult.schema.fields.map((field) => `${rightPrefix}${field.name}`)
|
|
1452
|
-
];
|
|
1453
|
-
const rows = [];
|
|
1454
|
-
for (const leftRow of leftRows) {
|
|
1455
|
-
for (const rightRow of rightRows) {
|
|
1456
|
-
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) {
|
|
1457
|
-
rows.push({
|
|
1458
|
-
...leftRow,
|
|
1459
|
-
...Object.fromEntries(Object.entries(rightRow).map(([key, value]) => [`${rightPrefix}${key}`, value]))
|
|
1460
|
-
});
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
const outputColumns = options.columns || defaultOutputColumns;
|
|
1465
|
-
const outputRows = rows.map((row) => Object.fromEntries(outputColumns.map((column) => [column, row[column]])));
|
|
1466
|
-
const limitedRows = outputRows.slice(0, options.limit);
|
|
1467
|
-
return limitedRows.length ? convertRowsToArrowTable(limitedRows) : createEmptyRelationalResult(sourceTable, outputColumns, options, new Map(rightResult.schema.fields.map((field) => [
|
|
1468
|
-
`${rightPrefix}${field.name}`,
|
|
1469
|
-
new arrow7.Field(`${rightPrefix}${field.name}`, field.type, field.nullable, field.metadata)
|
|
1470
|
-
])));
|
|
1471
1238
|
}
|
|
1472
1239
|
function validateArrowJoinQuery(sourceTable, options) {
|
|
1473
1240
|
var _a, _b, _c;
|
|
@@ -1515,171 +1282,6 @@ function validateArrowJoinQuery(sourceTable, options) {
|
|
|
1515
1282
|
}
|
|
1516
1283
|
}
|
|
1517
1284
|
}
|
|
1518
|
-
function arrowTableToRows(data) {
|
|
1519
|
-
const columns = data.schema.fields.map((field) => ({
|
|
1520
|
-
name: field.name,
|
|
1521
|
-
vector: data.getChild(field.name)
|
|
1522
|
-
}));
|
|
1523
|
-
return Array.from({ length: data.numRows }, (_, rowIndex) => {
|
|
1524
|
-
const row = {};
|
|
1525
|
-
for (const column of columns) {
|
|
1526
|
-
if (!column.vector)
|
|
1527
|
-
throw new Error(`Arrow relational query could not read ${column.name}`);
|
|
1528
|
-
row[column.name] = column.vector.get(rowIndex);
|
|
1529
|
-
}
|
|
1530
|
-
return row;
|
|
1531
|
-
});
|
|
1532
|
-
}
|
|
1533
|
-
function evaluateRelationalExpression(expression, row) {
|
|
1534
|
-
const definition = expression.expression;
|
|
1535
|
-
if (definition.op === "literal")
|
|
1536
|
-
return definition.value;
|
|
1537
|
-
if (definition.op === "column")
|
|
1538
|
-
return row[definition.column];
|
|
1539
|
-
const left = row[definition.left];
|
|
1540
|
-
const right = row[definition.right];
|
|
1541
|
-
if (left === null || left === void 0 || right === null || right === void 0)
|
|
1542
|
-
return null;
|
|
1543
|
-
if (typeof left !== "number" || typeof right !== "number") {
|
|
1544
|
-
throw new Error(`Arrow relational expression ${expression.name} requires numeric operands.`);
|
|
1545
|
-
}
|
|
1546
|
-
switch (definition.op) {
|
|
1547
|
-
case "add":
|
|
1548
|
-
return left + right;
|
|
1549
|
-
case "subtract":
|
|
1550
|
-
return left - right;
|
|
1551
|
-
case "multiply":
|
|
1552
|
-
return left * right;
|
|
1553
|
-
case "divide":
|
|
1554
|
-
return right === 0 ? null : left / right;
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
function compareRows(left, right, orderBy) {
|
|
1558
|
-
for (const key of orderBy) {
|
|
1559
|
-
const leftValue = left[key.column];
|
|
1560
|
-
const rightValue = right[key.column];
|
|
1561
|
-
const nulls = key.nulls || "last";
|
|
1562
|
-
if (leftValue === null || leftValue === void 0 || rightValue === null || rightValue === void 0) {
|
|
1563
|
-
if (leftValue === rightValue)
|
|
1564
|
-
continue;
|
|
1565
|
-
const nullResult = leftValue === null || leftValue === void 0 ? -1 : 1;
|
|
1566
|
-
return nulls === "first" ? nullResult : -nullResult;
|
|
1567
|
-
}
|
|
1568
|
-
const result = compareSortValues(leftValue, rightValue);
|
|
1569
|
-
if (result)
|
|
1570
|
-
return (key.direction === "desc" ? -1 : 1) * result;
|
|
1571
|
-
}
|
|
1572
|
-
return 0;
|
|
1573
|
-
}
|
|
1574
|
-
function compareSortValues(left, right) {
|
|
1575
|
-
if (left instanceof Date && right instanceof Date)
|
|
1576
|
-
return compareArrowQueryNumbers(left.getTime(), right.getTime());
|
|
1577
|
-
if (typeof left === "bigint" && typeof right === "bigint")
|
|
1578
|
-
return left === right ? 0 : left < right ? -1 : 1;
|
|
1579
|
-
if (typeof left === "number" && typeof right === "number")
|
|
1580
|
-
return compareArrowQueryNumbers(left, right);
|
|
1581
|
-
if (typeof left === "string" && typeof right === "string")
|
|
1582
|
-
return left === right ? 0 : left < right ? -1 : 1;
|
|
1583
|
-
if (typeof left === "boolean" && typeof right === "boolean")
|
|
1584
|
-
return Number(left) - Number(right);
|
|
1585
|
-
throw new Error(`Arrow relational order cannot compare ${getArrowQueryValueType(left)} with ${getArrowQueryValueType(right)}.`);
|
|
1586
|
-
}
|
|
1587
|
-
function aggregateRows(rows, groupBy, aggregates) {
|
|
1588
|
-
const groups = /* @__PURE__ */ new Map();
|
|
1589
|
-
for (const row of rows) {
|
|
1590
|
-
const key = serializeGroupKey(groupBy.map((column) => row[column]));
|
|
1591
|
-
const group = groups.get(key) || [];
|
|
1592
|
-
group.push(row);
|
|
1593
|
-
groups.set(key, group);
|
|
1594
|
-
}
|
|
1595
|
-
if (!groupBy.length && !rows.length)
|
|
1596
|
-
groups.set("[]", []);
|
|
1597
|
-
return [...groups.values()].map((group) => {
|
|
1598
|
-
var _a;
|
|
1599
|
-
const output = {};
|
|
1600
|
-
for (const column of groupBy)
|
|
1601
|
-
output[column] = ((_a = group[0]) == null ? void 0 : _a[column]) ?? null;
|
|
1602
|
-
for (const aggregate of aggregates)
|
|
1603
|
-
output[aggregate.name] = evaluateAggregate(aggregate, group);
|
|
1604
|
-
return output;
|
|
1605
|
-
});
|
|
1606
|
-
}
|
|
1607
|
-
function serializeGroupKey(values) {
|
|
1608
|
-
return values.map((value) => {
|
|
1609
|
-
if (value === null || value === void 0)
|
|
1610
|
-
return "null:";
|
|
1611
|
-
if (value instanceof Date)
|
|
1612
|
-
return `date:${value.getTime()}`;
|
|
1613
|
-
if (value instanceof Uint8Array)
|
|
1614
|
-
return `bytes:${Array.from(value).join(".")}`;
|
|
1615
|
-
return `${typeof value}:${String(value)}`;
|
|
1616
|
-
}).join("");
|
|
1617
|
-
}
|
|
1618
|
-
function createEmptyRelationalResult(sourceData, outputColumns, options, additionalFields) {
|
|
1619
|
-
const sourceFields = new Map(sourceData.schema.fields.map((field) => [field.name, field]));
|
|
1620
|
-
const expressions = new Map((options.expressions || []).map((expression) => [expression.name, expression]));
|
|
1621
|
-
const aggregates = new Map((options.aggregates || []).map((aggregate) => [aggregate.name, aggregate]));
|
|
1622
|
-
const fields = outputColumns.map((columnName) => {
|
|
1623
|
-
const sourceField = sourceFields.get(columnName);
|
|
1624
|
-
if (sourceField)
|
|
1625
|
-
return sourceField;
|
|
1626
|
-
const additionalField = additionalFields == null ? void 0 : additionalFields.get(columnName);
|
|
1627
|
-
if (additionalField)
|
|
1628
|
-
return additionalField;
|
|
1629
|
-
const expression = expressions.get(columnName);
|
|
1630
|
-
if (expression)
|
|
1631
|
-
return new arrow7.Field(columnName, getExpressionType(expression, sourceFields), true);
|
|
1632
|
-
const aggregate = aggregates.get(columnName);
|
|
1633
|
-
if (aggregate)
|
|
1634
|
-
return new arrow7.Field(columnName, getAggregateType(aggregate, sourceFields), true);
|
|
1635
|
-
return new arrow7.Field(columnName, new arrow7.Utf8(), true);
|
|
1636
|
-
});
|
|
1637
|
-
const columns = {};
|
|
1638
|
-
for (const field of fields)
|
|
1639
|
-
columns[field.name] = arrow7.vectorFromArray([], field.type);
|
|
1640
|
-
return new arrow7.Table(new arrow7.Schema(fields), columns);
|
|
1641
|
-
}
|
|
1642
|
-
function getExpressionType(expression, sourceFields) {
|
|
1643
|
-
var _a;
|
|
1644
|
-
if (expression.expression.op === "literal") {
|
|
1645
|
-
const value = expression.expression.value;
|
|
1646
|
-
if (typeof value === "boolean")
|
|
1647
|
-
return new arrow7.Bool();
|
|
1648
|
-
if (typeof value === "number")
|
|
1649
|
-
return new arrow7.Float64();
|
|
1650
|
-
return new arrow7.Utf8();
|
|
1651
|
-
}
|
|
1652
|
-
if (expression.expression.op === "column") {
|
|
1653
|
-
return ((_a = sourceFields.get(expression.expression.column)) == null ? void 0 : _a.type) || new arrow7.Utf8();
|
|
1654
|
-
}
|
|
1655
|
-
return new arrow7.Float64();
|
|
1656
|
-
}
|
|
1657
|
-
function getAggregateType(aggregate, sourceFields) {
|
|
1658
|
-
var _a;
|
|
1659
|
-
if (aggregate.function === "count")
|
|
1660
|
-
return new arrow7.Int32();
|
|
1661
|
-
return aggregate.column ? ((_a = sourceFields.get(aggregate.column)) == null ? void 0 : _a.type) || new arrow7.Float64() : new arrow7.Float64();
|
|
1662
|
-
}
|
|
1663
|
-
function evaluateAggregate(aggregate, rows) {
|
|
1664
|
-
if (aggregate.function === "count")
|
|
1665
|
-
return aggregate.column ? rows.filter((row) => row[aggregate.column] != null).length : rows.length;
|
|
1666
|
-
const values = rows.map((row) => row[aggregate.column]).filter((value) => value != null);
|
|
1667
|
-
if (!values.length)
|
|
1668
|
-
return null;
|
|
1669
|
-
if (!values.every((value) => typeof value === "number"))
|
|
1670
|
-
throw new Error(`Arrow aggregate ${aggregate.function} requires numeric values.`);
|
|
1671
|
-
const numericValues = values;
|
|
1672
|
-
switch (aggregate.function) {
|
|
1673
|
-
case "sum":
|
|
1674
|
-
return numericValues.reduce((sum, value) => sum + value, 0);
|
|
1675
|
-
case "avg":
|
|
1676
|
-
return numericValues.reduce((sum, value) => sum + value, 0) / numericValues.length;
|
|
1677
|
-
case "min":
|
|
1678
|
-
return Math.min(...numericValues);
|
|
1679
|
-
case "max":
|
|
1680
|
-
return Math.max(...numericValues);
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
1285
|
function throwIfAborted(signal) {
|
|
1684
1286
|
if (signal == null ? void 0 : signal.aborted) {
|
|
1685
1287
|
const error = new Error("Arrow query was aborted.");
|
|
@@ -1842,7 +1444,7 @@ var FederatedTableScanSource = class {
|
|
|
1842
1444
|
sourceRowsRead += batchLength;
|
|
1843
1445
|
if (batchLength <= 0)
|
|
1844
1446
|
continue;
|
|
1845
|
-
const physicalTable = native ? new
|
|
1447
|
+
const physicalTable = native ? new arrow5.Table(input.schema, [input]) : convertTableToArrow2(input.schema ? input : { ...input, schema: resolvedSource.metadata.schema });
|
|
1846
1448
|
const sourceResult = queryArrowTable(physicalTable, {
|
|
1847
1449
|
predicate: sourceResidualPredicate,
|
|
1848
1450
|
limit: Number.isFinite(sourceRemaining) ? sourceRemaining : void 0,
|
|
@@ -1881,7 +1483,7 @@ var FederatedTableScanSource = class {
|
|
|
1881
1483
|
for (const recordBatch of result.batches) {
|
|
1882
1484
|
const metadata = new Map(native && resultLength === batchLength ? input.metadata : void 0);
|
|
1883
1485
|
metadata.set("loaders.gl.federation", JSON.stringify(provenance));
|
|
1884
|
-
yield new
|
|
1486
|
+
yield new arrow5.RecordBatch(recordBatch.schema, recordBatch.data, metadata);
|
|
1885
1487
|
}
|
|
1886
1488
|
remaining -= resultLength;
|
|
1887
1489
|
}
|
|
@@ -2086,7 +1688,7 @@ function createSourceReadOptions(source, requiredOutputColumns, remaining, optio
|
|
|
2086
1688
|
const sourceResidualPredicate = getSourceResidualPredicate(source);
|
|
2087
1689
|
const requiredSourceColumns = requiredOutputColumns.map((outputName) => source.sourceNameByOutputName.get(outputName)).filter((sourceName) => Boolean(sourceName));
|
|
2088
1690
|
if (sourceResidualPredicate) {
|
|
2089
|
-
requiredSourceColumns.push(...getColumnarPredicateColumns(sourceResidualPredicate));
|
|
1691
|
+
requiredSourceColumns.push(...(0, import_columnar_predicate2.getColumnarPredicateColumns)(sourceResidualPredicate));
|
|
2090
1692
|
}
|
|
2091
1693
|
if (!requiredSourceColumns.length) {
|
|
2092
1694
|
requiredSourceColumns.push(source.fields[0].sourceName);
|
|
@@ -2114,9 +1716,9 @@ function createCanonicalArrowTable(schema, source, physicalTable) {
|
|
|
2114
1716
|
const sourceName = source.sourceNameByOutputName.get(field.name);
|
|
2115
1717
|
const vector = sourceName ? physicalTable.getChild(sourceName) : null;
|
|
2116
1718
|
const mappedField = source.fields.find((sourceField) => sourceField.outputName === field.name);
|
|
2117
|
-
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);
|
|
2118
1720
|
}
|
|
2119
|
-
return new
|
|
1721
|
+
return new arrow5.Table(arrowSchema, columns);
|
|
2120
1722
|
}
|
|
2121
1723
|
function createSourceTelemetry(options) {
|
|
2122
1724
|
var _a;
|