@uwdata/mosaic-sql 0.12.1 → 0.13.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/README.md +1 -1
- package/dist/types/ast/column-param.d.ts +6 -0
- package/dist/types/ast/query.d.ts +59 -14
- package/dist/types/ast/with.d.ts +11 -1
- package/dist/types/functions/aggregate.d.ts +6 -0
- package/dist/types/functions/cte.d.ts +13 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/transforms/bin-linear-1d.d.ts +2 -1
- package/dist/types/transforms/bin-linear-2d.d.ts +2 -2
- package/dist/types/types.d.ts +3 -1
- package/package.json +9 -9
- package/src/ast/column-param.js +9 -0
- package/src/ast/literal.js +1 -1
- package/src/ast/query.js +102 -33
- package/src/ast/with.js +16 -2
- package/src/functions/aggregate.js +9 -0
- package/src/functions/cte.js +16 -0
- package/src/index.js +3 -2
- package/src/transforms/bin-linear-1d.js +4 -3
- package/src/transforms/bin-linear-2d.js +2 -2
- package/src/transforms/m4.js +12 -3
- package/src/types.ts +6 -1
- package/src/visit/visitors.js +2 -2
- package/vitest.config.ts +3 -0
- package/dist/mosaic-sql.js +0 -2606
- package/dist/mosaic-sql.min.js +0 -1
package/src/transforms/m4.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Query } from '../ast/query.js';
|
|
1
|
+
import { Query, isQuery } from '../ast/query.js';
|
|
2
2
|
import { argmax, argmin, max, min } from '../functions/aggregate.js';
|
|
3
3
|
import { int32 } from '../functions/cast.js';
|
|
4
|
+
import { cte } from '../functions/cte.js';
|
|
4
5
|
import { floor } from '../functions/numeric.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -22,12 +23,20 @@ import { floor } from '../functions/numeric.js';
|
|
|
22
23
|
export function m4(input, bin, x, y, groups = []) {
|
|
23
24
|
const pixel = int32(floor(bin));
|
|
24
25
|
|
|
26
|
+
// Below, we treat input as a CTE when it is a query. In this case,
|
|
27
|
+
// we also request that the CTE be explicitly materialized.
|
|
28
|
+
const useCTE = isQuery(input);
|
|
29
|
+
const from = useCTE ? 'input' : input;
|
|
30
|
+
const query = useCTE
|
|
31
|
+
? Query.with(cte(/** @type {string} */(from), input, true))
|
|
32
|
+
: Query;
|
|
33
|
+
|
|
25
34
|
const q = (sel) => Query
|
|
26
|
-
.from(
|
|
35
|
+
.from(from)
|
|
27
36
|
.select(sel)
|
|
28
37
|
.groupby(pixel, groups);
|
|
29
38
|
|
|
30
|
-
return
|
|
39
|
+
return query
|
|
31
40
|
.union(
|
|
32
41
|
q([{ [x]: min(x), [y]: argmin(y, x) }, ...groups]),
|
|
33
42
|
q([{ [x]: max(x), [y]: argmax(y, x) }, ...groups]),
|
package/src/types.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ColumnRefNode } from './ast/column-ref.js';
|
|
|
2
2
|
import { ExprNode, SQLNode } from './ast/node.js';
|
|
3
3
|
import { TableRefNode } from './ast/table-ref.js';
|
|
4
4
|
import { Query } from './ast/query.js';
|
|
5
|
+
import { WithClauseNode } from './ast/with.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Interface representing a dynamic parameter value.
|
|
@@ -80,7 +81,11 @@ export type SelectEntry =
|
|
|
80
81
|
|
|
81
82
|
export type SelectExpr = MaybeArray<SelectEntry>;
|
|
82
83
|
|
|
83
|
-
export type
|
|
84
|
+
export type WithEntry =
|
|
85
|
+
| WithClauseNode
|
|
86
|
+
| Record<string, Query>;
|
|
87
|
+
|
|
88
|
+
export type WithExpr = MaybeArray<WithEntry>;
|
|
84
89
|
|
|
85
90
|
export type FromEntry =
|
|
86
91
|
| string
|
package/src/visit/visitors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AGGREGATE, COLUMN_REF, FRAGMENT, PARAM, VERBATIM, WINDOW } from '../constants.js';
|
|
1
|
+
import { AGGREGATE, COLUMN_PARAM, COLUMN_REF, FRAGMENT, PARAM, VERBATIM, WINDOW } from '../constants.js';
|
|
2
2
|
import { aggregateNames, AggregateNode } from '../ast/aggregate.js';
|
|
3
3
|
import { ColumnRefNode } from '../ast/column-ref.js';
|
|
4
4
|
import { SQLNode } from '../ast/node.js';
|
|
@@ -82,7 +82,7 @@ export function collectAggregates(root) {
|
|
|
82
82
|
export function collectColumns(root) {
|
|
83
83
|
const cols = {};
|
|
84
84
|
walk(root, (node) => {
|
|
85
|
-
if (node.type === COLUMN_REF) {
|
|
85
|
+
if (node.type === COLUMN_REF || node.type === COLUMN_PARAM) {
|
|
86
86
|
cols[node] = node; // key on string-coerced node
|
|
87
87
|
}
|
|
88
88
|
});
|
package/vitest.config.ts
ADDED