@math.gl/sql 5.0.0-beta.11 → 5.0.0-beta.12
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/aggregates.js +1 -1
- package/dist/arrow/aggregates.js.map +1 -1
- package/dist/arrow/buffers.js.map +1 -1
- package/dist/arrow/cast.d.ts +1 -1
- package/dist/arrow/cast.js +1 -1
- package/dist/arrow/cast.js.map +1 -1
- package/dist/arrow/compiler.d.ts.map +1 -1
- package/dist/arrow/compiler.js +146 -29
- package/dist/arrow/compiler.js.map +1 -1
- package/dist/arrow/index.cjs +124 -23
- package/dist/arrow/index.cjs.map +1 -1
- package/dist/arrow/index.d.ts.map +1 -1
- package/dist/arrow/index.js.map +1 -1
- package/dist/arrow/list-values.d.ts.map +1 -1
- package/dist/arrow/list-values.js +27 -6
- package/dist/arrow/list-values.js.map +1 -1
- package/dist/arrow/predicate.d.ts.map +1 -1
- package/dist/arrow/predicate.js.map +1 -1
- package/dist/arrow/query-arrow-sql.d.ts +2 -2
- package/dist/arrow/query-arrow-sql.d.ts.map +1 -1
- package/dist/arrow/query-arrow-sql.js +40 -8
- package/dist/arrow/query-arrow-sql.js.map +1 -1
- package/dist/arrow/query-arrow-table.d.ts +1 -1
- package/dist/arrow/query-arrow-table.d.ts.map +1 -1
- package/dist/arrow/query-arrow-table.js +1 -1
- package/dist/arrow/query-arrow-table.js.map +1 -1
- package/dist/arrow/query-worker.d.ts +1 -1
- package/dist/arrow/query-worker.d.ts.map +1 -1
- package/dist/arrow/query-worker.js +1 -1
- package/dist/arrow/query-worker.js.map +1 -1
- package/dist/arrow/registry.d.ts.map +1 -1
- package/dist/arrow/registry.js +1 -0
- package/dist/arrow/registry.js.map +1 -1
- package/dist/arrow/relational-query.js +2 -2
- package/dist/arrow/relational-query.js.map +1 -1
- package/dist/arrow/temporal-cast.js.map +1 -1
- package/dist/arrow/types.d.ts.map +1 -1
- package/dist/arrow/unnest-arrow-column.d.ts +22 -0
- package/dist/arrow/unnest-arrow-column.d.ts.map +1 -0
- package/dist/arrow/unnest-arrow-column.js +112 -0
- package/dist/arrow/unnest-arrow-column.js.map +1 -0
- package/dist/arrow/worker.cjs +130 -29
- package/dist/arrow/worker.cjs.map +1 -1
- package/dist/arrow/worker.d.ts +1 -1
- package/dist/arrow/worker.d.ts.map +1 -1
- package/dist/arrow/worker.js +1 -1
- package/dist/arrow/worker.js.map +1 -1
- package/dist/{color → color-functions}/index.cjs +2 -2
- package/dist/{color → color-functions}/index.cjs.map +1 -1
- package/dist/color-functions/index.d.ts.map +1 -0
- package/dist/color-functions/index.js.map +1 -0
- package/dist/expressions/ast.js +3 -1
- package/dist/expressions/ast.js.map +1 -1
- package/dist/expressions/expression-eval.d.ts +10 -1
- package/dist/expressions/expression-eval.d.ts.map +1 -1
- package/dist/expressions/expression-eval.js.map +1 -1
- package/dist/expressions/index.cjs +1 -1
- package/dist/expressions/index.cjs.map +1 -1
- package/dist/index.cjs +2792 -2363
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/{math → math-functions}/index.cjs +2 -2
- package/dist/{math → math-functions}/index.cjs.map +1 -1
- package/dist/math-functions/index.d.ts.map +1 -0
- package/dist/math-functions/index.js.map +1 -0
- package/dist/parser/bind-sql-predicate.d.ts.map +1 -0
- package/dist/parser/bind-sql-predicate.js.map +1 -0
- package/dist/{sql → parser}/index.cjs +348 -129
- package/dist/parser/index.cjs.map +6 -0
- package/dist/{sql → parser}/index.d.ts +2 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/{sql → parser}/index.js +1 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/parameter-snapshots.d.ts +21 -0
- package/dist/parser/parameter-snapshots.d.ts.map +1 -0
- package/dist/parser/parameter-snapshots.js +85 -0
- package/dist/parser/parameter-snapshots.js.map +1 -0
- package/dist/{sql → parser}/parse-sql-expression.d.ts +8 -2
- package/dist/parser/parse-sql-expression.d.ts.map +1 -0
- package/dist/{sql → parser}/parse-sql-expression.js +51 -5
- package/dist/parser/parse-sql-expression.js.map +1 -0
- package/dist/parser/parse-sql-predicate.d.ts.map +1 -0
- package/dist/parser/parse-sql-predicate.js.map +1 -0
- package/dist/{sql → parser}/parse-sql-query.d.ts +2 -1
- package/dist/parser/parse-sql-query.d.ts.map +1 -0
- package/dist/{sql → parser}/parse-sql-query.js +21 -6
- package/dist/parser/parse-sql-query.js.map +1 -0
- package/dist/{sql → parser}/parse-sql-select.d.ts +4 -2
- package/dist/parser/parse-sql-select.d.ts.map +1 -0
- package/dist/{sql → parser}/parse-sql-select.js +6 -3
- package/dist/parser/parse-sql-select.js.map +1 -0
- package/dist/{sql → parser}/parse-sql-statement.d.ts +9 -5
- package/dist/parser/parse-sql-statement.d.ts.map +1 -0
- package/dist/{sql → parser}/parse-sql-statement.js +39 -14
- package/dist/parser/parse-sql-statement.js.map +1 -0
- package/dist/parser/query-types.d.ts.map +1 -0
- package/dist/parser/query-types.js.map +1 -0
- package/dist/parser/sql-parameters.d.ts +29 -0
- package/dist/parser/sql-parameters.d.ts.map +1 -0
- package/dist/parser/sql-parameters.js +110 -0
- package/dist/parser/sql-parameters.js.map +1 -0
- package/dist/parser/sql-parse-error.d.ts.map +1 -0
- package/dist/parser/sql-parse-error.js.map +1 -0
- package/dist/parser/sql-predicate-schema.d.ts.map +1 -0
- package/dist/parser/sql-predicate-schema.js.map +1 -0
- package/dist/parser/sql-predicate-types.d.ts.map +1 -0
- package/dist/parser/sql-predicate-types.js.map +1 -0
- package/dist/parser/sql-predicate.d.ts.map +1 -0
- package/dist/parser/sql-predicate.js.map +1 -0
- package/dist/scales/arrow-domains.d.ts +8 -1
- package/dist/scales/arrow-domains.d.ts.map +1 -1
- package/dist/scales/arrow-domains.js +48 -6
- package/dist/scales/arrow-domains.js.map +1 -1
- package/dist/scales/arrow-scales.d.ts +28 -4
- package/dist/scales/arrow-scales.d.ts.map +1 -1
- package/dist/scales/arrow-scales.js +158 -12
- package/dist/scales/arrow-scales.js.map +1 -1
- package/dist/scales/compile-scale.d.ts +1 -6
- package/dist/scales/compile-scale.d.ts.map +1 -1
- package/dist/scales/compile-scale.js +1 -191
- package/dist/scales/compile-scale.js.map +1 -1
- package/dist/scales/conformance.cjs +180 -0
- package/dist/scales/conformance.cjs.map +6 -0
- package/dist/scales/conformance.d.ts +26 -0
- package/dist/scales/conformance.d.ts.map +1 -0
- package/dist/scales/conformance.js +164 -0
- package/dist/scales/conformance.js.map +1 -0
- package/dist/scales/hdr-colors.d.ts +1 -12
- package/dist/scales/hdr-colors.d.ts.map +1 -1
- package/dist/scales/hdr-colors.js +1 -111
- package/dist/scales/hdr-colors.js.map +1 -1
- package/dist/scales/index.cjs +3738 -618
- package/dist/scales/index.cjs.map +3 -3
- package/dist/scales/index.d.ts +2 -1
- package/dist/scales/index.d.ts.map +1 -1
- package/dist/scales/index.js +2 -1
- package/dist/scales/index.js.map +1 -1
- package/dist/scales/palettes.d.ts +1 -4
- package/dist/scales/palettes.d.ts.map +1 -1
- package/dist/scales/palettes.js +1 -81
- package/dist/scales/palettes.js.map +1 -1
- package/dist/scales/parse-sql-scale.d.ts +14 -1
- package/dist/scales/parse-sql-scale.d.ts.map +1 -1
- package/dist/scales/parse-sql-scale.js +110 -18
- package/dist/scales/parse-sql-scale.js.map +1 -1
- package/dist/scales/quantile-sketch.d.ts +1 -21
- package/dist/scales/quantile-sketch.d.ts.map +1 -1
- package/dist/scales/quantile-sketch.js +1 -104
- package/dist/scales/quantile-sketch.js.map +1 -1
- package/dist/scales/scale-types.d.ts +1 -91
- package/dist/scales/scale-types.d.ts.map +1 -1
- package/dist/scales/scale-types.js +1 -115
- package/dist/scales/scale-types.js.map +1 -1
- package/dist/scales/streaming-domains.d.ts.map +1 -1
- package/dist/scales/streaming-domains.js +8 -2
- package/dist/scales/streaming-domains.js.map +1 -1
- package/package.json +19 -19
- package/src/arrow/aggregates.ts +1 -1
- package/src/arrow/buffers.ts +1 -1
- package/src/arrow/cast.ts +3 -3
- package/src/arrow/compiler.ts +155 -36
- package/src/arrow/index.ts +1 -1
- package/src/arrow/list-values.ts +28 -7
- package/src/arrow/predicate.ts +1 -1
- package/src/arrow/query-arrow-sql.ts +38 -10
- package/src/arrow/query-arrow-table.ts +3 -3
- package/src/arrow/query-worker.ts +5 -1
- package/src/arrow/registry.ts +1 -0
- package/src/arrow/relational-query.ts +2 -2
- package/src/arrow/temporal-cast.ts +1 -1
- package/src/arrow/types.ts +1 -1
- package/src/arrow/unnest-arrow-column.ts +145 -0
- package/src/arrow/worker.ts +6 -2
- package/src/expressions/ast.ts +3 -1
- package/src/expressions/expression-eval.ts +10 -1
- package/src/index.ts +14 -0
- package/src/{math → math-functions}/index.ts +2 -2
- package/src/{sql → parser}/index.ts +15 -0
- package/src/parser/parameter-snapshots.ts +103 -0
- package/src/{sql → parser}/parse-sql-expression.ts +49 -6
- package/src/{sql → parser}/parse-sql-query.ts +24 -6
- package/src/{sql → parser}/parse-sql-select.ts +14 -8
- package/src/{sql → parser}/parse-sql-statement.ts +42 -24
- package/src/{sql → parser}/query-types.ts +1 -1
- package/src/parser/sql-parameters.ts +174 -0
- package/src/scales/arrow-domains.ts +66 -7
- package/src/scales/arrow-scales.ts +221 -14
- package/src/scales/compile-scale.ts +1 -213
- package/src/scales/conformance.ts +186 -0
- package/src/scales/hdr-colors.ts +1 -122
- package/src/scales/index.ts +3 -1
- package/src/scales/palettes.ts +1 -82
- package/src/scales/parse-sql-scale.ts +126 -21
- package/src/scales/quantile-sketch.ts +1 -102
- package/src/scales/scale-types.ts +1 -220
- package/src/scales/streaming-domains.ts +8 -2
- package/dist/color/index.d.ts.map +0 -1
- package/dist/color/index.js.map +0 -1
- package/dist/math/index.d.ts.map +0 -1
- package/dist/math/index.js.map +0 -1
- package/dist/scales/arrow-scales.cjs +0 -3837
- package/dist/scales/arrow-scales.cjs.map +0 -6
- package/dist/sql/bind-sql-predicate.d.ts.map +0 -1
- package/dist/sql/bind-sql-predicate.js.map +0 -1
- package/dist/sql/index.cjs.map +0 -6
- package/dist/sql/index.d.ts.map +0 -1
- package/dist/sql/index.js.map +0 -1
- package/dist/sql/parse-sql-expression.d.ts.map +0 -1
- package/dist/sql/parse-sql-expression.js.map +0 -1
- package/dist/sql/parse-sql-predicate.d.ts.map +0 -1
- package/dist/sql/parse-sql-predicate.js.map +0 -1
- package/dist/sql/parse-sql-query.d.ts.map +0 -1
- package/dist/sql/parse-sql-query.js.map +0 -1
- package/dist/sql/parse-sql-select.d.ts.map +0 -1
- package/dist/sql/parse-sql-select.js.map +0 -1
- package/dist/sql/parse-sql-statement.d.ts.map +0 -1
- package/dist/sql/parse-sql-statement.js.map +0 -1
- package/dist/sql/query-types.d.ts.map +0 -1
- package/dist/sql/query-types.js.map +0 -1
- package/dist/sql/sql-parse-error.d.ts.map +0 -1
- package/dist/sql/sql-parse-error.js.map +0 -1
- package/dist/sql/sql-predicate-schema.d.ts.map +0 -1
- package/dist/sql/sql-predicate-schema.js.map +0 -1
- package/dist/sql/sql-predicate-types.d.ts.map +0 -1
- package/dist/sql/sql-predicate-types.js.map +0 -1
- package/dist/sql/sql-predicate.d.ts.map +0 -1
- package/dist/sql/sql-predicate.js.map +0 -1
- package/src/expressions/vendor/jsep/README.md +0 -22
- /package/dist/{color → color-functions}/index.d.ts +0 -0
- /package/dist/{color → color-functions}/index.js +0 -0
- /package/dist/{math → math-functions}/index.d.ts +0 -0
- /package/dist/{math → math-functions}/index.js +0 -0
- /package/dist/{sql → parser}/bind-sql-predicate.d.ts +0 -0
- /package/dist/{sql → parser}/bind-sql-predicate.js +0 -0
- /package/dist/{sql → parser}/parse-sql-predicate.d.ts +0 -0
- /package/dist/{sql → parser}/parse-sql-predicate.js +0 -0
- /package/dist/{sql → parser}/query-types.d.ts +0 -0
- /package/dist/{sql → parser}/query-types.js +0 -0
- /package/dist/{sql → parser}/sql-parse-error.d.ts +0 -0
- /package/dist/{sql → parser}/sql-parse-error.js +0 -0
- /package/dist/{sql → parser}/sql-predicate-schema.d.ts +0 -0
- /package/dist/{sql → parser}/sql-predicate-schema.js +0 -0
- /package/dist/{sql → parser}/sql-predicate-types.d.ts +0 -0
- /package/dist/{sql → parser}/sql-predicate-types.js +0 -0
- /package/dist/{sql → parser}/sql-predicate.d.ts +0 -0
- /package/dist/{sql → parser}/sql-predicate.js +0 -0
- /package/src/{color → color-functions}/index.ts +0 -0
- /package/src/{sql → parser}/bind-sql-predicate.ts +0 -0
- /package/src/{sql → parser}/parse-sql-predicate.ts +0 -0
- /package/src/{sql → parser}/sql-parse-error.ts +0 -0
- /package/src/{sql → parser}/sql-predicate-schema.ts +0 -0
- /package/src/{sql → parser}/sql-predicate-types.ts +0 -0
- /package/src/{sql → parser}/sql-predicate.ts +0 -0
|
@@ -10,7 +10,13 @@ import { ScaleQuantileSketch } from "./quantile-sketch.js";
|
|
|
10
10
|
export function createStreamingDomainAccumulator(domains, options = {}) {
|
|
11
11
|
const columns = new Map();
|
|
12
12
|
const quantileColumns = new Set(options.quantileColumns ?? []);
|
|
13
|
-
|
|
13
|
+
const streamingDomains = domains.map(domain => {
|
|
14
|
+
if (domain.type === 'expression-extent') {
|
|
15
|
+
throw new Error('Streaming scale domains require computed values in a projected column');
|
|
16
|
+
}
|
|
17
|
+
return domain;
|
|
18
|
+
});
|
|
19
|
+
for (const domain of streamingDomains) {
|
|
14
20
|
if (domain.type === 'fixed')
|
|
15
21
|
continue;
|
|
16
22
|
const previous = columns.get(domain.column);
|
|
@@ -69,7 +75,7 @@ export function createStreamingDomainAccumulator(domains, options = {}) {
|
|
|
69
75
|
}
|
|
70
76
|
},
|
|
71
77
|
result() {
|
|
72
|
-
return
|
|
78
|
+
return streamingDomains.map(domain => {
|
|
73
79
|
if (domain.type === 'fixed')
|
|
74
80
|
return [...domain.values];
|
|
75
81
|
const state = columns.get(domain.column);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming-domains.js","sourceRoot":"","sources":["../../src/scales/streaming-domains.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAI5D,OAAO,EAAC,eAAe,EAAC,2BAAwB;AAEhD,OAAO,EAAC,mBAAmB,EAAC,6BAA0B;AAiBtD;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAC9C,OAA+B,EAC/B,UAAkC,EAAE;IAMpC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC/C,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC;IAC/D,
|
|
1
|
+
{"version":3,"file":"streaming-domains.js","sourceRoot":"","sources":["../../src/scales/streaming-domains.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAI5D,OAAO,EAAC,eAAe,EAAC,2BAAwB;AAEhD,OAAO,EAAC,mBAAmB,EAAC,6BAA0B;AAiBtD;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAC9C,OAA+B,EAC/B,UAAkC,EAAE;IAMpC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC/C,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC;IAC/D,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;QAC5C,IAAI,MAAM,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;QAC3F,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;IACH,KAAK,MAAM,MAAM,IAAI,gBAAgB,EAAE,CAAC;QACtC,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO;YAAE,SAAS;QACtC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM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C;QAC1F,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@math.gl/sql",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.12",
|
|
4
4
|
"description": "Lightweight SQL query engine for Apache Arrow tables",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -33,15 +33,15 @@
|
|
|
33
33
|
"import": "./dist/scales/index.js",
|
|
34
34
|
"require": "./dist/scales/index.cjs"
|
|
35
35
|
},
|
|
36
|
-
"./
|
|
37
|
-
"types": "./dist/scales/
|
|
38
|
-
"import": "./dist/scales/
|
|
39
|
-
"require": "./dist/scales/
|
|
36
|
+
"./scales/conformance": {
|
|
37
|
+
"types": "./dist/scales/conformance.d.ts",
|
|
38
|
+
"import": "./dist/scales/conformance.js",
|
|
39
|
+
"require": "./dist/scales/conformance.cjs"
|
|
40
40
|
},
|
|
41
41
|
"./parser": {
|
|
42
|
-
"types": "./dist/
|
|
43
|
-
"import": "./dist/
|
|
44
|
-
"require": "./dist/
|
|
42
|
+
"types": "./dist/parser/index.d.ts",
|
|
43
|
+
"import": "./dist/parser/index.js",
|
|
44
|
+
"require": "./dist/parser/index.cjs"
|
|
45
45
|
},
|
|
46
46
|
"./expressions": {
|
|
47
47
|
"types": "./dist/expressions/index.d.ts",
|
|
@@ -61,14 +61,14 @@
|
|
|
61
61
|
"./worker-entry.js": "./dist/arrow/worker-entry.js",
|
|
62
62
|
"./query-worker-entry.js": "./dist/arrow/query-worker-entry.js",
|
|
63
63
|
"./math-functions": {
|
|
64
|
-
"types": "./dist/math/index.d.ts",
|
|
65
|
-
"import": "./dist/math/index.js",
|
|
66
|
-
"require": "./dist/math/index.cjs"
|
|
64
|
+
"types": "./dist/math-functions/index.d.ts",
|
|
65
|
+
"import": "./dist/math-functions/index.js",
|
|
66
|
+
"require": "./dist/math-functions/index.cjs"
|
|
67
67
|
},
|
|
68
68
|
"./color-functions": {
|
|
69
|
-
"types": "./dist/color/index.d.ts",
|
|
70
|
-
"import": "./dist/color/index.js",
|
|
71
|
-
"require": "./dist/color/index.cjs"
|
|
69
|
+
"types": "./dist/color-functions/index.d.ts",
|
|
70
|
+
"import": "./dist/color-functions/index.js",
|
|
71
|
+
"require": "./dist/color-functions/index.cjs"
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
"sideEffects": [
|
|
@@ -78,10 +78,9 @@
|
|
|
78
78
|
"./src/arrow/query-worker-entry.ts"
|
|
79
79
|
],
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@math.gl/
|
|
82
|
-
"@math.gl/
|
|
83
|
-
"@math.gl/
|
|
84
|
-
"@math.gl/tasks": "5.0.0-beta.11"
|
|
81
|
+
"@math.gl/core": "5.0.0-beta.12",
|
|
82
|
+
"@math.gl/geometry": "5.0.0-beta.12",
|
|
83
|
+
"@math.gl/tasks": "5.0.0-beta.12"
|
|
85
84
|
},
|
|
86
85
|
"peerDependencies": {
|
|
87
86
|
"apache-arrow": ">=17.0.0"
|
|
@@ -90,5 +89,6 @@
|
|
|
90
89
|
"apache-arrow": {
|
|
91
90
|
"optional": true
|
|
92
91
|
}
|
|
93
|
-
}
|
|
92
|
+
},
|
|
93
|
+
"gitHead": "f48cd096d5f3b61dced52d5fcd5906a7e9541b12"
|
|
94
94
|
}
|
package/src/arrow/aggregates.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {DataType, type Table, type RecordBatch} from 'apache-arrow';
|
|
6
|
-
import {compareUTF8} from '@math.gl/
|
|
6
|
+
import {compareUTF8} from '@math.gl/core/utf8';
|
|
7
7
|
import {ColumnReader, valueType} from './buffers';
|
|
8
8
|
import {compileArrowExpression} from './compiler';
|
|
9
9
|
import type {
|
package/src/arrow/buffers.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import {DataType, DateUnit, Precision, TimeUnit, type Vector, type Data} from 'apache-arrow';
|
|
6
6
|
import {float16Values, requireFloat16} from './float16';
|
|
7
|
-
import {ExpressionEvaluationError} from '../expressions
|
|
7
|
+
import {ExpressionEvaluationError} from '../expressions';
|
|
8
8
|
import type {ArrowExpressionValue} from './types';
|
|
9
9
|
|
|
10
10
|
/** Dictionary encodings do not change expression value types. */
|
package/src/arrow/cast.ts
CHANGED
|
@@ -21,9 +21,9 @@ import {
|
|
|
21
21
|
Uint64,
|
|
22
22
|
Utf8
|
|
23
23
|
} from 'apache-arrow';
|
|
24
|
-
import {isColumnarScalarType} from '../expressions
|
|
25
|
-
import {parseUTF8Number, parseUTF8BigInt, parseUTF8Boolean} from '@math.gl/
|
|
26
|
-
import {ExpressionEvaluationError} from '../expressions
|
|
24
|
+
import {isColumnarScalarType} from '../expressions';
|
|
25
|
+
import {parseUTF8Number, parseUTF8BigInt, parseUTF8Boolean} from '@math.gl/core/utf8';
|
|
26
|
+
import {ExpressionEvaluationError} from '../expressions';
|
|
27
27
|
import {bindTemporalCast} from './temporal-cast';
|
|
28
28
|
import {roundFloat16} from './float16';
|
|
29
29
|
import {typeKey, createValueValidator} from './buffers';
|
package/src/arrow/compiler.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
FixedSizeList,
|
|
15
15
|
Dictionary,
|
|
16
16
|
Int64,
|
|
17
|
+
TimestampMicrosecond,
|
|
17
18
|
Int32,
|
|
18
19
|
Uint8,
|
|
19
20
|
Null,
|
|
@@ -26,14 +27,14 @@ import {
|
|
|
26
27
|
type Table,
|
|
27
28
|
type Schema
|
|
28
29
|
} from 'apache-arrow';
|
|
29
|
-
import {compareUTF8, parseUTF8Number, parseUTF8BigInt, parseUTF8Boolean} from '@math.gl/
|
|
30
|
-
import {parse, validateExpressionAST, type Expression} from '../expressions
|
|
30
|
+
import {compareUTF8, parseUTF8Number, parseUTF8BigInt, parseUTF8Boolean} from '@math.gl/core/utf8';
|
|
31
|
+
import {parse, validateExpressionAST, type Expression} from '../expressions';
|
|
31
32
|
import {ColumnReader, typeKey, valueType, validateValue, createValueValidator} from './buffers';
|
|
32
33
|
import {bindCast} from './cast';
|
|
33
34
|
import {compileUTF8Like} from './like';
|
|
34
35
|
import {float16Values, roundFloat16} from './float16';
|
|
35
36
|
import {physicalKey, extensionKey} from './signature';
|
|
36
|
-
import {ExpressionEvaluationError, isExpressionEvaluationError} from '../expressions
|
|
37
|
+
import {ExpressionEvaluationError, isExpressionEvaluationError} from '../expressions';
|
|
37
38
|
import {createFunctionLookup} from './registry';
|
|
38
39
|
import {
|
|
39
40
|
isTupleType,
|
|
@@ -67,6 +68,8 @@ type Prepared = {
|
|
|
67
68
|
vector?: Vector;
|
|
68
69
|
};
|
|
69
70
|
type Node = {
|
|
71
|
+
/** Preconverted literal storage, shared by all batches of a compiled expression. */
|
|
72
|
+
constant?: Prepared;
|
|
70
73
|
field: Field;
|
|
71
74
|
hasKernel: boolean;
|
|
72
75
|
prepare: (batch: RecordBatch, active: Mask, context: ExecutionContext) => Prepared;
|
|
@@ -129,8 +132,8 @@ export function compileArrowExpression(
|
|
|
129
132
|
: isNestedType(root.field.type)
|
|
130
133
|
? nestedVector(prepared.vector!, root.field.type, active)
|
|
131
134
|
: prepared.vector &&
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
(root.constant ||
|
|
136
|
+
(!DataType.isDictionary(prepared.vector.type) && !active.some(value => !value)))
|
|
134
137
|
? prepared.vector
|
|
135
138
|
: output(root.field, active, prepared.get);
|
|
136
139
|
evaluation.signal?.throwIfAborted();
|
|
@@ -416,7 +419,15 @@ function bindNode(
|
|
|
416
419
|
if (ast.type === 'Literal') {
|
|
417
420
|
if (vectorInput && expected && DataType.isDictionary(expected))
|
|
418
421
|
throw new Error('Dictionary function arguments require a dictionary-encoded source column');
|
|
419
|
-
|
|
422
|
+
// Dates enter as immutable parameter snapshots; physical Arrow storage uses days
|
|
423
|
+
// or microseconds, chosen once from the receiving schema.
|
|
424
|
+
const date = ast.value instanceof Date ? ast.value : undefined;
|
|
425
|
+
let value: ArrowExpressionValue = date
|
|
426
|
+
? expected && DataType.isDate(expected)
|
|
427
|
+
? Math.floor(date.getTime() / 86400000)
|
|
428
|
+
: BigInt(date.getTime()) * 1000n
|
|
429
|
+
: ast.value;
|
|
430
|
+
if (value instanceof Uint8Array) value = new Uint8Array(value);
|
|
420
431
|
if (
|
|
421
432
|
expected &&
|
|
422
433
|
DataType.isInt(expected) &&
|
|
@@ -427,15 +438,19 @@ function bindNode(
|
|
|
427
438
|
value = BigInt(value);
|
|
428
439
|
const type =
|
|
429
440
|
expected ??
|
|
430
|
-
(
|
|
431
|
-
? new
|
|
432
|
-
:
|
|
433
|
-
?
|
|
434
|
-
:
|
|
435
|
-
? new
|
|
436
|
-
: typeof value === '
|
|
437
|
-
?
|
|
438
|
-
:
|
|
441
|
+
(date
|
|
442
|
+
? new TimestampMicrosecond('UTC')
|
|
443
|
+
: value instanceof Uint8Array
|
|
444
|
+
? new Binary()
|
|
445
|
+
: value === null
|
|
446
|
+
? new Null()
|
|
447
|
+
: typeof value === 'boolean'
|
|
448
|
+
? bool
|
|
449
|
+
: typeof value === 'number'
|
|
450
|
+
? new Float64()
|
|
451
|
+
: typeof value === 'bigint'
|
|
452
|
+
? new Int64()
|
|
453
|
+
: new Utf8());
|
|
439
454
|
if (value === null && isTupleType(type))
|
|
440
455
|
return {
|
|
441
456
|
field: new Field('literal', type, true),
|
|
@@ -471,16 +486,38 @@ function bindNode(
|
|
|
471
486
|
const rounded = roundToType(type)(value);
|
|
472
487
|
if (typeof value === 'number' && Number.isFinite(value) && !Number.isFinite(rounded))
|
|
473
488
|
throw new Error(`Numeric literal overflow for ${type}`);
|
|
474
|
-
|
|
489
|
+
// A tagged UTF-8 parameter supplies physical bytes. Check the optional annotation
|
|
490
|
+
// against the portable value once, so edited external ASTs cannot change semantics.
|
|
491
|
+
const encoded =
|
|
492
|
+
typeof value === 'string'
|
|
493
|
+
? ast.utf8 instanceof Uint8Array &&
|
|
494
|
+
new TextDecoder('utf-8', {ignoreBOM: true}).decode(ast.utf8) === value
|
|
495
|
+
? new Uint8Array(ast.utf8)
|
|
496
|
+
: encoder.encode(value)
|
|
497
|
+
: undefined;
|
|
475
498
|
const range: Range | undefined = encoded ? [encoded, 0, encoded.length] : undefined;
|
|
499
|
+
const constant: Prepared = {
|
|
500
|
+
get: () => rounded,
|
|
501
|
+
isNull: () => value === null,
|
|
502
|
+
bytes: range ? () => range : undefined
|
|
503
|
+
};
|
|
476
504
|
return {
|
|
477
505
|
field: new Field('literal', type, value === null),
|
|
478
506
|
hasKernel: false,
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
507
|
+
constant,
|
|
508
|
+
prepare: (_batch, active) => {
|
|
509
|
+
if (!encoded) return constant;
|
|
510
|
+
let vector: Vector | undefined;
|
|
511
|
+
return {
|
|
512
|
+
...constant,
|
|
513
|
+
// Comparisons only read bytes. Materialize physical UTF-8 only when a
|
|
514
|
+
// projection or vector function actually requests a batch-sized vector.
|
|
515
|
+
get vector() {
|
|
516
|
+
if (!vector) vector = repeatUTF8(encoded, active);
|
|
517
|
+
return vector;
|
|
518
|
+
}
|
|
519
|
+
};
|
|
520
|
+
}
|
|
484
521
|
};
|
|
485
522
|
}
|
|
486
523
|
if (ast.type === 'CallExpression') return bindCall(ast, options, expected);
|
|
@@ -913,7 +950,21 @@ function bindMembership(arguments_: any[], options: BindingOptions): Node {
|
|
|
913
950
|
throw new Error('IN requires a value and 1 to 4096 scalar literals');
|
|
914
951
|
const argument = bind(arguments_[0], options);
|
|
915
952
|
const utf8 = typeKey(argument.field.type) === 'utf8';
|
|
953
|
+
const binary =
|
|
954
|
+
DataType.isBinary(argument.field.type) || DataType.isFixedSizeBinary(argument.field.type);
|
|
916
955
|
const literals = arguments_.slice(1).map(value => bind(value, options, argument.field.type));
|
|
956
|
+
// Every membership item is a scalar literal: convert and index once at compilation.
|
|
957
|
+
const prepared = literals.map(value => value.constant!);
|
|
958
|
+
const values = new Set(prepared.map(value => value.get(0)));
|
|
959
|
+
const ranges: Range[] = utf8
|
|
960
|
+
? prepared.map(value => bytes(value, 0)).filter((range): range is Range => range !== null)
|
|
961
|
+
: binary
|
|
962
|
+
? prepared.flatMap(value => {
|
|
963
|
+
const data = value.get(0) as Uint8Array | null;
|
|
964
|
+
return data === null ? [] : [[data, 0, data.length] as Range];
|
|
965
|
+
})
|
|
966
|
+
: [];
|
|
967
|
+
ranges.sort((a, b) => compareUTF8(a[0], a[1], a[2], b[0], b[1], b[2]));
|
|
917
968
|
return {
|
|
918
969
|
field: new Field(
|
|
919
970
|
'in',
|
|
@@ -923,24 +974,17 @@ function bindMembership(arguments_: any[], options: BindingOptions): Node {
|
|
|
923
974
|
hasKernel: argument.hasKernel,
|
|
924
975
|
prepare(batch, active, context) {
|
|
925
976
|
const source = argument.prepare(batch, active, context);
|
|
926
|
-
const constantMask = Uint8Array.of(1);
|
|
927
|
-
const prepared = literals.map(value => value.prepare(batch, constantMask, {}));
|
|
928
|
-
const values = new Set(prepared.map(value => value.get(0)));
|
|
929
|
-
const ranges = utf8
|
|
930
|
-
? prepared.map(value => bytes(value, 0)).filter(range => range !== null)
|
|
931
|
-
: [];
|
|
932
977
|
return {
|
|
933
978
|
get(row) {
|
|
934
|
-
if (utf8) {
|
|
935
|
-
const
|
|
979
|
+
if (utf8 || binary) {
|
|
980
|
+
const data = binary ? (source.get(row) as Uint8Array | null) : null;
|
|
981
|
+
const value: Range | null = utf8
|
|
982
|
+
? bytes(source, row)
|
|
983
|
+
: data === null
|
|
984
|
+
? null
|
|
985
|
+
: [data, 0, data.length];
|
|
936
986
|
if (!value) return null;
|
|
937
|
-
if (
|
|
938
|
-
ranges.some(
|
|
939
|
-
range =>
|
|
940
|
-
compareUTF8(value[0], value[1], value[2], range[0], range[1], range[2]) === 0
|
|
941
|
-
)
|
|
942
|
-
)
|
|
943
|
-
return true;
|
|
987
|
+
if (containsByteRange(ranges, value)) return true;
|
|
944
988
|
} else {
|
|
945
989
|
const value = source.get(row);
|
|
946
990
|
if (value === null) return null;
|
|
@@ -953,6 +997,55 @@ function bindMembership(arguments_: any[], options: BindingOptions): Node {
|
|
|
953
997
|
};
|
|
954
998
|
}
|
|
955
999
|
|
|
1000
|
+
/** Broadcasts pre-encoded text to Arrow storage without re-encoding strings per row. */
|
|
1001
|
+
function repeatUTF8(encoded: Uint8Array, active: Mask): Vector<Utf8> {
|
|
1002
|
+
const count = active.reduce((sum, value) => sum + value, 0);
|
|
1003
|
+
const data = new Uint8Array(count * encoded.length);
|
|
1004
|
+
const offsets = new Int32Array(active.length + 1);
|
|
1005
|
+
const validity = new Uint8Array(Math.ceil(active.length / 8));
|
|
1006
|
+
let position = 0;
|
|
1007
|
+
for (let row = 0; row < active.length; row++) {
|
|
1008
|
+
if (active[row]) {
|
|
1009
|
+
data.set(encoded, position);
|
|
1010
|
+
position += encoded.length;
|
|
1011
|
+
validity[row >> 3] |= 1 << (row & 7);
|
|
1012
|
+
}
|
|
1013
|
+
offsets[row + 1] = position;
|
|
1014
|
+
}
|
|
1015
|
+
return makeVector(
|
|
1016
|
+
makeData({
|
|
1017
|
+
type: new Utf8(),
|
|
1018
|
+
length: active.length,
|
|
1019
|
+
data,
|
|
1020
|
+
valueOffsets: offsets,
|
|
1021
|
+
nullBitmap: validity,
|
|
1022
|
+
nullCount: active.length - count
|
|
1023
|
+
})
|
|
1024
|
+
);
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
/** Searches pre-sorted UTF-8 or binary constants without decoding source values. */
|
|
1028
|
+
function containsByteRange(ranges: readonly Range[], value: Range): boolean {
|
|
1029
|
+
let low = 0;
|
|
1030
|
+
let high = ranges.length - 1;
|
|
1031
|
+
while (low <= high) {
|
|
1032
|
+
const middle = (low + high) >>> 1;
|
|
1033
|
+
const candidate = ranges[middle]!;
|
|
1034
|
+
const order = compareUTF8(
|
|
1035
|
+
value[0],
|
|
1036
|
+
value[1],
|
|
1037
|
+
value[2],
|
|
1038
|
+
candidate[0],
|
|
1039
|
+
candidate[1],
|
|
1040
|
+
candidate[2]
|
|
1041
|
+
);
|
|
1042
|
+
if (order === 0) return true;
|
|
1043
|
+
if (order < 0) high = middle - 1;
|
|
1044
|
+
else low = middle + 1;
|
|
1045
|
+
}
|
|
1046
|
+
return false;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
956
1049
|
/** Binds SQL pattern matching and precompiles literal patterns. */
|
|
957
1050
|
function bindLike(args: any[], options: BindingOptions, insensitive: boolean): Node {
|
|
958
1051
|
if (args.length < 2 || args.length > 3) throw new Error('LIKE requires two or three arguments');
|
|
@@ -1154,6 +1247,7 @@ function bindCall(ast: any, options: BindingOptions, expected?: DataType): Node
|
|
|
1154
1247
|
'array_float64',
|
|
1155
1248
|
'array_uint8',
|
|
1156
1249
|
'PACK_UNORM8',
|
|
1250
|
+
'EPOCH_MS',
|
|
1157
1251
|
'LIST_EXTRACT',
|
|
1158
1252
|
'STRUCT_EXTRACT',
|
|
1159
1253
|
'cast',
|
|
@@ -1309,6 +1403,31 @@ function bindCall(ast: any, options: BindingOptions, expected?: DataType): Node
|
|
|
1309
1403
|
};
|
|
1310
1404
|
}
|
|
1311
1405
|
if (name === 'in') return bindMembership(ast.arguments, options);
|
|
1406
|
+
if (name === 'EPOCH_MS') {
|
|
1407
|
+
if (ast.arguments.length !== 1) throw new Error('EPOCH_MS requires one argument');
|
|
1408
|
+
const argument = bind(ast.arguments[0], options);
|
|
1409
|
+
const key = typeKey(argument.field.type);
|
|
1410
|
+
if (key !== 'date32' && !key.startsWith('timestamp_us:')) {
|
|
1411
|
+
throw new Error('EPOCH_MS requires DATE or microsecond TIMESTAMP');
|
|
1412
|
+
}
|
|
1413
|
+
return {
|
|
1414
|
+
field: new Field('epoch_ms', new Float64(), argument.field.nullable),
|
|
1415
|
+
hasKernel: argument.hasKernel,
|
|
1416
|
+
prepare(batch, active, context) {
|
|
1417
|
+
const input = argument.prepare(batch, active, context);
|
|
1418
|
+
return {
|
|
1419
|
+
get(row) {
|
|
1420
|
+
const value = input.get(row);
|
|
1421
|
+
if (value === null) return null;
|
|
1422
|
+
// Divide before conversion to retain submillisecond precision around the epoch.
|
|
1423
|
+
return key === 'date32'
|
|
1424
|
+
? Number(value) * 86400000
|
|
1425
|
+
: Number((value as bigint) / 1000n) + Number((value as bigint) % 1000n) / 1000;
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
}
|
|
1312
1431
|
if (name === 'cast') {
|
|
1313
1432
|
if (ast.arguments.length !== 2 || ast.arguments[1]?.type !== 'Literal')
|
|
1314
1433
|
throw new Error('cast requires a value and a literal scalar target');
|
package/src/arrow/index.ts
CHANGED
package/src/arrow/list-values.ts
CHANGED
|
@@ -169,7 +169,30 @@ export function compileArrayLiteral(ast: any, type: DataType): (length: number)
|
|
|
169
169
|
}
|
|
170
170
|
return value;
|
|
171
171
|
});
|
|
172
|
-
|
|
172
|
+
// Typed parameter storage can already have the exact physical element layout.
|
|
173
|
+
// Keep the portable elements authoritative if an external caller edits the AST.
|
|
174
|
+
const typed = ast.typedValues;
|
|
175
|
+
const matchingStorage =
|
|
176
|
+
typed &&
|
|
177
|
+
typed.constructor === child.type.ArrayType &&
|
|
178
|
+
typed.length === values.length &&
|
|
179
|
+
values.every((value, index) => Object.is(value, typed[index]));
|
|
180
|
+
const literal: Vector<List | FixedSizeList> = matchingStorage
|
|
181
|
+
? new Vector<List | FixedSizeList>([
|
|
182
|
+
DataType.isList(listType)
|
|
183
|
+
? makeData({
|
|
184
|
+
type: listType,
|
|
185
|
+
length: 1,
|
|
186
|
+
valueOffsets: Int32Array.of(0, values.length),
|
|
187
|
+
child: makeData({type: child.type, length: values.length, data: typed.slice()})
|
|
188
|
+
})
|
|
189
|
+
: makeData({
|
|
190
|
+
type: listType,
|
|
191
|
+
length: 1,
|
|
192
|
+
child: makeData({type: child.type, length: values.length, data: typed.slice()})
|
|
193
|
+
})
|
|
194
|
+
])
|
|
195
|
+
: vectorFromArray([values], listType);
|
|
173
196
|
const dictionaryType = new Dictionary(listType, new Uint8());
|
|
174
197
|
let cached: Vector | undefined;
|
|
175
198
|
return length => {
|
|
@@ -179,14 +202,12 @@ export function compileArrayLiteral(ast: any, type: DataType): (length: number)
|
|
|
179
202
|
const result = nullTupleVector(listType, length);
|
|
180
203
|
const data = result.data[0]!;
|
|
181
204
|
const childData = data.children[0]!;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
: childData.values;
|
|
205
|
+
// Copy the already converted physical values, including Float16 bits. Repeating
|
|
206
|
+
// a tuple must not re-encode or re-round its JavaScript components for each row.
|
|
207
|
+
const components = literal.data[0]!.children[0]!.values.subarray(0, listType.listSize);
|
|
186
208
|
for (let row = 0; row < length; row++) {
|
|
187
209
|
data.setValid(row, true);
|
|
188
|
-
|
|
189
|
-
components[row * listType.listSize + component] = values[component] as any;
|
|
210
|
+
childData.values.set(components, row * listType.listSize);
|
|
190
211
|
}
|
|
191
212
|
cached = result;
|
|
192
213
|
} else {
|
package/src/arrow/predicate.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
columnarPredicateToExpression,
|
|
7
7
|
type ParameterizedColumnarPredicate,
|
|
8
8
|
type ColumnarPredicateParameterValues
|
|
9
|
-
} from '../expressions
|
|
9
|
+
} from '../expressions';
|
|
10
10
|
import {compileArrowExpression} from './compiler';
|
|
11
11
|
import type {ArrowExpressionOptions, CompiledArrowExpression} from './types';
|
|
12
12
|
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type
|
|
6
|
-
import
|
|
5
|
+
import {DataType, type Table} from 'apache-arrow';
|
|
6
|
+
import {unnestArrowColumn} from './unnest-arrow-column';
|
|
7
|
+
import type {Expression} from '../expressions';
|
|
7
8
|
import {
|
|
8
9
|
parseSQLSelectCompound,
|
|
9
10
|
type SQLSelectStatement,
|
|
10
11
|
type SQLSelectStatementOptions,
|
|
11
12
|
type SQLSort
|
|
12
|
-
} from '../
|
|
13
|
+
} from '../parser/parse-sql-statement';
|
|
13
14
|
import {queryArrowTable, type ArrowTableQuery} from './query-arrow-table';
|
|
14
15
|
import type {ArrowAggregate} from './aggregates';
|
|
15
16
|
|
|
@@ -48,11 +49,15 @@ export function queryArrowSQL(
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
function planOrder(orderBy?: readonly SQLSort[]) {
|
|
51
|
-
return orderBy?.map(({expression, direction, nulls}) =>
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
return orderBy?.map(({expression, direction, nulls}) => {
|
|
53
|
+
/** Qualified projected output name, including UNNEST aliases. */
|
|
54
|
+
const column = qualifiedColumn(expression);
|
|
55
|
+
return {
|
|
56
|
+
column: column?.qualifier ? column.qualifier + '.' + column.name : requireColumn(expression),
|
|
57
|
+
direction,
|
|
58
|
+
nulls
|
|
59
|
+
};
|
|
60
|
+
});
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
function executeSelect(
|
|
@@ -60,13 +65,36 @@ function executeSelect(
|
|
|
60
65
|
tables: ReadonlyMap<string, Table>,
|
|
61
66
|
execution: Execution
|
|
62
67
|
): Table {
|
|
63
|
-
|
|
68
|
+
let source = getTable(tables, statement.from.name);
|
|
64
69
|
const leftAlias = statement.from.alias ?? statement.from.name;
|
|
65
70
|
const [right] = statement.joins;
|
|
66
71
|
let join: ArrowTableQuery['join'];
|
|
67
72
|
let rightAlias: string | undefined;
|
|
68
73
|
let rightTable: Table | undefined;
|
|
69
|
-
if (right) {
|
|
74
|
+
if (right?.unnest) {
|
|
75
|
+
if (statement.joins.length !== 1)
|
|
76
|
+
throw new Error('UNNEST currently supports one expansion per SELECT');
|
|
77
|
+
const {expression, columns, ordinality} = right.unnest;
|
|
78
|
+
const column = qualifiedColumn(expression);
|
|
79
|
+
if (!column || (column.qualifier && column.qualifier !== leftAlias))
|
|
80
|
+
throw new Error('UNNEST requires a column of its parent table');
|
|
81
|
+
const field = source.schema.fields.find(field => field.name === column.name);
|
|
82
|
+
if (!field) throw new Error(`Unknown UNNEST column: ${column.name}`);
|
|
83
|
+
const map = DataType.isMap(field.type);
|
|
84
|
+
if (!map && !DataType.isList(field.type) && !DataType.isFixedSizeList(field.type))
|
|
85
|
+
throw new Error('SQL UNNEST requires List, FixedSizeList or Map');
|
|
86
|
+
if (columns.length !== (map ? 2 : 1) + (ordinality ? 1 : 0))
|
|
87
|
+
throw new Error('UNNEST column alias count does not match its output');
|
|
88
|
+
rightAlias = right.table.alias!;
|
|
89
|
+
if (rightAlias === leftAlias) throw new Error('Duplicate Arrow SQL table alias');
|
|
90
|
+
source = unnestArrowColumn(source, column.name, {
|
|
91
|
+
valueColumn: rightAlias + '.' + columns[map ? 1 : 0],
|
|
92
|
+
keyColumn: map ? rightAlias + '.' + columns[0] : undefined,
|
|
93
|
+
ordinalColumn: ordinality ? rightAlias + '.' + columns[map ? 2 : 1] : undefined,
|
|
94
|
+
outer: right.type === 'left',
|
|
95
|
+
signal: execution.signal
|
|
96
|
+
});
|
|
97
|
+
} else if (right) {
|
|
70
98
|
if (statement.joins.length > 1 || right.type !== 'inner')
|
|
71
99
|
throw new Error('Arrow SQL supports one INNER JOIN per SELECT');
|
|
72
100
|
rightAlias = right.table.alias ?? right.table.name;
|
|
@@ -17,12 +17,12 @@ import {
|
|
|
17
17
|
createRecordBatchWithMetadata,
|
|
18
18
|
validateArrowTableSchema,
|
|
19
19
|
takeArrowTableRows
|
|
20
|
-
} from '@math.gl/arrow';
|
|
20
|
+
} from '@math.gl/core/arrow';
|
|
21
21
|
import type {
|
|
22
22
|
ColumnarPredicateParameterValues,
|
|
23
23
|
ParameterizedColumnarPredicate
|
|
24
|
-
} from '../expressions
|
|
25
|
-
import type {TableQuery} from '../
|
|
24
|
+
} from '../expressions';
|
|
25
|
+
import type {TableQuery} from '../parser/query-types';
|
|
26
26
|
import {compileArrowArray, compileArrowExpression} from './compiler';
|
|
27
27
|
import {compileArrowPredicate} from './predicate';
|
|
28
28
|
import type {ArrowAggregate} from './aggregates';
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {Table} from 'apache-arrow';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
dehydrateArrowTable,
|
|
8
|
+
hydrateArrowTable,
|
|
9
|
+
type DehydratedArrowTable
|
|
10
|
+
} from '@math.gl/core/arrow';
|
|
7
11
|
import {TaskRunner, type Task, type TaskWorker} from '@math.gl/tasks';
|
|
8
12
|
import {queryArrowTable, type ArrowTableQuery} from './query-arrow-table';
|
|
9
13
|
import type {ArrowTableFunction} from './types';
|
package/src/arrow/registry.ts
CHANGED
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
vectorFromArray,
|
|
13
13
|
type Vector
|
|
14
14
|
} from 'apache-arrow';
|
|
15
|
-
import {takeArrowTableRows, validateArrowTableSchema} from '@math.gl/arrow';
|
|
15
|
+
import {takeArrowTableRows, validateArrowTableSchema} from '@math.gl/core/arrow';
|
|
16
16
|
import {compileArrowAggregates, type ArrowAggregate} from './aggregates';
|
|
17
|
-
import {compareUTF8} from '@math.gl/
|
|
17
|
+
import {compareUTF8} from '@math.gl/core/utf8';
|
|
18
18
|
import {ColumnReader, valueType} from './buffers';
|
|
19
19
|
import {compileArrowExpression} from './compiler';
|
|
20
20
|
import type {ArrowExpressionOptions, ArrowExpressionValue} from './types';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {DateDay, TimestampMicrosecond, type DataType} from 'apache-arrow';
|
|
6
|
-
import {ExpressionEvaluationError} from '../expressions
|
|
6
|
+
import {ExpressionEvaluationError} from '../expressions';
|
|
7
7
|
import {typeKey} from './buffers';
|
|
8
8
|
import type {ArrowExpressionValue} from './types';
|
|
9
9
|
|