@malloydata/malloy 0.0.224-dev241217194410 → 0.0.224

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 repeat = {
11
+ takes: { 'str': 'string', 'n': 'number' },
12
+ returns: 'string',
13
+ impl: { function: 'REPEAT' },
14
+ };
10
15
  const list_extract = {
11
16
  takes: { 'value': { array: { generic: 'T' } }, 'index': 'number' },
12
17
  generic: { 'T': ['any'] },
@@ -85,6 +90,7 @@ exports.DUCKDB_DIALECT_FUNCTIONS = {
85
90
  count_approx,
86
91
  dayname,
87
92
  to_timestamp,
93
+ repeat,
88
94
  string_agg,
89
95
  string_agg_distinct,
90
96
  to_seconds,
@@ -53,7 +53,7 @@ type Standard = {
53
53
  pow: D;
54
54
  rand: D;
55
55
  regexp_extract: D;
56
- repeat: D;
56
+ string_repeat: D;
57
57
  replace: {
58
58
  string: D;
59
59
  regular_expression: D;
@@ -190,7 +190,7 @@ const regexp_extract = {
190
190
  returns: 'string',
191
191
  impl: { function: 'REGEXP_EXTRACT' },
192
192
  };
193
- const repeat = {
193
+ const string_repeat = {
194
194
  takes: { 'value': 'string', 'count': 'number' },
195
195
  returns: 'string',
196
196
  impl: { function: 'REPEAT' },
@@ -559,7 +559,6 @@ exports.MALLOY_STANDARD_FUNCTIONS = {
559
559
  pow,
560
560
  rand,
561
561
  regexp_extract,
562
- repeat,
563
562
  replace,
564
563
  reverse,
565
564
  round,
@@ -568,6 +567,7 @@ exports.MALLOY_STANDARD_FUNCTIONS = {
568
567
  sin,
569
568
  sqrt,
570
569
  starts_with,
570
+ string_repeat,
571
571
  strpos,
572
572
  substr,
573
573
  tan,
@@ -7,6 +7,11 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.MYSQL_DIALECT_FUNCTIONS = void 0;
10
+ const repeat = {
11
+ takes: { 'str': 'string', 'n': 'number' },
12
+ returns: 'string',
13
+ impl: { function: 'REPEAT' },
14
+ };
10
15
  const string_agg = {
11
16
  default_separator: {
12
17
  takes: { 'value': { dimension: 'string' } },
@@ -47,5 +52,6 @@ const string_agg_distinct = {
47
52
  exports.MYSQL_DIALECT_FUNCTIONS = {
48
53
  string_agg,
49
54
  string_agg_distinct,
55
+ repeat,
50
56
  };
51
57
  //# sourceMappingURL=dialect_functions.js.map
@@ -7,6 +7,11 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.POSTGRES_DIALECT_FUNCTIONS = void 0;
10
+ const repeat = {
11
+ takes: { 'str': 'string', 'n': 'number' },
12
+ returns: 'string',
13
+ impl: { function: 'REPEAT' },
14
+ };
10
15
  const string_agg = {
11
16
  default_separator: {
12
17
  takes: { 'value': { dimension: 'string' } },
@@ -47,5 +52,6 @@ const string_agg_distinct = {
47
52
  exports.POSTGRES_DIALECT_FUNCTIONS = {
48
53
  string_agg,
49
54
  string_agg_distinct,
55
+ repeat,
50
56
  };
51
57
  //# sourceMappingURL=dialect_functions.js.map
@@ -8,6 +8,11 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.SNOWFLAKE_DIALECT_FUNCTIONS = void 0;
10
10
  const util_1 = require("../functions/util");
11
+ const repeat = {
12
+ takes: { 'str': 'string', 'n': 'number' },
13
+ returns: 'string',
14
+ impl: { function: 'REPEAT' },
15
+ };
11
16
  const order_by = {
12
17
  node: 'aggregate_order_by',
13
18
  prefix: ' WITHIN GROUP(',
@@ -53,5 +58,6 @@ const string_agg_distinct = {
53
58
  exports.SNOWFLAKE_DIALECT_FUNCTIONS = {
54
59
  string_agg,
55
60
  string_agg_distinct,
61
+ repeat,
56
62
  };
57
63
  //# sourceMappingURL=dialect_functions.js.map
@@ -7,6 +7,11 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.STANDARDSQL_DIALECT_FUNCTIONS = void 0;
10
+ const repeat = {
11
+ takes: { 'str': 'string', 'n': 'number' },
12
+ returns: 'string',
13
+ impl: { function: 'REPEAT' },
14
+ };
10
15
  const date_from_unix_date = {
11
16
  takes: { 'unix_date': 'number' },
12
17
  returns: 'date',
@@ -61,5 +66,6 @@ exports.STANDARDSQL_DIALECT_FUNCTIONS = {
61
66
  date_from_unix_date,
62
67
  string_agg,
63
68
  string_agg_distinct,
69
+ repeat,
64
70
  };
65
71
  //# sourceMappingURL=dialect_functions.js.map
@@ -1,2 +1,3 @@
1
1
  import { DefinitionBlueprintMap } from '../functions/util';
2
2
  export declare const TRINO_DIALECT_FUNCTIONS: DefinitionBlueprintMap;
3
+ export declare const PRESTO_DIALECT_FUNCTIONS: DefinitionBlueprintMap;
@@ -6,7 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.TRINO_DIALECT_FUNCTIONS = void 0;
9
+ exports.PRESTO_DIALECT_FUNCTIONS = exports.TRINO_DIALECT_FUNCTIONS = void 0;
10
+ const T = { generic: 'T' };
10
11
  // Aggregate functions:
11
12
  // TODO: Approx percentile can be called with a third argument; we probably
12
13
  // want to implement that at some point
@@ -21,8 +22,8 @@ const approx_percentile = {
21
22
  };
22
23
  const arbitrary = {
23
24
  generic: { 'T': ['string', 'number', 'date', 'timestamp', 'boolean', 'json'] },
24
- takes: { 'value': { dimension: { generic: 'T' } } },
25
- returns: { measure: { generic: 'T' } },
25
+ takes: { 'value': { dimension: T } },
26
+ returns: { measure: T },
26
27
  impl: { function: 'ARBITRARY' },
27
28
  };
28
29
  const bitwise_and_agg = {
@@ -123,20 +124,20 @@ const hll_import = {
123
124
  const max_by = {
124
125
  generic: { 'T': ['string', 'number', 'date', 'timestamp', 'boolean', 'json'] },
125
126
  takes: {
126
- 'value': { dimension: { generic: 'T' } },
127
+ 'value': { dimension: T },
127
128
  'order_by_val': { dimension: 'any' },
128
129
  },
129
- returns: { measure: { generic: 'T' } },
130
+ returns: { measure: T },
130
131
  impl: { function: 'MAX_BY' },
131
132
  isSymmetric: true,
132
133
  };
133
134
  const min_by = {
134
135
  generic: { 'T': ['string', 'number', 'date', 'timestamp', 'boolean', 'json'] },
135
136
  takes: {
136
- 'value': { dimension: { generic: 'T' } },
137
+ 'value': { dimension: T },
137
138
  'order_by_val': { dimension: 'any' },
138
139
  },
139
- returns: { measure: { generic: 'T' } },
140
+ returns: { measure: T },
140
141
  impl: { function: 'MIN_BY' },
141
142
  isSymmetric: true,
142
143
  };
@@ -296,10 +297,47 @@ const url_extract_query = {
296
297
  returns: 'string',
297
298
  impl: { function: 'URL_EXTRACT_QUERY' },
298
299
  };
299
- const split = {
300
- takes: { 'src': 'string', 'splitChar': 'string' },
301
- returns: { array: 'string' },
302
- impl: { function: 'SPLIT' },
300
+ const array_join = {
301
+ skip_nulls: {
302
+ takes: {
303
+ 'theArray': { array: T },
304
+ 'sep': 'string',
305
+ },
306
+ generic: { T: ['any'] },
307
+ returns: 'string',
308
+ impl: { function: 'ARRAY_JOIN' },
309
+ },
310
+ null_aware: {
311
+ takes: {
312
+ 'theArray': T,
313
+ 'sep': 'string',
314
+ 'nullStr': 'string',
315
+ },
316
+ generic: { T: ['any'] },
317
+ returns: 'string',
318
+ impl: { function: 'ARRAY_JOIN' },
319
+ },
320
+ };
321
+ const sequence = {
322
+ num_to_num: {
323
+ takes: { 'start': 'number', 'stop': 'number' },
324
+ generic: { 'T': ['any'] },
325
+ returns: { array: 'number' },
326
+ impl: { function: 'SEQUENCE' },
327
+ },
328
+ num_to_num_step: {
329
+ takes: { 'start': 'number', 'stop': 'number', 'step': 'number' },
330
+ generic: { 'T': ['any'] },
331
+ returns: { array: 'number' },
332
+ impl: { function: 'SEQUENCE' },
333
+ },
334
+ date_to_date: {
335
+ takes: { 'start': 'date', 'stop': 'date' },
336
+ generic: { 'T': ['any'] },
337
+ returns: { array: 'date' },
338
+ impl: { function: 'SEQUENCE' },
339
+ },
340
+ // mtoy todo document missing sequence
303
341
  };
304
342
  exports.TRINO_DIALECT_FUNCTIONS = {
305
343
  // aggregate functions
@@ -341,6 +379,121 @@ exports.TRINO_DIALECT_FUNCTIONS = {
341
379
  url_extract_query,
342
380
  // window functions
343
381
  percent_rank,
344
- split,
382
+ // array functions except those below
383
+ array_join,
384
+ sequence,
385
+ };
386
+ /**
387
+ * Lazy function to add wrapper blueprint definition for non overloaded functions
388
+ * which have generic array in their parameter list or return value
389
+ * @param name function name
390
+ * @param types list of types, last is return type
391
+ */
392
+ function define(name, takes, returns) {
393
+ const newDef = {
394
+ takes,
395
+ generic: { 'T': ['any'] },
396
+ returns,
397
+ impl: { function: name.toUpperCase() },
398
+ };
399
+ exports.TRINO_DIALECT_FUNCTIONS[name] = newDef;
400
+ }
401
+ define('array_distinct', { x: { array: T } }, { array: T });
402
+ define('array_except', { x: { array: T }, y: { array: T } }, { array: T });
403
+ define('array_intersect', { x: { array: T }, y: { array: T } }, { array: T });
404
+ define('array_max', { x: { array: T } }, T);
405
+ define('array_min', { x: { array: T } }, T);
406
+ define('array_normalize', { x: { array: T }, p: 'number' }, { array: T });
407
+ define('array_remove', { x: { array: T }, element: T }, { array: T });
408
+ // mtoy todo document missing lambda sort
409
+ define('array_sort', { x: { array: T } }, { array: T });
410
+ define('array_split_into_chunks', { x: { array: T }, n: 'number' }, { array: { array: T } });
411
+ define('arrays_overlap', { x: { array: T }, y: { array: T } }, 'boolean');
412
+ define('array_union', { x: { array: T }, y: { array: T } }, { array: T });
413
+ define('cardinality', { x: { array: T } }, 'number');
414
+ // mtoy todo move overload version?
415
+ // define('reverse', {x: {array: T}}, {array: T});
416
+ define('shuffle', { x: { array: T } }, { array: T });
417
+ define('combinations', { x: { array: T }, n: 'number' }, { array: { array: T } });
418
+ define('contains', { x: { array: T }, element: T }, 'boolean');
419
+ define('element_at', { x: { array: T }, oridnal: 'number' }, T);
420
+ // hard to believe, but this is what flatten does
421
+ define('flatten', { x: { array: { array: T } } }, { array: T });
422
+ define('ngrams', { x: { array: T }, n: 'number' }, { array: { array: T } });
423
+ define('repeat', { x: T, n: 'number' }, { array: T });
424
+ define('slice', { x: { array: T }, start: 'number', len: 'number' }, { array: T });
425
+ define('split', { to_split: 'string', seperator: 'string' }, { array: 'string' });
426
+ define('trim_array', { x: { array: T }, n: 'number' }, { array: T });
427
+ /******** Presto Only *********/
428
+ const array_position = {
429
+ first_instance: {
430
+ takes: { x: { array: T }, el: T },
431
+ generic: { T: ['any'] },
432
+ returns: 'number',
433
+ impl: { function: 'ARRAY_POSITION' },
434
+ },
435
+ nth_instance: {
436
+ takes: { x: { array: T }, el: T, instance: 'number' },
437
+ generic: { T: ['any'] },
438
+ returns: 'number',
439
+ impl: { function: 'ARRAY_POSITION' },
440
+ },
441
+ };
442
+ const array_intersect = {
443
+ two_arrays: {
444
+ takes: {
445
+ 'a': { array: T },
446
+ 'b': { array: T },
447
+ },
448
+ generic: { 'T': ['any'] },
449
+ returns: { array: T },
450
+ impl: { function: 'ARRAY_INTERSECT' },
451
+ },
452
+ nested_array: {
453
+ takes: { 'a': { array: { array: T } } },
454
+ generic: { 'T': ['any'] },
455
+ returns: { array: T },
456
+ impl: { function: 'ARRAY_INTERSECT' },
457
+ },
458
+ };
459
+ const array_least_frequent = {
460
+ array_only: {
461
+ takes: { 'theArray': { array: T } },
462
+ generic: { 'T': ['any'] },
463
+ returns: { array: T },
464
+ impl: { function: 'ARRAY_LEAST_FREQUENT' },
465
+ },
466
+ bottom: {
467
+ takes: {
468
+ 'theArray': { array: T },
469
+ 'count': 'number',
470
+ },
471
+ generic: { 'T': ['any'] },
472
+ returns: { array: T },
473
+ impl: { function: 'ARRAY_LEAST_FREQUENT' },
474
+ },
475
+ };
476
+ function def(name, takes, returns) {
477
+ const newDef = {
478
+ takes,
479
+ generic: { 'T': ['any'] },
480
+ returns,
481
+ impl: { function: name.toUpperCase() },
482
+ };
483
+ return { [name]: newDef };
484
+ }
485
+ exports.PRESTO_DIALECT_FUNCTIONS = {
486
+ ...exports.TRINO_DIALECT_FUNCTIONS,
487
+ array_intersect,
488
+ array_least_frequent,
489
+ array_position,
490
+ ...def('array_average', { x: { array: T } }, 'number'),
491
+ ...def('array_has_duplicates', { x: { array: T } }, 'boolean'),
492
+ ...def('array_cum_sum', { numeric_array: { array: T } }, { array: 'number' }),
493
+ ...def('array_duplicates', { x: { array: T } }, { array: T }),
494
+ ...def('array_sum', { x: { array: T } }, 'number'),
495
+ ...def('array_sort_desc', { x: { array: T } }, { array: T }),
496
+ ...def('remove_nulls', { x: { array: T } }, { array: T }),
497
+ ...def('array_top_n', { x: { array: T }, n: 'number' }, { array: T }),
345
498
  };
346
499
  //# sourceMappingURL=dialect_functions.js.map
@@ -25,7 +25,7 @@ exports.TRINO_MALLOY_STANDARD_OVERLOADS = {
25
25
  // Trino has it but Presto doesn't
26
26
  // TODO only apply this override for Presto, not Trino
27
27
  log: { sql: '(LN(${value}) / LN(${base}))' },
28
- repeat: {
28
+ string_repeat: {
29
29
  sql: "ARRAY_JOIN(REPEAT(${value}, CASE WHEN ${value} IS NOT NULL THEN ${count} END),'')",
30
30
  },
31
31
  reverse: {
@@ -81,4 +81,7 @@ export declare class PrestoDialect extends TrinoDialect {
81
81
  supportsLeftJoinUnnest: boolean;
82
82
  sqlGenerateUUID(): string;
83
83
  sqlUnnestAlias(source: string, alias: string, _fieldList: DialectFieldList, needDistinctKey: boolean, isArray: boolean, _isInNestedPipeline: boolean): string;
84
+ getDialectFunctions(): {
85
+ [name: string]: DialectFunctionOverloadDef[];
86
+ };
84
87
  }
@@ -576,6 +576,9 @@ class PrestoDialect extends TrinoDialect {
576
576
  return `CROSS JOIN UNNEST(COALESCE(${source}, ARRAY[NULL])) as ${alias}_outer(${alias})`;
577
577
  }
578
578
  }
579
+ getDialectFunctions() {
580
+ return (0, functions_1.expandBlueprintMap)(dialect_functions_1.PRESTO_DIALECT_FUNCTIONS);
581
+ }
579
582
  }
580
583
  exports.PrestoDialect = PrestoDialect;
581
584
  //# sourceMappingURL=trino.js.map
@@ -55,12 +55,12 @@ class ArrayLiteral extends expression_def_1.ExpressionDef {
55
55
  continue;
56
56
  }
57
57
  if (firstValue) {
58
- if (!TDU.typeEq(firstValue, v)) {
58
+ if (v.type !== 'null' && !TDU.typeEq(firstValue, v)) {
59
59
  nextElement.logError('array-values-incompatible', 'All array elements must be same type');
60
60
  continue;
61
61
  }
62
62
  }
63
- else {
63
+ else if (v.type !== 'null') {
64
64
  firstValue = v;
65
65
  }
66
66
  values.push(v.value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.224-dev241217194410",
3
+ "version": "0.0.224",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",