@uwdata/mosaic-sql 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mosaic-sql.js +2242 -1064
- package/dist/mosaic-sql.min.js +1 -1
- package/dist/types/ast/aggregate.d.ts +70 -0
- package/dist/types/ast/between-op.d.ts +46 -0
- package/dist/types/ast/binary-op.d.ts +28 -0
- package/dist/types/ast/case.d.ts +68 -0
- package/dist/types/ast/cast.d.ts +21 -0
- package/dist/types/ast/column-param.d.ts +17 -0
- package/dist/types/ast/column-ref.d.ts +39 -0
- package/dist/types/ast/fragment.d.ts +14 -0
- package/dist/types/ast/from.d.ts +21 -0
- package/dist/types/ast/function.d.ts +21 -0
- package/dist/types/ast/in-op.d.ts +21 -0
- package/dist/types/ast/interval.d.ts +21 -0
- package/dist/types/ast/literal.d.ts +15 -0
- package/dist/types/ast/logical-op.d.ts +46 -0
- package/dist/types/ast/node.d.ts +24 -0
- package/dist/types/ast/order-by.d.ts +29 -0
- package/dist/types/ast/param.d.ts +19 -0
- package/dist/types/ast/query.d.ts +268 -0
- package/dist/types/ast/sample.d.ts +42 -0
- package/dist/types/ast/select.d.ts +22 -0
- package/dist/types/ast/table-ref.d.ts +25 -0
- package/dist/types/ast/unary-op.d.ts +39 -0
- package/dist/types/ast/verbatim.d.ts +9 -0
- package/dist/types/ast/window.d.ts +177 -0
- package/dist/types/ast/with.d.ts +22 -0
- package/dist/types/constants.d.ts +38 -0
- package/dist/types/functions/aggregate.d.ts +229 -0
- package/dist/types/functions/case.d.ts +15 -0
- package/dist/types/functions/cast.d.ts +26 -0
- package/dist/types/functions/column.d.ts +9 -0
- package/dist/types/functions/datetime.d.ts +44 -0
- package/dist/types/functions/literal.d.ts +16 -0
- package/dist/types/functions/numeric.d.ts +93 -0
- package/dist/types/functions/operators.d.ts +198 -0
- package/dist/types/functions/order-by.d.ts +17 -0
- package/dist/types/functions/spatial.d.ts +37 -0
- package/dist/types/functions/sql-template-tag.d.ts +16 -0
- package/dist/types/functions/string.d.ts +55 -0
- package/dist/types/functions/table-ref.d.ts +9 -0
- package/dist/types/functions/window.d.ts +87 -0
- package/dist/types/index-types.d.ts +2 -0
- package/dist/types/index.d.ts +53 -0
- package/dist/types/load/create.d.ts +8 -0
- package/dist/types/load/extension.d.ts +1 -0
- package/dist/types/load/load.d.ts +12 -0
- package/dist/types/load/sql-from.d.ts +11 -0
- package/dist/types/transforms/bin-1d.d.ts +14 -0
- package/dist/types/transforms/bin-2d.d.ts +18 -0
- package/dist/types/transforms/bin-linear-1d.d.ts +9 -0
- package/dist/types/transforms/bin-linear-2d.d.ts +18 -0
- package/dist/types/transforms/line-density.d.ts +23 -0
- package/dist/types/transforms/m4.d.ts +18 -0
- package/dist/types/transforms/scales.d.ts +1 -0
- package/dist/types/types.d.ts +59 -0
- package/dist/types/util/ast.d.ts +60 -0
- package/dist/types/util/function.d.ts +54 -0
- package/dist/types/util/string.d.ts +3 -0
- package/dist/types/util/type-check.d.ts +18 -0
- package/dist/types/visit/recurse.d.ts +28 -0
- package/dist/types/visit/rewrite.d.ts +10 -0
- package/dist/types/visit/visitors.d.ts +33 -0
- package/dist/types/visit/walk.d.ts +7 -0
- package/jsconfig.json +11 -0
- package/package.json +6 -4
- package/src/ast/aggregate.js +164 -0
- package/src/ast/between-op.js +75 -0
- package/src/ast/binary-op.js +40 -0
- package/src/ast/case.js +105 -0
- package/src/ast/cast.js +34 -0
- package/src/ast/column-param.js +29 -0
- package/src/ast/column-ref.js +72 -0
- package/src/ast/fragment.js +26 -0
- package/src/ast/from.js +40 -0
- package/src/ast/function.js +34 -0
- package/src/ast/in-op.js +33 -0
- package/src/ast/interval.js +33 -0
- package/src/ast/literal.js +55 -0
- package/src/ast/logical-op.js +67 -0
- package/src/ast/node.js +29 -0
- package/src/ast/order-by.js +48 -0
- package/src/ast/param.js +35 -0
- package/src/ast/query.js +578 -0
- package/src/ast/sample.js +53 -0
- package/src/ast/select.js +44 -0
- package/src/ast/table-ref.js +44 -0
- package/src/ast/unary-op.js +64 -0
- package/src/ast/verbatim.js +26 -0
- package/src/ast/window.js +290 -0
- package/src/ast/with.js +30 -0
- package/src/constants.js +44 -0
- package/src/functions/aggregate.js +335 -0
- package/src/functions/case.js +21 -0
- package/src/functions/cast.js +39 -0
- package/src/functions/column.js +20 -0
- package/src/functions/datetime.js +65 -0
- package/src/functions/literal.js +22 -0
- package/src/functions/numeric.js +139 -0
- package/src/functions/operators.js +298 -0
- package/src/functions/order-by.js +24 -0
- package/src/functions/spatial.js +56 -0
- package/src/functions/sql-template-tag.js +51 -0
- package/src/functions/string.js +82 -0
- package/src/functions/table-ref.js +14 -0
- package/src/functions/window.js +121 -0
- package/src/index-types.ts +2 -0
- package/src/index.js +57 -155
- package/src/load/create.js +10 -2
- package/src/load/load.js +4 -4
- package/src/load/sql-from.js +7 -6
- package/src/transforms/bin-1d.js +21 -0
- package/src/transforms/bin-2d.js +29 -0
- package/src/transforms/bin-linear-1d.js +26 -0
- package/src/transforms/bin-linear-2d.js +71 -0
- package/src/transforms/line-density.js +113 -0
- package/src/transforms/m4.js +38 -0
- package/src/{scales.js → transforms/scales.js} +31 -17
- package/src/types.ts +96 -0
- package/src/util/ast.js +96 -0
- package/src/util/function.js +78 -0
- package/src/util/string.js +16 -0
- package/src/util/type-check.js +29 -0
- package/src/visit/recurse.js +57 -0
- package/src/visit/rewrite.js +32 -0
- package/src/visit/visitors.js +108 -0
- package/src/visit/walk.js +30 -0
- package/tsconfig.json +12 -0
- package/src/Query.js +0 -593
- package/src/aggregates.js +0 -185
- package/src/cast.js +0 -19
- package/src/datetime.js +0 -31
- package/src/desc.js +0 -13
- package/src/expression.js +0 -170
- package/src/functions.js +0 -25
- package/src/literal.js +0 -6
- package/src/operators.js +0 -54
- package/src/ref.js +0 -109
- package/src/repeat.js +0 -3
- package/src/spatial.js +0 -10
- package/src/to-sql.js +0 -52
- package/src/windows.js +0 -239
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { UNARY_OPERATOR, UNARY_POSTFIX_OPERATOR } from '../constants.js';
|
|
2
|
+
import { ExprNode } from './node.js';
|
|
3
|
+
|
|
4
|
+
class AbstractUnaryOpNode extends ExprNode {
|
|
5
|
+
/**
|
|
6
|
+
* Instantiate an abstract unary operator node.
|
|
7
|
+
* @param {string} type The node type.
|
|
8
|
+
* @param {string} op The operator type.
|
|
9
|
+
* @param {ExprNode} expr The input expression.
|
|
10
|
+
*/
|
|
11
|
+
constructor(type, op, expr) {
|
|
12
|
+
super(type);
|
|
13
|
+
/**
|
|
14
|
+
* The operator type.
|
|
15
|
+
* @type {string}
|
|
16
|
+
* @readonly
|
|
17
|
+
*/
|
|
18
|
+
this.op = op;
|
|
19
|
+
/**
|
|
20
|
+
* The input expression.
|
|
21
|
+
* @type {ExprNode}
|
|
22
|
+
* @readonly
|
|
23
|
+
*/
|
|
24
|
+
this.expr = expr;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class UnaryOpNode extends AbstractUnaryOpNode {
|
|
29
|
+
/**
|
|
30
|
+
* Instantiate a unary operator node.
|
|
31
|
+
* @param {string} op The operator type.
|
|
32
|
+
* @param {ExprNode} expr The input expression.
|
|
33
|
+
*/
|
|
34
|
+
constructor(op, expr) {
|
|
35
|
+
super(UNARY_OPERATOR, op, expr);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Generate a SQL query string for this node.
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
42
|
+
toString() {
|
|
43
|
+
return `(${this.op} ${this.expr})`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class UnaryPosftixOpNode extends AbstractUnaryOpNode {
|
|
48
|
+
/**
|
|
49
|
+
* Instantiate a unary operator node.
|
|
50
|
+
* @param {string} op The operator type.
|
|
51
|
+
* @param {ExprNode} expr The input expression.
|
|
52
|
+
*/
|
|
53
|
+
constructor(op, expr) {
|
|
54
|
+
super(UNARY_POSTFIX_OPERATOR, op, expr);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Generate a SQL query string for this node.
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
toString() {
|
|
62
|
+
return `(${this.expr} ${this.op})`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { VERBATIM } from '../constants.js';
|
|
2
|
+
import { ExprNode } from './node.js';
|
|
3
|
+
|
|
4
|
+
export class VerbatimNode extends ExprNode {
|
|
5
|
+
/**
|
|
6
|
+
* Instantiate a raw node with verbatim content.
|
|
7
|
+
* @param {string} value The verbatim content to include.
|
|
8
|
+
*/
|
|
9
|
+
constructor(value) {
|
|
10
|
+
super(VERBATIM);
|
|
11
|
+
/**
|
|
12
|
+
* The verbatim content to include.
|
|
13
|
+
* @type {string}
|
|
14
|
+
* @readonly
|
|
15
|
+
*/
|
|
16
|
+
this.value = value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Generate a SQL query string for this node.
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
toString() {
|
|
24
|
+
return this.value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { WINDOW, WINDOW_CLAUSE, WINDOW_DEF, WINDOW_FRAME } from '../constants.js';
|
|
2
|
+
import { exprList } from '../util/function.js';
|
|
3
|
+
import { quoteIdentifier } from '../util/string.js';
|
|
4
|
+
import { isParamLike } from '../util/type-check.js';
|
|
5
|
+
import { AggregateNode } from './aggregate.js';
|
|
6
|
+
import { FunctionNode } from './function.js';
|
|
7
|
+
import { ExprNode, isNode, SQLNode } from './node.js';
|
|
8
|
+
import { ParamNode } from './param.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {[any, any] | import('../types.js').ParamLike} FrameExtent
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export class WindowClauseNode extends SQLNode {
|
|
15
|
+
/**
|
|
16
|
+
* Instantiate a window clause node.
|
|
17
|
+
* @param {string} name The window name.
|
|
18
|
+
* @param {WindowDefNode} def The window definition.
|
|
19
|
+
*/
|
|
20
|
+
constructor(name, def) {
|
|
21
|
+
super(WINDOW_CLAUSE);
|
|
22
|
+
/**
|
|
23
|
+
* The window name.
|
|
24
|
+
* @type {string}
|
|
25
|
+
* @readonly
|
|
26
|
+
*/
|
|
27
|
+
this.name = name;
|
|
28
|
+
/**
|
|
29
|
+
* The window definition.
|
|
30
|
+
* @type {WindowDefNode}
|
|
31
|
+
* @readonly
|
|
32
|
+
*/
|
|
33
|
+
this.def = def;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
toString() {
|
|
37
|
+
return `${quoteIdentifier(this.name)} AS ${this.def}`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class WindowNode extends ExprNode {
|
|
42
|
+
/**
|
|
43
|
+
* Instantiate a window node.
|
|
44
|
+
* @param {WindowFunctionNode | AggregateNode} func The window function call.
|
|
45
|
+
* @param {WindowDefNode} [over] The window definition or name.
|
|
46
|
+
*/
|
|
47
|
+
constructor(func, over = new WindowDefNode()) {
|
|
48
|
+
super(WINDOW);
|
|
49
|
+
/**
|
|
50
|
+
* @type {WindowFunctionNode | AggregateNode}
|
|
51
|
+
* @readonly
|
|
52
|
+
*/
|
|
53
|
+
this.func = func;
|
|
54
|
+
/**
|
|
55
|
+
* @type {WindowDefNode}
|
|
56
|
+
* @readonly
|
|
57
|
+
*/
|
|
58
|
+
this.def = over;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Return an updated window over a named window definition.
|
|
63
|
+
* @param {string} name The window definition name.
|
|
64
|
+
* @returns {WindowNode} A new window node.
|
|
65
|
+
*/
|
|
66
|
+
over(name) {
|
|
67
|
+
return new WindowNode(this.func, this.def.over(name));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Return an updated window with the given partitions.
|
|
72
|
+
* @param {...import('../types.js').ExprVarArgs} expr The partition by criteria.
|
|
73
|
+
* @returns {WindowNode} A new window node.
|
|
74
|
+
*/
|
|
75
|
+
partitionby(...expr) {
|
|
76
|
+
return new WindowNode(this.func, this.def.partitionby(...expr));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Return an updated window with the given ordering.
|
|
81
|
+
* @param {...import('../types.js').ExprVarArgs} expr The order by criteria.
|
|
82
|
+
* @returns {WindowNode} A new window node.
|
|
83
|
+
*/
|
|
84
|
+
orderby(...expr) {
|
|
85
|
+
return new WindowNode(this.func, this.def.orderby(...expr));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Return an updated window with the given rows frame.
|
|
90
|
+
* @param {FrameExtent} extent The row-based window frame extent.
|
|
91
|
+
* @returns {WindowNode} A new window node.
|
|
92
|
+
*/
|
|
93
|
+
rows(extent) {
|
|
94
|
+
return new WindowNode(this.func, this.def.rows(extent));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Return an updated window with the given range frame.
|
|
99
|
+
* @param {FrameExtent} extent The range-based window frame extent.
|
|
100
|
+
* @returns {WindowNode} A new window node.
|
|
101
|
+
*/
|
|
102
|
+
range(extent) {
|
|
103
|
+
return new WindowNode(this.func, this.def.range(extent));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Generate a SQL query string for this node.
|
|
108
|
+
* @returns {string}
|
|
109
|
+
*/
|
|
110
|
+
toString() {
|
|
111
|
+
return `${this.func} OVER ${this.def}`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export class WindowFunctionNode extends FunctionNode {
|
|
116
|
+
/**
|
|
117
|
+
* Instantiate a window function call node.
|
|
118
|
+
* @param {import('../types.js').WindowFunctionName} name The function name.
|
|
119
|
+
* @param {ExprNode[]} [args=[]] The function arguments.
|
|
120
|
+
*/
|
|
121
|
+
constructor(name, args) {
|
|
122
|
+
super(name, args);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export class WindowDefNode extends SQLNode {
|
|
127
|
+
/**
|
|
128
|
+
* Instantiate a window definition node.
|
|
129
|
+
* @param {string} [name] The base window definition name.
|
|
130
|
+
* @param {ExprNode[]} [partition] The partition by criteria.
|
|
131
|
+
* @param {ExprNode[]} [order] The order by criteria.
|
|
132
|
+
* @param {WindowFrameNode} [frame] The window frame definition.
|
|
133
|
+
*/
|
|
134
|
+
constructor(name, partition, order, frame) {
|
|
135
|
+
super(WINDOW_DEF);
|
|
136
|
+
/**
|
|
137
|
+
* The base window definition name.
|
|
138
|
+
* @type {string}
|
|
139
|
+
* @readonly
|
|
140
|
+
*/
|
|
141
|
+
this.name = name;
|
|
142
|
+
/**
|
|
143
|
+
* The partition by criteria.
|
|
144
|
+
* @type {ExprNode[]}
|
|
145
|
+
* @readonly
|
|
146
|
+
*/
|
|
147
|
+
this.partition = partition;
|
|
148
|
+
/**
|
|
149
|
+
* The order by criteria.
|
|
150
|
+
* @type {ExprNode[]}
|
|
151
|
+
* @readonly
|
|
152
|
+
*/
|
|
153
|
+
this.order = order;
|
|
154
|
+
/**
|
|
155
|
+
* The window frame definition.
|
|
156
|
+
* @type {WindowFrameNode}
|
|
157
|
+
* @readonly
|
|
158
|
+
*/
|
|
159
|
+
this.frame = frame;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Return an updated window definition with the given base name.
|
|
164
|
+
* @param {string} name The base window definition name.
|
|
165
|
+
* @returns {WindowDefNode} A new window definition node.
|
|
166
|
+
*/
|
|
167
|
+
over(name) {
|
|
168
|
+
return deriveDef(this, { name });
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Return an updated window definition with the given partitions.
|
|
173
|
+
* @param {...import('../types.js').ExprVarArgs} expr The partition by criteria.
|
|
174
|
+
* @returns {WindowDefNode} A new window definition node.
|
|
175
|
+
*/
|
|
176
|
+
partitionby(...expr) {
|
|
177
|
+
return deriveDef(this, { partition: exprList(expr) });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Return an updated window definition with the given ordering.
|
|
182
|
+
* @param {...import('../types.js').ExprVarArgs} expr The order by criteria.
|
|
183
|
+
* @returns {WindowDefNode} A new window definition node.
|
|
184
|
+
*/
|
|
185
|
+
orderby(...expr) {
|
|
186
|
+
return deriveDef(this, { order: exprList(expr) });
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Return an updated window definition with the given rows frame.
|
|
191
|
+
* @param {FrameExtent} extent The row-based window frame extent.
|
|
192
|
+
* @returns {WindowDefNode} A new window definition node.
|
|
193
|
+
*/
|
|
194
|
+
rows(extent) {
|
|
195
|
+
return deriveDef(this, { frame: new WindowFrameNode(extent) });
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Return an updated window definition with the given range frame.
|
|
200
|
+
* @param {FrameExtent} extent The range-based window frame extent.
|
|
201
|
+
* @returns {WindowDefNode} A new window definition node.
|
|
202
|
+
*/
|
|
203
|
+
range(extent) {
|
|
204
|
+
return deriveDef(this, { frame: new WindowFrameNode(extent, true) });
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Generate a SQL query string for this node.
|
|
209
|
+
* @returns {string}
|
|
210
|
+
*/
|
|
211
|
+
toString() {
|
|
212
|
+
const { name, partition, order, frame } = this;
|
|
213
|
+
const base = name && quoteIdentifier(name);
|
|
214
|
+
const def = [
|
|
215
|
+
base,
|
|
216
|
+
partition?.length && `PARTITION BY ${partition.join(', ')}`,
|
|
217
|
+
order?.length && `ORDER BY ${order.join(', ')}`,
|
|
218
|
+
frame
|
|
219
|
+
].filter(x => x);
|
|
220
|
+
return base && def.length < 2 ? base : `(${def.join(' ')})`;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export class WindowFrameNode extends SQLNode {
|
|
225
|
+
/**
|
|
226
|
+
* Instantiate a window frame definition node.
|
|
227
|
+
* @param {FrameExtent} extent The frame extent as [preceding, following]
|
|
228
|
+
* row or interval offsets.
|
|
229
|
+
* @param {boolean} [range] The frame type: `true` for range, otherwise rows.
|
|
230
|
+
* @param {ExprNode} [exclude] The window exclusion criteria.
|
|
231
|
+
*/
|
|
232
|
+
constructor(extent, range = false, exclude = undefined) {
|
|
233
|
+
super(WINDOW_FRAME);
|
|
234
|
+
/**
|
|
235
|
+
* The frame extent as [preceding, following] row or interval offsets.
|
|
236
|
+
* @type {ParamNode | [any, any]}
|
|
237
|
+
* @readonly
|
|
238
|
+
*/
|
|
239
|
+
this.extent = isParamLike(extent) ? new ParamNode(extent) : extent;
|
|
240
|
+
/**
|
|
241
|
+
* The frame type: `true` for range, otherwise rows.
|
|
242
|
+
* @type {boolean}
|
|
243
|
+
* @readonly
|
|
244
|
+
*/
|
|
245
|
+
this.range = range;
|
|
246
|
+
/**
|
|
247
|
+
* The window exclusion criteria.
|
|
248
|
+
* @type {ExprNode}
|
|
249
|
+
* @readonly
|
|
250
|
+
*/
|
|
251
|
+
this.exclude = exclude;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Generate a SQL query string for this node.
|
|
256
|
+
* @returns {string}
|
|
257
|
+
*/
|
|
258
|
+
toString() {
|
|
259
|
+
const { range, exclude, extent } = this;
|
|
260
|
+
const type = range ? 'RANGE' : 'ROWS';
|
|
261
|
+
const [prev, next] = isNode(extent) ? extent.value : extent;
|
|
262
|
+
const a = frameValue(prev, 'PRECEDING');
|
|
263
|
+
const b = frameValue(next, 'FOLLOWING');
|
|
264
|
+
return `${type} BETWEEN ${a} AND ${b}${exclude ? ` ${exclude}` : ''}`;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Derive a new window definition node from an existing one.
|
|
270
|
+
* @param {WindowDefNode} def The existing window definition.
|
|
271
|
+
* @param {object} options An options object with new definition properties.
|
|
272
|
+
* @param {string} [options.name] The base window definition name.
|
|
273
|
+
* @param {ExprNode[]} [options.partition] The partition by criteria.
|
|
274
|
+
* @param {ExprNode[]} [options.order] The order by criteria.
|
|
275
|
+
* @param {WindowFrameNode} [options.frame] The window frame definition.
|
|
276
|
+
*/
|
|
277
|
+
function deriveDef(def, options) {
|
|
278
|
+
return new WindowDefNode(
|
|
279
|
+
options.name ?? def.name,
|
|
280
|
+
options.partition ?? def.partition,
|
|
281
|
+
options.order ?? def.order,
|
|
282
|
+
options.frame ?? def.frame
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function frameValue(value, order) {
|
|
287
|
+
return value === 0 ? 'CURRENT ROW'
|
|
288
|
+
: Number.isFinite(value) ? `${Math.abs(value)} ${order}`
|
|
289
|
+
: `UNBOUNDED ${order}`;
|
|
290
|
+
}
|
package/src/ast/with.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { WITH_CLAUSE } from '../constants.js';
|
|
2
|
+
import { SQLNode } from './node.js';
|
|
3
|
+
import { Query } from './query.js';
|
|
4
|
+
|
|
5
|
+
export class WithClauseNode extends SQLNode {
|
|
6
|
+
/**
|
|
7
|
+
* Instantiate a with clause node for a common table expression (CTE).
|
|
8
|
+
* @param {string} name The common table expression (CTE) name.
|
|
9
|
+
* @param {Query} query The common table expression (CTE) query.
|
|
10
|
+
*/
|
|
11
|
+
constructor(name, query) {
|
|
12
|
+
super(WITH_CLAUSE);
|
|
13
|
+
/**
|
|
14
|
+
* The common table expression (CTE) name.
|
|
15
|
+
* @type {string}
|
|
16
|
+
* @readonly
|
|
17
|
+
*/
|
|
18
|
+
this.name = name;
|
|
19
|
+
/**
|
|
20
|
+
* The common table expression (CTE) query.
|
|
21
|
+
* @type {Query}
|
|
22
|
+
* @readonly
|
|
23
|
+
*/
|
|
24
|
+
this.query = query;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
toString() {
|
|
28
|
+
return `"${this.name}" AS (${this.query})`;
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export const COLUMN_REF = 'COLUMN_REF';
|
|
2
|
+
export const COLUMN_PARAM = 'COLUMN_PARAM';
|
|
3
|
+
export const TABLE_REF = 'TABLE_REF';
|
|
4
|
+
export const LITERAL = 'LITERAL';
|
|
5
|
+
export const INTERVAL = 'INTERVAL';
|
|
6
|
+
|
|
7
|
+
export const ORDER_BY = 'ORDER_BY';
|
|
8
|
+
export const CAST = 'CAST';
|
|
9
|
+
export const CASE = 'CASE';
|
|
10
|
+
export const WHEN = 'WHEN';
|
|
11
|
+
|
|
12
|
+
export const UNARY_OPERATOR = 'UNARY';
|
|
13
|
+
export const UNARY_POSTFIX_OPERATOR = 'UNARY_POSTFIX';
|
|
14
|
+
export const BINARY_OPERATOR = 'BINARY';
|
|
15
|
+
export const BETWEEN_OPERATOR = 'BETWEEN';
|
|
16
|
+
export const NOT_BETWEEN_OPERATOR = 'NOT_BETWEEN';
|
|
17
|
+
export const LOGICAL_OPERATOR = 'LOGICAL_OPERATOR';
|
|
18
|
+
export const IN_OPERATOR = 'IN';
|
|
19
|
+
|
|
20
|
+
export const FUNCTION = 'FUNCTION';
|
|
21
|
+
export const AGGREGATE = 'AGGREGATE';
|
|
22
|
+
export const WINDOW = 'WINDOW';
|
|
23
|
+
export const WINDOW_DEF = 'WINDOW_DEF';
|
|
24
|
+
export const WINDOW_FRAME = 'WINDOW_FRAME';
|
|
25
|
+
|
|
26
|
+
export const EXPRESSION = 'EXPRESSION';
|
|
27
|
+
export const FRAGMENT = 'FRAGMENT';
|
|
28
|
+
export const VERBATIM = 'VERBATIM';
|
|
29
|
+
export const PARAM = 'PARAM';
|
|
30
|
+
|
|
31
|
+
export const WITH_CLAUSE = 'WITH_CLAUSE';
|
|
32
|
+
export const SELECT_CLAUSE = 'SELECT_CLAUSE';
|
|
33
|
+
export const FROM_CLAUSE = 'FROM_CLAUSE';
|
|
34
|
+
export const WHERE_CLAUSE = 'WHERE_CLAUSE';
|
|
35
|
+
export const SAMPLE_CLAUSE = 'SAMPLE_CLAUSE';
|
|
36
|
+
export const GROUPBY_CLAUSE = 'GROUPBY_CLAUSE';
|
|
37
|
+
export const HAVING_CLAUSE = 'HAVING_CLAUSE';
|
|
38
|
+
export const WINDOW_CLAUSE = 'WINDOW_CLAUSE';
|
|
39
|
+
export const QUALIFY_CLAUSE = 'QUALIFY_CLAUSE';
|
|
40
|
+
export const ORDERBY_CLAUSE = 'ORDERBY_CLAUSE';
|
|
41
|
+
|
|
42
|
+
export const SELECT_QUERY = 'SELECT_QUERY';
|
|
43
|
+
export const DESCRIBE_QUERY = 'DESCRIBE_QUERY';
|
|
44
|
+
export const SET_OPERATION = 'SET_OPERATION';
|