@malloydata/malloy 0.0.183-dev240913195502 → 0.0.183-dev240917170343

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.
@@ -7,6 +7,11 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.DUCKDB_DIALECT_FUNCTIONS = void 0;
10
+ const dayname = {
11
+ takes: { 'date_value': ['date', 'timestamp'] },
12
+ returns: 'string',
13
+ impl: { function: 'DAYNAME' },
14
+ };
10
15
  const to_timestamp = {
11
16
  takes: { 'epoch_seconds': 'number' },
12
17
  returns: 'timestamp',
@@ -60,6 +65,7 @@ const string_agg_distinct = {
60
65
  };
61
66
  exports.DUCKDB_DIALECT_FUNCTIONS = {
62
67
  count_approx,
68
+ dayname,
63
69
  to_timestamp,
64
70
  string_agg,
65
71
  string_agg_distinct,
@@ -7,16 +7,79 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.TRINO_DIALECT_FUNCTIONS = void 0;
10
- const from_unixtime = {
11
- takes: { 'unixtime': 'number' },
12
- returns: 'timestamp',
13
- impl: { function: 'FROM_UNIXTIME' },
10
+ // Aggregate functions:
11
+ // TODO: Approx percentile can be called with a third argument; we probably
12
+ // want to implement that at some point
13
+ // In Presto, this is an "error" parameter between 0 and 1
14
+ // In Trino, this is a "weight" parameter between 1 and 99
15
+ const approx_percentile = {
16
+ takes: { 'value': 'number', 'percentage': 'number' },
17
+ returns: { measure: 'number' },
18
+ impl: {
19
+ function: 'APPROX_PERCENTILE',
20
+ },
21
+ };
22
+ const arbitrary = {
23
+ generic: ['T', ['string', 'number', 'date', 'timestamp', 'boolean', 'json']],
24
+ takes: { 'value': { dimension: { generic: 'T' } } },
25
+ returns: { measure: { generic: 'T' } },
26
+ impl: { function: 'ARBITRARY' },
27
+ };
28
+ const bitwise_and_agg = {
29
+ takes: { 'value': { dimension: 'number' } },
30
+ returns: { measure: 'number' },
31
+ impl: { function: 'BITWISE_OR_AGG' },
32
+ };
33
+ const bitwise_or_agg = {
34
+ takes: { 'value': { dimension: 'number' } },
35
+ returns: { measure: 'number' },
36
+ impl: { function: 'BITWISE_AND_AGG' },
37
+ };
38
+ const bitwise_xor_agg = {
39
+ takes: { 'value': { dimension: 'number' } },
40
+ returns: { measure: 'number' },
41
+ impl: { function: 'BITWISE_XOR_AGG' },
42
+ };
43
+ const bool_and = {
44
+ takes: { 'value': { dimension: 'boolean' } },
45
+ returns: { measure: 'boolean' },
46
+ impl: { function: 'BOOL_AND' },
47
+ };
48
+ const bool_or = {
49
+ takes: { 'value': { dimension: 'boolean' } },
50
+ returns: { measure: 'boolean' },
51
+ impl: { function: 'BOOL_OR' },
52
+ };
53
+ const corr = {
54
+ takes: { 'y': { dimension: 'number' }, 'x': { dimension: 'number' } },
55
+ returns: { measure: 'number' },
56
+ impl: {
57
+ sql: 'CORR(${y}, ${x})',
58
+ },
14
59
  };
15
60
  const count_approx = {
16
61
  takes: { 'value': { dimension: 'any' } },
17
62
  returns: { measure: 'number' },
18
63
  impl: { function: 'APPROX_DISTINCT' },
19
64
  };
65
+ const max_by = {
66
+ generic: ['T', ['string', 'number', 'date', 'timestamp', 'boolean', 'json']],
67
+ takes: {
68
+ 'value': { dimension: { generic: 'T' } },
69
+ 'order_by_val': { dimension: 'any' },
70
+ },
71
+ returns: { measure: { generic: 'T' } },
72
+ impl: { function: 'MAX_BY' },
73
+ };
74
+ const min_by = {
75
+ generic: ['T', ['string', 'number', 'date', 'timestamp', 'boolean', 'json']],
76
+ takes: {
77
+ 'value': { dimension: { generic: 'T' } },
78
+ 'order_by_val': { dimension: 'any' },
79
+ },
80
+ returns: { measure: { generic: 'T' } },
81
+ impl: { function: 'MIN_BY' },
82
+ };
20
83
  const string_agg = {
21
84
  default_separator: {
22
85
  takes: { 'value': { dimension: 'string' } },
@@ -54,10 +117,110 @@ const string_agg_distinct = {
54
117
  },
55
118
  },
56
119
  };
120
+ const variance = {
121
+ takes: { 'value': { dimension: 'number' } },
122
+ returns: { measure: 'number' },
123
+ impl: { function: 'VARIANCE' },
124
+ };
125
+ // Scalar functions
126
+ const bitwise_and = {
127
+ takes: { 'val1': 'number', 'val2': 'number' },
128
+ returns: 'number',
129
+ impl: {
130
+ function: 'BITWISE_AND',
131
+ },
132
+ };
133
+ const bitwise_or = {
134
+ takes: { 'val1': 'number', 'val2': 'number' },
135
+ returns: 'number',
136
+ impl: {
137
+ function: 'BITWISE_OR',
138
+ },
139
+ };
140
+ const date_format = {
141
+ takes: { 'ts_val': 'timestamp', 'format': 'string' },
142
+ returns: 'string',
143
+ impl: {
144
+ function: 'DATE_FORMAT',
145
+ },
146
+ };
147
+ const date_parse = {
148
+ takes: { 'ts_string': 'string', 'format': 'string' },
149
+ returns: 'timestamp',
150
+ impl: {
151
+ sql: 'DATE_PARSE(${ts_string}, ${format})',
152
+ },
153
+ };
154
+ const from_unixtime = {
155
+ takes: { 'unixtime': 'number' },
156
+ returns: 'timestamp',
157
+ impl: { function: 'FROM_UNIXTIME' },
158
+ };
159
+ // TODO: support Presto JSON types
160
+ // eventually, this should take 'json_val': ['string', 'json']
161
+ const json_extract_scalar = {
162
+ takes: { 'json_val': 'string', 'json_path': 'string' },
163
+ returns: 'string',
164
+ impl: { function: 'JSON_EXTRACT_SCALAR' },
165
+ };
166
+ const regexp_like = {
167
+ takes: { 'str': 'string', 'pattern': ['string', 'regular expression'] },
168
+ returns: 'boolean',
169
+ impl: { function: 'REGEXP_LIKE' },
170
+ };
171
+ const regexp_replace = {
172
+ remove_matches: {
173
+ takes: {
174
+ 'input_val': 'string',
175
+ 'regexp_pattern': ['string', 'regular expression'],
176
+ },
177
+ returns: 'string',
178
+ impl: {
179
+ function: 'REGEXP_REPLACE',
180
+ },
181
+ },
182
+ replace_matches: {
183
+ takes: {
184
+ 'input_val': 'string',
185
+ 'regexp_pattern': ['string', 'regular expression'],
186
+ 'replacement': 'string',
187
+ },
188
+ returns: 'string',
189
+ impl: {
190
+ function: 'REGEXP_REPLACE',
191
+ },
192
+ },
193
+ };
194
+ const to_unixtime = {
195
+ takes: { 'ts_val': 'timestamp' },
196
+ returns: 'number',
197
+ impl: { function: 'TO_UNIXTIME' },
198
+ };
57
199
  exports.TRINO_DIALECT_FUNCTIONS = {
200
+ // aggregate functions
201
+ approx_percentile,
202
+ arbitrary,
203
+ bitwise_and_agg,
204
+ bitwise_or_agg,
205
+ bitwise_xor_agg,
206
+ bool_and,
207
+ bool_or,
208
+ corr,
58
209
  count_approx,
59
- from_unixtime,
210
+ max_by,
211
+ min_by,
60
212
  string_agg,
61
213
  string_agg_distinct,
214
+ variance,
215
+ // scalar functions
216
+ bitwise_and,
217
+ bitwise_or,
218
+ date_format,
219
+ date_parse,
220
+ from_unixtime,
221
+ json_extract_scalar,
222
+ regexp_like,
223
+ regexp_replace,
224
+ to_unixtime,
62
225
  };
63
226
  //# sourceMappingURL=dialect_functions.js.map
@@ -263,8 +263,13 @@ function equality(fs, left, op, right) {
263
263
  case '~':
264
264
  case '!~': {
265
265
  if (lhs.dataType !== 'string' || rhs.dataType !== 'string') {
266
- const regexCmp = regexEqual(lhs, rhs);
267
- if (regexCmp === undefined) {
266
+ let regexCmp = regexEqual(lhs, rhs);
267
+ if (regexCmp) {
268
+ if (op[0] === '!') {
269
+ regexCmp = { node: 'not', e: { ...regexCmp } };
270
+ }
271
+ }
272
+ else {
268
273
  throw new TypeMismatch("Incompatible types for match('~') operator");
269
274
  }
270
275
  value = regexCmp;
@@ -112,6 +112,12 @@ describe('expressions', () => {
112
112
  test('not match', () => {
113
113
  expect("'forty-two' !~ 'fifty-four'").compilesTo('{"forty-two" !like "fifty-four"}');
114
114
  });
115
+ test('regexp-match', () => {
116
+ expect("'forty-two' ~ r'fifty-four'").compilesTo('{"forty-two" regex-match /fifty-four/}');
117
+ });
118
+ test('not regexp-match', () => {
119
+ expect("'forty-two' !~ r'fifty-four'").compilesTo('{not {"forty-two" regex-match /fifty-four/}}');
120
+ });
115
121
  test('apply as equality', () => {
116
122
  expect("'forty-two' ? 'fifty-four'").compilesTo('{"forty-two" = "fifty-four"}');
117
123
  });
@@ -161,6 +161,8 @@ function eToStr(e, symbols) {
161
161
  return `"${e.literal}"`;
162
162
  case 'timeLiteral':
163
163
  return `@${e.literal}`;
164
+ case 'regexpLiteral':
165
+ return `/${e.literal}/`;
164
166
  case 'trunc':
165
167
  return `{timeTrunc-${e.units} ${subExpr(e.e)}}`;
166
168
  case 'delta':
@@ -168,6 +170,8 @@ function eToStr(e, symbols) {
168
170
  case 'true':
169
171
  case 'false':
170
172
  return e.node;
173
+ case 'regexpMatch':
174
+ return `{${subExpr(e.kids.expr)} regex-match ${subExpr(e.kids.regex)}}`;
171
175
  }
172
176
  if ((0, model_1.exprHasKids)(e) && e.kids['left'] && e.kids['right']) {
173
177
  return `{${subExpr(e.kids['left'])} ${e.node} ${subExpr(e.kids['right'])}}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.183-dev240913195502",
3
+ "version": "0.0.183-dev240917170343",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",