@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
|
@@ -5,6 +5,14 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res, err) => function __init() {
|
|
9
|
+
if (err) throw err[0];
|
|
10
|
+
try {
|
|
11
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
throw err = [e], e;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
8
16
|
var __export = (target, all) => {
|
|
9
17
|
for (var name in all)
|
|
10
18
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -27,1230 +35,611 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
35
|
));
|
|
28
36
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
37
|
|
|
30
|
-
//
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
// src/loader-utils/lib/scan-utils/columnar-predicate.ts
|
|
39
|
+
var import_columnar_predicate, import_columnar_predicate2;
|
|
40
|
+
var init_columnar_predicate = __esm({
|
|
41
|
+
"src/loader-utils/lib/scan-utils/columnar-predicate.ts"() {
|
|
42
|
+
"use strict";
|
|
43
|
+
import_columnar_predicate = require("@math.gl/sql/columnar-predicate");
|
|
44
|
+
import_columnar_predicate2 = require("@math.gl/sql/columnar-predicate");
|
|
45
|
+
}
|
|
36
46
|
});
|
|
37
|
-
module.exports = __toCommonJS(vector_table_scan_source_exports);
|
|
38
47
|
|
|
39
|
-
// src/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
// src/loader-utils/lib/scan-utils/scan-query-metadata.ts
|
|
49
|
+
function createScanQueryMetadata(options) {
|
|
50
|
+
validateScanExecutionSupport(options.queryType, options.execution);
|
|
51
|
+
const schema = Object.freeze({
|
|
52
|
+
fields: Object.freeze(
|
|
53
|
+
options.schema.fields.map(
|
|
54
|
+
(field) => Object.freeze({ ...field, metadata: Object.freeze({ ...field.metadata }) })
|
|
55
|
+
)
|
|
56
|
+
),
|
|
57
|
+
metadata: Object.freeze({ ...options.schema.metadata })
|
|
58
|
+
});
|
|
59
|
+
const columns = schema.fields.map(
|
|
60
|
+
(field) => {
|
|
61
|
+
var _a;
|
|
62
|
+
return Object.freeze({
|
|
63
|
+
name: field.name,
|
|
64
|
+
type: field.type,
|
|
65
|
+
nullable: field.nullable !== false,
|
|
66
|
+
role: ((_a = options.columnRoles) == null ? void 0 : _a[field.name]) || "attribute",
|
|
67
|
+
title: getNonEmptyMetadataValue(field.metadata, "title"),
|
|
68
|
+
description: getNonEmptyMetadataValue(field.metadata, "description"),
|
|
69
|
+
metadata: field.metadata || Object.freeze({})
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
const queryCapabilities = Object.freeze({ ...options.capabilities });
|
|
74
|
+
return Object.freeze({
|
|
75
|
+
sourceType: options.sourceType,
|
|
76
|
+
queryType: options.queryType,
|
|
77
|
+
execution: Object.freeze({ ...options.execution }),
|
|
78
|
+
name: options.name,
|
|
79
|
+
description: options.description,
|
|
80
|
+
schema,
|
|
81
|
+
columns: Object.freeze(columns),
|
|
82
|
+
capabilities: queryCapabilities,
|
|
83
|
+
queryCapabilities,
|
|
84
|
+
...options.hasDefaultRowWindow ? { hasDefaultRowWindow: true } : {},
|
|
85
|
+
spatial: options.spatial ? Object.freeze({
|
|
86
|
+
...options.spatial,
|
|
87
|
+
bounds: options.spatial.bounds ? Object.freeze({
|
|
88
|
+
minimum: Object.freeze([...options.spatial.bounds.minimum]),
|
|
89
|
+
maximum: Object.freeze([...options.spatial.bounds.maximum])
|
|
90
|
+
}) : void 0,
|
|
91
|
+
coordinateReferenceSystems: options.spatial.coordinateReferenceSystems ? Object.freeze([...options.spatial.coordinateReferenceSystems]) : void 0,
|
|
92
|
+
spatialReference: options.spatial.spatialReference ? (0, import_crs.createSpatialReference)(options.spatial.spatialReference) : void 0
|
|
93
|
+
}) : void 0,
|
|
94
|
+
statistics: options.statistics ? Object.freeze({ ...options.statistics }) : void 0,
|
|
95
|
+
levels: options.levels ? Object.freeze(
|
|
96
|
+
options.levels.map(
|
|
97
|
+
(level) => Object.freeze({
|
|
98
|
+
...level,
|
|
99
|
+
scale: level.scale ? Object.freeze([...level.scale]) : void 0
|
|
100
|
+
})
|
|
101
|
+
)
|
|
102
|
+
) : void 0
|
|
103
|
+
});
|
|
43
104
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
105
|
+
function validateScanExecutionSupport(queryType, execution) {
|
|
106
|
+
if (execution.status === "metadata-only") {
|
|
107
|
+
if (!execution.reason.trim()) {
|
|
108
|
+
throw new Error("Metadata-only scan support requires a concrete reason");
|
|
109
|
+
}
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const validMethods = {
|
|
113
|
+
table: ["read", "query"],
|
|
114
|
+
raster: ["getRaster"],
|
|
115
|
+
"point-cloud": ["scan"]
|
|
48
116
|
};
|
|
117
|
+
if (!validMethods[queryType].includes(execution.method)) {
|
|
118
|
+
throw new Error(
|
|
119
|
+
`Scan execution method "${execution.method}" is not valid for ${queryType} queries`
|
|
120
|
+
);
|
|
121
|
+
}
|
|
49
122
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
deserializeArrowMetadata(schema.metadata)
|
|
54
|
-
);
|
|
123
|
+
function getNonEmptyMetadataValue(metadata, key) {
|
|
124
|
+
const value = metadata == null ? void 0 : metadata[key];
|
|
125
|
+
return value || void 0;
|
|
55
126
|
}
|
|
56
|
-
|
|
57
|
-
|
|
127
|
+
var import_crs;
|
|
128
|
+
var init_scan_query_metadata = __esm({
|
|
129
|
+
"src/loader-utils/lib/scan-utils/scan-query-metadata.ts"() {
|
|
130
|
+
"use strict";
|
|
131
|
+
import_crs = require("@math.gl/geospatial/crs");
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// src/loader-utils/lib/scan-utils/table-query.ts
|
|
136
|
+
function planTableQuery(sourceColumnNames, options = {}) {
|
|
137
|
+
validateTableQueryOptions(sourceColumnNames, options);
|
|
138
|
+
const outputColumnNames = options.columns ? [...options.columns] : [...sourceColumnNames];
|
|
139
|
+
const predicateColumnNames = options.predicate ? (0, import_columnar_predicate2.getColumnarPredicateColumns)(options.predicate) : [];
|
|
140
|
+
const requiredColumnNames = /* @__PURE__ */ new Set([...outputColumnNames, ...predicateColumnNames]);
|
|
141
|
+
const scanColumnNames = sourceColumnNames.filter(
|
|
142
|
+
(columnName) => requiredColumnNames.has(columnName)
|
|
143
|
+
);
|
|
144
|
+
const steps = [
|
|
145
|
+
Object.freeze({ kind: "scan", columns: Object.freeze(scanColumnNames) })
|
|
146
|
+
];
|
|
147
|
+
if (options.predicate) {
|
|
148
|
+
steps.push(Object.freeze({ kind: "filter", predicate: options.predicate }));
|
|
149
|
+
}
|
|
150
|
+
steps.push(Object.freeze({ kind: "project", columns: Object.freeze(outputColumnNames) }));
|
|
151
|
+
if (options.limit !== void 0) {
|
|
152
|
+
steps.push(Object.freeze({ kind: "limit", limit: options.limit }));
|
|
153
|
+
}
|
|
154
|
+
return Object.freeze(steps);
|
|
58
155
|
}
|
|
59
|
-
function
|
|
60
|
-
|
|
156
|
+
function validateTableQueryOptions(sourceColumnNames, options) {
|
|
157
|
+
const availableColumnNames = new Set(sourceColumnNames);
|
|
158
|
+
const outputColumnNames = options.columns ?? sourceColumnNames;
|
|
159
|
+
const seenColumnNames = /* @__PURE__ */ new Set();
|
|
160
|
+
for (const columnName of outputColumnNames) {
|
|
161
|
+
if (!availableColumnNames.has(columnName)) {
|
|
162
|
+
throw new Error(`Table query column not found: ${columnName}`);
|
|
163
|
+
}
|
|
164
|
+
if (seenColumnNames.has(columnName)) {
|
|
165
|
+
throw new Error(`Table query column was selected more than once: ${columnName}`);
|
|
166
|
+
}
|
|
167
|
+
seenColumnNames.add(columnName);
|
|
168
|
+
}
|
|
169
|
+
validateTableQueryLimit(options.limit);
|
|
170
|
+
if (options.predicate) {
|
|
171
|
+
(0, import_columnar_predicate2.validateColumnarPredicate)(options.predicate, availableColumnNames);
|
|
172
|
+
}
|
|
61
173
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
nullable: field.nullable,
|
|
67
|
-
metadata: serializeArrowMetadata(field.metadata)
|
|
68
|
-
};
|
|
174
|
+
function validateTableQueryLimit(limit) {
|
|
175
|
+
if (limit !== void 0 && (!Number.isSafeInteger(limit) || limit < 0)) {
|
|
176
|
+
throw new Error("Table query limit must be a non-negative safe integer.");
|
|
177
|
+
}
|
|
69
178
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
179
|
+
var init_table_query = __esm({
|
|
180
|
+
"src/loader-utils/lib/scan-utils/table-query.ts"() {
|
|
181
|
+
"use strict";
|
|
182
|
+
init_columnar_predicate();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// src/loader-utils/lib/scan-utils/relational-query.ts
|
|
187
|
+
function planRelationalQuery(sourceColumnNames, options = {}) {
|
|
188
|
+
var _a, _b, _c, _d, _e, _f;
|
|
189
|
+
const available = new Set(sourceColumnNames);
|
|
190
|
+
const expressionNames = /* @__PURE__ */ new Set();
|
|
191
|
+
for (const expression of options.expressions || []) {
|
|
192
|
+
if (!expression.name) throw new Error("Relational expression names must be non-empty.");
|
|
193
|
+
if (available.has(expression.name) || expressionNames.has(expression.name)) {
|
|
194
|
+
throw new Error(`Relational expression duplicates column: ${expression.name}`);
|
|
195
|
+
}
|
|
196
|
+
expressionNames.add(expression.name);
|
|
197
|
+
}
|
|
198
|
+
const aggregateNames = new Set((options.aggregates || []).map((aggregate) => aggregate.name));
|
|
199
|
+
const requiredColumns = /* @__PURE__ */ new Set();
|
|
200
|
+
const availableColumns = new Set(sourceColumnNames);
|
|
201
|
+
for (const expression of options.expressions || []) {
|
|
202
|
+
const definition = expression.expression;
|
|
203
|
+
if (definition.op === "column") {
|
|
204
|
+
validateRelationalColumnReference(definition.column, availableColumns);
|
|
205
|
+
if (available.has(definition.column)) requiredColumns.add(definition.column);
|
|
206
|
+
}
|
|
207
|
+
if ("left" in definition) {
|
|
208
|
+
validateRelationalColumnReference(definition.left, availableColumns);
|
|
209
|
+
validateRelationalColumnReference(definition.right, availableColumns);
|
|
210
|
+
if (available.has(definition.left)) requiredColumns.add(definition.left);
|
|
211
|
+
if (available.has(definition.right)) requiredColumns.add(definition.right);
|
|
212
|
+
}
|
|
213
|
+
availableColumns.add(expression.name);
|
|
214
|
+
}
|
|
215
|
+
for (const key of options.orderBy || []) requiredColumns.add(key.column);
|
|
216
|
+
for (const key of options.groupBy || []) requiredColumns.add(key);
|
|
217
|
+
for (const aggregate of options.aggregates || []) {
|
|
218
|
+
if (aggregate.column) requiredColumns.add(aggregate.column);
|
|
219
|
+
}
|
|
220
|
+
const outputColumns = (_a = options.columns) == null ? void 0 : _a.filter(
|
|
221
|
+
(column) => !expressionNames.has(column) && !aggregateNames.has(column)
|
|
76
222
|
);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
223
|
+
const tablePlan = [
|
|
224
|
+
...planTableQuery(sourceColumnNames, {
|
|
225
|
+
...options,
|
|
226
|
+
columns: outputColumns,
|
|
227
|
+
predicate: options.predicate
|
|
228
|
+
})
|
|
229
|
+
];
|
|
230
|
+
const scanStep = tablePlan[0];
|
|
231
|
+
if ((scanStep == null ? void 0 : scanStep.kind) === "scan") {
|
|
232
|
+
const scanColumns = new Set(scanStep.columns);
|
|
233
|
+
for (const column of requiredColumns) {
|
|
234
|
+
if (available.has(column)) scanColumns.add(column);
|
|
235
|
+
}
|
|
236
|
+
tablePlan[0] = Object.freeze({ kind: "scan", columns: Object.freeze([...scanColumns]) });
|
|
81
237
|
}
|
|
82
|
-
|
|
83
|
-
|
|
238
|
+
for (const expression of expressionNames) available.add(expression);
|
|
239
|
+
for (const aggregate of aggregateNames) available.add(aggregate);
|
|
240
|
+
for (const key of options.orderBy || []) {
|
|
241
|
+
if (!available.has(key.column))
|
|
242
|
+
throw new Error(`Relational order column not found: ${key.column}`);
|
|
84
243
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return {
|
|
88
|
-
type: "large-list",
|
|
89
|
-
children: [serializeArrowField(largeListType.valueField)]
|
|
90
|
-
};
|
|
244
|
+
for (const key of options.groupBy || []) {
|
|
245
|
+
if (!available.has(key)) throw new Error(`Relational group column not found: ${key}`);
|
|
91
246
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
type: "fixed-size-binary",
|
|
100
|
-
byteWidth: arrowType.byteWidth
|
|
101
|
-
};
|
|
102
|
-
case arrow.Bool:
|
|
103
|
-
return "bool";
|
|
104
|
-
case arrow.Int:
|
|
105
|
-
const intType = arrowType;
|
|
106
|
-
return `${intType.isSigned ? "" : "u"}int${intType.bitWidth}`;
|
|
107
|
-
case arrow.Int8:
|
|
108
|
-
return "int8";
|
|
109
|
-
case arrow.Int16:
|
|
110
|
-
return "int16";
|
|
111
|
-
case arrow.Int32:
|
|
112
|
-
return "int32";
|
|
113
|
-
case arrow.Int64:
|
|
114
|
-
return "int64";
|
|
115
|
-
case arrow.Uint8:
|
|
116
|
-
return "uint8";
|
|
117
|
-
case arrow.Uint16:
|
|
118
|
-
return "uint16";
|
|
119
|
-
case arrow.Uint32:
|
|
120
|
-
return "uint32";
|
|
121
|
-
case arrow.Uint64:
|
|
122
|
-
return "uint64";
|
|
123
|
-
case arrow.Float:
|
|
124
|
-
const precision = arrowType.precision;
|
|
125
|
-
switch (precision) {
|
|
126
|
-
case arrow.Precision.HALF:
|
|
127
|
-
return "float16";
|
|
128
|
-
case arrow.Precision.SINGLE:
|
|
129
|
-
return "float32";
|
|
130
|
-
case arrow.Precision.DOUBLE:
|
|
131
|
-
return "float64";
|
|
132
|
-
default:
|
|
133
|
-
return "float16";
|
|
134
|
-
}
|
|
135
|
-
case arrow.Float16:
|
|
136
|
-
return "float16";
|
|
137
|
-
case arrow.Float32:
|
|
138
|
-
return "float32";
|
|
139
|
-
case arrow.Float64:
|
|
140
|
-
return "float64";
|
|
141
|
-
case arrow.Utf8:
|
|
142
|
-
return "utf8";
|
|
143
|
-
case arrow.Decimal:
|
|
144
|
-
const decimal = arrowType;
|
|
145
|
-
return {
|
|
146
|
-
type: "decimal",
|
|
147
|
-
bitWidth: decimal.bitWidth,
|
|
148
|
-
precision: decimal.precision,
|
|
149
|
-
scale: decimal.scale
|
|
150
|
-
};
|
|
151
|
-
case arrow.Date_:
|
|
152
|
-
const dateUnit = arrowType.unit;
|
|
153
|
-
return dateUnit === arrow.DateUnit.DAY ? "date-day" : "date-millisecond";
|
|
154
|
-
case arrow.DateDay:
|
|
155
|
-
return "date-day";
|
|
156
|
-
case arrow.DateMillisecond:
|
|
157
|
-
return "date-millisecond";
|
|
158
|
-
case arrow.Time:
|
|
159
|
-
const timeUnit = arrowType.unit;
|
|
160
|
-
switch (timeUnit) {
|
|
161
|
-
case arrow.TimeUnit.SECOND:
|
|
162
|
-
return "time-second";
|
|
163
|
-
case arrow.TimeUnit.MILLISECOND:
|
|
164
|
-
return "time-millisecond";
|
|
165
|
-
case arrow.TimeUnit.MICROSECOND:
|
|
166
|
-
return "time-microsecond";
|
|
167
|
-
case arrow.TimeUnit.NANOSECOND:
|
|
168
|
-
return "time-nanosecond";
|
|
169
|
-
default:
|
|
170
|
-
return "time-second";
|
|
171
|
-
}
|
|
172
|
-
case arrow.TimeMillisecond:
|
|
173
|
-
return "time-millisecond";
|
|
174
|
-
case arrow.TimeSecond:
|
|
175
|
-
return "time-second";
|
|
176
|
-
case arrow.TimeMicrosecond:
|
|
177
|
-
return "time-microsecond";
|
|
178
|
-
case arrow.TimeNanosecond:
|
|
179
|
-
return "time-nanosecond";
|
|
180
|
-
case arrow.Timestamp:
|
|
181
|
-
const timeStampUnit = arrowType.unit;
|
|
182
|
-
switch (timeStampUnit) {
|
|
183
|
-
case arrow.TimeUnit.SECOND:
|
|
184
|
-
return "timestamp-second";
|
|
185
|
-
case arrow.TimeUnit.MILLISECOND:
|
|
186
|
-
return "timestamp-millisecond";
|
|
187
|
-
case arrow.TimeUnit.MICROSECOND:
|
|
188
|
-
return "timestamp-microsecond";
|
|
189
|
-
case arrow.TimeUnit.NANOSECOND:
|
|
190
|
-
return "timestamp-nanosecond";
|
|
191
|
-
default:
|
|
192
|
-
return "timestamp-second";
|
|
193
|
-
}
|
|
194
|
-
case arrow.TimestampSecond:
|
|
195
|
-
return "timestamp-second";
|
|
196
|
-
case arrow.TimestampMillisecond:
|
|
197
|
-
return "timestamp-millisecond";
|
|
198
|
-
case arrow.TimestampMicrosecond:
|
|
199
|
-
return "timestamp-microsecond";
|
|
200
|
-
case arrow.TimestampNanosecond:
|
|
201
|
-
return "timestamp-nanosecond";
|
|
202
|
-
case arrow.Interval:
|
|
203
|
-
const intervalUnit = arrowType.unit;
|
|
204
|
-
switch (intervalUnit) {
|
|
205
|
-
case arrow.IntervalUnit.DAY_TIME:
|
|
206
|
-
return "interval-daytime";
|
|
207
|
-
case arrow.IntervalUnit.YEAR_MONTH:
|
|
208
|
-
return "interval-yearmonth";
|
|
209
|
-
default:
|
|
210
|
-
return "interval-daytime";
|
|
211
|
-
}
|
|
212
|
-
case arrow.IntervalDayTime:
|
|
213
|
-
return "interval-daytime";
|
|
214
|
-
case arrow.IntervalYearMonth:
|
|
215
|
-
return "interval-yearmonth";
|
|
216
|
-
case arrow.Map_:
|
|
217
|
-
const mapType = arrowType;
|
|
218
|
-
return {
|
|
219
|
-
type: "map",
|
|
220
|
-
keysSorted: mapType.keysSorted,
|
|
221
|
-
children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
|
|
222
|
-
};
|
|
223
|
-
case arrow.List:
|
|
224
|
-
const listType = arrowType;
|
|
225
|
-
const listField = listType.valueField;
|
|
226
|
-
return {
|
|
227
|
-
type: "list",
|
|
228
|
-
children: [serializeArrowField(listField)]
|
|
229
|
-
};
|
|
230
|
-
case arrow.FixedSizeList:
|
|
231
|
-
const fixedSizeList = arrowType;
|
|
232
|
-
return {
|
|
233
|
-
type: "fixed-size-list",
|
|
234
|
-
listSize: fixedSizeList.listSize,
|
|
235
|
-
children: [serializeArrowField(fixedSizeList.children[0])]
|
|
236
|
-
};
|
|
237
|
-
case arrow.Struct:
|
|
238
|
-
const structType = arrowType;
|
|
239
|
-
return {
|
|
240
|
-
type: "struct",
|
|
241
|
-
children: structType.children.map((arrowField) => serializeArrowField(arrowField))
|
|
242
|
-
};
|
|
243
|
-
case arrow.SparseUnion:
|
|
244
|
-
case arrow.DenseUnion:
|
|
245
|
-
const unionType = arrowType;
|
|
246
|
-
return {
|
|
247
|
-
type: unionType instanceof arrow.DenseUnion ? "dense-union" : "sparse-union",
|
|
248
|
-
typeIds: unionType.typeIds,
|
|
249
|
-
children: unionType.children.map((arrowField) => serializeArrowField(arrowField)),
|
|
250
|
-
typeIdToChildIndex: { ...unionType.typeIdToChildIndex }
|
|
251
|
-
};
|
|
252
|
-
case arrow.Dictionary:
|
|
253
|
-
const dictionaryType = arrowType;
|
|
254
|
-
return {
|
|
255
|
-
type: "dictionary",
|
|
256
|
-
id: dictionaryType.id,
|
|
257
|
-
indices: serializeArrowDictionaryKeyType(dictionaryType.indices),
|
|
258
|
-
dictionary: serializeArrowType(dictionaryType.dictionary),
|
|
259
|
-
isOrdered: dictionaryType.isOrdered
|
|
260
|
-
};
|
|
261
|
-
default:
|
|
262
|
-
throw new Error(`arrow type not supported: ${arrowType.constructor.name}`);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
function deserializeArrowType(dataType, options) {
|
|
266
|
-
if (typeof dataType === "object") {
|
|
267
|
-
switch (dataType.type) {
|
|
268
|
-
case "decimal":
|
|
269
|
-
return new arrow.Decimal(dataType.scale, dataType.precision, dataType.bitWidth);
|
|
270
|
-
case "map": {
|
|
271
|
-
const children = dataType.children.map(
|
|
272
|
-
(arrowField) => deserializeArrowField(arrowField, options)
|
|
273
|
-
);
|
|
274
|
-
return new arrow.Map_(children[0], dataType.keysSorted);
|
|
275
|
-
}
|
|
276
|
-
case "list": {
|
|
277
|
-
const field = deserializeArrowField(dataType.children[0], options);
|
|
278
|
-
return new arrow.List(field);
|
|
279
|
-
}
|
|
280
|
-
case "large-list": {
|
|
281
|
-
const field = deserializeArrowField(dataType.children[0], options);
|
|
282
|
-
const LargeList = getOptionalArrowConstructor("LargeList");
|
|
283
|
-
if (!LargeList) {
|
|
284
|
-
throw new Error(
|
|
285
|
-
"LargeList requires an Apache Arrow runtime that exports the LargeList constructor"
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
return new LargeList(field);
|
|
289
|
-
}
|
|
290
|
-
case "fixed-size-list": {
|
|
291
|
-
const child = deserializeArrowField(dataType.children[0], options);
|
|
292
|
-
return new arrow.FixedSizeList(dataType.listSize, child);
|
|
293
|
-
}
|
|
294
|
-
case "fixed-size-binary":
|
|
295
|
-
return new arrow.FixedSizeBinary(dataType.byteWidth);
|
|
296
|
-
case "struct": {
|
|
297
|
-
const children = dataType.children.map(
|
|
298
|
-
(arrowField) => deserializeArrowField(arrowField, options)
|
|
299
|
-
);
|
|
300
|
-
return new arrow.Struct(children);
|
|
301
|
-
}
|
|
302
|
-
case "sparse-union":
|
|
303
|
-
case "dense-union": {
|
|
304
|
-
const children = dataType.children.map(
|
|
305
|
-
(arrowField) => deserializeArrowField(arrowField, options)
|
|
306
|
-
);
|
|
307
|
-
return dataType.type === "dense-union" ? new arrow.DenseUnion(dataType.typeIds, children) : new arrow.SparseUnion(dataType.typeIds, children);
|
|
308
|
-
}
|
|
309
|
-
case "dictionary": {
|
|
310
|
-
return new arrow.Dictionary(
|
|
311
|
-
deserializeArrowType(dataType.dictionary, options),
|
|
312
|
-
deserializeArrowDictionaryKeyType(dataType.indices),
|
|
313
|
-
dataType.id,
|
|
314
|
-
dataType.isOrdered
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
default:
|
|
318
|
-
throw new Error("array type not supported");
|
|
247
|
+
for (const aggregate of options.aggregates || []) {
|
|
248
|
+
if (!aggregate.name) throw new Error("Relational aggregate names must be non-empty.");
|
|
249
|
+
if (aggregate.function !== "count" && !aggregate.column) {
|
|
250
|
+
throw new Error(`Relational aggregate ${aggregate.function} requires a column.`);
|
|
251
|
+
}
|
|
252
|
+
if (aggregate.column && !available.has(aggregate.column)) {
|
|
253
|
+
throw new Error(`Relational aggregate column not found: ${aggregate.column}`);
|
|
319
254
|
}
|
|
320
255
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
case "int8":
|
|
331
|
-
return new arrow.Int8();
|
|
332
|
-
case "int16":
|
|
333
|
-
return new arrow.Int16();
|
|
334
|
-
case "int32":
|
|
335
|
-
return new arrow.Int32();
|
|
336
|
-
case "int64":
|
|
337
|
-
return new arrow.Int64();
|
|
338
|
-
case "uint8":
|
|
339
|
-
return new arrow.Uint8();
|
|
340
|
-
case "uint16":
|
|
341
|
-
return new arrow.Uint16();
|
|
342
|
-
case "uint32":
|
|
343
|
-
return new arrow.Uint32();
|
|
344
|
-
case "uint64":
|
|
345
|
-
return new arrow.Uint64();
|
|
346
|
-
case "float16":
|
|
347
|
-
return new arrow.Float16();
|
|
348
|
-
case "float32":
|
|
349
|
-
return new arrow.Float32();
|
|
350
|
-
case "float64":
|
|
351
|
-
return new arrow.Float64();
|
|
352
|
-
case "utf8":
|
|
353
|
-
return makeVariableWidthArrowType("Utf8View", new arrow.Utf8(), options);
|
|
354
|
-
case "utf8-view":
|
|
355
|
-
return makeRequiredArrowViewType("Utf8View");
|
|
356
|
-
case "date-day":
|
|
357
|
-
return new arrow.DateDay();
|
|
358
|
-
case "date-millisecond":
|
|
359
|
-
return new arrow.DateMillisecond();
|
|
360
|
-
case "time-second":
|
|
361
|
-
return new arrow.TimeSecond();
|
|
362
|
-
case "time-millisecond":
|
|
363
|
-
return new arrow.TimeMillisecond();
|
|
364
|
-
case "time-microsecond":
|
|
365
|
-
return new arrow.TimeMicrosecond();
|
|
366
|
-
case "time-nanosecond":
|
|
367
|
-
return new arrow.TimeNanosecond();
|
|
368
|
-
case "timestamp-second":
|
|
369
|
-
return new arrow.TimestampSecond();
|
|
370
|
-
case "timestamp-millisecond":
|
|
371
|
-
return new arrow.TimestampMillisecond();
|
|
372
|
-
case "timestamp-microsecond":
|
|
373
|
-
return new arrow.TimestampMicrosecond();
|
|
374
|
-
case "timestamp-nanosecond":
|
|
375
|
-
return new arrow.TimestampNanosecond();
|
|
376
|
-
case "interval-daytime":
|
|
377
|
-
return new arrow.IntervalDayTime();
|
|
378
|
-
case "interval-yearmonth":
|
|
379
|
-
return new arrow.IntervalYearMonth();
|
|
380
|
-
default:
|
|
381
|
-
throw new Error("array type not supported");
|
|
256
|
+
const relationalSteps = [];
|
|
257
|
+
if ((_b = options.expressions) == null ? void 0 : _b.length)
|
|
258
|
+
relationalSteps.push({ kind: "expression", detail: options.expressions });
|
|
259
|
+
if ((_c = options.orderBy) == null ? void 0 : _c.length) relationalSteps.push({ kind: "order", detail: options.orderBy });
|
|
260
|
+
if (((_d = options.aggregates) == null ? void 0 : _d.length) || ((_e = options.groupBy) == null ? void 0 : _e.length)) {
|
|
261
|
+
relationalSteps.push({
|
|
262
|
+
kind: "aggregate",
|
|
263
|
+
detail: { groupBy: options.groupBy, aggregates: options.aggregates }
|
|
264
|
+
});
|
|
382
265
|
}
|
|
266
|
+
if ((_f = options.union) == null ? void 0 : _f.length) relationalSteps.push({ kind: "union", detail: options.union });
|
|
267
|
+
if (options.join) relationalSteps.push({ kind: "join", detail: options.join });
|
|
268
|
+
return { tablePlan, relationalSteps: Object.freeze(relationalSteps) };
|
|
383
269
|
}
|
|
384
|
-
function
|
|
385
|
-
|
|
270
|
+
function validateRelationalColumnReference(columnName, availableColumns) {
|
|
271
|
+
if (!availableColumns.has(columnName)) {
|
|
272
|
+
throw new Error(`Relational expression column not found: ${columnName}`);
|
|
273
|
+
}
|
|
386
274
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
275
|
+
var init_relational_query = __esm({
|
|
276
|
+
"src/loader-utils/lib/scan-utils/relational-query.ts"() {
|
|
277
|
+
"use strict";
|
|
278
|
+
init_table_query();
|
|
391
279
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// src/loader-utils/lib/scan-utils/table-query-explain.ts
|
|
283
|
+
function explainTableQuery(sourceColumnNames, options, capabilities) {
|
|
284
|
+
const plan = planTableQuery(sourceColumnNames, options);
|
|
285
|
+
const outputColumns = options.columns ? [...options.columns] : [...sourceColumnNames];
|
|
286
|
+
const predicateColumns = options.predicate ? (0, import_columnar_predicate2.getColumnarPredicateColumns)(options.predicate) : [];
|
|
287
|
+
const requiredColumns = [...plan[0].kind === "scan" ? plan[0].columns : []];
|
|
288
|
+
return Object.freeze({
|
|
289
|
+
sourceColumns: Object.freeze([...sourceColumnNames]),
|
|
290
|
+
outputColumns: Object.freeze(outputColumns),
|
|
291
|
+
requiredColumns: Object.freeze(requiredColumns),
|
|
292
|
+
predicateColumns: Object.freeze(predicateColumns),
|
|
293
|
+
plan,
|
|
294
|
+
capabilities: Object.freeze({ ...capabilities }),
|
|
295
|
+
operators: Object.freeze({
|
|
296
|
+
projection: createOperatorExplanation(options.columns !== void 0, capabilities.projection),
|
|
297
|
+
predicate: createOperatorExplanation(options.predicate !== void 0, capabilities.predicate),
|
|
298
|
+
limit: createOperatorExplanation(options.limit !== void 0, capabilities.limit)
|
|
299
|
+
})
|
|
300
|
+
});
|
|
395
301
|
}
|
|
396
|
-
function
|
|
397
|
-
|
|
398
|
-
return Boolean(constructor && arrowType instanceof constructor);
|
|
302
|
+
function createOperatorExplanation(enabled, support) {
|
|
303
|
+
return Object.freeze({ enabled, support });
|
|
399
304
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
const constructor = getOptionalArrowConstructor(viewTypeName);
|
|
406
|
-
if (constructor) {
|
|
407
|
-
return new constructor();
|
|
305
|
+
var init_table_query_explain = __esm({
|
|
306
|
+
"src/loader-utils/lib/scan-utils/table-query-explain.ts"() {
|
|
307
|
+
"use strict";
|
|
308
|
+
init_columnar_predicate();
|
|
309
|
+
init_table_query();
|
|
408
310
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
// src/loader-utils/index.ts
|
|
314
|
+
var init_loader_utils = __esm({
|
|
315
|
+
"src/loader-utils/index.ts"() {
|
|
316
|
+
"use strict";
|
|
317
|
+
init_columnar_predicate();
|
|
318
|
+
init_relational_query();
|
|
319
|
+
init_scan_query_metadata();
|
|
320
|
+
init_table_query();
|
|
321
|
+
init_table_query_explain();
|
|
413
322
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
// dist/scan/table-query-capabilities.js
|
|
326
|
+
var ARROW_TABLE_QUERY_CAPABILITIES, SQL_DATA_SOURCE_TABLE_QUERY_CAPABILITIES;
|
|
327
|
+
var init_table_query_capabilities = __esm({
|
|
328
|
+
"dist/scan/table-query-capabilities.js"() {
|
|
329
|
+
"use strict";
|
|
330
|
+
ARROW_TABLE_QUERY_CAPABILITIES = Object.freeze({
|
|
331
|
+
projection: "residual",
|
|
332
|
+
predicate: "residual",
|
|
333
|
+
limit: "residual",
|
|
334
|
+
streaming: false,
|
|
335
|
+
cancellation: true,
|
|
336
|
+
expressions: "residual",
|
|
337
|
+
orderBy: "residual",
|
|
338
|
+
aggregates: "residual"
|
|
339
|
+
});
|
|
340
|
+
SQL_DATA_SOURCE_TABLE_QUERY_CAPABILITIES = Object.freeze({
|
|
341
|
+
projection: "pushdown",
|
|
342
|
+
predicate: "pushdown",
|
|
343
|
+
limit: "pushdown",
|
|
344
|
+
streaming: false,
|
|
345
|
+
cancellation: false,
|
|
346
|
+
expressions: "pushdown",
|
|
347
|
+
orderBy: "pushdown",
|
|
348
|
+
aggregates: "pushdown"
|
|
349
|
+
});
|
|
422
350
|
}
|
|
423
|
-
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
// dist/scan/arrow-execution/filter-arrow-table.js
|
|
354
|
+
function filterArrowTable(source, predicate, options = {}) {
|
|
355
|
+
(0, import_columnar_predicate2.validateColumnarPredicate)(predicate, new Set(source.schema.fields.map((field) => field.name)));
|
|
356
|
+
const boundPredicate = normalizeArrowDatePredicate(predicate);
|
|
357
|
+
return filterArrowRows(source, (batch) => {
|
|
358
|
+
const evaluate = (0, import_columnar_predicate6.compileColumnarPredicate)(boundPredicate, (path) => bindPredicateColumn(batch, path));
|
|
359
|
+
return (rowIndex) => evaluate(rowIndex) === true;
|
|
360
|
+
}, options);
|
|
424
361
|
}
|
|
425
|
-
function
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
362
|
+
function bindPredicateColumn(batch, [name, ...properties]) {
|
|
363
|
+
const column = batch.getChild(name);
|
|
364
|
+
if (!column)
|
|
365
|
+
throw new Error(`Arrow query column not found: ${name}`);
|
|
366
|
+
return (rowIndex) => {
|
|
367
|
+
let value = column.get(rowIndex);
|
|
368
|
+
for (const property of properties) {
|
|
369
|
+
if (value == null)
|
|
370
|
+
return null;
|
|
371
|
+
value = value[property];
|
|
431
372
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
case arrow.Int8:
|
|
435
|
-
return "int8";
|
|
436
|
-
case arrow.Int16:
|
|
437
|
-
return "int16";
|
|
438
|
-
case arrow.Int32:
|
|
439
|
-
return "int32";
|
|
440
|
-
case arrow.Uint8:
|
|
441
|
-
return "uint8";
|
|
442
|
-
case arrow.Uint16:
|
|
443
|
-
return "uint16";
|
|
444
|
-
case arrow.Uint32:
|
|
445
|
-
return "uint32";
|
|
446
|
-
default:
|
|
447
|
-
throw new Error(`arrow dictionary index type not supported: ${arrowType.constructor.name}`);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
function isSchemaDictionaryKeyType(keyType) {
|
|
451
|
-
return ["int8", "int16", "int32", "uint8", "uint16", "uint32"].includes(keyType);
|
|
373
|
+
return dateToMilliseconds(value);
|
|
374
|
+
};
|
|
452
375
|
}
|
|
453
|
-
function
|
|
454
|
-
switch (
|
|
455
|
-
case "
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
return new arrow.Uint16();
|
|
465
|
-
case "uint32":
|
|
466
|
-
return new arrow.Uint32();
|
|
376
|
+
function normalizeArrowDatePredicate(predicate) {
|
|
377
|
+
switch (predicate.op) {
|
|
378
|
+
case "and":
|
|
379
|
+
case "or":
|
|
380
|
+
return { ...predicate, args: predicate.args.map(normalizeArrowDatePredicate) };
|
|
381
|
+
case "not":
|
|
382
|
+
return { ...predicate, args: [normalizeArrowDatePredicate(predicate.args[0])] };
|
|
383
|
+
case "isNull":
|
|
384
|
+
return predicate;
|
|
385
|
+
case "in":
|
|
386
|
+
return { ...predicate, args: [predicate.args[0], predicate.args[1].map(dateToMilliseconds)] };
|
|
467
387
|
default:
|
|
468
|
-
|
|
388
|
+
return { ...predicate, args: [predicate.args[0], dateToMilliseconds(predicate.args[1])] };
|
|
469
389
|
}
|
|
470
390
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
var arrow2 = __toESM(require("apache-arrow"), 1);
|
|
474
|
-
function snapshotArrowSchema(schema) {
|
|
475
|
-
return deserializeArrowSchema(serializeArrowSchema(schema));
|
|
476
|
-
}
|
|
477
|
-
function makeArrowMetadataBatch(schema) {
|
|
478
|
-
return new arrow2.RecordBatch(snapshotArrowSchema(schema), void 0);
|
|
391
|
+
function dateToMilliseconds(value) {
|
|
392
|
+
return value instanceof Date ? value.getTime() : value;
|
|
479
393
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
paths.set(path.join("\0"), path);
|
|
499
|
-
}
|
|
500
|
-
});
|
|
501
|
-
return [...paths.values()];
|
|
502
|
-
}
|
|
503
|
-
function validateColumnarPredicate(predicate, availableColumns) {
|
|
504
|
-
visitColumnarPredicate(predicate, (child) => {
|
|
505
|
-
if (child.op === "and" || child.op === "or") {
|
|
506
|
-
if (child.args.length < 2)
|
|
507
|
-
throw new Error(`Columnar predicate ${child.op} requires at least two child predicates`);
|
|
508
|
-
return;
|
|
509
|
-
}
|
|
510
|
-
if (child.op === "not") return;
|
|
511
|
-
const leaf = child;
|
|
512
|
-
const path = getColumnarPredicatePath(leaf.args[0]);
|
|
513
|
-
if (!path.length || path.some((component) => !component)) {
|
|
514
|
-
throw new Error("Columnar predicate property path must contain non-empty strings");
|
|
515
|
-
}
|
|
516
|
-
if (!availableColumns.has(path[0]))
|
|
517
|
-
throw new Error(`Columnar predicate column not found: ${path.join(".")}`);
|
|
518
|
-
if (leaf.op === "in" && leaf.args[1].length === 0) {
|
|
519
|
-
throw new Error("Columnar predicate in requires at least one value");
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
function isColumnarPredicateParameter(value) {
|
|
524
|
-
const parameterValue = value;
|
|
525
|
-
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;
|
|
526
|
-
}
|
|
527
|
-
function visitColumnarPredicate(predicate, visitor) {
|
|
528
|
-
visitor(predicate);
|
|
529
|
-
if (predicate.op === "and" || predicate.op === "or")
|
|
530
|
-
predicate.args.forEach((child) => visitColumnarPredicate(child, visitor));
|
|
531
|
-
else if (predicate.op === "not") visitColumnarPredicate(predicate.args[0], visitor);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
// src/loader-utils/lib/scan-utils/scan-query-metadata.ts
|
|
535
|
-
var import_crs = require("@math.gl/geospatial/crs");
|
|
536
|
-
function createScanQueryMetadata(options) {
|
|
537
|
-
validateScanExecutionSupport(options.queryType, options.execution);
|
|
538
|
-
const schema = Object.freeze({
|
|
539
|
-
fields: Object.freeze(
|
|
540
|
-
options.schema.fields.map(
|
|
541
|
-
(field) => Object.freeze({ ...field, metadata: Object.freeze({ ...field.metadata }) })
|
|
542
|
-
)
|
|
543
|
-
),
|
|
544
|
-
metadata: Object.freeze({ ...options.schema.metadata })
|
|
545
|
-
});
|
|
546
|
-
const columns = schema.fields.map(
|
|
547
|
-
(field) => {
|
|
548
|
-
var _a;
|
|
549
|
-
return Object.freeze({
|
|
550
|
-
name: field.name,
|
|
551
|
-
type: field.type,
|
|
552
|
-
nullable: field.nullable !== false,
|
|
553
|
-
role: ((_a = options.columnRoles) == null ? void 0 : _a[field.name]) || "attribute",
|
|
554
|
-
title: getNonEmptyMetadataValue(field.metadata, "title"),
|
|
555
|
-
description: getNonEmptyMetadataValue(field.metadata, "description"),
|
|
556
|
-
metadata: field.metadata || Object.freeze({})
|
|
557
|
-
});
|
|
394
|
+
function filterArrowRows(source, selectBatch, options = {}) {
|
|
395
|
+
var _a, _b, _c;
|
|
396
|
+
let remaining = options.limit ?? Infinity;
|
|
397
|
+
if (remaining !== Infinity && (!Number.isSafeInteger(remaining) || remaining < 0)) {
|
|
398
|
+
throw new Error("Arrow filter limit must be a non-negative safe integer.");
|
|
399
|
+
}
|
|
400
|
+
(_a = options.signal) == null ? void 0 : _a.throwIfAborted();
|
|
401
|
+
const batches = [];
|
|
402
|
+
for (const batch of source.batches) {
|
|
403
|
+
if (remaining === 0)
|
|
404
|
+
break;
|
|
405
|
+
(_b = options.signal) == null ? void 0 : _b.throwIfAborted();
|
|
406
|
+
const selectRow = selectBatch(batch);
|
|
407
|
+
const indices = [];
|
|
408
|
+
for (let rowIndex = 0; rowIndex < batch.numRows && indices.length < remaining; rowIndex++) {
|
|
409
|
+
(_c = options.signal) == null ? void 0 : _c.throwIfAborted();
|
|
410
|
+
if (selectRow(rowIndex))
|
|
411
|
+
indices.push(rowIndex);
|
|
558
412
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
name: options.name,
|
|
566
|
-
description: options.description,
|
|
567
|
-
schema,
|
|
568
|
-
columns: Object.freeze(columns),
|
|
569
|
-
capabilities: queryCapabilities,
|
|
570
|
-
queryCapabilities,
|
|
571
|
-
...options.hasDefaultRowWindow ? { hasDefaultRowWindow: true } : {},
|
|
572
|
-
spatial: options.spatial ? Object.freeze({
|
|
573
|
-
...options.spatial,
|
|
574
|
-
bounds: options.spatial.bounds ? Object.freeze({
|
|
575
|
-
minimum: Object.freeze([...options.spatial.bounds.minimum]),
|
|
576
|
-
maximum: Object.freeze([...options.spatial.bounds.maximum])
|
|
577
|
-
}) : void 0,
|
|
578
|
-
coordinateReferenceSystems: options.spatial.coordinateReferenceSystems ? Object.freeze([...options.spatial.coordinateReferenceSystems]) : void 0,
|
|
579
|
-
spatialReference: options.spatial.spatialReference ? (0, import_crs.createSpatialReference)(options.spatial.spatialReference) : void 0
|
|
580
|
-
}) : void 0,
|
|
581
|
-
statistics: options.statistics ? Object.freeze({ ...options.statistics }) : void 0,
|
|
582
|
-
levels: options.levels ? Object.freeze(
|
|
583
|
-
options.levels.map(
|
|
584
|
-
(level) => Object.freeze({
|
|
585
|
-
...level,
|
|
586
|
-
scale: level.scale ? Object.freeze([...level.scale]) : void 0
|
|
587
|
-
})
|
|
588
|
-
)
|
|
589
|
-
) : void 0
|
|
590
|
-
});
|
|
413
|
+
remaining -= indices.length;
|
|
414
|
+
const selected = (0, import_arrow2.selectArrowBatchRows)(batch, indices);
|
|
415
|
+
if (selected)
|
|
416
|
+
batches.push(selected);
|
|
417
|
+
}
|
|
418
|
+
return new arrow3.Table(source.schema, batches);
|
|
591
419
|
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
420
|
+
var arrow3, import_arrow2, import_columnar_predicate6;
|
|
421
|
+
var init_filter_arrow_table = __esm({
|
|
422
|
+
"dist/scan/arrow-execution/filter-arrow-table.js"() {
|
|
423
|
+
"use strict";
|
|
424
|
+
arrow3 = __toESM(require("apache-arrow"), 1);
|
|
425
|
+
import_arrow2 = require("@math.gl/core/arrow");
|
|
426
|
+
import_columnar_predicate6 = require("@math.gl/sql/columnar-predicate");
|
|
427
|
+
init_loader_utils();
|
|
598
428
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
);
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
// dist/scan/arrow-execution.js
|
|
432
|
+
var import_arrow3;
|
|
433
|
+
var init_arrow_execution = __esm({
|
|
434
|
+
"dist/scan/arrow-execution.js"() {
|
|
435
|
+
"use strict";
|
|
436
|
+
import_arrow3 = require("@math.gl/core/arrow");
|
|
437
|
+
init_filter_arrow_table();
|
|
608
438
|
}
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
// dist/scan/sql-predicate-schema.js
|
|
442
|
+
function validateSQLPredicate(value) {
|
|
443
|
+
(0, import_parser.validateSQLPredicate)(value);
|
|
444
|
+
rejectPredicateCasts(value, "$");
|
|
609
445
|
}
|
|
610
|
-
function
|
|
611
|
-
|
|
612
|
-
|
|
446
|
+
function rejectPredicateCasts(predicate, path) {
|
|
447
|
+
if (predicate.op === "and" || predicate.op === "or" || predicate.op === "not") {
|
|
448
|
+
predicate.args.forEach((child, index) => rejectPredicateCasts(child, path + ".args[" + index + "]"));
|
|
449
|
+
} else if (Object.hasOwn(predicate.args[0], "casts")) {
|
|
450
|
+
throw new Error("SQL predicate " + path + ".args[0] requires a non-empty property reference");
|
|
451
|
+
}
|
|
613
452
|
}
|
|
453
|
+
var import_parser;
|
|
454
|
+
var init_sql_predicate_schema = __esm({
|
|
455
|
+
"dist/scan/sql-predicate-schema.js"() {
|
|
456
|
+
"use strict";
|
|
457
|
+
import_parser = require("@math.gl/sql/parser");
|
|
458
|
+
}
|
|
459
|
+
});
|
|
614
460
|
|
|
615
|
-
//
|
|
616
|
-
function
|
|
617
|
-
validateTableQueryOptions(sourceColumnNames, options);
|
|
618
|
-
const outputColumnNames = options.columns ? [...options.columns] : [...sourceColumnNames];
|
|
619
|
-
const predicateColumnNames = options.predicate ? getColumnarPredicateColumns(options.predicate) : [];
|
|
620
|
-
const requiredColumnNames = /* @__PURE__ */ new Set([...outputColumnNames, ...predicateColumnNames]);
|
|
621
|
-
const scanColumnNames = sourceColumnNames.filter(
|
|
622
|
-
(columnName) => requiredColumnNames.has(columnName)
|
|
623
|
-
);
|
|
624
|
-
const steps = [
|
|
625
|
-
Object.freeze({ kind: "scan", columns: Object.freeze(scanColumnNames) })
|
|
626
|
-
];
|
|
461
|
+
// dist/scan/table-query.js
|
|
462
|
+
function planTableQuery2(sourceColumnNames, options = {}) {
|
|
627
463
|
if (options.predicate) {
|
|
628
|
-
|
|
629
|
-
}
|
|
630
|
-
steps.push(Object.freeze({ kind: "project", columns: Object.freeze(outputColumnNames) }));
|
|
631
|
-
if (options.limit !== void 0) {
|
|
632
|
-
steps.push(Object.freeze({ kind: "limit", limit: options.limit }));
|
|
464
|
+
validateSQLPredicate(options.predicate);
|
|
633
465
|
}
|
|
634
|
-
return
|
|
466
|
+
return planTableQuery(sourceColumnNames, options);
|
|
635
467
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
468
|
+
var init_table_query2 = __esm({
|
|
469
|
+
"dist/scan/table-query.js"() {
|
|
470
|
+
"use strict";
|
|
471
|
+
init_loader_utils();
|
|
472
|
+
init_sql_predicate_schema();
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
// dist/scan/plan-arrow-table-query.js
|
|
477
|
+
function explainArrowTableQuery(sourceTable, options = {}) {
|
|
478
|
+
if (options.select !== void 0) {
|
|
479
|
+
if (options.columns !== void 0 || hasRelationalOperators(options) || options.join) {
|
|
480
|
+
throw new Error("Arrow select cannot be combined with columns or relational operators.");
|
|
646
481
|
}
|
|
647
|
-
|
|
482
|
+
const projected = (0, import_arrow3.projectArrowTable)(sourceTable, options.select);
|
|
483
|
+
const columns = [
|
|
484
|
+
...new Set(options.select.map((selection) => typeof selection === "string" ? selection : selection.column))
|
|
485
|
+
];
|
|
486
|
+
const { select, ...remainingOptions } = options;
|
|
487
|
+
const explanation = explainArrowTableQuery(sourceTable, { ...remainingOptions, columns });
|
|
488
|
+
const outputColumns = Object.freeze(projected.schema.fields.map((field) => field.name));
|
|
489
|
+
return Object.freeze({
|
|
490
|
+
...explanation,
|
|
491
|
+
outputColumns,
|
|
492
|
+
plan: Object.freeze(explanation.plan.map((step) => step.kind === "project" ? Object.freeze({ ...step, columns: outputColumns, select }) : step))
|
|
493
|
+
});
|
|
648
494
|
}
|
|
649
|
-
validateTableQueryLimit(options.limit);
|
|
650
495
|
if (options.predicate) {
|
|
651
|
-
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
function validateTableQueryLimit(limit) {
|
|
655
|
-
if (limit !== void 0 && (!Number.isSafeInteger(limit) || limit < 0)) {
|
|
656
|
-
throw new Error("Table query limit must be a non-negative safe integer.");
|
|
496
|
+
validateSQLPredicate(options.predicate);
|
|
657
497
|
}
|
|
498
|
+
return explainTableQuery(sourceTable.schema.fields.map((field) => field.name), options, ARROW_TABLE_QUERY_CAPABILITIES);
|
|
658
499
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
const expressionNames = /* @__PURE__ */ new Set();
|
|
665
|
-
for (const expression of options.expressions || []) {
|
|
666
|
-
if (!expression.name) throw new Error("Relational expression names must be non-empty.");
|
|
667
|
-
if (available.has(expression.name) || expressionNames.has(expression.name)) {
|
|
668
|
-
throw new Error(`Relational expression duplicates column: ${expression.name}`);
|
|
500
|
+
function queryArrowTable(sourceTable, options = {}, execute) {
|
|
501
|
+
throwIfAborted(options.signal);
|
|
502
|
+
if (options.select !== void 0) {
|
|
503
|
+
if (options.columns !== void 0 || hasRelationalOperators(options) || options.join) {
|
|
504
|
+
throw new Error("Arrow select cannot be combined with columns or relational operators.");
|
|
669
505
|
}
|
|
670
|
-
|
|
506
|
+
return (execute ?? executePortableArrowQuery)(sourceTable, {
|
|
507
|
+
where: options.predicate,
|
|
508
|
+
select: options.select,
|
|
509
|
+
limit: options.limit,
|
|
510
|
+
signal: options.signal
|
|
511
|
+
});
|
|
671
512
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
validateRelationalColumnReference(definition.column, availableColumns);
|
|
679
|
-
if (available.has(definition.column)) requiredColumns.add(definition.column);
|
|
680
|
-
}
|
|
681
|
-
if ("left" in definition) {
|
|
682
|
-
validateRelationalColumnReference(definition.left, availableColumns);
|
|
683
|
-
validateRelationalColumnReference(definition.right, availableColumns);
|
|
684
|
-
if (available.has(definition.left)) requiredColumns.add(definition.left);
|
|
685
|
-
if (available.has(definition.right)) requiredColumns.add(definition.right);
|
|
513
|
+
if (options.join || hasRelationalOperators(options)) {
|
|
514
|
+
if (options.join) {
|
|
515
|
+
validateArrowJoinQuery(sourceTable, options);
|
|
516
|
+
if (hasRelationalOperators(options)) {
|
|
517
|
+
throw new Error("Arrow joins cannot yet be combined with other relational operators.");
|
|
518
|
+
}
|
|
686
519
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
for (const key of options.groupBy || []) requiredColumns.add(key);
|
|
691
|
-
for (const aggregate of options.aggregates || []) {
|
|
692
|
-
if (aggregate.column) requiredColumns.add(aggregate.column);
|
|
520
|
+
if (!execute)
|
|
521
|
+
throw new Error("Relational queries require the SQL executor.");
|
|
522
|
+
return options.join ? queryArrowJoin(sourceTable, options, execute) : queryArrowTableRelational(sourceTable, options, execute);
|
|
693
523
|
}
|
|
694
|
-
const
|
|
695
|
-
|
|
696
|
-
)
|
|
697
|
-
|
|
698
|
-
|
|
524
|
+
const plan = planTableQuery2(sourceTable.schema.fields.map((field) => field.name), options);
|
|
525
|
+
const projection = plan.find((step) => step.kind === "project");
|
|
526
|
+
return (execute ?? executePortableArrowQuery)(sourceTable, {
|
|
527
|
+
where: options.predicate,
|
|
528
|
+
select: projection == null ? void 0 : projection.columns,
|
|
529
|
+
limit: options.limit,
|
|
530
|
+
signal: options.signal
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
function queryArrowTableRelational(sourceTable, options, execute) {
|
|
534
|
+
var _a, _b, _c;
|
|
535
|
+
const sourceColumns = sourceTable.schema.fields.map((field) => field.name);
|
|
536
|
+
const grouped = ((_a = options.groupBy) == null ? void 0 : _a.length) || ((_b = options.aggregates) == null ? void 0 : _b.length);
|
|
537
|
+
const outputColumns = options.columns ?? (grouped ? [...options.groupBy ?? [], ...(options.aggregates ?? []).map((aggregate) => aggregate.name)] : sourceColumns);
|
|
538
|
+
const plan = planRelationalQuery(sourceColumns, { ...options, columns: outputColumns });
|
|
539
|
+
const scan = plan.tablePlan.find((step) => step.kind === "scan");
|
|
540
|
+
let table = execute(sourceTable, {
|
|
541
|
+
where: options.predicate,
|
|
542
|
+
select: scan.columns,
|
|
543
|
+
signal: options.signal
|
|
544
|
+
});
|
|
545
|
+
if ((_c = options.union) == null ? void 0 : _c.length) {
|
|
546
|
+
const childPlan = planRelationalQuery(sourceColumns, {
|
|
699
547
|
...options,
|
|
700
548
|
columns: outputColumns,
|
|
701
|
-
predicate:
|
|
702
|
-
})
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
549
|
+
predicate: void 0
|
|
550
|
+
});
|
|
551
|
+
const columns = childPlan.tablePlan.find((step) => step.kind === "scan").columns;
|
|
552
|
+
const union = options.union.map((child) => {
|
|
553
|
+
var _a2;
|
|
554
|
+
const input = (_a2 = options.tables) == null ? void 0 : _a2[child.source];
|
|
555
|
+
if (!input)
|
|
556
|
+
throw new Error("Arrow union source not found: " + child.source);
|
|
557
|
+
return queryArrowTable(input, { ...child.query, columns, signal: options.signal }, execute);
|
|
558
|
+
});
|
|
559
|
+
table = execute((0, import_arrow3.projectArrowTable)(table, columns), { union, signal: options.signal });
|
|
711
560
|
}
|
|
712
|
-
for (const expression of
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
throw new Error(`Relational order column not found: ${key.column}`);
|
|
717
|
-
}
|
|
718
|
-
for (const key of options.groupBy || []) {
|
|
719
|
-
if (!available.has(key)) throw new Error(`Relational group column not found: ${key}`);
|
|
720
|
-
}
|
|
721
|
-
for (const aggregate of options.aggregates || []) {
|
|
722
|
-
if (!aggregate.name) throw new Error("Relational aggregate names must be non-empty.");
|
|
723
|
-
if (aggregate.function !== "count" && !aggregate.column) {
|
|
724
|
-
throw new Error(`Relational aggregate ${aggregate.function} requires a column.`);
|
|
725
|
-
}
|
|
726
|
-
if (aggregate.column && !available.has(aggregate.column)) {
|
|
727
|
-
throw new Error(`Relational aggregate column not found: ${aggregate.column}`);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
const relationalSteps = [];
|
|
731
|
-
if ((_b = options.expressions) == null ? void 0 : _b.length)
|
|
732
|
-
relationalSteps.push({ kind: "expression", detail: options.expressions });
|
|
733
|
-
if ((_c = options.orderBy) == null ? void 0 : _c.length) relationalSteps.push({ kind: "order", detail: options.orderBy });
|
|
734
|
-
if (((_d = options.aggregates) == null ? void 0 : _d.length) || ((_e = options.groupBy) == null ? void 0 : _e.length)) {
|
|
735
|
-
relationalSteps.push({
|
|
736
|
-
kind: "aggregate",
|
|
737
|
-
detail: { groupBy: options.groupBy, aggregates: options.aggregates }
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
if ((_f = options.union) == null ? void 0 : _f.length) relationalSteps.push({ kind: "union", detail: options.union });
|
|
741
|
-
if (options.join) relationalSteps.push({ kind: "join", detail: options.join });
|
|
742
|
-
return { tablePlan, relationalSteps: Object.freeze(relationalSteps) };
|
|
743
|
-
}
|
|
744
|
-
function validateRelationalColumnReference(columnName, availableColumns) {
|
|
745
|
-
if (!availableColumns.has(columnName)) {
|
|
746
|
-
throw new Error(`Relational expression column not found: ${columnName}`);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
// src/loader-utils/lib/scan-utils/table-query-explain.ts
|
|
751
|
-
function explainTableQuery(sourceColumnNames, options, capabilities) {
|
|
752
|
-
const plan = planTableQuery(sourceColumnNames, options);
|
|
753
|
-
const outputColumns = options.columns ? [...options.columns] : [...sourceColumnNames];
|
|
754
|
-
const predicateColumns = options.predicate ? getColumnarPredicateColumns(options.predicate) : [];
|
|
755
|
-
const requiredColumns = [...plan[0].kind === "scan" ? plan[0].columns : []];
|
|
756
|
-
return Object.freeze({
|
|
757
|
-
sourceColumns: Object.freeze([...sourceColumnNames]),
|
|
758
|
-
outputColumns: Object.freeze(outputColumns),
|
|
759
|
-
requiredColumns: Object.freeze(requiredColumns),
|
|
760
|
-
predicateColumns: Object.freeze(predicateColumns),
|
|
761
|
-
plan,
|
|
762
|
-
capabilities: Object.freeze({ ...capabilities }),
|
|
763
|
-
operators: Object.freeze({
|
|
764
|
-
projection: createOperatorExplanation(options.columns !== void 0, capabilities.projection),
|
|
765
|
-
predicate: createOperatorExplanation(options.predicate !== void 0, capabilities.predicate),
|
|
766
|
-
limit: createOperatorExplanation(options.limit !== void 0, capabilities.limit)
|
|
767
|
-
})
|
|
768
|
-
});
|
|
769
|
-
}
|
|
770
|
-
function createOperatorExplanation(enabled, support) {
|
|
771
|
-
return Object.freeze({ enabled, support });
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
// dist/scan/table-query-capabilities.js
|
|
775
|
-
var ARROW_TABLE_QUERY_CAPABILITIES = Object.freeze({
|
|
776
|
-
projection: "residual",
|
|
777
|
-
predicate: "residual",
|
|
778
|
-
limit: "residual",
|
|
779
|
-
streaming: false,
|
|
780
|
-
cancellation: true,
|
|
781
|
-
expressions: "residual",
|
|
782
|
-
orderBy: "residual",
|
|
783
|
-
aggregates: "residual"
|
|
784
|
-
});
|
|
785
|
-
var SQL_DATA_SOURCE_TABLE_QUERY_CAPABILITIES = Object.freeze({
|
|
786
|
-
projection: "pushdown",
|
|
787
|
-
predicate: "pushdown",
|
|
788
|
-
limit: "pushdown",
|
|
789
|
-
streaming: false,
|
|
790
|
-
cancellation: false,
|
|
791
|
-
expressions: "pushdown",
|
|
792
|
-
orderBy: "pushdown",
|
|
793
|
-
aggregates: "pushdown"
|
|
794
|
-
});
|
|
795
|
-
|
|
796
|
-
// dist/scan/query-arrow-table.js
|
|
797
|
-
var arrow6 = __toESM(require("apache-arrow"), 1);
|
|
798
|
-
|
|
799
|
-
// dist/scan/arrow-execution/project-arrow-table.js
|
|
800
|
-
var arrow3 = __toESM(require("apache-arrow"), 1);
|
|
801
|
-
function projectArrowTable(source, selections) {
|
|
802
|
-
const outputNames = /* @__PURE__ */ new Set();
|
|
803
|
-
const indices = [];
|
|
804
|
-
const fields = selections.map((selection) => {
|
|
805
|
-
const column = typeof selection === "string" ? selection : selection.column;
|
|
806
|
-
const name = typeof selection === "string" ? selection : selection.as === void 0 ? column : selection.as;
|
|
807
|
-
const index = source.schema.fields.findIndex((field) => field.name === column);
|
|
808
|
-
if (index < 0)
|
|
809
|
-
throw new Error(`Arrow projection column not found: ${column}`);
|
|
810
|
-
if (typeof name !== "string" || typeof selection !== "string" && selection.as !== void 0 && !name.length || outputNames.has(name)) {
|
|
811
|
-
throw new Error(`Invalid or duplicate Arrow projection output name: ${name}`);
|
|
812
|
-
}
|
|
813
|
-
outputNames.add(name);
|
|
814
|
-
indices.push(index);
|
|
815
|
-
return source.schema.fields[index].clone({ name });
|
|
816
|
-
});
|
|
817
|
-
const schema = new arrow3.Schema(fields, source.schema.metadata);
|
|
818
|
-
const batches = source.batches.map((batch) => new arrow3.RecordBatch(schema, arrow3.makeData({
|
|
819
|
-
type: new arrow3.Struct(fields),
|
|
820
|
-
length: batch.numRows,
|
|
821
|
-
children: indices.map((index) => batch.data.children[index])
|
|
822
|
-
}), batch.metadata));
|
|
823
|
-
return new arrow3.Table(schema, batches);
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
// dist/scan/arrow-execution/filter-arrow-table.js
|
|
827
|
-
var arrow4 = __toESM(require("apache-arrow"), 1);
|
|
828
|
-
var import_arrow = require("@math.gl/core/arrow");
|
|
829
|
-
function filterArrowTable(source, predicate, options = {}) {
|
|
830
|
-
validateColumnarPredicate(predicate, new Set(source.schema.fields.map((field) => field.name)));
|
|
831
|
-
const columnNames = getColumnarPredicateColumns(predicate);
|
|
832
|
-
return filterArrowRows(source, (batch) => {
|
|
833
|
-
const columns = getPredicateColumns(new arrow4.Table(source.schema, [batch]), columnNames);
|
|
834
|
-
return (rowIndex) => evaluatePredicate(predicate, columns, rowIndex) === true;
|
|
835
|
-
}, options);
|
|
836
|
-
}
|
|
837
|
-
function filterArrowRows(source, selectBatch, options = {}) {
|
|
838
|
-
var _a, _b, _c;
|
|
839
|
-
let remaining = options.limit ?? Infinity;
|
|
840
|
-
if (remaining !== Infinity && (!Number.isSafeInteger(remaining) || remaining < 0)) {
|
|
841
|
-
throw new Error("Arrow filter limit must be a non-negative safe integer.");
|
|
842
|
-
}
|
|
843
|
-
(_a = options.signal) == null ? void 0 : _a.throwIfAborted();
|
|
844
|
-
const batches = [];
|
|
845
|
-
for (const batch of source.batches) {
|
|
846
|
-
if (remaining === 0)
|
|
847
|
-
break;
|
|
848
|
-
(_b = options.signal) == null ? void 0 : _b.throwIfAborted();
|
|
849
|
-
const data = new arrow4.Table(source.schema, [batch]);
|
|
850
|
-
const selectRow = selectBatch(batch);
|
|
851
|
-
const indices = [];
|
|
852
|
-
for (let rowIndex = 0; rowIndex < batch.numRows && indices.length < remaining; rowIndex++) {
|
|
853
|
-
(_c = options.signal) == null ? void 0 : _c.throwIfAborted();
|
|
854
|
-
if (selectRow(rowIndex))
|
|
855
|
-
indices.push(rowIndex);
|
|
856
|
-
}
|
|
857
|
-
remaining -= indices.length;
|
|
858
|
-
if (indices.length === 0)
|
|
859
|
-
continue;
|
|
860
|
-
if (indices.length === batch.numRows) {
|
|
861
|
-
batches.push(batch);
|
|
862
|
-
continue;
|
|
863
|
-
}
|
|
864
|
-
if (indices[indices.length - 1] - indices[0] + 1 === indices.length) {
|
|
865
|
-
batches.push(batch.slice(indices[0], indices[indices.length - 1] + 1));
|
|
866
|
-
continue;
|
|
867
|
-
}
|
|
868
|
-
const gathered = (0, import_arrow.takeArrowTableRows)(data, Int32Array.from(indices));
|
|
869
|
-
batches.push(...gathered.batches);
|
|
870
|
-
}
|
|
871
|
-
return new arrow4.Table(source.schema, batches);
|
|
872
|
-
}
|
|
873
|
-
function getPredicateColumns(sourceTable, columnNames) {
|
|
874
|
-
const columns = {};
|
|
875
|
-
for (const columnName of columnNames) {
|
|
876
|
-
const column = sourceTable.getChild(columnName);
|
|
877
|
-
if (!column) {
|
|
878
|
-
throw new Error(`Arrow query column not found: ${columnName}`);
|
|
879
|
-
}
|
|
880
|
-
columns[columnName] = column;
|
|
881
|
-
}
|
|
882
|
-
return columns;
|
|
883
|
-
}
|
|
884
|
-
function evaluatePredicate(predicate, columns, rowIndex) {
|
|
885
|
-
if (isLogicalPredicate(predicate)) {
|
|
886
|
-
const values = predicate.args.map((child) => evaluatePredicate(child, columns, rowIndex));
|
|
887
|
-
return predicate.op === "and" ? evaluateAnd(values) : evaluateOr(values);
|
|
888
|
-
}
|
|
889
|
-
if (isNotPredicate(predicate)) {
|
|
890
|
-
const value2 = evaluatePredicate(predicate.args[0], columns, rowIndex);
|
|
891
|
-
return value2 === null ? null : !value2;
|
|
892
|
-
}
|
|
893
|
-
const value = getColumnValue(columns, predicate.args[0].property, rowIndex);
|
|
894
|
-
if (isNullPredicate(predicate)) {
|
|
895
|
-
return value === null || value === void 0;
|
|
896
|
-
}
|
|
897
|
-
if (isInPredicate(predicate)) {
|
|
898
|
-
return evaluateIn(value, predicate.args[1]);
|
|
899
|
-
}
|
|
900
|
-
return evaluateComparison(value, predicate);
|
|
901
|
-
}
|
|
902
|
-
function getColumnValue(columns, columnName, rowIndex) {
|
|
903
|
-
const path = typeof columnName === "string" ? [columnName] : columnName;
|
|
904
|
-
const column = columns[path[0]];
|
|
905
|
-
if (!column) {
|
|
906
|
-
throw new Error(`Arrow query could not read predicate column "${columnName}".`);
|
|
907
|
-
}
|
|
908
|
-
let value = column.get(rowIndex);
|
|
909
|
-
for (const property of path.slice(1)) {
|
|
910
|
-
if (value === null || value === void 0)
|
|
911
|
-
return null;
|
|
912
|
-
value = value[property];
|
|
913
|
-
}
|
|
914
|
-
return value;
|
|
915
|
-
}
|
|
916
|
-
function evaluateAnd(values) {
|
|
917
|
-
if (values.includes(false)) {
|
|
918
|
-
return false;
|
|
919
|
-
}
|
|
920
|
-
return values.includes(null) ? null : true;
|
|
921
|
-
}
|
|
922
|
-
function evaluateOr(values) {
|
|
923
|
-
if (values.includes(true)) {
|
|
924
|
-
return true;
|
|
925
|
-
}
|
|
926
|
-
return values.includes(null) ? null : false;
|
|
927
|
-
}
|
|
928
|
-
function evaluateIn(value, candidates) {
|
|
929
|
-
if (value === null || value === void 0) {
|
|
930
|
-
return null;
|
|
931
|
-
}
|
|
932
|
-
for (const candidate of candidates) {
|
|
933
|
-
if (compareValues(value, candidate) === 0) {
|
|
934
|
-
return true;
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
return false;
|
|
938
|
-
}
|
|
939
|
-
function evaluateComparison(value, predicate) {
|
|
940
|
-
if (value === null || value === void 0) {
|
|
941
|
-
return null;
|
|
942
|
-
}
|
|
943
|
-
const comparison = compareValues(value, predicate.args[1]);
|
|
944
|
-
switch (predicate.op) {
|
|
945
|
-
case "=":
|
|
946
|
-
return comparison === 0;
|
|
947
|
-
case "<>":
|
|
948
|
-
return comparison !== 0;
|
|
949
|
-
case "<":
|
|
950
|
-
return comparison < 0;
|
|
951
|
-
case "<=":
|
|
952
|
-
return comparison <= 0;
|
|
953
|
-
case ">":
|
|
954
|
-
return comparison > 0;
|
|
955
|
-
case ">=":
|
|
956
|
-
return comparison >= 0;
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
function compareValues(left, right) {
|
|
960
|
-
if (isColumnarPredicateParameter(right)) {
|
|
961
|
-
throw new Error(`Arrow query parameter ":${right.parameter}" must be bound before query execution.`);
|
|
962
|
-
}
|
|
963
|
-
if (left instanceof Date && right instanceof Date) {
|
|
964
|
-
return compareArrowQueryNumbers(left.getTime(), right.getTime());
|
|
965
|
-
}
|
|
966
|
-
if (typeof left === "number" && right instanceof Date) {
|
|
967
|
-
return compareArrowQueryNumbers(left, right.getTime());
|
|
968
|
-
}
|
|
969
|
-
if (left instanceof Uint8Array && right instanceof Uint8Array) {
|
|
970
|
-
return compareBinary(left, right);
|
|
971
|
-
}
|
|
972
|
-
if (typeof left === "bigint" && typeof right === "bigint") {
|
|
973
|
-
return left === right ? 0 : left < right ? -1 : 1;
|
|
974
|
-
}
|
|
975
|
-
if (typeof left === "bigint" && typeof right === "number" || typeof left === "number" && typeof right === "bigint") {
|
|
976
|
-
const numericValue = typeof left === "number" ? left : right;
|
|
977
|
-
if (!Number.isFinite(numericValue))
|
|
978
|
-
throw new Error("Arrow query cannot compare non-finite numbers.");
|
|
979
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
980
|
-
}
|
|
981
|
-
if (typeof left === "number" && typeof right === "number") {
|
|
982
|
-
return compareArrowQueryNumbers(left, right);
|
|
983
|
-
}
|
|
984
|
-
if (typeof left === "string" && typeof right === "string") {
|
|
985
|
-
return left === right ? 0 : left < right ? -1 : 1;
|
|
986
|
-
}
|
|
987
|
-
if (typeof left === "boolean" && typeof right === "boolean") {
|
|
988
|
-
return Number(left) - Number(right);
|
|
989
|
-
}
|
|
990
|
-
throw new Error(`Arrow query cannot compare ${getArrowQueryValueType(left)} with ${getArrowQueryValueType(right)} values.`);
|
|
991
|
-
}
|
|
992
|
-
function compareArrowQueryNumbers(left, right) {
|
|
993
|
-
if (!Number.isFinite(left) || !Number.isFinite(right)) {
|
|
994
|
-
throw new Error("Arrow query cannot compare non-finite numbers.");
|
|
995
|
-
}
|
|
996
|
-
return left === right ? 0 : left < right ? -1 : 1;
|
|
997
|
-
}
|
|
998
|
-
function compareBinary(left, right) {
|
|
999
|
-
const commonLength = Math.min(left.length, right.length);
|
|
1000
|
-
for (let index = 0; index < commonLength; index++) {
|
|
1001
|
-
if (left[index] !== right[index]) {
|
|
1002
|
-
return left[index] < right[index] ? -1 : 1;
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
return left.length === right.length ? 0 : left.length < right.length ? -1 : 1;
|
|
1006
|
-
}
|
|
1007
|
-
function getArrowQueryValueType(value) {
|
|
1008
|
-
if (value instanceof Date) {
|
|
1009
|
-
return "Date";
|
|
1010
|
-
}
|
|
1011
|
-
if (value instanceof Uint8Array) {
|
|
1012
|
-
return "Uint8Array";
|
|
1013
|
-
}
|
|
1014
|
-
return typeof value;
|
|
1015
|
-
}
|
|
1016
|
-
function isLogicalPredicate(predicate) {
|
|
1017
|
-
return predicate.op === "and" || predicate.op === "or";
|
|
1018
|
-
}
|
|
1019
|
-
function isNotPredicate(predicate) {
|
|
1020
|
-
return predicate.op === "not";
|
|
1021
|
-
}
|
|
1022
|
-
function isNullPredicate(predicate) {
|
|
1023
|
-
return predicate.op === "isNull";
|
|
1024
|
-
}
|
|
1025
|
-
function isInPredicate(predicate) {
|
|
1026
|
-
return predicate.op === "in";
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
// dist/scan/rows-to-arrow.js
|
|
1030
|
-
var arrow5 = __toESM(require("apache-arrow"), 1);
|
|
1031
|
-
function convertRowsToArrowTable(rows) {
|
|
1032
|
-
return arrow5.tableFromJSON(rows);
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
// dist/scan/sql-predicate-schema.js
|
|
1036
|
-
var import_parser = require("@math.gl/sql/parser");
|
|
1037
|
-
function validateSQLPredicate(value) {
|
|
1038
|
-
(0, import_parser.validateSQLPredicate)(value);
|
|
1039
|
-
rejectPredicateCasts(value, "$");
|
|
1040
|
-
}
|
|
1041
|
-
function rejectPredicateCasts(predicate, path) {
|
|
1042
|
-
if (predicate.op === "and" || predicate.op === "or" || predicate.op === "not") {
|
|
1043
|
-
predicate.args.forEach((child, index) => rejectPredicateCasts(child, path + ".args[" + index + "]"));
|
|
1044
|
-
} else if (Object.hasOwn(predicate.args[0], "casts")) {
|
|
1045
|
-
throw new Error("SQL predicate " + path + ".args[0] requires a non-empty property reference");
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
// dist/scan/table-query.js
|
|
1050
|
-
function planTableQuery2(sourceColumnNames, options = {}) {
|
|
1051
|
-
if (options.predicate) {
|
|
1052
|
-
validateSQLPredicate(options.predicate);
|
|
1053
|
-
}
|
|
1054
|
-
return planTableQuery(sourceColumnNames, options);
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
// dist/scan/query-arrow-table.js
|
|
1058
|
-
function explainArrowTableQuery(sourceTable, options = {}) {
|
|
1059
|
-
if (options.select !== void 0) {
|
|
1060
|
-
if (options.columns !== void 0 || hasRelationalOperators(options) || options.join) {
|
|
1061
|
-
throw new Error("Arrow select cannot be combined with columns or relational operators.");
|
|
1062
|
-
}
|
|
1063
|
-
const projected = projectArrowTable(sourceTable, options.select);
|
|
1064
|
-
const columns = [
|
|
1065
|
-
...new Set(options.select.map((selection) => typeof selection === "string" ? selection : selection.column))
|
|
1066
|
-
];
|
|
1067
|
-
const { select, ...remainingOptions } = options;
|
|
1068
|
-
const explanation = explainArrowTableQuery(sourceTable, { ...remainingOptions, columns });
|
|
1069
|
-
const outputColumns = Object.freeze(projected.schema.fields.map((field) => field.name));
|
|
1070
|
-
return Object.freeze({
|
|
1071
|
-
...explanation,
|
|
1072
|
-
outputColumns,
|
|
1073
|
-
plan: Object.freeze(explanation.plan.map((step) => step.kind === "project" ? Object.freeze({ ...step, columns: outputColumns, select }) : step))
|
|
1074
|
-
});
|
|
1075
|
-
}
|
|
1076
|
-
if (options.predicate) {
|
|
1077
|
-
validateSQLPredicate(options.predicate);
|
|
1078
|
-
}
|
|
1079
|
-
return explainTableQuery(sourceTable.schema.fields.map((field) => field.name), options, ARROW_TABLE_QUERY_CAPABILITIES);
|
|
1080
|
-
}
|
|
1081
|
-
var executePortableArrowQuery = (table, { select, where, limit, signal }) => {
|
|
1082
|
-
if (where)
|
|
1083
|
-
table = filterArrowTable(table, where, { limit, signal });
|
|
1084
|
-
const projected = select ? projectArrowTable(table, select) : table;
|
|
1085
|
-
return projected.numRows === 0 || limit === void 0 ? projected : projected.slice(0, limit);
|
|
1086
|
-
};
|
|
1087
|
-
function queryArrowTable(sourceTable, options = {}, executeLinear = executePortableArrowQuery) {
|
|
1088
|
-
throwIfAborted(options.signal);
|
|
1089
|
-
if (options.select !== void 0) {
|
|
1090
|
-
if (options.columns !== void 0 || hasRelationalOperators(options) || options.join) {
|
|
1091
|
-
throw new Error("Arrow select cannot be combined with columns or relational operators.");
|
|
1092
|
-
}
|
|
1093
|
-
projectArrowTable(sourceTable, options.select);
|
|
1094
|
-
const columns = [
|
|
1095
|
-
...new Set(options.select.map((selection) => typeof selection === "string" ? selection : selection.column))
|
|
561
|
+
for (const { name, expression } of options.expressions ?? []) {
|
|
562
|
+
const select = [
|
|
563
|
+
...table.schema.fields.map((field) => field.name),
|
|
564
|
+
expression.op === "column" ? { column: expression.column, as: name } : { expression: toArrowExpression(expression), as: name }
|
|
1096
565
|
];
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
const plan = planTableQuery2(sourceTable.schema.fields.map((field) => field.name), options);
|
|
1114
|
-
const projection = plan.find((step) => step.kind === "project");
|
|
1115
|
-
return executeLinear(sourceTable, {
|
|
1116
|
-
where: options.predicate,
|
|
1117
|
-
select: projection == null ? void 0 : projection.columns,
|
|
566
|
+
table = execute(table, { select, signal: options.signal });
|
|
567
|
+
}
|
|
568
|
+
return execute(table, {
|
|
569
|
+
select: outputColumns,
|
|
570
|
+
groupBy: options.groupBy,
|
|
571
|
+
aggregates: Object.fromEntries((options.aggregates ?? []).map((aggregate) => {
|
|
572
|
+
const expression = aggregate.column === void 0 ? void 0 : identifier(aggregate.column);
|
|
573
|
+
if (aggregate.function === "count")
|
|
574
|
+
return [aggregate.name, { operation: "COUNT", expression }];
|
|
575
|
+
const operations = { sum: "SUM", min: "MIN", max: "MAX", avg: "AVG" };
|
|
576
|
+
return [
|
|
577
|
+
aggregate.name,
|
|
578
|
+
{ operation: operations[aggregate.function], expression }
|
|
579
|
+
];
|
|
580
|
+
})),
|
|
581
|
+
orderBy: options.orderBy,
|
|
1118
582
|
limit: options.limit,
|
|
1119
583
|
signal: options.signal
|
|
1120
584
|
});
|
|
1121
585
|
}
|
|
1122
|
-
function
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
...child.query || {},
|
|
1144
|
-
columns: getUnionChildColumns(sourceColumnNames, options),
|
|
1145
|
-
signal: options.signal
|
|
1146
|
-
});
|
|
1147
|
-
rows = rows.concat(arrowTableToRows(childResult));
|
|
1148
|
-
}
|
|
1149
|
-
for (const expression of options.expressions || []) {
|
|
1150
|
-
for (const row of rows) {
|
|
1151
|
-
row[expression.name] = evaluateRelationalExpression(expression, row);
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
if (((_b = options.groupBy) == null ? void 0 : _b.length) || ((_c = options.aggregates) == null ? void 0 : _c.length)) {
|
|
1155
|
-
rows = aggregateRows(rows, options.groupBy || [], options.aggregates || []);
|
|
1156
|
-
}
|
|
1157
|
-
if ((_d = options.orderBy) == null ? void 0 : _d.length) {
|
|
1158
|
-
const orderBy = options.orderBy;
|
|
1159
|
-
rows = rows.map((row, index) => ({ row, index })).sort((left, right) => compareRows(left.row, right.row, orderBy) || left.index - right.index).map((entry) => entry.row);
|
|
1160
|
-
}
|
|
1161
|
-
const outputColumns = options.columns || (((_e = options.groupBy) == null ? void 0 : _e.length) || ((_f = options.aggregates) == null ? void 0 : _f.length) ? [...options.groupBy || [], ...(options.aggregates || []).map((aggregate) => aggregate.name)] : sourceColumnNames);
|
|
1162
|
-
const outputRows = rows.map((row) => {
|
|
1163
|
-
const output = {};
|
|
1164
|
-
for (const columnName of outputColumns) {
|
|
1165
|
-
if (!(columnName in row)) {
|
|
1166
|
-
throw new Error(`Arrow relational query column not found: ${columnName}`);
|
|
1167
|
-
}
|
|
1168
|
-
output[columnName] = row[columnName];
|
|
1169
|
-
}
|
|
1170
|
-
return output;
|
|
1171
|
-
});
|
|
1172
|
-
const limit = options.limit === void 0 ? outputRows.length : options.limit;
|
|
1173
|
-
const limitedRows = outputRows.slice(0, limit);
|
|
1174
|
-
return limitedRows.length ? convertRowsToArrowTable(limitedRows) : createEmptyRelationalResult(sourceData, outputColumns, options);
|
|
586
|
+
function identifier(name) {
|
|
587
|
+
return { type: "Identifier", name };
|
|
588
|
+
}
|
|
589
|
+
function toArrowExpression(expression) {
|
|
590
|
+
if (expression.op === "literal")
|
|
591
|
+
return literal(expression.value);
|
|
592
|
+
const operators = { add: "+", subtract: "-", multiply: "*", divide: "/" };
|
|
593
|
+
const binary = {
|
|
594
|
+
type: "BinaryExpression",
|
|
595
|
+
operator: operators[expression.op],
|
|
596
|
+
left: identifier(expression.left),
|
|
597
|
+
right: identifier(expression.right)
|
|
598
|
+
};
|
|
599
|
+
if (expression.op !== "divide")
|
|
600
|
+
return binary;
|
|
601
|
+
return {
|
|
602
|
+
type: "ConditionalExpression",
|
|
603
|
+
test: { ...binary, operator: "===", left: binary.right, right: literal(0) },
|
|
604
|
+
consequent: literal(null),
|
|
605
|
+
alternate: binary
|
|
606
|
+
};
|
|
1175
607
|
}
|
|
1176
|
-
function
|
|
1177
|
-
|
|
1178
|
-
const expressionNames = new Set((options.expressions || []).map((expression) => expression.name));
|
|
1179
|
-
const aggregateNames = new Set((options.aggregates || []).map((aggregate) => aggregate.name));
|
|
1180
|
-
const outputColumns = options.columns || (((_a = options.groupBy) == null ? void 0 : _a.length) || ((_b = options.aggregates) == null ? void 0 : _b.length) ? [...options.groupBy || [], ...(options.aggregates || []).map((aggregate) => aggregate.name)] : sourceColumnNames);
|
|
1181
|
-
const requiredColumns = new Set(outputColumns.filter((column) => !expressionNames.has(column) && !aggregateNames.has(column)));
|
|
1182
|
-
for (const expression of options.expressions || []) {
|
|
1183
|
-
const definition = expression.expression;
|
|
1184
|
-
if (definition.op === "column")
|
|
1185
|
-
requiredColumns.add(definition.column);
|
|
1186
|
-
if ("left" in definition) {
|
|
1187
|
-
requiredColumns.add(definition.left);
|
|
1188
|
-
requiredColumns.add(definition.right);
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
for (const key of options.orderBy || []) {
|
|
1192
|
-
if (!expressionNames.has(key.column) && !aggregateNames.has(key.column)) {
|
|
1193
|
-
requiredColumns.add(key.column);
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
for (const column of options.groupBy || [])
|
|
1197
|
-
requiredColumns.add(column);
|
|
1198
|
-
for (const aggregate of options.aggregates || []) {
|
|
1199
|
-
if (aggregate.column)
|
|
1200
|
-
requiredColumns.add(aggregate.column);
|
|
1201
|
-
}
|
|
1202
|
-
return sourceColumnNames.filter((column) => requiredColumns.has(column));
|
|
608
|
+
function literal(value) {
|
|
609
|
+
return { type: "Literal", value };
|
|
1203
610
|
}
|
|
1204
611
|
function hasRelationalOperators(options) {
|
|
1205
|
-
var _a, _b, _c, _d, _e;
|
|
1206
|
-
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);
|
|
1207
|
-
}
|
|
1208
|
-
function hasRelationalOperatorsExceptJoin(options) {
|
|
1209
612
|
var _a, _b, _c, _d, _e;
|
|
1210
613
|
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));
|
|
1211
614
|
}
|
|
1212
|
-
function queryArrowJoin(sourceTable, options) {
|
|
1213
|
-
var _a;
|
|
615
|
+
function queryArrowJoin(sourceTable, options, executeRelational) {
|
|
616
|
+
var _a, _b, _c, _d;
|
|
1214
617
|
const join = options.join;
|
|
1215
|
-
if (!join)
|
|
1216
|
-
throw new Error("Arrow join query is missing a join definition.");
|
|
1217
618
|
const childTable = (_a = options.tables) == null ? void 0 : _a[join.child.source];
|
|
1218
619
|
if (!childTable)
|
|
1219
620
|
throw new Error(`Arrow join source not found: ${join.child.source}`);
|
|
1220
|
-
const
|
|
1221
|
-
|
|
1222
|
-
columns: void 0,
|
|
621
|
+
const left = executeRelational(sourceTable, {
|
|
622
|
+
where: options.predicate,
|
|
1223
623
|
signal: options.signal
|
|
1224
624
|
});
|
|
1225
|
-
const
|
|
1226
|
-
|
|
625
|
+
const right = executeRelational(childTable, {
|
|
626
|
+
where: (_b = join.child.query) == null ? void 0 : _b.predicate,
|
|
627
|
+
select: (_c = join.child.query) == null ? void 0 : _c.columns,
|
|
628
|
+
limit: (_d = join.child.query) == null ? void 0 : _d.limit,
|
|
629
|
+
signal: options.signal
|
|
630
|
+
});
|
|
631
|
+
return executeRelational(left, {
|
|
632
|
+
join: {
|
|
633
|
+
table: right,
|
|
634
|
+
type: join.type,
|
|
635
|
+
left: join.left,
|
|
636
|
+
right: join.right,
|
|
637
|
+
rightPrefix: `${join.child.source}.`
|
|
638
|
+
},
|
|
639
|
+
select: options.columns,
|
|
640
|
+
limit: options.limit,
|
|
1227
641
|
signal: options.signal
|
|
1228
642
|
});
|
|
1229
|
-
const leftRows = arrowTableToRows(leftResult);
|
|
1230
|
-
const rightRows = arrowTableToRows(rightResult);
|
|
1231
|
-
const rightPrefix = `${join.child.source}.`;
|
|
1232
|
-
const defaultOutputColumns = [
|
|
1233
|
-
...sourceTable.schema.fields.map((field) => field.name),
|
|
1234
|
-
...rightResult.schema.fields.map((field) => `${rightPrefix}${field.name}`)
|
|
1235
|
-
];
|
|
1236
|
-
const rows = [];
|
|
1237
|
-
for (const leftRow of leftRows) {
|
|
1238
|
-
for (const rightRow of rightRows) {
|
|
1239
|
-
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) {
|
|
1240
|
-
rows.push({
|
|
1241
|
-
...leftRow,
|
|
1242
|
-
...Object.fromEntries(Object.entries(rightRow).map(([key, value]) => [`${rightPrefix}${key}`, value]))
|
|
1243
|
-
});
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
const outputColumns = options.columns || defaultOutputColumns;
|
|
1248
|
-
const outputRows = rows.map((row) => Object.fromEntries(outputColumns.map((column) => [column, row[column]])));
|
|
1249
|
-
const limitedRows = outputRows.slice(0, options.limit);
|
|
1250
|
-
return limitedRows.length ? convertRowsToArrowTable(limitedRows) : createEmptyRelationalResult(sourceTable, outputColumns, options, new Map(rightResult.schema.fields.map((field) => [
|
|
1251
|
-
`${rightPrefix}${field.name}`,
|
|
1252
|
-
new arrow6.Field(`${rightPrefix}${field.name}`, field.type, field.nullable, field.metadata)
|
|
1253
|
-
])));
|
|
1254
643
|
}
|
|
1255
644
|
function validateArrowJoinQuery(sourceTable, options) {
|
|
1256
645
|
var _a, _b, _c;
|
|
@@ -1298,180 +687,330 @@ function validateArrowJoinQuery(sourceTable, options) {
|
|
|
1298
687
|
}
|
|
1299
688
|
}
|
|
1300
689
|
}
|
|
1301
|
-
function
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
const row = {};
|
|
1308
|
-
for (const column of columns) {
|
|
1309
|
-
if (!column.vector)
|
|
1310
|
-
throw new Error(`Arrow relational query could not read ${column.name}`);
|
|
1311
|
-
row[column.name] = column.vector.get(rowIndex);
|
|
1312
|
-
}
|
|
1313
|
-
return row;
|
|
1314
|
-
});
|
|
1315
|
-
}
|
|
1316
|
-
function evaluateRelationalExpression(expression, row) {
|
|
1317
|
-
const definition = expression.expression;
|
|
1318
|
-
if (definition.op === "literal")
|
|
1319
|
-
return definition.value;
|
|
1320
|
-
if (definition.op === "column")
|
|
1321
|
-
return row[definition.column];
|
|
1322
|
-
const left = row[definition.left];
|
|
1323
|
-
const right = row[definition.right];
|
|
1324
|
-
if (left === null || left === void 0 || right === null || right === void 0)
|
|
1325
|
-
return null;
|
|
1326
|
-
if (typeof left !== "number" || typeof right !== "number") {
|
|
1327
|
-
throw new Error(`Arrow relational expression ${expression.name} requires numeric operands.`);
|
|
1328
|
-
}
|
|
1329
|
-
switch (definition.op) {
|
|
1330
|
-
case "add":
|
|
1331
|
-
return left + right;
|
|
1332
|
-
case "subtract":
|
|
1333
|
-
return left - right;
|
|
1334
|
-
case "multiply":
|
|
1335
|
-
return left * right;
|
|
1336
|
-
case "divide":
|
|
1337
|
-
return right === 0 ? null : left / right;
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
function compareRows(left, right, orderBy) {
|
|
1341
|
-
for (const key of orderBy) {
|
|
1342
|
-
const leftValue = left[key.column];
|
|
1343
|
-
const rightValue = right[key.column];
|
|
1344
|
-
const nulls = key.nulls || "last";
|
|
1345
|
-
if (leftValue === null || leftValue === void 0 || rightValue === null || rightValue === void 0) {
|
|
1346
|
-
if (leftValue === rightValue)
|
|
1347
|
-
continue;
|
|
1348
|
-
const nullResult = leftValue === null || leftValue === void 0 ? -1 : 1;
|
|
1349
|
-
return nulls === "first" ? nullResult : -nullResult;
|
|
1350
|
-
}
|
|
1351
|
-
const result = compareSortValues(leftValue, rightValue);
|
|
1352
|
-
if (result)
|
|
1353
|
-
return (key.direction === "desc" ? -1 : 1) * result;
|
|
1354
|
-
}
|
|
1355
|
-
return 0;
|
|
690
|
+
function throwIfAborted(signal) {
|
|
691
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
692
|
+
const error = new Error("Arrow query was aborted.");
|
|
693
|
+
error.name = "AbortError";
|
|
694
|
+
throw error;
|
|
695
|
+
}
|
|
1356
696
|
}
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
697
|
+
var executePortableArrowQuery;
|
|
698
|
+
var init_plan_arrow_table_query = __esm({
|
|
699
|
+
"dist/scan/plan-arrow-table-query.js"() {
|
|
700
|
+
"use strict";
|
|
701
|
+
init_arrow_execution();
|
|
702
|
+
init_table_query2();
|
|
703
|
+
init_loader_utils();
|
|
704
|
+
init_table_query_capabilities();
|
|
705
|
+
init_sql_predicate_schema();
|
|
706
|
+
executePortableArrowQuery = (table, { select, where, limit, signal }) => {
|
|
707
|
+
if (where)
|
|
708
|
+
table = filterArrowTable(table, where, { limit, signal });
|
|
709
|
+
const projected = select ? (0, import_arrow3.projectArrowTable)(table, select) : table;
|
|
710
|
+
return projected.numRows === 0 || limit === void 0 ? projected : projected.slice(0, limit);
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
// dist/scan/query-arrow-table.js
|
|
716
|
+
var query_arrow_table_exports = {};
|
|
717
|
+
__export(query_arrow_table_exports, {
|
|
718
|
+
ARROW_TABLE_QUERY_CAPABILITIES: () => ARROW_TABLE_QUERY_CAPABILITIES,
|
|
719
|
+
explainArrowTableQuery: () => explainArrowTableQuery,
|
|
720
|
+
queryArrowTable: () => queryArrowTable2
|
|
721
|
+
});
|
|
722
|
+
function queryArrowTable2(source, options) {
|
|
723
|
+
return queryArrowTable(source, options, import_query.queryArrowTable);
|
|
1369
724
|
}
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
725
|
+
var import_query;
|
|
726
|
+
var init_query_arrow_table = __esm({
|
|
727
|
+
"dist/scan/query-arrow-table.js"() {
|
|
728
|
+
"use strict";
|
|
729
|
+
import_query = require("@math.gl/sql/query");
|
|
730
|
+
init_plan_arrow_table_query();
|
|
731
|
+
init_plan_arrow_table_query();
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
// dist/vector-table-scan-source.js
|
|
736
|
+
var vector_table_scan_source_exports = {};
|
|
737
|
+
__export(vector_table_scan_source_exports, {
|
|
738
|
+
AddressedVectorTableScanSource: () => AddressedVectorTableScanSource,
|
|
739
|
+
VectorFeatureTableScanSource: () => VectorFeatureTableScanSource,
|
|
740
|
+
VectorTileTableScanSource: () => VectorTileTableScanSource
|
|
741
|
+
});
|
|
742
|
+
module.exports = __toCommonJS(vector_table_scan_source_exports);
|
|
743
|
+
|
|
744
|
+
// src/schema-utils/lib/schema/convert-arrow-schema.ts
|
|
745
|
+
var arrow = __toESM(require("apache-arrow"), 1);
|
|
746
|
+
function convertArrowToSchema(arrowSchema) {
|
|
747
|
+
return serializeArrowSchema(arrowSchema);
|
|
1389
748
|
}
|
|
1390
|
-
function
|
|
1391
|
-
return
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
return `date:${value.getTime()}`;
|
|
1396
|
-
if (value instanceof Uint8Array)
|
|
1397
|
-
return `bytes:${Array.from(value).join(".")}`;
|
|
1398
|
-
return `${typeof value}:${String(value)}`;
|
|
1399
|
-
}).join("");
|
|
749
|
+
function serializeArrowSchema(arrowSchema) {
|
|
750
|
+
return {
|
|
751
|
+
fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
|
|
752
|
+
metadata: serializeArrowMetadata(arrowSchema.metadata)
|
|
753
|
+
};
|
|
1400
754
|
}
|
|
1401
|
-
function
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
return additionalField;
|
|
1412
|
-
const expression = expressions.get(columnName);
|
|
1413
|
-
if (expression)
|
|
1414
|
-
return new arrow6.Field(columnName, getExpressionType(expression, sourceFields), true);
|
|
1415
|
-
const aggregate = aggregates.get(columnName);
|
|
1416
|
-
if (aggregate)
|
|
1417
|
-
return new arrow6.Field(columnName, getAggregateType(aggregate, sourceFields), true);
|
|
1418
|
-
return new arrow6.Field(columnName, new arrow6.Utf8(), true);
|
|
1419
|
-
});
|
|
1420
|
-
const columns = {};
|
|
1421
|
-
for (const field of fields)
|
|
1422
|
-
columns[field.name] = arrow6.vectorFromArray([], field.type);
|
|
1423
|
-
return new arrow6.Table(new arrow6.Schema(fields), columns);
|
|
755
|
+
function serializeArrowMetadata(arrowMetadata) {
|
|
756
|
+
return Object.fromEntries(arrowMetadata);
|
|
757
|
+
}
|
|
758
|
+
function serializeArrowField(field) {
|
|
759
|
+
return {
|
|
760
|
+
name: field.name,
|
|
761
|
+
type: serializeArrowType(field.type),
|
|
762
|
+
nullable: field.nullable,
|
|
763
|
+
metadata: serializeArrowMetadata(field.metadata)
|
|
764
|
+
};
|
|
1424
765
|
}
|
|
1425
|
-
function
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
766
|
+
function serializeArrowType(arrowType) {
|
|
767
|
+
if (isArrowViewType(arrowType, "BinaryView")) {
|
|
768
|
+
return "binary-view";
|
|
769
|
+
}
|
|
770
|
+
if (isArrowViewType(arrowType, "Utf8View")) {
|
|
771
|
+
return "utf8-view";
|
|
772
|
+
}
|
|
773
|
+
if (isOptionalArrowType(arrowType, "LargeList")) {
|
|
774
|
+
const largeListType = arrowType;
|
|
775
|
+
return {
|
|
776
|
+
type: "large-list",
|
|
777
|
+
children: [serializeArrowField(largeListType.valueField)]
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
switch (arrowType.constructor) {
|
|
781
|
+
case arrow.Null:
|
|
782
|
+
return "null";
|
|
783
|
+
case arrow.Binary:
|
|
784
|
+
return "binary";
|
|
785
|
+
case arrow.FixedSizeBinary:
|
|
786
|
+
return {
|
|
787
|
+
type: "fixed-size-binary",
|
|
788
|
+
byteWidth: arrowType.byteWidth
|
|
789
|
+
};
|
|
790
|
+
case arrow.Bool:
|
|
791
|
+
return "bool";
|
|
792
|
+
case arrow.Int:
|
|
793
|
+
const intType = arrowType;
|
|
794
|
+
return `${intType.isSigned ? "" : "u"}int${intType.bitWidth}`;
|
|
795
|
+
case arrow.Int8:
|
|
796
|
+
return "int8";
|
|
797
|
+
case arrow.Int16:
|
|
798
|
+
return "int16";
|
|
799
|
+
case arrow.Int32:
|
|
800
|
+
return "int32";
|
|
801
|
+
case arrow.Int64:
|
|
802
|
+
return "int64";
|
|
803
|
+
case arrow.Uint8:
|
|
804
|
+
return "uint8";
|
|
805
|
+
case arrow.Uint16:
|
|
806
|
+
return "uint16";
|
|
807
|
+
case arrow.Uint32:
|
|
808
|
+
return "uint32";
|
|
809
|
+
case arrow.Uint64:
|
|
810
|
+
return "uint64";
|
|
811
|
+
case arrow.Float:
|
|
812
|
+
const precision = arrowType.precision;
|
|
813
|
+
switch (precision) {
|
|
814
|
+
case arrow.Precision.HALF:
|
|
815
|
+
return "float16";
|
|
816
|
+
case arrow.Precision.SINGLE:
|
|
817
|
+
return "float32";
|
|
818
|
+
case arrow.Precision.DOUBLE:
|
|
819
|
+
return "float64";
|
|
820
|
+
default:
|
|
821
|
+
return "float16";
|
|
822
|
+
}
|
|
823
|
+
case arrow.Float16:
|
|
824
|
+
return "float16";
|
|
825
|
+
case arrow.Float32:
|
|
826
|
+
return "float32";
|
|
827
|
+
case arrow.Float64:
|
|
828
|
+
return "float64";
|
|
829
|
+
case arrow.Utf8:
|
|
830
|
+
return "utf8";
|
|
831
|
+
case arrow.Decimal:
|
|
832
|
+
const decimal = arrowType;
|
|
833
|
+
return {
|
|
834
|
+
type: "decimal",
|
|
835
|
+
bitWidth: decimal.bitWidth,
|
|
836
|
+
precision: decimal.precision,
|
|
837
|
+
scale: decimal.scale
|
|
838
|
+
};
|
|
839
|
+
case arrow.Date_:
|
|
840
|
+
const dateUnit = arrowType.unit;
|
|
841
|
+
return dateUnit === arrow.DateUnit.DAY ? "date-day" : "date-millisecond";
|
|
842
|
+
case arrow.DateDay:
|
|
843
|
+
return "date-day";
|
|
844
|
+
case arrow.DateMillisecond:
|
|
845
|
+
return "date-millisecond";
|
|
846
|
+
case arrow.Time:
|
|
847
|
+
const timeUnit = arrowType.unit;
|
|
848
|
+
switch (timeUnit) {
|
|
849
|
+
case arrow.TimeUnit.SECOND:
|
|
850
|
+
return "time-second";
|
|
851
|
+
case arrow.TimeUnit.MILLISECOND:
|
|
852
|
+
return "time-millisecond";
|
|
853
|
+
case arrow.TimeUnit.MICROSECOND:
|
|
854
|
+
return "time-microsecond";
|
|
855
|
+
case arrow.TimeUnit.NANOSECOND:
|
|
856
|
+
return "time-nanosecond";
|
|
857
|
+
default:
|
|
858
|
+
return "time-second";
|
|
859
|
+
}
|
|
860
|
+
case arrow.TimeMillisecond:
|
|
861
|
+
return "time-millisecond";
|
|
862
|
+
case arrow.TimeSecond:
|
|
863
|
+
return "time-second";
|
|
864
|
+
case arrow.TimeMicrosecond:
|
|
865
|
+
return "time-microsecond";
|
|
866
|
+
case arrow.TimeNanosecond:
|
|
867
|
+
return "time-nanosecond";
|
|
868
|
+
case arrow.Timestamp:
|
|
869
|
+
const timeStampUnit = arrowType.unit;
|
|
870
|
+
switch (timeStampUnit) {
|
|
871
|
+
case arrow.TimeUnit.SECOND:
|
|
872
|
+
return "timestamp-second";
|
|
873
|
+
case arrow.TimeUnit.MILLISECOND:
|
|
874
|
+
return "timestamp-millisecond";
|
|
875
|
+
case arrow.TimeUnit.MICROSECOND:
|
|
876
|
+
return "timestamp-microsecond";
|
|
877
|
+
case arrow.TimeUnit.NANOSECOND:
|
|
878
|
+
return "timestamp-nanosecond";
|
|
879
|
+
default:
|
|
880
|
+
return "timestamp-second";
|
|
881
|
+
}
|
|
882
|
+
case arrow.TimestampSecond:
|
|
883
|
+
return "timestamp-second";
|
|
884
|
+
case arrow.TimestampMillisecond:
|
|
885
|
+
return "timestamp-millisecond";
|
|
886
|
+
case arrow.TimestampMicrosecond:
|
|
887
|
+
return "timestamp-microsecond";
|
|
888
|
+
case arrow.TimestampNanosecond:
|
|
889
|
+
return "timestamp-nanosecond";
|
|
890
|
+
case arrow.Interval:
|
|
891
|
+
const intervalUnit = arrowType.unit;
|
|
892
|
+
switch (intervalUnit) {
|
|
893
|
+
case arrow.IntervalUnit.DAY_TIME:
|
|
894
|
+
return "interval-daytime";
|
|
895
|
+
case arrow.IntervalUnit.YEAR_MONTH:
|
|
896
|
+
return "interval-yearmonth";
|
|
897
|
+
default:
|
|
898
|
+
return "interval-daytime";
|
|
899
|
+
}
|
|
900
|
+
case arrow.IntervalDayTime:
|
|
901
|
+
return "interval-daytime";
|
|
902
|
+
case arrow.IntervalYearMonth:
|
|
903
|
+
return "interval-yearmonth";
|
|
904
|
+
case arrow.Map_:
|
|
905
|
+
const mapType = arrowType;
|
|
906
|
+
return {
|
|
907
|
+
type: "map",
|
|
908
|
+
keysSorted: mapType.keysSorted,
|
|
909
|
+
children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
|
|
910
|
+
};
|
|
911
|
+
case arrow.List:
|
|
912
|
+
const listType = arrowType;
|
|
913
|
+
const listField = listType.valueField;
|
|
914
|
+
return {
|
|
915
|
+
type: "list",
|
|
916
|
+
children: [serializeArrowField(listField)]
|
|
917
|
+
};
|
|
918
|
+
case arrow.FixedSizeList:
|
|
919
|
+
const fixedSizeList = arrowType;
|
|
920
|
+
return {
|
|
921
|
+
type: "fixed-size-list",
|
|
922
|
+
listSize: fixedSizeList.listSize,
|
|
923
|
+
children: [serializeArrowField(fixedSizeList.children[0])]
|
|
924
|
+
};
|
|
925
|
+
case arrow.Struct:
|
|
926
|
+
const structType = arrowType;
|
|
927
|
+
return {
|
|
928
|
+
type: "struct",
|
|
929
|
+
children: structType.children.map((arrowField) => serializeArrowField(arrowField))
|
|
930
|
+
};
|
|
931
|
+
case arrow.SparseUnion:
|
|
932
|
+
case arrow.DenseUnion:
|
|
933
|
+
const unionType = arrowType;
|
|
934
|
+
return {
|
|
935
|
+
type: unionType instanceof arrow.DenseUnion ? "dense-union" : "sparse-union",
|
|
936
|
+
typeIds: unionType.typeIds,
|
|
937
|
+
children: unionType.children.map((arrowField) => serializeArrowField(arrowField)),
|
|
938
|
+
typeIdToChildIndex: { ...unionType.typeIdToChildIndex }
|
|
939
|
+
};
|
|
940
|
+
case arrow.Dictionary:
|
|
941
|
+
const dictionaryType = arrowType;
|
|
942
|
+
return {
|
|
943
|
+
type: "dictionary",
|
|
944
|
+
id: dictionaryType.id,
|
|
945
|
+
indices: serializeArrowDictionaryKeyType(dictionaryType.indices),
|
|
946
|
+
dictionary: serializeArrowType(dictionaryType.dictionary),
|
|
947
|
+
isOrdered: dictionaryType.isOrdered
|
|
948
|
+
};
|
|
949
|
+
default:
|
|
950
|
+
throw new Error(`arrow type not supported: ${arrowType.constructor.name}`);
|
|
951
|
+
}
|
|
1439
952
|
}
|
|
1440
|
-
function
|
|
1441
|
-
|
|
1442
|
-
if (aggregate.function === "count")
|
|
1443
|
-
return new arrow6.Int32();
|
|
1444
|
-
return aggregate.column ? ((_a = sourceFields.get(aggregate.column)) == null ? void 0 : _a.type) || new arrow6.Float64() : new arrow6.Float64();
|
|
953
|
+
function getOptionalArrowConstructor(typeName) {
|
|
954
|
+
return arrow[typeName];
|
|
1445
955
|
}
|
|
1446
|
-
function
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
if (!values.length)
|
|
1451
|
-
return null;
|
|
1452
|
-
if (!values.every((value) => typeof value === "number"))
|
|
1453
|
-
throw new Error(`Arrow aggregate ${aggregate.function} requires numeric values.`);
|
|
1454
|
-
const numericValues = values;
|
|
1455
|
-
switch (aggregate.function) {
|
|
1456
|
-
case "sum":
|
|
1457
|
-
return numericValues.reduce((sum, value) => sum + value, 0);
|
|
1458
|
-
case "avg":
|
|
1459
|
-
return numericValues.reduce((sum, value) => sum + value, 0) / numericValues.length;
|
|
1460
|
-
case "min":
|
|
1461
|
-
return Math.min(...numericValues);
|
|
1462
|
-
case "max":
|
|
1463
|
-
return Math.max(...numericValues);
|
|
956
|
+
function isArrowViewType(arrowType, viewTypeName) {
|
|
957
|
+
const constructor = getOptionalArrowConstructor(viewTypeName);
|
|
958
|
+
if (constructor && arrowType instanceof constructor) {
|
|
959
|
+
return true;
|
|
1464
960
|
}
|
|
961
|
+
const guards = arrow.DataType;
|
|
962
|
+
const guard = viewTypeName === "BinaryView" ? guards.isBinaryView : guards.isUtf8View;
|
|
963
|
+
return Boolean(guard == null ? void 0 : guard(arrowType));
|
|
1465
964
|
}
|
|
1466
|
-
function
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
965
|
+
function isOptionalArrowType(arrowType, typeName) {
|
|
966
|
+
const constructor = getOptionalArrowConstructor(typeName);
|
|
967
|
+
return Boolean(constructor && arrowType instanceof constructor);
|
|
968
|
+
}
|
|
969
|
+
function serializeArrowDictionaryKeyType(arrowType) {
|
|
970
|
+
if (arrowType instanceof arrow.Int) {
|
|
971
|
+
const prefix = arrowType.isSigned ? "int" : "uint";
|
|
972
|
+
const keyType = `${prefix}${arrowType.bitWidth}`;
|
|
973
|
+
if (isSchemaDictionaryKeyType(keyType)) {
|
|
974
|
+
return keyType;
|
|
975
|
+
}
|
|
1471
976
|
}
|
|
977
|
+
switch (arrowType.constructor) {
|
|
978
|
+
case arrow.Int8:
|
|
979
|
+
return "int8";
|
|
980
|
+
case arrow.Int16:
|
|
981
|
+
return "int16";
|
|
982
|
+
case arrow.Int32:
|
|
983
|
+
return "int32";
|
|
984
|
+
case arrow.Uint8:
|
|
985
|
+
return "uint8";
|
|
986
|
+
case arrow.Uint16:
|
|
987
|
+
return "uint16";
|
|
988
|
+
case arrow.Uint32:
|
|
989
|
+
return "uint32";
|
|
990
|
+
default:
|
|
991
|
+
throw new Error(`arrow dictionary index type not supported: ${arrowType.constructor.name}`);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
function isSchemaDictionaryKeyType(keyType) {
|
|
995
|
+
return ["int8", "int16", "int32", "uint8", "uint16", "uint32"].includes(keyType);
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// src/schema-utils/lib/arrow/arrow-metadata.ts
|
|
999
|
+
var arrow2 = __toESM(require("apache-arrow"), 1);
|
|
1000
|
+
var import_arrow = require("@math.gl/core/arrow");
|
|
1001
|
+
function makeArrowMetadataBatch(schema) {
|
|
1002
|
+
return new arrow2.RecordBatch((0, import_arrow.snapshotArrowSchema)(schema), void 0);
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
// dist/lib/loader-utils/native-arrow.js
|
|
1006
|
+
function isArrowTable(value) {
|
|
1007
|
+
return Boolean(value && typeof value === "object" && "schema" in value && "batches" in value && Array.isArray(value.batches) && "numRows" in value && typeof value.numRows === "number" && "getChildAt" in value && typeof value.getChildAt === "function");
|
|
1472
1008
|
}
|
|
1473
1009
|
|
|
1474
1010
|
// dist/scan/vector-table-scan-source.js
|
|
1011
|
+
init_loader_utils();
|
|
1012
|
+
init_table_query_capabilities();
|
|
1013
|
+
init_plan_arrow_table_query();
|
|
1475
1014
|
var AddressedVectorTableScanSource = class {
|
|
1476
1015
|
/** Stable adapter type reported by `getQueryMetadata()`. */
|
|
1477
1016
|
sourceType;
|
|
@@ -1513,7 +1052,8 @@ var AddressedVectorTableScanSource = class {
|
|
|
1513
1052
|
/** Applies the portable Arrow query to the addressed feature table. */
|
|
1514
1053
|
async query(options = {}) {
|
|
1515
1054
|
const table = await this.getTable(options.signal);
|
|
1516
|
-
|
|
1055
|
+
const { queryArrowTable: queryArrowTable3 } = await Promise.resolve().then(() => (init_query_arrow_table(), query_arrow_table_exports));
|
|
1056
|
+
return queryArrowTable3(table, options);
|
|
1517
1057
|
}
|
|
1518
1058
|
/** Explains the residual Arrow plan after resolving the addressed feature table. */
|
|
1519
1059
|
async explain(options = {}) {
|