@uwdata/mosaic-sql 0.11.0 → 0.12.1

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 (143) hide show
  1. package/README.md +2 -0
  2. package/dist/mosaic-sql.js +2242 -1064
  3. package/dist/mosaic-sql.min.js +1 -1
  4. package/dist/types/ast/aggregate.d.ts +70 -0
  5. package/dist/types/ast/between-op.d.ts +46 -0
  6. package/dist/types/ast/binary-op.d.ts +28 -0
  7. package/dist/types/ast/case.d.ts +68 -0
  8. package/dist/types/ast/cast.d.ts +21 -0
  9. package/dist/types/ast/column-param.d.ts +17 -0
  10. package/dist/types/ast/column-ref.d.ts +39 -0
  11. package/dist/types/ast/fragment.d.ts +14 -0
  12. package/dist/types/ast/from.d.ts +21 -0
  13. package/dist/types/ast/function.d.ts +21 -0
  14. package/dist/types/ast/in-op.d.ts +21 -0
  15. package/dist/types/ast/interval.d.ts +21 -0
  16. package/dist/types/ast/literal.d.ts +15 -0
  17. package/dist/types/ast/logical-op.d.ts +46 -0
  18. package/dist/types/ast/node.d.ts +24 -0
  19. package/dist/types/ast/order-by.d.ts +29 -0
  20. package/dist/types/ast/param.d.ts +19 -0
  21. package/dist/types/ast/query.d.ts +268 -0
  22. package/dist/types/ast/sample.d.ts +42 -0
  23. package/dist/types/ast/select.d.ts +22 -0
  24. package/dist/types/ast/table-ref.d.ts +25 -0
  25. package/dist/types/ast/unary-op.d.ts +39 -0
  26. package/dist/types/ast/verbatim.d.ts +9 -0
  27. package/dist/types/ast/window.d.ts +177 -0
  28. package/dist/types/ast/with.d.ts +22 -0
  29. package/dist/types/constants.d.ts +38 -0
  30. package/dist/types/functions/aggregate.d.ts +229 -0
  31. package/dist/types/functions/case.d.ts +15 -0
  32. package/dist/types/functions/cast.d.ts +26 -0
  33. package/dist/types/functions/column.d.ts +9 -0
  34. package/dist/types/functions/datetime.d.ts +44 -0
  35. package/dist/types/functions/literal.d.ts +16 -0
  36. package/dist/types/functions/numeric.d.ts +93 -0
  37. package/dist/types/functions/operators.d.ts +198 -0
  38. package/dist/types/functions/order-by.d.ts +17 -0
  39. package/dist/types/functions/spatial.d.ts +37 -0
  40. package/dist/types/functions/sql-template-tag.d.ts +16 -0
  41. package/dist/types/functions/string.d.ts +55 -0
  42. package/dist/types/functions/table-ref.d.ts +9 -0
  43. package/dist/types/functions/window.d.ts +87 -0
  44. package/dist/types/index-types.d.ts +2 -0
  45. package/dist/types/index.d.ts +53 -0
  46. package/dist/types/load/create.d.ts +8 -0
  47. package/dist/types/load/extension.d.ts +1 -0
  48. package/dist/types/load/load.d.ts +12 -0
  49. package/dist/types/load/sql-from.d.ts +11 -0
  50. package/dist/types/transforms/bin-1d.d.ts +14 -0
  51. package/dist/types/transforms/bin-2d.d.ts +18 -0
  52. package/dist/types/transforms/bin-linear-1d.d.ts +9 -0
  53. package/dist/types/transforms/bin-linear-2d.d.ts +18 -0
  54. package/dist/types/transforms/line-density.d.ts +23 -0
  55. package/dist/types/transforms/m4.d.ts +18 -0
  56. package/dist/types/transforms/scales.d.ts +1 -0
  57. package/dist/types/types.d.ts +59 -0
  58. package/dist/types/util/ast.d.ts +60 -0
  59. package/dist/types/util/function.d.ts +54 -0
  60. package/dist/types/util/string.d.ts +3 -0
  61. package/dist/types/util/type-check.d.ts +18 -0
  62. package/dist/types/visit/recurse.d.ts +28 -0
  63. package/dist/types/visit/rewrite.d.ts +10 -0
  64. package/dist/types/visit/visitors.d.ts +33 -0
  65. package/dist/types/visit/walk.d.ts +7 -0
  66. package/jsconfig.json +11 -0
  67. package/package.json +6 -4
  68. package/src/ast/aggregate.js +164 -0
  69. package/src/ast/between-op.js +75 -0
  70. package/src/ast/binary-op.js +40 -0
  71. package/src/ast/case.js +105 -0
  72. package/src/ast/cast.js +34 -0
  73. package/src/ast/column-param.js +29 -0
  74. package/src/ast/column-ref.js +72 -0
  75. package/src/ast/fragment.js +26 -0
  76. package/src/ast/from.js +40 -0
  77. package/src/ast/function.js +34 -0
  78. package/src/ast/in-op.js +33 -0
  79. package/src/ast/interval.js +33 -0
  80. package/src/ast/literal.js +55 -0
  81. package/src/ast/logical-op.js +67 -0
  82. package/src/ast/node.js +29 -0
  83. package/src/ast/order-by.js +48 -0
  84. package/src/ast/param.js +35 -0
  85. package/src/ast/query.js +578 -0
  86. package/src/ast/sample.js +53 -0
  87. package/src/ast/select.js +44 -0
  88. package/src/ast/table-ref.js +44 -0
  89. package/src/ast/unary-op.js +64 -0
  90. package/src/ast/verbatim.js +26 -0
  91. package/src/ast/window.js +290 -0
  92. package/src/ast/with.js +30 -0
  93. package/src/constants.js +44 -0
  94. package/src/functions/aggregate.js +335 -0
  95. package/src/functions/case.js +21 -0
  96. package/src/functions/cast.js +39 -0
  97. package/src/functions/column.js +20 -0
  98. package/src/functions/datetime.js +65 -0
  99. package/src/functions/literal.js +22 -0
  100. package/src/functions/numeric.js +139 -0
  101. package/src/functions/operators.js +298 -0
  102. package/src/functions/order-by.js +24 -0
  103. package/src/functions/spatial.js +56 -0
  104. package/src/functions/sql-template-tag.js +51 -0
  105. package/src/functions/string.js +82 -0
  106. package/src/functions/table-ref.js +14 -0
  107. package/src/functions/window.js +121 -0
  108. package/src/index-types.ts +2 -0
  109. package/src/index.js +57 -155
  110. package/src/load/create.js +10 -2
  111. package/src/load/load.js +4 -4
  112. package/src/load/sql-from.js +7 -6
  113. package/src/transforms/bin-1d.js +21 -0
  114. package/src/transforms/bin-2d.js +29 -0
  115. package/src/transforms/bin-linear-1d.js +26 -0
  116. package/src/transforms/bin-linear-2d.js +71 -0
  117. package/src/transforms/line-density.js +113 -0
  118. package/src/transforms/m4.js +38 -0
  119. package/src/{scales.js → transforms/scales.js} +31 -17
  120. package/src/types.ts +96 -0
  121. package/src/util/ast.js +96 -0
  122. package/src/util/function.js +78 -0
  123. package/src/util/string.js +16 -0
  124. package/src/util/type-check.js +29 -0
  125. package/src/visit/recurse.js +57 -0
  126. package/src/visit/rewrite.js +32 -0
  127. package/src/visit/visitors.js +108 -0
  128. package/src/visit/walk.js +30 -0
  129. package/tsconfig.json +12 -0
  130. package/src/Query.js +0 -593
  131. package/src/aggregates.js +0 -185
  132. package/src/cast.js +0 -19
  133. package/src/datetime.js +0 -31
  134. package/src/desc.js +0 -13
  135. package/src/expression.js +0 -170
  136. package/src/functions.js +0 -25
  137. package/src/literal.js +0 -6
  138. package/src/operators.js +0 -54
  139. package/src/ref.js +0 -109
  140. package/src/repeat.js +0 -3
  141. package/src/spatial.js +0 -10
  142. package/src/to-sql.js +0 -52
  143. package/src/windows.js +0 -239
