@malloydata/malloy 0.0.177-dev240828173040 → 0.0.177-dev240829030921

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 (121) hide show
  1. package/dist/dialect/dialect.d.ts +23 -13
  2. package/dist/dialect/dialect.js +33 -27
  3. package/dist/dialect/duckdb/duckdb.d.ts +7 -11
  4. package/dist/dialect/duckdb/duckdb.js +34 -100
  5. package/dist/dialect/duckdb/functions/greatest_and_least.js +5 -12
  6. package/dist/dialect/functions/concat.js +1 -1
  7. package/dist/dialect/functions/greatest_and_least.js +1 -1
  8. package/dist/dialect/functions/simple_numeric_functions.js +1 -1
  9. package/dist/dialect/functions/sql.js +5 -15
  10. package/dist/dialect/functions/string_agg.js +2 -2
  11. package/dist/dialect/functions/trim_functions.js +2 -2
  12. package/dist/dialect/functions/util.d.ts +6 -9
  13. package/dist/dialect/functions/util.js +29 -38
  14. package/dist/dialect/index.d.ts +1 -1
  15. package/dist/dialect/index.js +1 -2
  16. package/dist/dialect/pg_impl.d.ts +15 -0
  17. package/dist/dialect/pg_impl.js +91 -0
  18. package/dist/dialect/postgres/functions/greatest_and_least.js +1 -3
  19. package/dist/dialect/postgres/functions/string_agg.js +2 -2
  20. package/dist/dialect/postgres/postgres.d.ts +7 -11
  21. package/dist/dialect/postgres/postgres.js +29 -92
  22. package/dist/dialect/snowflake/functions/string_agg.js +2 -2
  23. package/dist/dialect/snowflake/snowflake.d.ts +9 -9
  24. package/dist/dialect/snowflake/snowflake.js +41 -48
  25. package/dist/dialect/standardsql/functions/string_agg.js +4 -4
  26. package/dist/dialect/standardsql/standardsql.d.ts +9 -9
  27. package/dist/dialect/standardsql/standardsql.js +56 -51
  28. package/dist/dialect/trino/functions/concat.js +1 -1
  29. package/dist/dialect/trino/functions/string_agg.js +2 -2
  30. package/dist/dialect/trino/trino.d.ts +11 -12
  31. package/dist/dialect/trino/trino.js +59 -83
  32. package/dist/index.d.ts +3 -3
  33. package/dist/index.js +3 -4
  34. package/dist/lang/ast/ast-utils.d.ts +1 -1
  35. package/dist/lang/ast/ast-utils.js +2 -2
  36. package/dist/lang/ast/expressions/apply.js +1 -2
  37. package/dist/lang/ast/expressions/binary-boolean.d.ts +2 -1
  38. package/dist/lang/ast/expressions/binary-boolean.js +6 -3
  39. package/dist/lang/ast/expressions/binary-numeric.d.ts +2 -1
  40. package/dist/lang/ast/expressions/boolean.js +1 -1
  41. package/dist/lang/ast/expressions/constant-expression.d.ts +3 -3
  42. package/dist/lang/ast/expressions/constant-expression.js +0 -23
  43. package/dist/lang/ast/expressions/expr-aggregate-function.js +24 -34
  44. package/dist/lang/ast/expressions/expr-alternation-tree.d.ts +6 -3
  45. package/dist/lang/ast/expressions/expr-alternation-tree.js +10 -5
  46. package/dist/lang/ast/expressions/expr-cast.js +1 -2
  47. package/dist/lang/ast/expressions/expr-coalesce.js +4 -1
  48. package/dist/lang/ast/expressions/expr-compare.d.ts +3 -3
  49. package/dist/lang/ast/expressions/expr-count-distinct.js +1 -1
  50. package/dist/lang/ast/expressions/expr-count.js +3 -3
  51. package/dist/lang/ast/expressions/expr-func.js +15 -18
  52. package/dist/lang/ast/expressions/expr-granular-time.js +8 -10
  53. package/dist/lang/ast/expressions/expr-id-reference.js +2 -2
  54. package/dist/lang/ast/expressions/expr-minus.js +5 -4
  55. package/dist/lang/ast/expressions/expr-not.js +1 -1
  56. package/dist/lang/ast/expressions/expr-now.js +1 -6
  57. package/dist/lang/ast/expressions/expr-null.js +1 -1
  58. package/dist/lang/ast/expressions/expr-number.js +1 -1
  59. package/dist/lang/ast/expressions/expr-parens.js +1 -1
  60. package/dist/lang/ast/expressions/expr-props.js +4 -7
  61. package/dist/lang/ast/expressions/expr-regex.js +1 -3
  62. package/dist/lang/ast/expressions/expr-string.js +1 -7
  63. package/dist/lang/ast/expressions/expr-time-extract.js +12 -16
  64. package/dist/lang/ast/expressions/expr-time.d.ts +2 -2
  65. package/dist/lang/ast/expressions/expr-time.js +4 -6
  66. package/dist/lang/ast/expressions/expr-ungroup.js +2 -2
  67. package/dist/lang/ast/expressions/for-range.d.ts +2 -1
  68. package/dist/lang/ast/expressions/function-ordering.js +5 -5
  69. package/dist/lang/ast/expressions/partial-compare.d.ts +3 -3
  70. package/dist/lang/ast/expressions/pick-when.js +24 -8
  71. package/dist/lang/ast/expressions/range.d.ts +2 -1
  72. package/dist/lang/ast/expressions/range.js +4 -2
  73. package/dist/lang/ast/expressions/time-literal.d.ts +4 -3
  74. package/dist/lang/ast/expressions/time-literal.js +5 -10
  75. package/dist/lang/ast/expressions/top-by.js +1 -2
  76. package/dist/lang/ast/expressions/utils.d.ts +3 -12
  77. package/dist/lang/ast/expressions/utils.js +8 -56
  78. package/dist/lang/ast/field-space/reference-field.js +1 -1
  79. package/dist/lang/ast/index.d.ts +1 -1
  80. package/dist/lang/ast/index.js +1 -1
  81. package/dist/lang/ast/query-builders/index-builder.d.ts +2 -2
  82. package/dist/lang/ast/query-builders/reduce-builder.d.ts +2 -2
  83. package/dist/lang/ast/query-items/field-declaration.js +1 -5
  84. package/dist/lang/ast/query-properties/filters.d.ts +3 -3
  85. package/dist/lang/ast/query-properties/filters.js +6 -5
  86. package/dist/lang/ast/query-properties/top.js +1 -2
  87. package/dist/lang/ast/source-elements/refined-source.js +1 -1
  88. package/dist/lang/ast/source-properties/joins.js +11 -10
  89. package/dist/lang/ast/time-utils.d.ts +5 -7
  90. package/dist/lang/ast/time-utils.js +17 -57
  91. package/dist/lang/ast/types/binary_operators.d.ts +9 -0
  92. package/dist/lang/ast/types/binary_operators.js +28 -0
  93. package/dist/lang/ast/types/expr-result.d.ts +3 -3
  94. package/dist/lang/ast/types/expression-def.d.ts +4 -3
  95. package/dist/lang/ast/types/expression-def.js +43 -50
  96. package/dist/lang/lib/Malloy/MalloyParser.d.ts +0 -11
  97. package/dist/lang/lib/Malloy/MalloyParser.js +803 -858
  98. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +0 -13
  99. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +0 -8
  100. package/dist/lang/malloy-to-ast.d.ts +0 -1
  101. package/dist/lang/malloy-to-ast.js +0 -4
  102. package/dist/lang/test/expressions.spec.js +42 -86
  103. package/dist/lang/test/field-symbols.spec.js +8 -6
  104. package/dist/lang/test/literals.spec.js +6 -6
  105. package/dist/lang/test/model_serialization.spec.js +5 -5
  106. package/dist/lang/test/test-translator.js +9 -7
  107. package/dist/malloy.d.ts +3 -3
  108. package/dist/malloy.js +1 -1
  109. package/dist/model/index.d.ts +1 -1
  110. package/dist/model/index.js +2 -1
  111. package/dist/model/malloy_query.d.ts +24 -19
  112. package/dist/model/malloy_query.js +272 -244
  113. package/dist/model/malloy_types.d.ts +224 -205
  114. package/dist/model/malloy_types.js +19 -98
  115. package/dist/model/utils.d.ts +10 -3
  116. package/dist/model/utils.js +84 -219
  117. package/package.json +1 -1
  118. package/dist/lang/ast/types/comparison.d.ts +0 -11
  119. package/dist/lang/ast/types/comparison.js +0 -41
  120. package/dist/lang/ast/types/equality.d.ts +0 -7
  121. package/dist/lang/ast/types/equality.js +0 -37
