@uwdata/mosaic-sql 0.13.0 → 0.14.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/types/ast/aggregate.d.ts +5 -4
- package/dist/types/ast/case.d.ts +6 -7
- package/dist/types/ast/column-param.d.ts +7 -7
- package/dist/types/ast/column-ref.d.ts +7 -6
- package/dist/types/ast/param.d.ts +5 -4
- package/dist/types/ast/query.d.ts +46 -39
- package/dist/types/ast/window.d.ts +15 -12
- package/dist/types/functions/aggregate.d.ts +89 -88
- package/dist/types/functions/case.d.ts +6 -8
- package/dist/types/functions/column.d.ts +5 -3
- package/dist/types/functions/datetime.d.ts +12 -11
- package/dist/types/functions/numeric.d.ts +48 -46
- package/dist/types/functions/operators.d.ts +80 -78
- package/dist/types/functions/order-by.d.ts +5 -4
- package/dist/types/functions/spatial.d.ts +14 -13
- package/dist/types/functions/sql-template-tag.d.ts +4 -5
- package/dist/types/functions/string.d.ts +22 -20
- package/dist/types/functions/util.d.ts +8 -0
- package/dist/types/functions/window.d.ts +18 -16
- package/dist/types/index.d.ts +3 -0
- package/dist/types/transforms/bin-1d.d.ts +3 -2
- package/dist/types/transforms/bin-2d.d.ts +6 -5
- package/dist/types/transforms/bin-date.d.ts +44 -0
- package/dist/types/transforms/bin-histogram.d.ts +51 -0
- package/dist/types/transforms/bin-linear-1d.d.ts +6 -4
- package/dist/types/transforms/bin-linear-2d.d.ts +6 -5
- package/dist/types/transforms/line-density.d.ts +5 -4
- package/dist/types/transforms/m4.d.ts +7 -4
- package/dist/types/transforms/util/bin-step.d.ts +61 -0
- package/dist/types/transforms/util/time-interval.d.ts +13 -0
- package/dist/types/types.d.ts +1 -0
- package/dist/types/util/ast.d.ts +6 -5
- package/dist/types/util/function.d.ts +6 -4
- package/dist/types/util/type-check.d.ts +6 -2
- package/dist/types/visit/visitors.d.ts +3 -2
- package/dist/types/visit/walk.d.ts +7 -4
- package/package.json +2 -2
- package/src/ast/aggregate.js +5 -2
- package/src/ast/case.js +6 -5
- package/src/ast/column-param.js +7 -5
- package/src/ast/column-ref.js +6 -3
- package/src/ast/param.js +5 -2
- package/src/ast/query.js +23 -19
- package/src/ast/window.js +10 -6
- package/src/functions/aggregate.js +55 -52
- package/src/functions/case.js +7 -7
- package/src/functions/column.js +6 -2
- package/src/functions/datetime.js +9 -6
- package/src/functions/numeric.js +35 -31
- package/src/functions/operators.js +53 -50
- package/src/functions/order-by.js +5 -2
- package/src/functions/spatial.js +10 -7
- package/src/functions/sql-template-tag.js +5 -5
- package/src/functions/string.js +16 -13
- package/src/functions/util.js +14 -0
- package/src/functions/window.js +13 -10
- package/src/index.js +3 -0
- package/src/transforms/bin-1d.js +4 -1
- package/src/transforms/bin-2d.js +7 -4
- package/src/transforms/bin-date.js +37 -0
- package/src/transforms/bin-histogram.js +52 -0
- package/src/transforms/bin-linear-1d.js +7 -3
- package/src/transforms/bin-linear-2d.js +12 -8
- package/src/transforms/line-density.js +7 -3
- package/src/transforms/m4.js +7 -3
- package/src/transforms/util/bin-step.js +79 -0
- package/src/transforms/util/time-interval.js +97 -0
- package/src/types.ts +11 -0
- package/src/util/ast.js +6 -3
- package/src/util/function.js +6 -2
- package/src/util/type-check.js +5 -1
- package/src/visit/visitors.js +6 -2
- package/src/visit/walk.js +8 -3
package/src/ast/window.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { ExprVarArgs, WindowFunctionName } from '../types.js'
|
|
3
|
+
* @import { ParamLike } from '../types.js'
|
|
4
|
+
*/
|
|
1
5
|
import { WINDOW, WINDOW_CLAUSE, WINDOW_DEF, WINDOW_FRAME } from '../constants.js';
|
|
2
6
|
import { exprList } from '../util/function.js';
|
|
3
7
|
import { quoteIdentifier } from '../util/string.js';
|
|
@@ -8,7 +12,7 @@ import { ExprNode, isNode, SQLNode } from './node.js';
|
|
|
8
12
|
import { ParamNode } from './param.js';
|
|
9
13
|
|
|
10
14
|
/**
|
|
11
|
-
* @typedef {[any, any] |
|
|
15
|
+
* @typedef {[any, any] | ParamLike} FrameExtent
|
|
12
16
|
*/
|
|
13
17
|
|
|
14
18
|
export class WindowClauseNode extends SQLNode {
|
|
@@ -69,7 +73,7 @@ export class WindowNode extends ExprNode {
|
|
|
69
73
|
|
|
70
74
|
/**
|
|
71
75
|
* Return an updated window with the given partitions.
|
|
72
|
-
* @param {...
|
|
76
|
+
* @param {...ExprVarArgs} expr The partition by criteria.
|
|
73
77
|
* @returns {WindowNode} A new window node.
|
|
74
78
|
*/
|
|
75
79
|
partitionby(...expr) {
|
|
@@ -78,7 +82,7 @@ export class WindowNode extends ExprNode {
|
|
|
78
82
|
|
|
79
83
|
/**
|
|
80
84
|
* Return an updated window with the given ordering.
|
|
81
|
-
* @param {...
|
|
85
|
+
* @param {...ExprVarArgs} expr The order by criteria.
|
|
82
86
|
* @returns {WindowNode} A new window node.
|
|
83
87
|
*/
|
|
84
88
|
orderby(...expr) {
|
|
@@ -115,7 +119,7 @@ export class WindowNode extends ExprNode {
|
|
|
115
119
|
export class WindowFunctionNode extends FunctionNode {
|
|
116
120
|
/**
|
|
117
121
|
* Instantiate a window function call node.
|
|
118
|
-
* @param {
|
|
122
|
+
* @param {WindowFunctionName} name The function name.
|
|
119
123
|
* @param {ExprNode[]} [args=[]] The function arguments.
|
|
120
124
|
*/
|
|
121
125
|
constructor(name, args) {
|
|
@@ -170,7 +174,7 @@ export class WindowDefNode extends SQLNode {
|
|
|
170
174
|
|
|
171
175
|
/**
|
|
172
176
|
* Return an updated window definition with the given partitions.
|
|
173
|
-
* @param {...
|
|
177
|
+
* @param {...ExprVarArgs} expr The partition by criteria.
|
|
174
178
|
* @returns {WindowDefNode} A new window definition node.
|
|
175
179
|
*/
|
|
176
180
|
partitionby(...expr) {
|
|
@@ -179,7 +183,7 @@ export class WindowDefNode extends SQLNode {
|
|
|
179
183
|
|
|
180
184
|
/**
|
|
181
185
|
* Return an updated window definition with the given ordering.
|
|
182
|
-
* @param {...
|
|
186
|
+
* @param {...ExprVarArgs} expr The order by criteria.
|
|
183
187
|
* @returns {WindowDefNode} A new window definition node.
|
|
184
188
|
*/
|
|
185
189
|
orderby(...expr) {
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @import { AggregateNode } from '../ast/aggregate.js'
|
|
3
|
+
* @import { ExprValue } from '../types.js'
|
|
4
|
+
*/
|
|
2
5
|
import { aggFn } from '../util/function.js';
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Compute an arg_max aggregate.
|
|
6
|
-
* @param {
|
|
7
|
-
* @param {
|
|
9
|
+
* @param {ExprValue} y The argument to return.
|
|
10
|
+
* @param {ExprValue} x The expression to maximize.
|
|
8
11
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
9
12
|
*/
|
|
10
13
|
export function argmax(y, x) {
|
|
@@ -13,8 +16,8 @@ export function argmax(y, x) {
|
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* Compute an arg_min aggregate.
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {
|
|
19
|
+
* @param {ExprValue} y The argument to return.
|
|
20
|
+
* @param {ExprValue} x The expression to minimize.
|
|
18
21
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
19
22
|
*/
|
|
20
23
|
export function argmin(y, x) {
|
|
@@ -23,7 +26,7 @@ export function argmin(y, x) {
|
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* Compute an array aggregation.
|
|
26
|
-
* @param {
|
|
29
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
27
30
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
28
31
|
*/
|
|
29
32
|
export function arrayAgg(expr) {
|
|
@@ -32,7 +35,7 @@ export function arrayAgg(expr) {
|
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
37
|
* Compute an average aggregate.
|
|
35
|
-
* @param {
|
|
38
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
36
39
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
37
40
|
*/
|
|
38
41
|
export function avg(expr) {
|
|
@@ -41,8 +44,8 @@ export function avg(expr) {
|
|
|
41
44
|
|
|
42
45
|
/**
|
|
43
46
|
* Compute a correlation aggregate.
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {
|
|
47
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
48
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
46
49
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
47
50
|
*/
|
|
48
51
|
export function corr(x, y) {
|
|
@@ -51,7 +54,7 @@ export function corr(x, y) {
|
|
|
51
54
|
|
|
52
55
|
/**
|
|
53
56
|
* Compute a count aggregate.
|
|
54
|
-
* @param {
|
|
57
|
+
* @param {ExprValue} [expr] An optional expression
|
|
55
58
|
* to count. If specified, only non-null expression values are counted.
|
|
56
59
|
* If omitted, all rows within a group are counted.
|
|
57
60
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
@@ -62,8 +65,8 @@ export function count(expr) {
|
|
|
62
65
|
|
|
63
66
|
/**
|
|
64
67
|
* Compute a sample covariance aggregate.
|
|
65
|
-
* @param {
|
|
66
|
-
* @param {
|
|
68
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
69
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
67
70
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
68
71
|
*/
|
|
69
72
|
export function covariance(x, y) {
|
|
@@ -72,8 +75,8 @@ export function covariance(x, y) {
|
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
77
|
* Compute a population covariance aggregate.
|
|
75
|
-
* @param {
|
|
76
|
-
* @param {
|
|
78
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
79
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
77
80
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
78
81
|
*/
|
|
79
82
|
export function covarPop(x, y) {
|
|
@@ -82,7 +85,7 @@ export function covarPop(x, y) {
|
|
|
82
85
|
|
|
83
86
|
/**
|
|
84
87
|
* Compute an entropy aggregate.
|
|
85
|
-
* @param {
|
|
88
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
86
89
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
87
90
|
*/
|
|
88
91
|
export function entropy(expr) {
|
|
@@ -91,7 +94,7 @@ export function entropy(expr) {
|
|
|
91
94
|
|
|
92
95
|
/**
|
|
93
96
|
* Compute a first aggregate.
|
|
94
|
-
* @param {
|
|
97
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
95
98
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
96
99
|
*/
|
|
97
100
|
export function first(expr) {
|
|
@@ -100,7 +103,7 @@ export function first(expr) {
|
|
|
100
103
|
|
|
101
104
|
/**
|
|
102
105
|
* Compute a geomean aggregate.
|
|
103
|
-
* @param {
|
|
106
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
104
107
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
105
108
|
*/
|
|
106
109
|
export function geomean(expr) {
|
|
@@ -109,7 +112,7 @@ export function geomean(expr) {
|
|
|
109
112
|
|
|
110
113
|
/**
|
|
111
114
|
* Compute a sample kurtosis aggregate.
|
|
112
|
-
* @param {
|
|
115
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
113
116
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
114
117
|
*/
|
|
115
118
|
export function kurtosis(expr) {
|
|
@@ -118,7 +121,7 @@ export function kurtosis(expr) {
|
|
|
118
121
|
|
|
119
122
|
/**
|
|
120
123
|
* Compute a median absolute deviation (MAD) aggregate.
|
|
121
|
-
* @param {
|
|
124
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
122
125
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
123
126
|
*/
|
|
124
127
|
export function mad(expr) {
|
|
@@ -127,7 +130,7 @@ export function mad(expr) {
|
|
|
127
130
|
|
|
128
131
|
/**
|
|
129
132
|
* Compute a maximum aggregate.
|
|
130
|
-
* @param {
|
|
133
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
131
134
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
132
135
|
*/
|
|
133
136
|
export function max(expr) {
|
|
@@ -136,7 +139,7 @@ export function max(expr) {
|
|
|
136
139
|
|
|
137
140
|
/**
|
|
138
141
|
* Compute a median aggregate.
|
|
139
|
-
* @param {
|
|
142
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
140
143
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
141
144
|
*/
|
|
142
145
|
export function median(expr) {
|
|
@@ -145,7 +148,7 @@ export function median(expr) {
|
|
|
145
148
|
|
|
146
149
|
/**
|
|
147
150
|
* Compute a minimum aggregate.
|
|
148
|
-
* @param {
|
|
151
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
149
152
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
150
153
|
*/
|
|
151
154
|
export function min(expr) {
|
|
@@ -154,7 +157,7 @@ export function min(expr) {
|
|
|
154
157
|
|
|
155
158
|
/**
|
|
156
159
|
* Compute a mode aggregate.
|
|
157
|
-
* @param {
|
|
160
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
158
161
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
159
162
|
*/
|
|
160
163
|
export function mode(expr) {
|
|
@@ -163,7 +166,7 @@ export function mode(expr) {
|
|
|
163
166
|
|
|
164
167
|
/**
|
|
165
168
|
* Compute a last aggregate.
|
|
166
|
-
* @param {
|
|
169
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
167
170
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
168
171
|
*/
|
|
169
172
|
export function last(expr) {
|
|
@@ -172,7 +175,7 @@ export function last(expr) {
|
|
|
172
175
|
|
|
173
176
|
/**
|
|
174
177
|
* Compute a product aggregate.
|
|
175
|
-
* @param {
|
|
178
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
176
179
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
177
180
|
*/
|
|
178
181
|
export function product(expr) {
|
|
@@ -181,8 +184,8 @@ export function product(expr) {
|
|
|
181
184
|
|
|
182
185
|
/**
|
|
183
186
|
* Compute a quantile aggregate.
|
|
184
|
-
* @param {
|
|
185
|
-
* @param {
|
|
187
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
188
|
+
* @param {ExprValue} p The quantile value.
|
|
186
189
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
187
190
|
*/
|
|
188
191
|
export function quantile(expr, p) {
|
|
@@ -191,8 +194,8 @@ export function quantile(expr, p) {
|
|
|
191
194
|
|
|
192
195
|
/**
|
|
193
196
|
* Compute a linear regression reg_avgX aggregate.
|
|
194
|
-
* @param {
|
|
195
|
-
* @param {
|
|
197
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
198
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
196
199
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
197
200
|
*/
|
|
198
201
|
export function regrAvgX(x, y) {
|
|
@@ -201,8 +204,8 @@ export function regrAvgX(x, y) {
|
|
|
201
204
|
|
|
202
205
|
/**
|
|
203
206
|
* Compute a linear regression reg_avgY aggregate.
|
|
204
|
-
* @param {
|
|
205
|
-
* @param {
|
|
207
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
208
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
206
209
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
207
210
|
*/
|
|
208
211
|
export function regrAvgY(x, y) {
|
|
@@ -212,8 +215,8 @@ export function regrAvgY(x, y) {
|
|
|
212
215
|
/**
|
|
213
216
|
* Compute a linear regression count aggregate.
|
|
214
217
|
* This returns the count of rows where both x and y are non-null.
|
|
215
|
-
* @param {
|
|
216
|
-
* @param {
|
|
218
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
219
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
217
220
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
218
221
|
*/
|
|
219
222
|
export function regrCount(x, y) {
|
|
@@ -222,8 +225,8 @@ export function regrCount(x, y) {
|
|
|
222
225
|
|
|
223
226
|
/**
|
|
224
227
|
* Compute a linear regression intercept aggregate.
|
|
225
|
-
* @param {
|
|
226
|
-
* @param {
|
|
228
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
229
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
227
230
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
228
231
|
*/
|
|
229
232
|
export function regrIntercept(x, y) {
|
|
@@ -232,8 +235,8 @@ export function regrIntercept(x, y) {
|
|
|
232
235
|
|
|
233
236
|
/**
|
|
234
237
|
* Compute a linear regression R^2 aggregate.
|
|
235
|
-
* @param {
|
|
236
|
-
* @param {
|
|
238
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
239
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
237
240
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
238
241
|
*/
|
|
239
242
|
export function regrR2(x, y) {
|
|
@@ -242,8 +245,8 @@ export function regrR2(x, y) {
|
|
|
242
245
|
|
|
243
246
|
/**
|
|
244
247
|
* Compute a linear regression regr_sxx aggregate.
|
|
245
|
-
* @param {
|
|
246
|
-
* @param {
|
|
248
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
249
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
247
250
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
248
251
|
*/
|
|
249
252
|
export function regrSXX(x, y) {
|
|
@@ -252,8 +255,8 @@ export function regrSXX(x, y) {
|
|
|
252
255
|
|
|
253
256
|
/**
|
|
254
257
|
* Compute a linear regression regr_sxy aggregate.
|
|
255
|
-
* @param {
|
|
256
|
-
* @param {
|
|
258
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
259
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
257
260
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
258
261
|
*/
|
|
259
262
|
export function regrSXY(x, y) {
|
|
@@ -262,8 +265,8 @@ export function regrSXY(x, y) {
|
|
|
262
265
|
|
|
263
266
|
/**
|
|
264
267
|
* Compute a linear regression regr_syy aggregate.
|
|
265
|
-
* @param {
|
|
266
|
-
* @param {
|
|
268
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
269
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
267
270
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
268
271
|
*/
|
|
269
272
|
export function regrSYY(x, y) {
|
|
@@ -272,8 +275,8 @@ export function regrSYY(x, y) {
|
|
|
272
275
|
|
|
273
276
|
/**
|
|
274
277
|
* Compute a linear regression slope aggregate.
|
|
275
|
-
* @param {
|
|
276
|
-
* @param {
|
|
278
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
279
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
277
280
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
278
281
|
*/
|
|
279
282
|
export function regrSlope(x, y) {
|
|
@@ -282,7 +285,7 @@ export function regrSlope(x, y) {
|
|
|
282
285
|
|
|
283
286
|
/**
|
|
284
287
|
* Compute a skewness aggregate.
|
|
285
|
-
* @param {
|
|
288
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
286
289
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
287
290
|
*/
|
|
288
291
|
export function skewness(expr) {
|
|
@@ -291,7 +294,7 @@ export function skewness(expr) {
|
|
|
291
294
|
|
|
292
295
|
/**
|
|
293
296
|
* Compute a sample standard deviation aggregate.
|
|
294
|
-
* @param {
|
|
297
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
295
298
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
296
299
|
*/
|
|
297
300
|
export function stddev(expr) {
|
|
@@ -300,7 +303,7 @@ export function stddev(expr) {
|
|
|
300
303
|
|
|
301
304
|
/**
|
|
302
305
|
* Compute a population standard deviation aggregate.
|
|
303
|
-
* @param {
|
|
306
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
304
307
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
305
308
|
*/
|
|
306
309
|
export function stddevPop(expr) {
|
|
@@ -309,7 +312,7 @@ export function stddevPop(expr) {
|
|
|
309
312
|
|
|
310
313
|
/**
|
|
311
314
|
* Compute a string aggregation.
|
|
312
|
-
* @param {
|
|
315
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
313
316
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
314
317
|
*/
|
|
315
318
|
export function stringAgg(expr) {
|
|
@@ -318,7 +321,7 @@ export function stringAgg(expr) {
|
|
|
318
321
|
|
|
319
322
|
/**
|
|
320
323
|
* Compute a sum aggregate.
|
|
321
|
-
* @param {
|
|
324
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
322
325
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
323
326
|
*/
|
|
324
327
|
export function sum(expr) {
|
|
@@ -327,7 +330,7 @@ export function sum(expr) {
|
|
|
327
330
|
|
|
328
331
|
/**
|
|
329
332
|
* Compute a sample variance aggregate.
|
|
330
|
-
* @param {
|
|
333
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
331
334
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
332
335
|
*/
|
|
333
336
|
export function variance(expr) {
|
|
@@ -336,7 +339,7 @@ export function variance(expr) {
|
|
|
336
339
|
|
|
337
340
|
/**
|
|
338
341
|
* Compute a population variance aggregate.
|
|
339
|
-
* @param {
|
|
342
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
340
343
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
341
344
|
*/
|
|
342
345
|
export function varPop(expr) {
|
package/src/functions/case.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { ExprValue } from '../types.js'
|
|
3
|
+
*/
|
|
1
4
|
import { CaseNode, WhenNode } from '../ast/case.js';
|
|
2
5
|
import { asNode } from '../util/ast.js';
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Create a new conditional CASE statement. If three arguments are provided,
|
|
6
|
-
* acts like a ternary conditional (if, then else). If no arguments are
|
|
9
|
+
* acts like a ternary conditional (if, then, else). If no arguments are
|
|
7
10
|
* provided, the chained `when` and `else` methods can be used to to complete
|
|
8
11
|
* a conditional statement with WHEN/THEN and ELSE expressions.
|
|
9
|
-
* @param {
|
|
10
|
-
*
|
|
11
|
-
* @param {
|
|
12
|
-
* A THEN value expression.
|
|
13
|
-
* @param {import('../types.js').ExprValue} [other]
|
|
14
|
-
* An ELSE expression.
|
|
12
|
+
* @param {ExprValue} [when] A conditional WHEN expression.
|
|
13
|
+
* @param {ExprValue} [then] A THEN value expression.
|
|
14
|
+
* @param {ExprValue} [other] An ELSE expression.
|
|
15
15
|
* @returns {CaseNode}
|
|
16
16
|
*/
|
|
17
17
|
export function cond(when, then, other) {
|
package/src/functions/column.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { ColumnRefNode } from '../ast/column-ref.js'
|
|
3
|
+
* @import { ParamLike } from '../types.js'
|
|
4
|
+
*/
|
|
1
5
|
import { ColumnParamNode } from '../ast/column-param.js';
|
|
2
6
|
import { ColumnNameRefNode } from '../ast/column-ref.js';
|
|
3
7
|
import { ParamNode } from '../ast/param.js';
|
|
@@ -7,10 +11,10 @@ import { isParamLike } from '../util/type-check.js';
|
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* Create a column reference.
|
|
10
|
-
* @param {string |
|
|
14
|
+
* @param {string | ParamLike} name The column name,
|
|
11
15
|
* as a string or as a dynamic parameter.
|
|
12
16
|
* @param {string | string[] | TableRefNode} [table] The table reference.
|
|
13
|
-
* @returns {
|
|
17
|
+
* @returns {ColumnRefNode}
|
|
14
18
|
*/
|
|
15
19
|
export function column(name, table) {
|
|
16
20
|
const tref = asTableRef(table);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @import { FunctionNode } from '../ast/function.js'
|
|
3
|
+
* @import { ExprValue } from '../types.js'
|
|
4
|
+
*/
|
|
2
5
|
import { IntervalNode } from '../ast/interval.js';
|
|
3
6
|
import { asNode } from '../util/ast.js';
|
|
4
7
|
import { fn } from '../util/function.js';
|
|
@@ -15,7 +18,7 @@ export function interval(unit, steps) {
|
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* Given a date/time value, return the milliseconds since the UNIX epoch.
|
|
18
|
-
* @param {
|
|
21
|
+
* @param {ExprValue} expr The date/time expression.
|
|
19
22
|
* @returns {FunctionNode}
|
|
20
23
|
*/
|
|
21
24
|
export function epoch_ms(expr) {
|
|
@@ -24,7 +27,7 @@ export function epoch_ms(expr) {
|
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* Perform data binning according to the provided interval unit and steps.
|
|
27
|
-
* @param {
|
|
30
|
+
* @param {ExprValue} expr The date/time expression to bin.
|
|
28
31
|
* @param {string} unit The datetime interval unit to bin by.
|
|
29
32
|
* @param {number} [steps=1] The number of interval steps.
|
|
30
33
|
* @returns {FunctionNode}
|
|
@@ -36,7 +39,7 @@ export function dateBin(expr, unit, steps = 1) {
|
|
|
36
39
|
/**
|
|
37
40
|
* Map date/times to a month value, all within the same year for comparison.
|
|
38
41
|
* The resulting value is still date-typed.
|
|
39
|
-
* @param {
|
|
42
|
+
* @param {ExprValue} expr The date/time expression.
|
|
40
43
|
* @returns {FunctionNode}
|
|
41
44
|
*/
|
|
42
45
|
export function dateMonth(expr) {
|
|
@@ -46,7 +49,7 @@ export function dateMonth(expr) {
|
|
|
46
49
|
/**
|
|
47
50
|
* Map date/times to a month and day value, all within the same year for
|
|
48
51
|
* comparison. The resulting value is still date-typed.
|
|
49
|
-
* @param {
|
|
52
|
+
* @param {ExprValue} expr The date/time expression.
|
|
50
53
|
* @returns {FunctionNode}
|
|
51
54
|
*/
|
|
52
55
|
export function dateMonthDay(expr) {
|
|
@@ -57,7 +60,7 @@ export function dateMonthDay(expr) {
|
|
|
57
60
|
/**
|
|
58
61
|
* Map date/times to a day of the month value, all within the same year and month
|
|
59
62
|
* for comparison. The resulting value is still date-typed.
|
|
60
|
-
* @param {
|
|
63
|
+
* @param {ExprValue} expr The date/time expression.
|
|
61
64
|
* @returns {FunctionNode}
|
|
62
65
|
*/
|
|
63
66
|
export function dateDay(expr) {
|
package/src/functions/numeric.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { FunctionNode } from '../ast/function.js'
|
|
3
|
+
* @import { ExprValue } from '../types.js'
|
|
4
|
+
*/
|
|
1
5
|
import { fn } from '../util/function.js';
|
|
2
6
|
|
|
3
7
|
/**
|
|
4
8
|
* Return true if the floating point value is not a number, false otherwise.
|
|
5
|
-
* @param {
|
|
6
|
-
* @returns {
|
|
9
|
+
* @param {ExprValue} expr The input number.
|
|
10
|
+
* @returns {FunctionNode}
|
|
7
11
|
*/
|
|
8
12
|
export function isNaN(expr) {
|
|
9
13
|
return fn('isnan', expr);
|
|
@@ -11,8 +15,8 @@ export function isNaN(expr) {
|
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
17
|
* Return true if the floating point value is finite, false otherwise.
|
|
14
|
-
* @param {
|
|
15
|
-
* @returns {
|
|
18
|
+
* @param {ExprValue} expr The input number.
|
|
19
|
+
* @returns {FunctionNode}
|
|
16
20
|
*/
|
|
17
21
|
export function isFinite(expr) {
|
|
18
22
|
return fn('isfinite', expr);
|
|
@@ -20,8 +24,8 @@ export function isFinite(expr) {
|
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* Return true if the floating point value is infinite, false otherwise.
|
|
23
|
-
* @param {
|
|
24
|
-
* @returns {
|
|
27
|
+
* @param {ExprValue} expr The input number.
|
|
28
|
+
* @returns {FunctionNode}
|
|
25
29
|
*/
|
|
26
30
|
export function isInfinite(expr) {
|
|
27
31
|
return fn('isinf', expr);
|
|
@@ -29,8 +33,8 @@ export function isInfinite(expr) {
|
|
|
29
33
|
|
|
30
34
|
/**
|
|
31
35
|
* Selects the largest value.
|
|
32
|
-
* @param {...
|
|
33
|
-
* @returns {
|
|
36
|
+
* @param {...ExprValue} expr The input expressions.
|
|
37
|
+
* @returns {FunctionNode}
|
|
34
38
|
*/
|
|
35
39
|
export function greatest(...expr) {
|
|
36
40
|
return fn('greatest', ...expr);
|
|
@@ -38,8 +42,8 @@ export function greatest(...expr) {
|
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
44
|
* Selects the smallest value.
|
|
41
|
-
* @param {...
|
|
42
|
-
* @returns {
|
|
45
|
+
* @param {...ExprValue} expr The input expressions.
|
|
46
|
+
* @returns {FunctionNode}
|
|
43
47
|
*/
|
|
44
48
|
export function least(...expr) {
|
|
45
49
|
return fn('least', ...expr);
|
|
@@ -47,8 +51,8 @@ export function least(...expr) {
|
|
|
47
51
|
|
|
48
52
|
/**
|
|
49
53
|
* Compute the exponentional function `e ** expr`.
|
|
50
|
-
* @param {
|
|
51
|
-
* @returns {
|
|
54
|
+
* @param {ExprValue} expr The input number.
|
|
55
|
+
* @returns {FunctionNode}
|
|
52
56
|
*/
|
|
53
57
|
export function exp(expr) {
|
|
54
58
|
return fn('exp', expr);
|
|
@@ -56,8 +60,8 @@ export function exp(expr) {
|
|
|
56
60
|
|
|
57
61
|
/**
|
|
58
62
|
* Compute a base 10 logarithm.
|
|
59
|
-
* @param {
|
|
60
|
-
* @returns {
|
|
63
|
+
* @param {ExprValue} expr The input number.
|
|
64
|
+
* @returns {FunctionNode}
|
|
61
65
|
*/
|
|
62
66
|
export function log(expr) {
|
|
63
67
|
return fn('log', expr);
|
|
@@ -65,8 +69,8 @@ export function log(expr) {
|
|
|
65
69
|
|
|
66
70
|
/**
|
|
67
71
|
* Compute a natural logarithm.
|
|
68
|
-
* @param {
|
|
69
|
-
* @returns {
|
|
72
|
+
* @param {ExprValue} expr The input number.
|
|
73
|
+
* @returns {FunctionNode}
|
|
70
74
|
*/
|
|
71
75
|
export function ln(expr) {
|
|
72
76
|
return fn('ln', expr);
|
|
@@ -74,8 +78,8 @@ export function ln(expr) {
|
|
|
74
78
|
|
|
75
79
|
/**
|
|
76
80
|
* Compute the sign of a number.
|
|
77
|
-
* @param {
|
|
78
|
-
* @returns {
|
|
81
|
+
* @param {ExprValue} expr The input number.
|
|
82
|
+
* @returns {FunctionNode}
|
|
79
83
|
*/
|
|
80
84
|
export function sign(expr) {
|
|
81
85
|
return fn('sign', expr);
|
|
@@ -83,8 +87,8 @@ export function sign(expr) {
|
|
|
83
87
|
|
|
84
88
|
/**
|
|
85
89
|
* Compute the absolute value of a number.
|
|
86
|
-
* @param {
|
|
87
|
-
* @returns {
|
|
90
|
+
* @param {ExprValue} expr The input number.
|
|
91
|
+
* @returns {FunctionNode}
|
|
88
92
|
*/
|
|
89
93
|
export function abs(expr) {
|
|
90
94
|
return fn('abs', expr);
|
|
@@ -92,8 +96,8 @@ export function abs(expr) {
|
|
|
92
96
|
|
|
93
97
|
/**
|
|
94
98
|
* Compute the square root of a number.
|
|
95
|
-
* @param {
|
|
96
|
-
* @returns {
|
|
99
|
+
* @param {ExprValue} expr The input number.
|
|
100
|
+
* @returns {FunctionNode}
|
|
97
101
|
*/
|
|
98
102
|
export function sqrt(expr) {
|
|
99
103
|
return fn('sqrt', expr);
|
|
@@ -101,8 +105,8 @@ export function sqrt(expr) {
|
|
|
101
105
|
|
|
102
106
|
/**
|
|
103
107
|
* Rounds the number up.
|
|
104
|
-
* @param {
|
|
105
|
-
* @returns {
|
|
108
|
+
* @param {ExprValue} expr The input number.
|
|
109
|
+
* @returns {FunctionNode}
|
|
106
110
|
*/
|
|
107
111
|
export function ceil(expr) {
|
|
108
112
|
return fn('ceil', expr);
|
|
@@ -110,8 +114,8 @@ export function ceil(expr) {
|
|
|
110
114
|
|
|
111
115
|
/**
|
|
112
116
|
* Rounds the number down.
|
|
113
|
-
* @param {
|
|
114
|
-
* @returns {
|
|
117
|
+
* @param {ExprValue} expr The input number.
|
|
118
|
+
* @returns {FunctionNode}
|
|
115
119
|
*/
|
|
116
120
|
export function floor(expr) {
|
|
117
121
|
return fn('floor', expr);
|
|
@@ -119,11 +123,11 @@ export function floor(expr) {
|
|
|
119
123
|
|
|
120
124
|
/**
|
|
121
125
|
* Round to the given decimal places.
|
|
122
|
-
* @param {
|
|
123
|
-
* @param {
|
|
126
|
+
* @param {ExprValue} expr The input number.
|
|
127
|
+
* @param {ExprValue} [places] The decimal places.
|
|
124
128
|
* Negative values are allowed, to round to tens, hundreds, etc.
|
|
125
129
|
* If unspecified, defaults to zero.
|
|
126
|
-
* @returns {
|
|
130
|
+
* @returns {FunctionNode}
|
|
127
131
|
*/
|
|
128
132
|
export function round(expr, places) {
|
|
129
133
|
return fn('round', expr, places);
|
|
@@ -131,8 +135,8 @@ export function round(expr, places) {
|
|
|
131
135
|
|
|
132
136
|
/**
|
|
133
137
|
* Truncates the number.
|
|
134
|
-
* @param {
|
|
135
|
-
* @returns {
|
|
138
|
+
* @param {ExprValue} expr The input number.
|
|
139
|
+
* @returns {FunctionNode}
|
|
136
140
|
*/
|
|
137
141
|
export function trunc(expr) {
|
|
138
142
|
return fn('trunc', expr);
|