@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.
Files changed (73) hide show
  1. package/dist/types/ast/aggregate.d.ts +5 -4
  2. package/dist/types/ast/case.d.ts +6 -7
  3. package/dist/types/ast/column-param.d.ts +7 -7
  4. package/dist/types/ast/column-ref.d.ts +7 -6
  5. package/dist/types/ast/param.d.ts +5 -4
  6. package/dist/types/ast/query.d.ts +46 -39
  7. package/dist/types/ast/window.d.ts +15 -12
  8. package/dist/types/functions/aggregate.d.ts +89 -88
  9. package/dist/types/functions/case.d.ts +6 -8
  10. package/dist/types/functions/column.d.ts +5 -3
  11. package/dist/types/functions/datetime.d.ts +12 -11
  12. package/dist/types/functions/numeric.d.ts +48 -46
  13. package/dist/types/functions/operators.d.ts +80 -78
  14. package/dist/types/functions/order-by.d.ts +5 -4
  15. package/dist/types/functions/spatial.d.ts +14 -13
  16. package/dist/types/functions/sql-template-tag.d.ts +4 -5
  17. package/dist/types/functions/string.d.ts +22 -20
  18. package/dist/types/functions/util.d.ts +8 -0
  19. package/dist/types/functions/window.d.ts +18 -16
  20. package/dist/types/index.d.ts +3 -0
  21. package/dist/types/transforms/bin-1d.d.ts +3 -2
  22. package/dist/types/transforms/bin-2d.d.ts +6 -5
  23. package/dist/types/transforms/bin-date.d.ts +44 -0
  24. package/dist/types/transforms/bin-histogram.d.ts +51 -0
  25. package/dist/types/transforms/bin-linear-1d.d.ts +6 -4
  26. package/dist/types/transforms/bin-linear-2d.d.ts +6 -5
  27. package/dist/types/transforms/line-density.d.ts +5 -4
  28. package/dist/types/transforms/m4.d.ts +7 -4
  29. package/dist/types/transforms/util/bin-step.d.ts +61 -0
  30. package/dist/types/transforms/util/time-interval.d.ts +13 -0
  31. package/dist/types/types.d.ts +1 -0
  32. package/dist/types/util/ast.d.ts +6 -5
  33. package/dist/types/util/function.d.ts +6 -4
  34. package/dist/types/util/type-check.d.ts +6 -2
  35. package/dist/types/visit/visitors.d.ts +3 -2
  36. package/dist/types/visit/walk.d.ts +7 -4
  37. package/package.json +2 -2
  38. package/src/ast/aggregate.js +5 -2
  39. package/src/ast/case.js +6 -5
  40. package/src/ast/column-param.js +7 -5
  41. package/src/ast/column-ref.js +6 -3
  42. package/src/ast/param.js +5 -2
  43. package/src/ast/query.js +23 -19
  44. package/src/ast/window.js +10 -6
  45. package/src/functions/aggregate.js +55 -52
  46. package/src/functions/case.js +7 -7
  47. package/src/functions/column.js +6 -2
  48. package/src/functions/datetime.js +9 -6
  49. package/src/functions/numeric.js +35 -31
  50. package/src/functions/operators.js +53 -50
  51. package/src/functions/order-by.js +5 -2
  52. package/src/functions/spatial.js +10 -7
  53. package/src/functions/sql-template-tag.js +5 -5
  54. package/src/functions/string.js +16 -13
  55. package/src/functions/util.js +14 -0
  56. package/src/functions/window.js +13 -10
  57. package/src/index.js +3 -0
  58. package/src/transforms/bin-1d.js +4 -1
  59. package/src/transforms/bin-2d.js +7 -4
  60. package/src/transforms/bin-date.js +37 -0
  61. package/src/transforms/bin-histogram.js +52 -0
  62. package/src/transforms/bin-linear-1d.js +7 -3
  63. package/src/transforms/bin-linear-2d.js +12 -8
  64. package/src/transforms/line-density.js +7 -3
  65. package/src/transforms/m4.js +7 -3
  66. package/src/transforms/util/bin-step.js +79 -0
  67. package/src/transforms/util/time-interval.js +97 -0
  68. package/src/types.ts +11 -0
  69. package/src/util/ast.js +6 -3
  70. package/src/util/function.js +6 -2
  71. package/src/util/type-check.js +5 -1
  72. package/src/visit/visitors.js +6 -2
  73. package/src/visit/walk.js +8 -3
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @import { ExprValue, ExprVarArgs } from '../types.js'
3
+ */
1
4
  import { BetweenOpNode, NotBetweenOpNode } from '../ast/between-op.js';