@@ -22,8 +22,9 @@
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.range = exports.joinWith = exports.exprWalk = exports.exprMap = exports.generateHash = exports.AndChain = exports.generateSQLStringLiteral = exports.indent = void 0;
25
+ exports.composeSQLExpr = exports.exprMap = exports.exprWalk = exports.exprKids = exports.range = exports.joinWith = exports.generateHash = exports.AndChain = exports.generateSQLStringLiteral = exports.indent = void 0;
26
26
  const uuid_1 = require("uuid");
27
+ const malloy_types_1 = require("./malloy_types");
27
28
  /** simple indent function */
28
29
  function indent(s) {
29
30
  const re = /(^|\n)/g;
@@ -97,224 +98,6 @@ function generateHash(input) {
97
98
  return (0, uuid_1.v5)(input, MALLOY_UUID);
98
99
  }
99
100
  exports.generateHash = generateHash;
100
- function exprMap(expr, func) {
101
- return expr.flatMap(fragment => {
102
- const mapped = func(fragment);
103
- return mapped.map(fragment => {
104
- if (typeof fragment === 'string') {
105
- return fragment;
106
- }
107
- switch (fragment.type) {
108
- case 'aggregate':
109
- case 'all':
110
- case 'spread':
111
- case 'sql_expression':
112
- case 'exclude':
113
- return {
114
- ...fragment,
115
- e: exprMap(fragment.e, func),
116
- };
117
- case 'apply':
118
- return {
119
- ...fragment,
120
- to: exprMap(fragment.to, func),
121
- value: exprMap(fragment.value, func),
122
- };
123
- case 'applyVal':
124
- case 'field':
125
- case 'function_parameter':
126
- case 'parameter':
127
- case 'outputField':
128
- case 'source-reference':
129
- case 'aggregate_limit':
130
- case 'aggregate_order_by':
131
- return fragment;
132
- case 'sql-string':
133
- return {
134
- ...fragment,
135
- e: exprMap(fragment.e, func),
136
- };
137
- case 'function_call':
138
- return {
139
- ...fragment,
140
- args: fragment.args.map(arg => exprMap(arg, func)),
141
- };
142
- case 'filterExpression':
143
- return {
144
- ...fragment,
145
- e: exprMap(fragment.e, func),
146
- filterList: fragment.filterList.map(filter => {
147
- return {
148
- ...filter,
149
- expression: exprMap(filter.expression, func),
150
- };
151
- }),
152
- };
153
- case 'dialect': {
154
- switch (fragment.function) {
155
- case 'cast':
156
- case 'regexpMatch':
157
- return {
158
- ...fragment,
159
- expr: exprMap(fragment.expr, func),
160
- };
161
- case 'delta':
162
- return {
163
- ...fragment,
164
- delta: exprMap(fragment.delta, func),
165
- };
166
- case 'div':
167
- return {
168
- ...fragment,
169
- denominator: exprMap(fragment.denominator, func),
170
- numerator: exprMap(fragment.numerator, func),
171
- };
172
- case 'now':
173
- case 'numberLiteral':
174
- case 'stringLiteral':
175
- case 'timeLiteral':
176
- case 'regexpLiteral':
177
- return fragment;
178
- case 'extract':
179
- case 'trunc':
180
- return {
181
- ...fragment,
182
- expr: {
183
- ...fragment.expr,
184
- value: exprMap(fragment.expr.value, func),
185
- },
186
- };
187
- case 'timeDiff':
188
- return {
189
- ...fragment,
190
- left: {
191
- ...fragment.left,
192
- value: exprMap(fragment.left.value, func),
193
- },
194
- right: {
195
- ...fragment.right,
196
- value: exprMap(fragment.right.value, func),
197
- },
198
- };
199
- default:
200
- throw new Error('unexpected dialect function');
201
- }
202
- }
203
- default:
204
- throw new Error('unexpected');
205
- }
206
- });
207
- });
208
- }
209
- exports.exprMap = exprMap;
210
- function exprWalk(expr, func) {
211
- expr.forEach(fragment => {
212
- func(fragment);
213
- if (typeof fragment === 'string') {
214
- return fragment;
215
- }
216
- switch (fragment.type) {
217
- case 'aggregate':
218
- case 'all':
219
- case 'spread':
220
- case 'sql_expression':
221
- case 'exclude':
222
- return {
223
- ...fragment,
224
- e: exprWalk(fragment.e, func),
225
- };
226
- case 'apply':
227
- return {
228
- ...fragment,
229
- to: exprWalk(fragment.to, func),
230
- value: exprWalk(fragment.value, func),
231
- };
232
- case 'applyVal':
233
- case 'field':
234
- case 'function_parameter':
235
- case 'parameter':
236
- case 'outputField':
237
- case 'source-reference':
238
- case 'aggregate_limit':
239
- case 'aggregate_order_by':
240
- return fragment;
241
- case 'function_call':
242
- return {
243
- ...fragment,
244
- args: fragment.args.map(arg => exprWalk(arg, func)),
245
- };
246
- case 'sql-string':
247
- return {
248
- ...fragment,
249
- e: exprWalk(fragment.e, func),
250
- };
251
- case 'filterExpression':
252
- return {
253
- ...fragment,
254
- e: exprWalk(fragment.e, func),
255
- filterList: fragment.filterList.map(filter => {
256
- return {
257
- ...filter,
258
- expression: exprWalk(filter.expression, func),
259
- };
260
- }),
261
- };
262
- case 'dialect': {
263
- switch (fragment.function) {
264
- case 'cast':
265
- case 'regexpMatch':
266
- return {
267
- ...fragment,
268
- expr: exprWalk(fragment.expr, func),
269
- };
270
- case 'delta':
271
- return {
272
- ...fragment,
273
- delta: exprWalk(fragment.delta, func),
274
- };
275
- case 'div':
276
- return {
277
- ...fragment,
278
- denominator: exprWalk(fragment.denominator, func),
279
- numerator: exprWalk(fragment.numerator, func),
280
- };
281
- case 'now':
282
- case 'numberLiteral':
283
- case 'stringLiteral':
284
- case 'timeLiteral':
285
- case 'regexpLiteral':
286
- return fragment;
287
- case 'extract':
288
- case 'trunc':
289
- return {
290
- ...fragment,
291
- expr: {
292
- ...fragment.expr,
293
- value: exprWalk(fragment.expr.value, func),
294
- },
295
- };
296
- case 'timeDiff':
297
- return {
298
- ...fragment,
299
- left: {
300
- ...fragment.left,
301
- value: exprWalk(fragment.left.value, func),
302
- },
303
- right: {
304
- ...fragment.right,
305
- value: exprWalk(fragment.right.value, func),
306
- },
307
- };
308
- default:
309
- throw new Error('unexpected dialect function');
310
- }
311
- }
312
- default:
313
- throw new Error(`unexpected fragment type ${fragment.type}`);
314
- }
315
- });
316
- }
317
- exports.exprWalk = exprWalk;
318
101
  function joinWith(els, sep) {
319
102
  const result = [];
320
103
  for (let i = 0; i < els.length; i++) {
@@ -330,4 +113,86 @@ function range(start, end) {
330
113
  return Array.from({ length: end - start }, (_, index) => index + start);
331
114
  }
332
115
  exports.range = range;
116
+ function* exprKids(eNode) {
117
+ if ((0, malloy_types_1.exprHasKids)(eNode)) {
118
+ for (const kidEnt of Object.values(eNode.kids)) {
119
+ if (Array.isArray(kidEnt)) {
120
+ yield* kidEnt;
121
+ }
122
+ else {
123
+ yield kidEnt;
124
+ }
125
+ }
126
+ }
127
+ else if ((0, malloy_types_1.exprHasE)(eNode)) {
128
+ yield eNode.e;
129
+ }
130
+ }
131
+ exports.exprKids = exprKids;
132
+ function* exprWalk(eNode, order = 'post') {
133
+ if (order === 'pre') {
134
+ yield eNode;
135
+ }
136
+ for (const kid of exprKids(eNode)) {
137
+ yield* exprWalk(kid, order);
138
+ }
139
+ if (order === 'post') {
140
+ yield eNode;
141
+ }
142
+ }
143
+ exports.exprWalk = exprWalk;
144
+ function exprMap(eNode, mapFunc) {
145
+ let mapExpr = { ...eNode };
146
+ if ((0, malloy_types_1.exprHasKids)(eNode)) {
147
+ const parentNode = { ...eNode };
148
+ parentNode.kids = {};
149
+ for (const [name, kidEnt] of Object.entries(eNode.kids)) {
150
+ if (Array.isArray(kidEnt)) {
151
+ parentNode.kids[name] = kidEnt.map(kidEl => mapFunc(kidEl));
152
+ }
153
+ else {
154
+ parentNode.kids[name] = mapFunc(kidEnt);
155
+ }
156
+ }
157
+ mapExpr = parentNode;
158
+ }
159
+ if ((0, malloy_types_1.exprHasE)(mapExpr)) {
160
+ mapExpr.e = mapFunc(mapExpr.e);
161
+ }
162
+ return mapFunc(mapExpr);
163
+ }
164
+ exports.exprMap = exprMap;
165
+ /**
166
+ * Take a mixed array of strings and Expr and turn it into an SQLExpr
167
+ * expression node.
168
+ */
169
+ function composeSQLExpr(from) {
170
+ const ret = {
171
+ node: 'genericSQLExpr',
172
+ kids: { args: [] },
173
+ src: [],
174
+ };
175
+ // Build the array of alternating strings and expressions
176
+ let lastWasString = false;
177
+ for (const el of from) {
178
+ if (typeof el === 'string') {
179
+ if (lastWasString) {
180
+ ret.src[ret.src.length - 1] += el;
181
+ }
182
+ else {
183
+ ret.src.push(el);
184
+ }
185
+ lastWasString = true;
186
+ }
187
+ else {
188
+ if (!lastWasString) {
189
+ ret.src.push('');
190
+ }
191
+ ret.kids.args.push(el);
192
+ lastWasString = false;
193
+ }
194
+ }
195
+ return ret;
196
+ }
197
+ exports.composeSQLExpr = composeSQLExpr;
333
198
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.177-dev240828173040",
3
+ "version": "0.0.177-dev240829030921",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -1,11 +0,0 @@
1
- export declare enum Comparison {
2
- Like = "~",
3
- NotLike = "!~",
4
- LessThan = "<",
5
- LessThanOrEqualTo = "<=",
6
- EqualTo = "=",
7
- GreaterThan = ">",
8
- GreaterThanOrEqualTo = ">=",
9
- NotEqualTo = "!="
10
- }
11
- export declare function isComparison(s: string): s is Comparison;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2023 Google LLC
4
- *
5
- * Permission is hereby granted, free of charge, to any person obtaining
6
- * a copy of this software and associated documentation files
7
- * (the "Software"), to deal in the Software without restriction,
8
- * including without limitation the rights to use, copy, modify, merge,
9
- * publish, distribute, sublicense, and/or sell copies of the Software,
10
- * and to permit persons to whom the Software is furnished to do so,
11
- * subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be
14
- * included in all copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
- */
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.isComparison = exports.Comparison = void 0;
26
- var Comparison;
27
- (function (Comparison) {
28
- Comparison["Like"] = "~";
29
- Comparison["NotLike"] = "!~";
30
- Comparison["LessThan"] = "<";
31
- Comparison["LessThanOrEqualTo"] = "<=";
32
- Comparison["EqualTo"] = "=";
33
- Comparison["GreaterThan"] = ">";
34
- Comparison["GreaterThanOrEqualTo"] = ">=";
35
- Comparison["NotEqualTo"] = "!=";
36
- })(Comparison || (exports.Comparison = Comparison = {}));
37
- function isComparison(s) {
38
- return Object.values(Comparison).includes(s);
39
- }
40
- exports.isComparison = isComparison;
41
- //# sourceMappingURL=comparison.js.map
@@ -1,7 +0,0 @@
1
- export declare enum Equality {
2
- Like = "~",
3
- NotLike = "!~",
4
- Equals = "=",
5
- NotEquals = "!="
6
- }
7
- export declare function isEquality(s: string): s is Equality;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2023 Google LLC
4
- *
5
- * Permission is hereby granted, free of charge, to any person obtaining
6
- * a copy of this software and associated documentation files
7
- * (the "Software"), to deal in the Software without restriction,
8
- * including without limitation the rights to use, copy, modify, merge,
9
- * publish, distribute, sublicense, and/or sell copies of the Software,
10
- * and to permit persons to whom the Software is furnished to do so,
11
- * subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be
14
- * included in all copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
- */
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.isEquality = exports.Equality = void 0;
26
- var Equality;
27
- (function (Equality) {
28
- Equality["Like"] = "~";
29
- Equality["NotLike"] = "!~";
30
- Equality["Equals"] = "=";
31
- Equality["NotEquals"] = "!=";
32
- })(Equality || (exports.Equality = Equality = {}));
33
- function isEquality(s) {
34
- return Object.values(Equality).includes(s);
35
- }
36
- exports.isEquality = isEquality;
37
- //# sourceMappingURL=equality.js.map