@uwdata/mosaic-sql 0.12.2 → 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/README.md +1 -1
- 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 +94 -42
- package/dist/types/ast/window.d.ts +15 -12
- package/dist/types/ast/with.d.ts +11 -1
- package/dist/types/functions/aggregate.d.ts +93 -86
- package/dist/types/functions/case.d.ts +6 -8
- package/dist/types/functions/column.d.ts +5 -3
- package/dist/types/functions/cte.d.ts +13 -0
- 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 +5 -1
- 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 +4 -1
- 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 +9 -9
- 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/literal.js +1 -1
- package/src/ast/param.js +5 -2
- package/src/ast/query.js +120 -47
- package/src/ast/window.js +10 -6
- package/src/ast/with.js +16 -2
- package/src/functions/aggregate.js +63 -51
- package/src/functions/case.js +7 -7
- package/src/functions/column.js +6 -2
- package/src/functions/cte.js +16 -0
- 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 +5 -1
- 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 +19 -6
- package/src/transforms/util/bin-step.js +79 -0
- package/src/transforms/util/time-interval.js +97 -0
- package/src/types.ts +17 -1
- 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/vitest.config.ts +3 -0
- package/dist/mosaic-sql.js +0 -2610
- package/dist/mosaic-sql.min.js +0 -1
|
@@ -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,16 +94,25 @@ 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) {
|
|
98
101
|
return aggFn('first', expr);
|
|
99
102
|
}
|
|
100
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Compute a geomean aggregate.
|
|
106
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
107
|
+
* @returns {AggregateNode} A SQL aggregate function call.
|
|
108
|
+
*/
|
|
109
|
+
export function geomean(expr) {
|
|
110
|
+
return aggFn('geomean', expr);
|
|
111
|
+
}
|
|
112
|
+
|
|
101
113
|
/**
|
|
102
114
|
* Compute a sample kurtosis aggregate.
|
|
103
|
-
* @param {
|
|
115
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
104
116
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
105
117
|
*/
|
|
106
118
|
export function kurtosis(expr) {
|
|
@@ -109,7 +121,7 @@ export function kurtosis(expr) {
|
|
|
109
121
|
|
|
110
122
|
/**
|
|
111
123
|
* Compute a median absolute deviation (MAD) aggregate.
|
|
112
|
-
* @param {
|
|
124
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
113
125
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
114
126
|
*/
|
|
115
127
|
export function mad(expr) {
|
|
@@ -118,7 +130,7 @@ export function mad(expr) {
|
|
|
118
130
|
|
|
119
131
|
/**
|
|
120
132
|
* Compute a maximum aggregate.
|
|
121
|
-
* @param {
|
|
133
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
122
134
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
123
135
|
*/
|
|
124
136
|
export function max(expr) {
|
|
@@ -127,7 +139,7 @@ export function max(expr) {
|
|
|
127
139
|
|
|
128
140
|
/**
|
|
129
141
|
* Compute a median aggregate.
|
|
130
|
-
* @param {
|
|
142
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
131
143
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
132
144
|
*/
|
|
133
145
|
export function median(expr) {
|
|
@@ -136,7 +148,7 @@ export function median(expr) {
|
|
|
136
148
|
|
|
137
149
|
/**
|
|
138
150
|
* Compute a minimum aggregate.
|
|
139
|
-
* @param {
|
|
151
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
140
152
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
141
153
|
*/
|
|
142
154
|
export function min(expr) {
|
|
@@ -145,7 +157,7 @@ export function min(expr) {
|
|
|
145
157
|
|
|
146
158
|
/**
|
|
147
159
|
* Compute a mode aggregate.
|
|
148
|
-
* @param {
|
|
160
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
149
161
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
150
162
|
*/
|
|
151
163
|
export function mode(expr) {
|
|
@@ -154,7 +166,7 @@ export function mode(expr) {
|
|
|
154
166
|
|
|
155
167
|
/**
|
|
156
168
|
* Compute a last aggregate.
|
|
157
|
-
* @param {
|
|
169
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
158
170
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
159
171
|
*/
|
|
160
172
|
export function last(expr) {
|
|
@@ -163,7 +175,7 @@ export function last(expr) {
|
|
|
163
175
|
|
|
164
176
|
/**
|
|
165
177
|
* Compute a product aggregate.
|
|
166
|
-
* @param {
|
|
178
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
167
179
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
168
180
|
*/
|
|
169
181
|
export function product(expr) {
|
|
@@ -172,8 +184,8 @@ export function product(expr) {
|
|
|
172
184
|
|
|
173
185
|
/**
|
|
174
186
|
* Compute a quantile aggregate.
|
|
175
|
-
* @param {
|
|
176
|
-
* @param {
|
|
187
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
188
|
+
* @param {ExprValue} p The quantile value.
|
|
177
189
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
178
190
|
*/
|
|
179
191
|
export function quantile(expr, p) {
|
|
@@ -182,8 +194,8 @@ export function quantile(expr, p) {
|
|
|
182
194
|
|
|
183
195
|
/**
|
|
184
196
|
* Compute a linear regression reg_avgX aggregate.
|
|
185
|
-
* @param {
|
|
186
|
-
* @param {
|
|
197
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
198
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
187
199
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
188
200
|
*/
|
|
189
201
|
export function regrAvgX(x, y) {
|
|
@@ -192,8 +204,8 @@ export function regrAvgX(x, y) {
|
|
|
192
204
|
|
|
193
205
|
/**
|
|
194
206
|
* Compute a linear regression reg_avgY aggregate.
|
|
195
|
-
* @param {
|
|
196
|
-
* @param {
|
|
207
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
208
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
197
209
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
198
210
|
*/
|
|
199
211
|
export function regrAvgY(x, y) {
|
|
@@ -203,8 +215,8 @@ export function regrAvgY(x, y) {
|
|
|
203
215
|
/**
|
|
204
216
|
* Compute a linear regression count aggregate.
|
|
205
217
|
* This returns the count of rows where both x and y are non-null.
|
|
206
|
-
* @param {
|
|
207
|
-
* @param {
|
|
218
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
219
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
208
220
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
209
221
|
*/
|
|
210
222
|
export function regrCount(x, y) {
|
|
@@ -213,8 +225,8 @@ export function regrCount(x, y) {
|
|
|
213
225
|
|
|
214
226
|
/**
|
|
215
227
|
* Compute a linear regression intercept aggregate.
|
|
216
|
-
* @param {
|
|
217
|
-
* @param {
|
|
228
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
229
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
218
230
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
219
231
|
*/
|
|
220
232
|
export function regrIntercept(x, y) {
|
|
@@ -223,8 +235,8 @@ export function regrIntercept(x, y) {
|
|
|
223
235
|
|
|
224
236
|
/**
|
|
225
237
|
* Compute a linear regression R^2 aggregate.
|
|
226
|
-
* @param {
|
|
227
|
-
* @param {
|
|
238
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
239
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
228
240
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
229
241
|
*/
|
|
230
242
|
export function regrR2(x, y) {
|
|
@@ -233,8 +245,8 @@ export function regrR2(x, y) {
|
|
|
233
245
|
|
|
234
246
|
/**
|
|
235
247
|
* Compute a linear regression regr_sxx aggregate.
|
|
236
|
-
* @param {
|
|
237
|
-
* @param {
|
|
248
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
249
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
238
250
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
239
251
|
*/
|
|
240
252
|
export function regrSXX(x, y) {
|
|
@@ -243,8 +255,8 @@ export function regrSXX(x, y) {
|
|
|
243
255
|
|
|
244
256
|
/**
|
|
245
257
|
* Compute a linear regression regr_sxy aggregate.
|
|
246
|
-
* @param {
|
|
247
|
-
* @param {
|
|
258
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
259
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
248
260
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
249
261
|
*/
|
|
250
262
|
export function regrSXY(x, y) {
|
|
@@ -253,8 +265,8 @@ export function regrSXY(x, y) {
|
|
|
253
265
|
|
|
254
266
|
/**
|
|
255
267
|
* Compute a linear regression regr_syy aggregate.
|
|
256
|
-
* @param {
|
|
257
|
-
* @param {
|
|
268
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
269
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
258
270
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
259
271
|
*/
|
|
260
272
|
export function regrSYY(x, y) {
|
|
@@ -263,8 +275,8 @@ export function regrSYY(x, y) {
|
|
|
263
275
|
|
|
264
276
|
/**
|
|
265
277
|
* Compute a linear regression slope aggregate.
|
|
266
|
-
* @param {
|
|
267
|
-
* @param {
|
|
278
|
+
* @param {ExprValue} x The x expression to aggregate.
|
|
279
|
+
* @param {ExprValue} y The y expression to aggregate.
|
|
268
280
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
269
281
|
*/
|
|
270
282
|
export function regrSlope(x, y) {
|
|
@@ -273,7 +285,7 @@ export function regrSlope(x, y) {
|
|
|
273
285
|
|
|
274
286
|
/**
|
|
275
287
|
* Compute a skewness aggregate.
|
|
276
|
-
* @param {
|
|
288
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
277
289
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
278
290
|
*/
|
|
279
291
|
export function skewness(expr) {
|
|
@@ -282,7 +294,7 @@ export function skewness(expr) {
|
|
|
282
294
|
|
|
283
295
|
/**
|
|
284
296
|
* Compute a sample standard deviation aggregate.
|
|
285
|
-
* @param {
|
|
297
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
286
298
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
287
299
|
*/
|
|
288
300
|
export function stddev(expr) {
|
|
@@ -291,7 +303,7 @@ export function stddev(expr) {
|
|
|
291
303
|
|
|
292
304
|
/**
|
|
293
305
|
* Compute a population standard deviation aggregate.
|
|
294
|
-
* @param {
|
|
306
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
295
307
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
296
308
|
*/
|
|
297
309
|
export function stddevPop(expr) {
|
|
@@ -300,7 +312,7 @@ export function stddevPop(expr) {
|
|
|
300
312
|
|
|
301
313
|
/**
|
|
302
314
|
* Compute a string aggregation.
|
|
303
|
-
* @param {
|
|
315
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
304
316
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
305
317
|
*/
|
|
306
318
|
export function stringAgg(expr) {
|
|
@@ -309,7 +321,7 @@ export function stringAgg(expr) {
|
|
|
309
321
|
|
|
310
322
|
/**
|
|
311
323
|
* Compute a sum aggregate.
|
|
312
|
-
* @param {
|
|
324
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
313
325
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
314
326
|
*/
|
|
315
327
|
export function sum(expr) {
|
|
@@ -318,7 +330,7 @@ export function sum(expr) {
|
|
|
318
330
|
|
|
319
331
|
/**
|
|
320
332
|
* Compute a sample variance aggregate.
|
|
321
|
-
* @param {
|
|
333
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
322
334
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
323
335
|
*/
|
|
324
336
|
export function variance(expr) {
|
|
@@ -327,7 +339,7 @@ export function variance(expr) {
|
|
|
327
339
|
|
|
328
340
|
/**
|
|
329
341
|
* Compute a population variance aggregate.
|
|
330
|
-
* @param {
|
|
342
|
+
* @param {ExprValue} expr The expression to aggregate.
|
|
331
343
|
* @returns {AggregateNode} A SQL aggregate function call.
|
|
332
344
|
*/
|
|
333
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);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Query } from '../ast/query.js';
|
|
2
|
+
import { WithClauseNode } from '../ast/with.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a common table expression (CTE) to include within a WITH clause.
|
|
6
|
+
* @param {string} name The common table expression (CTE) name.
|
|
7
|
+
* @param {Query} query The common table expression (CTE) query.
|
|
8
|
+
* @param {boolean | null} [materialized] The common table expression (CTE)
|
|
9
|
+
* materialization flag. If `true`, forces materialization of the CTE.
|
|
10
|
+
* If `false`, materialization is not performed. Otherwise (for example, if
|
|
11
|
+
* `undefined` or `null`), materialization is decided by the database.
|
|
12
|
+
* @returns {WithClauseNode}
|
|
13
|
+
*/
|
|
14
|
+
export function cte(name, query, materialized) {
|
|
15
|
+
return new WithClauseNode(name, query, materialized);
|
|
16
|
+
}
|
|
@@ -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);
|