2
5
  import { BinaryOpNode } from '../ast/binary-op.js';
3
6
  import { InOpNode } from '../ast/in-op.js';
@@ -25,7 +28,7 @@ function betweenOp(expr, extent, negate = false) {
25
28
 
26
29
  /**
27
30
  * Logical and (AND) operator.
28
- * @param {...import('../types.js').ExprVarArgs} clauses The input expressions.
31
+ * @param {...ExprVarArgs} clauses The input expressions.
29
32
  * @returns {AndNode}
30
33
  */
31
34
  export function and(...clauses) {
@@ -34,7 +37,7 @@ export function and(...clauses) {
34
37
 
35
38
  /**
36
39
  * Logical or (OR) operator.
37
- * @param {...import('../types.js').ExprVarArgs} clauses The input expressions.
40
+ * @param {...ExprVarArgs} clauses The input expressions.
38
41
  * @returns {OrNode}
39
42
  */
40
43
  export function or(...clauses) {
@@ -43,7 +46,7 @@ export function or(...clauses) {
43
46
 
44
47
  /**
45
48
  * Logical not (NOT) operator.
46
- * @param {import('../types.js').ExprValue} expr The expression to negate.
49
+ * @param {ExprValue} expr The expression to negate.
47
50
  * @returns {UnaryOpNode}
48
51
  */
49
52
  export function not(expr) {
@@ -52,7 +55,7 @@ export function not(expr) {
52
55
 
53
56
  /**
54
57
  * Null check (IS NULL) operator.
55
- * @param {import('../types.js').ExprValue} expr The expression to test.
58
+ * @param {ExprValue} expr The expression to test.
56
59
  * @returns {UnaryPosftixOpNode}
57
60
  */
58
61
  export function isNull(expr) {
@@ -61,7 +64,7 @@ export function isNull(expr) {
61
64
 
62
65
  /**
63
66
  * Non-null check (IS NOT NULL) operator.
64
- * @param {import('../types.js').ExprValue} expr The expression to test.
67
+ * @param {ExprValue} expr The expression to test.
65
68
  * @returns {UnaryPosftixOpNode}
66
69
  */
67
70
  export function isNotNull(expr) {
@@ -70,7 +73,7 @@ export function isNotNull(expr) {
70
73
 
71
74
  /**
72
75
  * Bitwise not (~) operator.
73
- * @param {import('../types.js').ExprValue} expr The input expression.
76
+ * @param {ExprValue} expr The input expression.
74
77
  * @returns {UnaryOpNode}
75
78
  */
76
79
  export function bitNot(expr) {
@@ -79,8 +82,8 @@ export function bitNot(expr) {
79
82
 
80
83
  /**
81
84
  * Bitwise and (&) operator.
82
- * @param {import('../types.js').ExprValue} left The left argument.
83
- * @param {import('../types.js').ExprValue} right The right argument.
85
+ * @param {ExprValue} left The left argument.
86
+ * @param {ExprValue} right The right argument.
84
87
  * @returns {BinaryOpNode}
85
88
  */
86
89
  export function bitAnd(left, right) {
@@ -89,8 +92,8 @@ export function bitAnd(left, right) {
89
92
 
90
93
  /**
91
94
  * Bitwise or (|) operator.
92
- * @param {import('../types.js').ExprValue} left The left argument.
93
- * @param {import('../types.js').ExprValue} right The right argument.
95
+ * @param {ExprValue} left The left argument.
96
+ * @param {ExprValue} right The right argument.
94
97
  * @returns {BinaryOpNode}
95
98
  */
96
99
  export function bitOr(left, right) {
@@ -99,8 +102,8 @@ export function bitOr(left, right) {
99
102
 
100
103
  /**
101
104
  * Bit shift left (<<) operator.
102
- * @param {import('../types.js').ExprValue} left The left argument.
103
- * @param {import('../types.js').ExprValue} right The right argument.
105
+ * @param {ExprValue} left The left argument.
106
+ * @param {ExprValue} right The right argument.
104
107
  * @returns {BinaryOpNode}
105
108
  */
106
109
  export function bitLeft(left, right) {
@@ -109,8 +112,8 @@ export function bitLeft(left, right) {
109
112
 
110
113
  /**
111
114
  * Bit shift right (>>) operator.
112
- * @param {import('../types.js').ExprValue} left The left argument.
113
- * @param {import('../types.js').ExprValue} right The right argument.
115
+ * @param {ExprValue} left The left argument.
116
+ * @param {ExprValue} right The right argument.
114
117
  * @returns {BinaryOpNode}
115
118
  */
116
119
  export function bitRight(left, right) {
@@ -119,8 +122,8 @@ export function bitRight(left, right) {
119
122
 
120
123
  /**
121
124
  * Addition (+) operator.
122
- * @param {import('../types.js').ExprValue} left The left argument.
123
- * @param {import('../types.js').ExprValue} right The right argument.
125
+ * @param {ExprValue} left The left argument.
126
+ * @param {ExprValue} right The right argument.
124
127
  * @returns {BinaryOpNode}
125
128
  */
126
129
  export function add(left, right) {
@@ -129,8 +132,8 @@ export function add(left, right) {
129
132
 
130
133
  /**
131
134
  * Subtraction (-) operator.
132
- * @param {import('../types.js').ExprValue} left The left argument.
133
- * @param {import('../types.js').ExprValue} right The right argument.
135
+ * @param {ExprValue} left The left argument.
136
+ * @param {ExprValue} right The right argument.
134
137
  * @returns {BinaryOpNode}
135
138
  */
136
139
  export function sub(left, right) {
@@ -139,8 +142,8 @@ export function sub(left, right) {
139
142
 
140
143
  /**
141
144
  * Multiplication (*) operator.
142
- * @param {import('../types.js').ExprValue} left The left argument.
143
- * @param {import('../types.js').ExprValue} right The right argument.
145
+ * @param {ExprValue} left The left argument.
146
+ * @param {ExprValue} right The right argument.
144
147
  * @returns {BinaryOpNode}
145
148
  */
146
149
  export function mul(left, right) {
@@ -149,8 +152,8 @@ export function mul(left, right) {
149
152
 
150
153
  /**
151
154
  * Division (/) operator.
152
- * @param {import('../types.js').ExprValue} left The left argument.
153
- * @param {import('../types.js').ExprValue} right The right argument.
155
+ * @param {ExprValue} left The left argument.
156
+ * @param {ExprValue} right The right argument.
154
157
  * @returns {BinaryOpNode}
155
158
  */
156
159
  export function div(left, right) {
@@ -159,8 +162,8 @@ export function div(left, right) {
159
162
 
160
163
  /**
161
164
  * Integer division (//) operator.
162
- * @param {import('../types.js').ExprValue} left The left argument.
163
- * @param {import('../types.js').ExprValue} right The right argument.
165
+ * @param {ExprValue} left The left argument.
166
+ * @param {ExprValue} right The right argument.
164
167
  * @returns {BinaryOpNode}
165
168
  */
166
169
  export function idiv(left, right) {
@@ -169,8 +172,8 @@ export function idiv(left, right) {
169
172
 
170
173
  /**
171
174
  * Modulo (%) operator.
172
- * @param {import('../types.js').ExprValue} left The left argument.
173
- * @param {import('../types.js').ExprValue} right The right argument.
175
+ * @param {ExprValue} left The left argument.
176
+ * @param {ExprValue} right The right argument.
174
177
  * @returns {BinaryOpNode}
175
178
  */
176
179
  export function mod(left, right) {
@@ -179,8 +182,8 @@ export function mod(left, right) {
179
182
 
180
183
  /**
181
184
  * Exponentiation (**) operator.
182
- * @param {import('../types.js').ExprValue} left The left argument.
183
- * @param {import('../types.js').ExprValue} right The right argument.
185
+ * @param {ExprValue} left The left argument.
186
+ * @param {ExprValue} right The right argument.
184
187
  * @returns {BinaryOpNode}
185
188
  */
186
189
  export function pow(left, right) {
@@ -189,8 +192,8 @@ export function pow(left, right) {
189
192
 
190
193
  /**
191
194
  * Equality comparision (=) operator.
192
- * @param {import('../types.js').ExprValue} left The left argument.
193
- * @param {import('../types.js').ExprValue} right The right argument.
195
+ * @param {ExprValue} left The left argument.
196
+ * @param {ExprValue} right The right argument.
194
197
  * @returns {BinaryOpNode}
195
198
  */
196
199
  export function eq(left, right) {
@@ -199,8 +202,8 @@ export function eq(left, right) {
199
202
 
200
203
  /**
201
204
  * Non-equality comparision (<>) operator.
202
- * @param {import('../types.js').ExprValue} left The left argument.
203
- * @param {import('../types.js').ExprValue} right The right argument.
205
+ * @param {ExprValue} left The left argument.
206
+ * @param {ExprValue} right The right argument.
204
207
  * @returns {BinaryOpNode}
205
208
  */
206
209
  export function neq(left, right) {
@@ -209,8 +212,8 @@ export function neq(left, right) {
209
212
 
210
213
  /**
211
214
  * Less-than comparision (<) operator.
212
- * @param {import('../types.js').ExprValue} left The left argument.
213
- * @param {import('../types.js').ExprValue} right The right argument.
215
+ * @param {ExprValue} left The left argument.
216
+ * @param {ExprValue} right The right argument.
214
217
  * @returns {BinaryOpNode}
215
218
  */
216
219
  export function lt(left, right) {
@@ -219,8 +222,8 @@ export function lt(left, right) {
219
222
 
220
223
  /**
221
224
  * Greater-than comparision (>) operator.
222
- * @param {import('../types.js').ExprValue} left The left argument.
223
- * @param {import('../types.js').ExprValue} right The right argument.
225
+ * @param {ExprValue} left The left argument.
226
+ * @param {ExprValue} right The right argument.
224
227
  * @returns {BinaryOpNode}
225
228
  */
226
229
  export function gt(left, right) {
@@ -229,8 +232,8 @@ export function gt(left, right) {
229
232
 
230
233
  /**
231
234
  * Less-than or equal comparision (<=) operator.
232
- * @param {import('../types.js').ExprValue} left The left argument.
233
- * @param {import('../types.js').ExprValue} right The right argument.
235
+ * @param {ExprValue} left The left argument.
236
+ * @param {ExprValue} right The right argument.
234
237
  * @returns {BinaryOpNode}
235
238
  */
236
239
  export function lte(left, right) {
@@ -239,8 +242,8 @@ export function lte(left, right) {
239
242
 
240
243
  /**
241
244
  * Greater-than or equal comparision (>=) operator.
242
- * @param {import('../types.js').ExprValue} left The left argument.
243
- * @param {import('../types.js').ExprValue} right The right argument.
245
+ * @param {ExprValue} left The left argument.
246
+ * @param {ExprValue} right The right argument.
244
247
  * @returns {BinaryOpNode}
245
248
  */
246
249
  export function gte(left, right) {
@@ -249,8 +252,8 @@ export function gte(left, right) {
249
252
 
250
253
  /**
251
254
  * Null-inclusive non-equality (IS DISTINCT FROM) operator.
252
- * @param {import('../types.js').ExprValue} left The left argument.
253
- * @param {import('../types.js').ExprValue} right The right argument.
255
+ * @param {ExprValue} left The left argument.
256
+ * @param {ExprValue} right The right argument.
254
257
  * @returns {BinaryOpNode}
255
258
  */
256
259
  export function isDistinct(left, right) {
@@ -259,8 +262,8 @@ export function isDistinct(left, right) {
259
262
 
260
263
  /**
261
264
  * Null-inclusive equality (IS NOT DISTINCT FROM) operator.
262
- * @param {import('../types.js').ExprValue} left The left argument.
263
- * @param {import('../types.js').ExprValue} right The right argument.
265
+ * @param {ExprValue} left The left argument.
266
+ * @param {ExprValue} right The right argument.
264
267
  * @returns {BinaryOpNode}
265
268
  */
266
269
  export function isNotDistinct(left, right) {
@@ -269,8 +272,8 @@ export function isNotDistinct(left, right) {
269
272
 
270
273
  /**
271
274
  * Range inclusion (BETWEEN) operator.
272
- * @param {import('../types.js').ExprValue} expr The expression to test.
273
- * @param {import('../types.js').ExprValue[]} extent The range extent.
275
+ * @param {ExprValue} expr The expression to test.
276
+ * @param {ExprValue[]} extent The range extent.
274
277
  * @returns {BetweenOpNode}
275
278
  */
276
279
  export function isBetween(expr, extent) {
@@ -279,8 +282,8 @@ export function isBetween(expr, extent) {
279
282
 
280
283
  /**
281
284
  * Range exclusion (NOT BETWEEN) operator.
282
- * @param {import('../types.js').ExprValue} expr The expression to test.
283
- * @param {import('../types.js').ExprValue[]} extent The range extent.
285
+ * @param {ExprValue} expr The expression to test.
286
+ * @param {ExprValue[]} extent The range extent.
284
287
  * @returns {NotBetweenOpNode}
285
288
  */
286
289
  export function isNotBetween(expr, extent) {
@@ -289,8 +292,8 @@ export function isNotBetween(expr, extent) {
289
292
 
290
293
  /**
291
294
  * Set inclusion (IN) operator.
292
- * @param {import('../types.js').ExprValue} expr The expression to test.
293
- * @param {import('../types.js').ExprValue[]} values The included values.
295
+ * @param {ExprValue} expr The expression to test.
296
+ * @param {ExprValue[]} values The included values.
294
297
  * @returns {InOpNode}
295
298
  */
296
299
  export function isIn(expr, values) {
@@ -1,9 +1,12 @@
1
+ /**
2
+ * @import { ExprValue } from '../types.js'
3
+ */
1
4
  import { OrderByNode } from '../ast/order-by.js';
2
5
  import { asNode } from '../util/ast.js';
3
6
 
4
7
  /**
5
8
  * Indicate ascending sort order for an expression.
6
- * @param {import('../types.js').ExprValue} expr An expression to order by.
9
+ * @param {ExprValue} expr An expression to order by.
7
10
  * @param {boolean | undefined} [nullsFirst] Flag indicating if null values
8
11
  * should be sorted first.
9
12
  * @returns {OrderByNode}
@@ -14,7 +17,7 @@ export function asc(expr, nullsFirst) {
14
17
 
15
18
  /**
16
19
  * Indicate descending sort order for an expression.
17
- * @param {import('../types.js').ExprValue} expr An expression to order by.
20
+ * @param {ExprValue} expr An expression to order by.
18
21
  * @param {boolean | undefined} [nullsFirst] Flag indicating if null values
19
22
  * should be sorted first.
20
23
  * @returns {OrderByNode}
@@ -1,9 +1,12 @@
1
- import { FunctionNode } from '../ast/function.js';
1
+ /**
2
+ * @import { FunctionNode } from '../ast/function.js'
3
+ * @import { ExprValue } from '../types.js'
4
+ */
2
5
  import { fn } from '../util/function.js';
3
6
 
4
7
  /**
5
8
  * Function that converts geometry data to GeoJSON format.
6
- * @param {import('../types.js').ExprValue} expr The input expression.
9
+ * @param {ExprValue} expr The input expression.
7
10
  * @returns {FunctionNode}
8
11
  */
9
12
  export function geojson(expr) {
@@ -12,7 +15,7 @@ export function geojson(expr) {
12
15
 
13
16
  /**
14
17
  * Function that returns a spatial x position (using ST_X).
15
- * @param {import('../types.js').ExprValue} expr The input expression.
18
+ * @param {ExprValue} expr The input expression.
16
19
  * @returns {FunctionNode}
17
20
  */
18
21
  export function x(expr) {
@@ -21,7 +24,7 @@ export function x(expr) {
21
24
 
22
25
  /**
23
26
  * Function that returns a spatial y position (using ST_Y).
24
- * @param {import('../types.js').ExprValue} expr The input expression.
27
+ * @param {ExprValue} expr The input expression.
25
28
  * @returns {FunctionNode}
26
29
  */
27
30
  export function y(expr) {
@@ -30,7 +33,7 @@ export function y(expr) {
30
33
 
31
34
  /**
32
35
  * Function that returns the centroid point for geometry data.
33
- * @param {import('../types.js').ExprValue} expr The input expression.
36
+ * @param {ExprValue} expr The input expression.
34
37
  * @returns {FunctionNode}
35
38
  */
36
39
  export function centroid(expr) {
@@ -39,7 +42,7 @@ export function centroid(expr) {
39
42
 
40
43
  /**
41
44
  * Function that returns the centroid x-coordinate for geometry data.
42
- * @param {import('../types.js').ExprValue} expr The input expression.
45
+ * @param {ExprValue} expr The input expression.
43
46
  * @returns {FunctionNode}
44
47
  */
45
48
  export function centroidX(expr) {
@@ -48,7 +51,7 @@ export function centroidX(expr) {
48
51
 
49
52
  /**
50
53
  * Function that returns yhe centroid y-coordinate for geometry data.
51
- * @param {import('../types.js').ExprValue} expr The input expression.
54
+ * @param {ExprValue} expr The input expression.
52
55
  * @returns {FunctionNode}
53
56
  */
54
57
  export function centroidY(expr) {
@@ -1,4 +1,7 @@
1
- /* eslint-disable jsdoc/no-undefined-types */
1
+ /**
2
+ * @import { ExprNode } from '../ast/node.js'
3
+ * @import { ParamLike } from '../types.js'
4
+ */
2
5
  import { FragmentNode } from '../ast/fragment.js';
3
6
  import { isNode } from '../ast/node.js';
4
7
  import { ParamNode } from '../ast/param.js';
@@ -7,10 +10,7 @@ import { isParamLike, isString } from '../util/type-check.js';
7
10
  import { literal } from './literal.js';
8
11
 
9
12
  /**
10
- * @typedef {import('../ast/node.js').ExprNode
11
- * | import('../types.js').ParamLike
12
- * | string | number | boolean | Date
13
- * } TemplateValue
13
+ * @typedef { ExprNode | ParamLike | string | number | boolean | Date } TemplateValue
14
14
  */
15
15
 
16
16
  /**
@@ -1,4 +1,7 @@
1
- import { FunctionNode } from '../ast/function.js';
1
+ /**
2
+ * @import { FunctionNode } from '../ast/function.js'
3
+ * @import { ExprValue, StringValue } from '../types.js'
4
+ */
2
5
  import { asLiteral } from '../util/ast.js';
3
6
  import { argsList, fn } from '../util/function.js';
4
7
 
@@ -9,9 +12,9 @@ function strFn(name, expr, ...args) {
9
12
  /**
10
13
  * Function that returns true if a string contains a regexp pattern,
11
14
  * false otherwise.
12
- * @param {import('../types.js').ExprValue} string The string match against.
13
- * @param {import('../types.js').StringValue} pattern The regular expression pattern to match.
14
- * @param {import('../types.js').StringValue} [options] Regular expression options:
15
+ * @param {ExprValue} string The string match against.
16
+ * @param {StringValue} pattern The regular expression pattern to match.
17
+ * @param {StringValue} [options] Regular expression options:
15
18
  * 'c': case-sensitive matching
16
19
  * 'i': case-insensitive matching
17
20
  * 'l': match literals instead of regular expression tokens
@@ -26,8 +29,8 @@ export function regexp_matches(string, pattern, options) {
26
29
 
27
30
  /**
28
31
  * Function that returns true if search_string is found within string.
29
- * @param {import('../types.js').ExprValue} string The string to match against.
30
- * @param {import('../types.js').StringValue} search_string The substring to search for.
32
+ * @param {ExprValue} string The string to match against.
33
+ * @param {StringValue} search_string The substring to search for.
31
34
  * @returns {FunctionNode}
32
35
  */
33
36
  export function contains(string, search_string) {
@@ -36,8 +39,8 @@ export function contains(string, search_string) {
36
39
 
37
40
  /**
38
41
  * Function that returns true if string begins with search_string.
39
- * @param {import('../types.js').ExprValue} string The string to match against.
40
- * @param {import('../types.js').StringValue} search_string The substring to search for.
42
+ * @param {ExprValue} string The string to match against.
43
+ * @param {StringValue} search_string The substring to search for.
41
44
  * @returns {FunctionNode}
42
45
  */
43
46
  export function prefix(string, search_string) {
@@ -46,8 +49,8 @@ export function prefix(string, search_string) {
46
49
 
47
50
  /**
48
51
  * Function that returns true if string ends with search_string.
49
- * @param {import('../types.js').ExprValue} string The string to match against.
50
- * @param {import('../types.js').StringValue} search_string The substring to search for.
52
+ * @param {ExprValue} string The string to match against.
53
+ * @param {StringValue} search_string The substring to search for.
51
54
  * @returns {FunctionNode}
52
55
  */
53
56
  export function suffix(string, search_string) {
@@ -56,7 +59,7 @@ export function suffix(string, search_string) {
56
59
 
57
60
  /**
58
61
  * Function that converts string to lower case.
59
- * @param {import('../types.js').ExprValue} string The string to convert.
62
+ * @param {ExprValue} string The string to convert.
60
63
  * @returns {FunctionNode}
61
64
  */
62
65
  export function lower(string) {
@@ -65,7 +68,7 @@ export function lower(string) {
65
68
 
66
69
  /**
67
70
  * Function that converts string to upper case.
68
- * @param {import('../types.js').ExprValue} string The string to convert.
71
+ * @param {ExprValue} string The string to convert.
69
72
  * @returns {FunctionNode}
70
73
  */
71
74
  export function upper(string) {
@@ -74,7 +77,7 @@ export function upper(string) {
74
77
 
75
78
  /**
76
79
  * Function that returns the number of characters in string.
77
- * @param {import('../types.js').ExprValue} value The string to measure.
80
+ * @param {ExprValue} value The string to measure.
78
81
  * @returns {FunctionNode}
79
82
  */
80
83
  export function length(value) {
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @import { FunctionNode } from '../ast/function.js'
3
+ * @import { ExprValue } from '../types.js'
4
+ */
5
+ import { fn } from '../util/function.js';
6
+
7
+ /**
8
+ * Returns the first non-null argument.
9
+ * @param {...ExprValue} expr The input expressions.
10
+ * @returns {FunctionNode}
11
+ */
12
+ export function coalesce(...expr) {
13
+ return fn('coalesce', ...expr);
14
+ }
@@ -1,4 +1,7 @@
1
- import { WindowNode } from '../ast/window.js';
1
+ /**
2
+ * @import { WindowNode } from '../ast/window.js'
3
+ * @import { ExprValue, NumberValue } from '../types.js'
4
+ */
2
5
  import { winFn } from '../util/function.js';
3
6
 
4
7
  /**
@@ -49,7 +52,7 @@ export function cume_dist() {
49
52
  /**
50
53
  * Create a window function that returns an integer ranging from 1 to the
51
54
  * argument value, dividing the partition as equally as possible.
52
- * @param {import('../types.js').NumberValue} num_buckets The number of
55
+ * @param {NumberValue} num_buckets The number of
53
56
  * quantile buckets.
54
57
  * @returns {WindowNode}
55
58
  */
@@ -63,8 +66,8 @@ export function ntile(num_buckets) {
63
66
  * If there is no such row, instead return default (which must be of the same
64
67
  * type as the expression). Both offset and default are evaluated with respect
65
68
  * to the current row. If omitted, offset defaults to 1 and default to null.
66
- * @param {import('../types.js').ExprValue} expr The expression to evaluate.
67
- * @param {import('../types.js').NumberValue} [offset] The row offset
69
+ * @param {ExprValue} expr The expression to evaluate.
70
+ * @param {NumberValue} [offset] The row offset
68
71
  * (default `1`).
69
72
  * @param {*} [defaultValue] The default value (default `null`).
70
73
  * @returns {WindowNode}
@@ -79,8 +82,8 @@ export function lag(expr, offset, defaultValue){
79
82
  * If there is no such row, instead return default (which must be of the same
80
83
  * type as the expression). Both offset and default are evaluated with respect
81
84
  * to the current row. If omitted, offset defaults to 1 and default to null.
82
- * @param {import('../types.js').ExprValue} expr The expression to evaluate.
83
- * @param {import('../types.js').NumberValue} [offset] The row offset
85
+ * @param {ExprValue} expr The expression to evaluate.
86
+ * @param {NumberValue} [offset] The row offset
84
87
  * (default `1`).
85
88
  * @param {*} [defaultValue] The default value (default `null`).
86
89
  * @returns {WindowNode}
@@ -92,7 +95,7 @@ export function lead(expr, offset, defaultValue){
92
95
  /**
93
96
  * Create a window function that returns the expression evaluated at the row
94
97
  * that is the first row of the window frame.
95
- * @param {import('../types.js').ExprValue} expr The expression to evaluate.
98
+ * @param {ExprValue} expr The expression to evaluate.
96
99
  * @returns {WindowNode}
97
100
  */
98
101
  export function first_value(expr) {
@@ -102,7 +105,7 @@ export function first_value(expr) {
102
105
  /**
103
106
  * Create a window function that returns the expression evaluated at the row
104
107
  * that is the last row of the window frame.
105
- * @param {import('../types.js').ExprValue} expr The expression to evaluate.
108
+ * @param {ExprValue} expr The expression to evaluate.
106
109
  * @returns {WindowNode}
107
110
  */
108
111
  export function last_value(expr) {
@@ -112,8 +115,8 @@ export function last_value(expr) {
112
115
  /**
113
116
  * Create a window function that returns the expression evaluated at the
114
117
  * nth row of the window frame (counting from 1), or null if no such row.
115
- * @param {import('../types.js').ExprValue} expr The expression to evaluate.
116
- * @param {import('../types.js').NumberValue} nth The 1-based window frame index.
118
+ * @param {ExprValue} expr The expression to evaluate.
119
+ * @param {NumberValue} nth The 1-based window frame index.
117
120
  * @returns {WindowNode}
118
121
  */
119
122
  export function nth_value(expr, nth) {
package/src/index.js CHANGED
@@ -37,6 +37,7 @@ export { asc, desc } from './functions/order-by.js';
37
37
  export { geojson, x, y, centroid, centroidX, centroidY } from './functions/spatial.js';
38
38
  export { sql } from './functions/sql-template-tag.js';
39
39
  export { regexp_matches, contains, prefix, suffix, lower, upper, length } from './functions/string.js';
40
+ export { coalesce } from './functions/util.js';
40
41
  export { cume_dist, dense_rank, first_value, lag, last_value, lead, nth_value, ntile, percent_rank, rank, row_number } from './functions/window.js';
41
42
 
42
43
  export { rewrite } from './visit/rewrite.js';
@@ -49,6 +50,8 @@ export { loadCSV, loadJSON, loadObjects, loadParquet, loadSpatial } from './load
49
50
 
50
51
  export { bin1d } from './transforms/bin-1d.js';
51
52
  export { bin2d } from './transforms/bin-2d.js';
53
+ export { binDate } from './transforms/bin-date.js';
54
+ export { binHistogram } from './transforms/bin-histogram.js';
52
55
  export { binLinear1d } from './transforms/bin-linear-1d.js';
53
56
  export { binLinear2d } from './transforms/bin-linear-2d.js';
54
57
  export { lineDensity } from './transforms/line-density.js';
@@ -1,9 +1,12 @@
1
+ /**
2
+ * @import { ExprValue } from '../types.js'
3
+ */
1
4
  import { float64 } from '../functions/cast.js';
2
5
  import { mul, sub } from '../functions/operators.js';
3
6
 
4
7
  /**
5
8
  * Compute binned values over a one-dimensional extent.
6
- * @param {import('../types.js').ExprValue} x The expression to bin.
9
+ * @param {ExprValue} x The expression to bin.
7
10
  * The expression must return numeric values. For example, to bin
8
11
  * datetime values, the input expression might map them to numeric
9
12
  * values such as milliseconds since the epoch.
@@ -1,4 +1,7 @@
1
- import { SelectQuery } from '../ast/query.js';
1
+ /**
2
+ * @import { SelectQuery } from '../ast/query.js'
3
+ * @import { ExprValue } from '../types.js'
4
+ */
2
5
  import { int32 } from '../functions/cast.js';
3
6
  import { floor } from '../functions/numeric.js';
4
7
  import { add, mul } from '../functions/operators.js';
@@ -11,9 +14,9 @@ import { add, mul } from '../functions/operators.js';
11
14
  * and uses a 2D integer bin index of the form (xbin + num_xbins * ybin).
12
15
  * @param {SelectQuery} q The input query. The FROM and WHERE clauses should
13
16
  * be added to the query separately, either before or after this method.
14
- * @param {import('../types.js').ExprValue} xp The x bin expression.
15
- * @param {import('../types.js').ExprValue} yp The y bin expression.
16
- * @param {Record<string, import('../types.js').ExprValue>} aggs Named
17
+ * @param {ExprValue} xp The x bin expression.
18
+ * @param {ExprValue} yp The y bin expression.
19
+ * @param {Record<string, ExprValue>} aggs Named
17
20
  * aggregate expressions over bins.
18
21
  * @param {number} xn The number of bins along the x dimension
19
22
  * @param {string[]} groupby Group by expressions.
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @import { ExprNode } from '../ast/node.js'
3
+ * @import { ExprValue, TimeUnit } from '../types.js'
4
+ */
5
+ import { dateBin, interval } from '../functions/datetime.js';
6
+ import { add } from '../functions/operators.js';
7
+ import { timeInterval } from './util/time-interval.js';
8
+
9
+ /**
10
+ * @typedef {object} BinDateOptions
11
+ * @property {TimeUnit} [interval] A string indicating a time interval
12
+ * unit, such as 'year', 'day', or 'hour'.
13
+ * @property {number} [step] The number of time interval steps to
14
+ * take, such as 2 years or 3 months.
15
+ * @property {number} [offset] The number of bin steps (default 0) by
16
+ * which to offset the result.
17
+ * @property {number} [steps] The desired number of binning steps.
18
+ * This value is a hint, it does not guarantee an exact number of steps.
19
+ */
20
+
21
+ /**
22
+ * Return a SQL expression for date/time bins.
23
+ * @param {ExprValue} field The column or expression to bin.
24
+ * @param {[Date|number, Date|number]} extent The min/max extent over which to bin.
25
+ * @param {BinDateOptions} [options] Datetime binning options.
26
+ * @returns {ExprNode}
27
+ */
28
+ export function binDate(field, extent, options = {}) {
29
+ const { offset = 0 } = options;
30
+
31
+ // use interval if provided, otherwise determine from extent
32
+ const { unit, step = 1 } = options.interval
33
+ ? { unit: options.interval, step: options.step }
34
+ : timeInterval(extent[0], extent[1], options.steps || 40);
35
+ const bin = dateBin(field, unit, step);
36
+ return offset ? add(bin, interval(unit, offset * step)) : bin;
37
+ }