@@ -0,0 +1,298 @@
1
+ import { BetweenOpNode, NotBetweenOpNode } from '../ast/between-op.js';
2
+ import { BinaryOpNode } from '../ast/binary-op.js';
3
+ import { InOpNode } from '../ast/in-op.js';
4
+ import { AndNode, OrNode } from '../ast/logical-op.js';
5
+ import { UnaryOpNode, UnaryPosftixOpNode } from '../ast/unary-op.js';
6
+ import { asNode } from '../util/ast.js';
7
+ import { exprList } from '../util/function.js';
8
+
9
+ function unaryOp(op, expr) {
10
+ return new UnaryOpNode(op, asNode(expr));
11
+ }
12
+
13
+ function unaryPostfixOp(op, expr) {
14
+ return new UnaryPosftixOpNode(op, asNode(expr));
15
+ }
16
+
17
+ function binaryOp(op, left, right) {
18
+ return new BinaryOpNode(op, asNode(left), asNode(right));
19
+ }
20
+
21
+ function betweenOp(expr, extent, negate = false) {
22
+ const Op = negate ? NotBetweenOpNode : BetweenOpNode;
23
+ return new Op(asNode(expr), extent?.map(asNode));
24
+ }
25
+
26
+ /**
27
+ * Logical and (AND) operator.
28
+ * @param {...import('../types.js').ExprVarArgs} clauses The input expressions.
29
+ * @returns {AndNode}
30
+ */
31
+ export function and(...clauses) {
32
+ return new AndNode(exprList(clauses));
33
+ }
34
+
35
+ /**
36
+ * Logical or (OR) operator.
37
+ * @param {...import('../types.js').ExprVarArgs} clauses The input expressions.
38
+ * @returns {OrNode}
39
+ */
40
+ export function or(...clauses) {
41
+ return new OrNode(exprList(clauses));
42
+ }
43
+
44
+ /**
45
+ * Logical not (NOT) operator.
46
+ * @param {import('../types.js').ExprValue} expr The expression to negate.
47
+ * @returns {UnaryOpNode}
48
+ */
49
+ export function not(expr) {
50
+ return unaryOp('NOT', expr);
51
+ }
52
+
53
+ /**
54
+ * Null check (IS NULL) operator.
55
+ * @param {import('../types.js').ExprValue} expr The expression to test.
56
+ * @returns {UnaryPosftixOpNode}
57
+ */
58
+ export function isNull(expr) {
59
+ return unaryPostfixOp('IS NULL', expr);
60
+ }
61
+
62
+ /**
63
+ * Non-null check (IS NOT NULL) operator.
64
+ * @param {import('../types.js').ExprValue} expr The expression to test.
65
+ * @returns {UnaryPosftixOpNode}
66
+ */
67
+ export function isNotNull(expr) {
68
+ return unaryPostfixOp('IS NOT NULL', expr);
69
+ }
70
+
71
+ /**
72
+ * Bitwise not (~) operator.
73
+ * @param {import('../types.js').ExprValue} expr The input expression.
74
+ * @returns {UnaryOpNode}
75
+ */
76
+ export function bitNot(expr) {
77
+ return unaryOp('~', expr);
78
+ }
79
+
80
+ /**
81
+ * Bitwise and (&) operator.
82
+ * @param {import('../types.js').ExprValue} left The left argument.
83
+ * @param {import('../types.js').ExprValue} right The right argument.
84
+ * @returns {BinaryOpNode}
85
+ */
86
+ export function bitAnd(left, right) {
87
+ return binaryOp('&', left, right);
88
+ }
89
+
90
+ /**
91
+ * Bitwise or (|) operator.
92
+ * @param {import('../types.js').ExprValue} left The left argument.
93
+ * @param {import('../types.js').ExprValue} right The right argument.
94
+ * @returns {BinaryOpNode}
95
+ */
96
+ export function bitOr(left, right) {
97
+ return binaryOp('|', left, right);
98
+ }
99
+
100
+ /**
101
+ * Bit shift left (<<) operator.
102
+ * @param {import('../types.js').ExprValue} left The left argument.
103
+ * @param {import('../types.js').ExprValue} right The right argument.
104
+ * @returns {BinaryOpNode}
105
+ */
106
+ export function bitLeft(left, right) {
107
+ return binaryOp('<<', left, right);
108
+ }
109
+
110
+ /**
111
+ * Bit shift right (>>) operator.
112
+ * @param {import('../types.js').ExprValue} left The left argument.
113
+ * @param {import('../types.js').ExprValue} right The right argument.
114
+ * @returns {BinaryOpNode}
115
+ */
116
+ export function bitRight(left, right) {
117
+ return binaryOp('>>', left, right);
118
+ }
119
+
120
+ /**
121
+ * Addition (+) operator.
122
+ * @param {import('../types.js').ExprValue} left The left argument.
123
+ * @param {import('../types.js').ExprValue} right The right argument.
124
+ * @returns {BinaryOpNode}
125
+ */
126
+ export function add(left, right) {
127
+ return binaryOp('+', left, right);
128
+ }
129
+
130
+ /**
131
+ * Subtraction (-) operator.
132
+ * @param {import('../types.js').ExprValue} left The left argument.
133
+ * @param {import('../types.js').ExprValue} right The right argument.
134
+ * @returns {BinaryOpNode}
135
+ */
136
+ export function sub(left, right) {
137
+ return binaryOp('-', left, right);
138
+ }
139
+
140
+ /**
141
+ * Multiplication (*) operator.
142
+ * @param {import('../types.js').ExprValue} left The left argument.
143
+ * @param {import('../types.js').ExprValue} right The right argument.
144
+ * @returns {BinaryOpNode}
145
+ */
146
+ export function mul(left, right) {
147
+ return binaryOp('*', left, right);
148
+ }
149
+
150
+ /**
151
+ * Division (/) operator.
152
+ * @param {import('../types.js').ExprValue} left The left argument.
153
+ * @param {import('../types.js').ExprValue} right The right argument.
154
+ * @returns {BinaryOpNode}
155
+ */
156
+ export function div(left, right) {
157
+ return binaryOp('/', left, right);
158
+ }
159
+
160
+ /**
161
+ * Integer division (//) operator.
162
+ * @param {import('../types.js').ExprValue} left The left argument.
163
+ * @param {import('../types.js').ExprValue} right The right argument.
164
+ * @returns {BinaryOpNode}
165
+ */
166
+ export function idiv(left, right) {
167
+ return binaryOp('//', left, right);
168
+ }
169
+
170
+ /**
171
+ * Modulo (%) operator.
172
+ * @param {import('../types.js').ExprValue} left The left argument.
173
+ * @param {import('../types.js').ExprValue} right The right argument.
174
+ * @returns {BinaryOpNode}
175
+ */
176
+ export function mod(left, right) {
177
+ return binaryOp('%', left, right);
178
+ }
179
+
180
+ /**
181
+ * Exponentiation (**) operator.
182
+ * @param {import('../types.js').ExprValue} left The left argument.
183
+ * @param {import('../types.js').ExprValue} right The right argument.
184
+ * @returns {BinaryOpNode}
185
+ */
186
+ export function pow(left, right) {
187
+ return binaryOp('**', left, right);
188
+ }
189
+
190
+ /**
191
+ * Equality comparision (=) operator.
192
+ * @param {import('../types.js').ExprValue} left The left argument.
193
+ * @param {import('../types.js').ExprValue} right The right argument.
194
+ * @returns {BinaryOpNode}
195
+ */
196
+ export function eq(left, right) {
197
+ return binaryOp('=', left, right);
198
+ }
199
+
200
+ /**
201
+ * Non-equality comparision (<>) operator.
202
+ * @param {import('../types.js').ExprValue} left The left argument.
203
+ * @param {import('../types.js').ExprValue} right The right argument.
204
+ * @returns {BinaryOpNode}
205
+ */
206
+ export function neq(left, right) {
207
+ return binaryOp('<>', left, right);
208
+ }
209
+
210
+ /**
211
+ * Less-than comparision (<) operator.
212
+ * @param {import('../types.js').ExprValue} left The left argument.
213
+ * @param {import('../types.js').ExprValue} right The right argument.
214
+ * @returns {BinaryOpNode}
215
+ */
216
+ export function lt(left, right) {
217
+ return binaryOp('<', left, right);
218
+ }
219
+
220
+ /**
221
+ * Greater-than comparision (>) operator.
222
+ * @param {import('../types.js').ExprValue} left The left argument.
223
+ * @param {import('../types.js').ExprValue} right The right argument.
224
+ * @returns {BinaryOpNode}
225
+ */
226
+ export function gt(left, right) {
227
+ return binaryOp('>', left, right);
228
+ }
229
+
230
+ /**
231
+ * 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.
234
+ * @returns {BinaryOpNode}
235
+ */
236
+ export function lte(left, right) {
237
+ return binaryOp('<=', left, right);
238
+ }
239
+
240
+ /**
241
+ * 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.
244
+ * @returns {BinaryOpNode}
245
+ */
246
+ export function gte(left, right) {
247
+ return binaryOp('>=', left, right);
248
+ }
249
+
250
+ /**
251
+ * 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.
254
+ * @returns {BinaryOpNode}
255
+ */
256
+ export function isDistinct(left, right) {
257
+ return binaryOp('IS DISTINCT FROM', left, right);
258
+ }
259
+
260
+ /**
261
+ * 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.
264
+ * @returns {BinaryOpNode}
265
+ */
266
+ export function isNotDistinct(left, right) {
267
+ return binaryOp('IS NOT DISTINCT FROM', left, right);
268
+ }
269
+
270
+ /**
271
+ * 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.
274
+ * @returns {BetweenOpNode}
275
+ */
276
+ export function isBetween(expr, extent) {
277
+ return betweenOp(expr, extent, false);
278
+ }
279
+
280
+ /**
281
+ * 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.
284
+ * @returns {NotBetweenOpNode}
285
+ */
286
+ export function isNotBetween(expr, extent) {
287
+ return betweenOp(expr, extent, true);
288
+ }
289
+
290
+ /**
291
+ * 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.
294
+ * @returns {InOpNode}
295
+ */
296
+ export function isIn(expr, values) {
297
+ return new InOpNode(asNode(expr), values.map(asNode));
298
+ }
@@ -0,0 +1,24 @@
1
+ import { OrderByNode } from '../ast/order-by.js';
2
+ import { asNode } from '../util/ast.js';
3
+
4
+ /**
5
+ * Indicate ascending sort order for an expression.
6
+ * @param {import('../types.js').ExprValue} expr An expression to order by.
7
+ * @param {boolean | undefined} [nullsFirst] Flag indicating if null values
8
+ * should be sorted first.
9
+ * @returns {OrderByNode}
10
+ */
11
+ export function asc(expr, nullsFirst) {
12
+ return new OrderByNode(asNode(expr), false, nullsFirst);
13
+ }
14
+
15
+ /**
16
+ * Indicate descending sort order for an expression.
17
+ * @param {import('../types.js').ExprValue} expr An expression to order by.
18
+ * @param {boolean | undefined} [nullsFirst] Flag indicating if null values
19
+ * should be sorted first.
20
+ * @returns {OrderByNode}
21
+ */
22
+ export function desc(expr, nullsFirst) {
23
+ return new OrderByNode(asNode(expr), true, nullsFirst);
24
+ }
@@ -0,0 +1,56 @@
1
+ import { FunctionNode } from '../ast/function.js';
2
+ import { fn } from '../util/function.js';
3
+
4
+ /**
5
+ * Function that converts geometry data to GeoJSON format.
6
+ * @param {import('../types.js').ExprValue} expr The input expression.
7
+ * @returns {FunctionNode}
8
+ */
9
+ export function geojson(expr) {
10
+ return fn('st_asgeojson', expr);
11
+ }
12
+
13
+ /**
14
+ * Function that returns a spatial x position (using ST_X).
15
+ * @param {import('../types.js').ExprValue} expr The input expression.
16
+ * @returns {FunctionNode}
17
+ */
18
+ export function x(expr) {
19
+ return fn('st_x', expr);
20
+ }
21
+
22
+ /**
23
+ * Function that returns a spatial y position (using ST_Y).
24
+ * @param {import('../types.js').ExprValue} expr The input expression.
25
+ * @returns {FunctionNode}
26
+ */
27
+ export function y(expr) {
28
+ return fn('st_y', expr);
29
+ }
30
+
31
+ /**
32
+ * Function that returns the centroid point for geometry data.
33
+ * @param {import('../types.js').ExprValue} expr The input expression.
34
+ * @returns {FunctionNode}
35
+ */
36
+ export function centroid(expr) {
37
+ return fn('st_centroid', expr);
38
+ }
39
+
40
+ /**
41
+ * Function that returns the centroid x-coordinate for geometry data.
42
+ * @param {import('../types.js').ExprValue} expr The input expression.
43
+ * @returns {FunctionNode}
44
+ */
45
+ export function centroidX(expr) {
46
+ return x(centroid(expr));
47
+ }
48
+
49
+ /**
50
+ * Function that returns yhe centroid y-coordinate for geometry data.
51
+ * @param {import('../types.js').ExprValue} expr The input expression.
52
+ * @returns {FunctionNode}
53
+ */
54
+ export function centroidY(expr) {
55
+ return y(centroid(expr));
56
+ }
@@ -0,0 +1,51 @@
1
+ /* eslint-disable jsdoc/no-undefined-types */
2
+ import { FragmentNode } from '../ast/fragment.js';
3
+ import { isNode } from '../ast/node.js';
4
+ import { ParamNode } from '../ast/param.js';
5
+ import { VerbatimNode } from '../ast/verbatim.js';
6
+ import { isParamLike, isString } from '../util/type-check.js';
7
+ import { literal } from './literal.js';
8
+
9
+ /**
10
+ * @typedef {import('../ast/node.js').ExprNode
11
+ * | import('../types.js').ParamLike
12
+ * | string | number | boolean | Date
13
+ * } TemplateValue
14
+ */
15
+
16
+ /**
17
+ * Template tag function for SQL fragments. Interpolated values
18
+ * may be strings, other SQL expression objects (such as column
19
+ * references), primitive values, or dynamic parameters.
20
+ * @param {TemplateStringsArray} strings Template string constants.
21
+ * @param {...TemplateValue} exprs Template expression values.
22
+ */
23
+ export function sql(strings, ...exprs) {
24
+ return new FragmentNode(parseSQL(strings, exprs));
25
+ }
26
+
27
+ function parseSQL(strings, exprs) {
28
+ const spans = [strings[0]];
29
+ const n = exprs.length;
30
+ for (let i = 0, k = 0; i < n;) {
31
+ const e = exprs[i];
32
+ if (isNode(e)) {
33
+ spans[++k] = e;
34
+ } else if (isParamLike(e)) {
35
+ spans[++k] = new ParamNode(e);
36
+ } else {
37
+ spans[k] += isString(e) ? e : literal(e);
38
+ }
39
+ const s = strings[++i];
40
+ if (isNode(spans[k])) {
41
+ spans[++k] = s;
42
+ } else {
43
+ spans[k] += s;
44
+ }
45
+ }
46
+
47
+ // remove empty strings and preserve verbatim content
48
+ return spans
49
+ .filter(s => s)
50
+ .map(s => isString(s) ? new VerbatimNode(s) : s);
51
+ }
@@ -0,0 +1,82 @@
1
+ import { FunctionNode } from '../ast/function.js';
2
+ import { asLiteral } from '../util/ast.js';
3
+ import { argsList, fn } from '../util/function.js';
4
+
5
+ function strFn(name, expr, ...args) {
6
+ return fn(name, expr, ...(argsList(args).map(asLiteral)));
7
+ }
8
+
9
+ /**
10
+ * Function that returns true if a string contains a regexp pattern,
11
+ * 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
+ * 'c': case-sensitive matching
16
+ * 'i': case-insensitive matching
17
+ * 'l': match literals instead of regular expression tokens
18
+ * 'm', 'n', 'p': newline sensitive matching
19
+ * 'g': global replace, only available for regexp_replace
20
+ * 's': non-newline sensitive matching
21
+ * @returns {FunctionNode}
22
+ */
23
+ export function regexp_matches(string, pattern, options) {
24
+ return strFn('regexp_matches', string, pattern, options);
25
+ }
26
+
27
+ /**
28
+ * 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.
31
+ * @returns {FunctionNode}
32
+ */
33
+ export function contains(string, search_string) {
34
+ return strFn('contains', string, search_string);
35
+ }
36
+
37
+ /**
38
+ * 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.
41
+ * @returns {FunctionNode}
42
+ */
43
+ export function prefix(string, search_string) {
44
+ return strFn('starts_with', string, search_string);
45
+ }
46
+
47
+ /**
48
+ * 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.
51
+ * @returns {FunctionNode}
52
+ */
53
+ export function suffix(string, search_string) {
54
+ return strFn('ends_with', string, search_string);
55
+ }
56
+
57
+ /**
58
+ * Function that converts string to lower case.
59
+ * @param {import('../types.js').ExprValue} string The string to convert.
60
+ * @returns {FunctionNode}
61
+ */
62
+ export function lower(string) {
63
+ return strFn('lower', string);
64
+ }
65
+
66
+ /**
67
+ * Function that converts string to upper case.
68
+ * @param {import('../types.js').ExprValue} string The string to convert.
69
+ * @returns {FunctionNode}
70
+ */
71
+ export function upper(string) {
72
+ return strFn('upper', string);
73
+ }
74
+
75
+ /**
76
+ * Function that returns the number of characters in string.
77
+ * @param {import('../types.js').ExprValue} value The string to measure.
78
+ * @returns {FunctionNode}
79
+ */
80
+ export function length(value) {
81
+ return strFn('length', value);
82
+ }
@@ -0,0 +1,14 @@
1
+ import { TableRefNode } from '../ast/table-ref.js';
2
+ import { exprList } from '../util/function.js';
3
+
4
+ /**
5
+ * Returns a named table or view reference.
6
+ * @param {...(string | string[])} ids Table and namespace identifiers.
7
+ * For example 'name' or ['schema', 'name'].
8
+ * @returns {TableRefNode | undefined} A table reference, or undefined
9
+ * if the input identifier list is empty.
10
+ */
11
+ export function tableRef(...ids) {
12
+ const args = exprList(ids, String);
13
+ return args?.length ? new TableRefNode(args) : undefined;
14
+ }
@@ -0,0 +1,121 @@
1
+ import { WindowNode } from '../ast/window.js';
2
+ import { winFn } from '../util/function.js';
3
+
4
+ /**
5
+ * Create a window function that returns the number of the current row
6
+ * within the partition, counting from 1.
7
+ * @returns {WindowNode}
8
+ */
9
+ export function row_number() {
10
+ return winFn('row_number');
11
+ }
12
+
13
+ /**
14
+ * Create a window function that returns the rank of the current row with gaps.
15
+ * This is the same as the row_number of its first peer.
16
+ * @returns {WindowNode}
17
+ */
18
+ export function rank() {
19
+ return winFn('rank');
20
+ }
21
+
22
+ /**
23
+ * Create a window function that returns the rank of the current row without
24
+ * gaps. The function counts peer groups.
25
+ * @returns {WindowNode}
26
+ */
27
+ export function dense_rank() {
28
+ return winFn('dense_rank');
29
+ }
30
+
31
+ /**
32
+ * Create a window function that returns the relative rank of the current row.
33
+ * Computed as (rank() - 1) / (total partition rows - 1).
34
+ * @returns {WindowNode}
35
+ */
36
+ export function percent_rank() {
37
+ return winFn('percent_rank');
38
+ }
39
+
40
+ /**
41
+ * Create a window function that returns the cumulative distribution. Computed
42
+ * as (number of preceding or peer partition rows) / total partition rows.
43
+ * @returns {WindowNode}
44
+ */
45
+ export function cume_dist() {
46
+ return winFn('cume_dist');
47
+ }
48
+
49
+ /**
50
+ * Create a window function that returns an integer ranging from 1 to the
51
+ * argument value, dividing the partition as equally as possible.
52
+ * @param {import('../types.js').NumberValue} num_buckets The number of
53
+ * quantile buckets.
54
+ * @returns {WindowNode}
55
+ */
56
+ export function ntile(num_buckets) {
57
+ return winFn('ntile', num_buckets);
58
+ }
59
+
60
+ /**
61
+ * Create a window function that returns the expression evaluated at the row
62
+ * that is offset rows before the current row within the partition.
63
+ * If there is no such row, instead return default (which must be of the same
64
+ * type as the expression). Both offset and default are evaluated with respect
65
+ * 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
68
+ * (default `1`).
69
+ * @param {*} [defaultValue] The default value (default `null`).
70
+ * @returns {WindowNode}
71
+ */
72
+ export function lag(expr, offset, defaultValue){
73
+ return winFn('lag', expr, offset, defaultValue);
74
+ }
75
+
76
+ /**
77
+ * Create a window function that returns the expression evaluated at the row
78
+ * that is offset rows after the current row within the partition.
79
+ * If there is no such row, instead return default (which must be of the same
80
+ * type as the expression). Both offset and default are evaluated with respect
81
+ * 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
84
+ * (default `1`).
85
+ * @param {*} [defaultValue] The default value (default `null`).
86
+ * @returns {WindowNode}
87
+ */
88
+ export function lead(expr, offset, defaultValue){
89
+ return winFn('lead', expr, offset, defaultValue);
90
+ }
91
+
92
+ /**
93
+ * Create a window function that returns the expression evaluated at the row
94
+ * that is the first row of the window frame.
95
+ * @param {import('../types.js').ExprValue} expr The expression to evaluate.
96
+ * @returns {WindowNode}
97
+ */
98
+ export function first_value(expr) {
99
+ return winFn('first_value', expr);
100
+ }
101
+
102
+ /**
103
+ * Create a window function that returns the expression evaluated at the row
104
+ * that is the last row of the window frame.
105
+ * @param {import('../types.js').ExprValue} expr The expression to evaluate.
106
+ * @returns {WindowNode}
107
+ */
108
+ export function last_value(expr) {
109
+ return winFn('last_value', expr);
110
+ }
111
+
112
+ /**
113
+ * Create a window function that returns the expression evaluated at the
114
+ * 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.
117
+ * @returns {WindowNode}
118
+ */
119
+ export function nth_value(expr, nth) {
120
+ return winFn('nth_value', expr, nth);
121
+ }
@@ -0,0 +1,2 @@
1
+ export * from './index.js';
2
+ export * from './types.js';