@malloydata/malloy 0.0.142-dev240411154213 → 0.0.142-dev240413014741

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.
@@ -53,6 +53,8 @@ export declare abstract class Dialect {
53
53
  orderByClause: OrderByClauseType;
54
54
  nullMatchesFunctionSignature: boolean;
55
55
  supportsSelectReplace: boolean;
56
+ supportsComplexFilteredSources: boolean;
57
+ supportsTempTables: boolean;
56
58
  abstract getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
57
59
  abstract quoteTablePath(tablePath: string): string;
58
60
  abstract sqlGroupSetTable(groupSetCount: number): string;
@@ -94,6 +96,7 @@ export declare abstract class Dialect {
94
96
  sqlOrderBy(orderTerms: string[]): string;
95
97
  sqlTzStr(qi: QueryInfo): string;
96
98
  sqlMakeUnnestKey(key: string, rowKey: string): string;
99
+ sqlStringAggDistinct(distinctKey: string, valueSQL: string, separatorSQL: string): string;
97
100
  abstract sqlTypeToMalloyType(sqlType: string): FieldAtomicTypeDef | undefined;
98
101
  abstract malloyTypeToSQLType(malloyType: FieldAtomicTypeDef): string;
99
102
  abstract validateTypeName(sqlType: string): boolean;
@@ -74,6 +74,10 @@ class Dialect {
74
74
  this.nullMatchesFunctionSignature = true;
75
75
  // support select * replace(...)
76
76
  this.supportsSelectReplace = true;
77
+ // ability to join source with a filter on a joined source.
78
+ this.supportsComplexFilteredSources = true;
79
+ // can create temp tables
80
+ this.supportsTempTables = true;
77
81
  }
78
82
  sqlFinalStage(_lastStageName, _fields) {
79
83
  throw new Error('Dialect has no final Stage but called Anyway');
@@ -152,6 +156,17 @@ class Dialect {
152
156
  sqlMakeUnnestKey(key, rowKey) {
153
157
  return this.concat(key, "'x'", rowKey);
154
158
  }
159
+ // default implementation
160
+ sqlStringAggDistinct(distinctKey, valueSQL, separatorSQL) {
161
+ const keyStart = '__STRING_AGG_KS__';
162
+ const keyEnd = '__STRING_AGG_KE__';
163
+ const distinctValueSQL = `concat('${keyStart}', ${distinctKey}, '${keyEnd}', ${valueSQL})`;
164
+ return `REGEXP_REPLACE(
165
+ STRING_AGG(DISTINCT ${distinctValueSQL}${separatorSQL.length > 0 ? ',' + separatorSQL : ''}),
166
+ '${keyStart}.*?${keyEnd}',
167
+ ''
168
+ )`;
169
+ }
155
170
  }
156
171
  exports.Dialect = Dialect;
157
172
  //# sourceMappingURL=dialect.js.map
@@ -14,8 +14,7 @@ export interface DialectFunctionOverloadDef {
14
14
  } | undefined;
15
15
  }
16
16
  export declare function arg(name: string): Fragment;
17
- export declare function spread(f: Fragment): Fragment;
18
- export declare function spreadCast(f: Fragment, _destType: string): Fragment;
17
+ export declare function spread(f: Fragment, prefix?: string | undefined, suffix?: string | undefined): Fragment;
19
18
  /**
20
19
  * Prefer `sql` when possible.
21
20
  */
@@ -22,7 +22,7 @@
22
22
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.overload = exports.minAnalytic = exports.minAggregate = exports.minScalar = exports.maxAnalytic = exports.maxUngroupedAggregate = exports.anyExprType = exports.maxAggregate = exports.maxScalar = exports.makeParam = exports.param = exports.params = exports.literal = exports.output = exports.constant = exports.sql = exports.sqlFragment = exports.spreadCast = exports.spread = exports.arg = void 0;
25
+ exports.overload = exports.minAnalytic = exports.minAggregate = exports.minScalar = exports.maxAnalytic = exports.maxUngroupedAggregate = exports.anyExprType = exports.maxAggregate = exports.maxScalar = exports.makeParam = exports.param = exports.params = exports.literal = exports.output = exports.constant = exports.sql = exports.sqlFragment = exports.spread = exports.arg = void 0;
26
26
  function arg(name) {
27
27
  return {
28
28
  type: 'function_parameter',
@@ -30,22 +30,15 @@ function arg(name) {
30
30
  };
31
31
  }
32
32
  exports.arg = arg;
33
- function spread(f) {
33
+ function spread(f, prefix = undefined, suffix = undefined) {
34
34
  return {
35
35
  type: 'spread',
36
36
  e: [f],
37
+ prefix,
38
+ suffix,
37
39
  };
38
40
  }
39
41
  exports.spread = spread;
40
- // LTABB: this doesn't work, needs to be rewriten in terms of function parameters.
41
- function spreadCast(f, _destType) {
42
- return {
43
- type: 'spread',
44
- e: [f],
45
- // e: ['CAST(', f, `AS ${destType})`],
46
- };
47
- }
48
- exports.spreadCast = spreadCast;
49
42
  /**
50
43
  * Prefer `sql` when possible.
51
44
  */
@@ -0,0 +1,4 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare function fnChr(): DialectFunctionOverloadDef[];
3
+ export declare function fnAscii(): DialectFunctionOverloadDef[];
4
+ export declare function fnUnicode(): DialectFunctionOverloadDef[];
@@ -0,0 +1,45 @@
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.fnUnicode = exports.fnAscii = exports.fnChr = void 0;
26
+ const util_1 = require("../../functions/util");
27
+ function fnChr() {
28
+ return [
29
+ (0, util_1.overload)((0, util_1.minScalar)('string'), [(0, util_1.param)('value', (0, util_1.anyExprType)('number'))], (0, util_1.sql) `CASE WHEN ${(0, util_1.arg)('value')} = 0 THEN '' ELSE CHR(${(0, util_1.arg)('value')}) END`),
30
+ ];
31
+ }
32
+ exports.fnChr = fnChr;
33
+ function fnAscii() {
34
+ return [
35
+ (0, util_1.overload)((0, util_1.minScalar)('number'), [(0, util_1.param)('value', (0, util_1.anyExprType)('string'))], (0, util_1.sql) `CODEPOINT(NULLIF(CAST(${(0, util_1.arg)('value')} as VARCHAR(1)),''))`),
36
+ ];
37
+ }
38
+ exports.fnAscii = fnAscii;
39
+ function fnUnicode() {
40
+ return [
41
+ (0, util_1.overload)((0, util_1.minScalar)('number'), [(0, util_1.param)('value', (0, util_1.anyExprType)('string'))], (0, util_1.sql) `CODEPOINT(NULLIF(CAST(${(0, util_1.arg)('value')} as VARCHAR(1)),''))`),
42
+ ];
43
+ }
44
+ exports.fnUnicode = fnUnicode;
45
+ //# sourceMappingURL=chr.js.map
@@ -31,7 +31,7 @@ function fnConcat() {
31
31
  (0, util_1.overload)((0, util_1.minScalar)('string'), [], [{ type: 'dialect', function: 'stringLiteral', literal: '' }]),
32
32
  (0, util_1.overload)((0, util_1.minScalar)('string'), [
33
33
  (0, util_1.params)('values', (0, util_1.anyExprType)('string'), (0, util_1.anyExprType)('number'), (0, util_1.anyExprType)('date'), (0, util_1.anyExprType)('timestamp'), (0, util_1.anyExprType)('boolean')),
34
- ], (0, util_1.sql) `CONCAT(${(0, util_1.spreadCast)((0, util_1.arg)('values'), 'VARCHAR')})`),
34
+ ], (0, util_1.sql) `CONCAT(${(0, util_1.spread)((0, util_1.arg)('values'), 'CAST(', 'AS VARCHAR)')})`),
35
35
  ];
36
36
  }
37
37
  exports.fnConcat = fnConcat;
@@ -0,0 +1,2 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare function fnDiv(): DialectFunctionOverloadDef[];
@@ -0,0 +1,36 @@
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.fnDiv = void 0;
26
+ const util_1 = require("../../functions/util");
27
+ function fnDiv() {
28
+ return [
29
+ (0, util_1.overload)((0, util_1.minScalar)('number'), [
30
+ (0, util_1.param)('dividend', (0, util_1.anyExprType)('number')),
31
+ (0, util_1.param)('divisor', (0, util_1.anyExprType)('number')),
32
+ ], (0, util_1.sql) `FLOOR(${(0, util_1.arg)('dividend')} / ${(0, util_1.arg)('divisor')})`),
33
+ ];
34
+ }
35
+ exports.fnDiv = fnDiv;
36
+ //# sourceMappingURL=div.js.map
@@ -0,0 +1,2 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare function fnIsInf(): DialectFunctionOverloadDef[];
@@ -0,0 +1,33 @@
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.fnIsInf = void 0;
26
+ const util_1 = require("../../functions/util");
27
+ function fnIsInf() {
28
+ return [
29
+ (0, util_1.overload)((0, util_1.minScalar)('boolean'), [(0, util_1.param)('value', (0, util_1.anyExprType)('number'))], (0, util_1.sql) `COALESCE(IS_INFINITE(${(0, util_1.arg)('value')}), false)`),
30
+ ];
31
+ }
32
+ exports.fnIsInf = fnIsInf;
33
+ //# sourceMappingURL=is_inf.js.map
@@ -0,0 +1,2 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare function fnRepeat(): DialectFunctionOverloadDef[];
@@ -0,0 +1,35 @@
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.fnRepeat = void 0;
26
+ const util_1 = require("../../functions/util");
27
+ function fnRepeat() {
28
+ const value = (0, util_1.makeParam)('value', (0, util_1.anyExprType)('string'));
29
+ const count = (0, util_1.makeParam)('count', (0, util_1.anyExprType)('number'));
30
+ return [
31
+ (0, util_1.overload)((0, util_1.minScalar)('string'), [value.param, count.param], (0, util_1.sql) `ARRAY_JOIN(REPEAT(${value.arg}, CASE WHEN ${value.arg} IS NOT NULL THEN ${count.arg} END),'')`),
32
+ ];
33
+ }
34
+ exports.fnRepeat = fnRepeat;
35
+ //# sourceMappingURL=repeat.js.map
@@ -0,0 +1,2 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare function fnReverse(): DialectFunctionOverloadDef[];
@@ -0,0 +1,34 @@
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.fnReverse = void 0;
26
+ const util_1 = require("../../functions/util");
27
+ function fnReverse() {
28
+ const value = (0, util_1.makeParam)('value', (0, util_1.anyExprType)('string'));
29
+ return [
30
+ (0, util_1.overload)((0, util_1.minScalar)('string'), [value.param], (0, util_1.sql) `REVERSE(CAST(${value.arg} AS VARCHAR))`),
31
+ ];
32
+ }
33
+ exports.fnReverse = fnReverse;
34
+ //# sourceMappingURL=reverse.js.map
@@ -0,0 +1,3 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare function fnStartsWith(): DialectFunctionOverloadDef[];
3
+ export declare function fnEndsWith(): DialectFunctionOverloadDef[];
@@ -0,0 +1,43 @@
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.fnEndsWith = exports.fnStartsWith = void 0;
26
+ const util_1 = require("../../functions/util");
27
+ function fnStartsWith() {
28
+ const value = (0, util_1.makeParam)('value', (0, util_1.anyExprType)('string'));
29
+ const prefix = (0, util_1.makeParam)('prefix', (0, util_1.anyExprType)('string'));
30
+ return [
31
+ (0, util_1.overload)((0, util_1.minScalar)('boolean'), [value.param, prefix.param], (0, util_1.sql) `COALESCE(STARTS_WITH(${value.arg}, ${prefix.arg}), false)`),
32
+ ];
33
+ }
34
+ exports.fnStartsWith = fnStartsWith;
35
+ function fnEndsWith() {
36
+ const value = (0, util_1.makeParam)('value', (0, util_1.anyExprType)('string'));
37
+ const suffix = (0, util_1.makeParam)('suffix', (0, util_1.anyExprType)('string'));
38
+ return [
39
+ (0, util_1.overload)((0, util_1.minScalar)('boolean'), [value.param, suffix.param], (0, util_1.sql) `COALESCE(STARTS_WITH(REVERSE(CAST(${value.arg} AS VARCHAR)), REVERSE(CAST(${suffix.arg} AS VARCHAR))), false)`),
40
+ ];
41
+ }
42
+ exports.fnEndsWith = fnEndsWith;
43
+ //# sourceMappingURL=starts_ends_with.js.map
@@ -0,0 +1,3 @@
1
+ import { DialectFunctionOverloadDef } from '../../functions/util';
2
+ export declare function fnStringAgg(): DialectFunctionOverloadDef[];
3
+ export declare function fnStringAggDistinct(): DialectFunctionOverloadDef[];
@@ -0,0 +1,55 @@
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.fnStringAggDistinct = exports.fnStringAgg = void 0;
26
+ const util_1 = require("../../functions/util");
27
+ function fnStringAgg() {
28
+ const value = (0, util_1.makeParam)('value', (0, util_1.maxScalar)('string'));
29
+ const separator = (0, util_1.makeParam)('separator', (0, util_1.literal)((0, util_1.maxScalar)('string')));
30
+ const orderBy = {
31
+ type: 'aggregate_order_by',
32
+ prefix: '',
33
+ suffix: '',
34
+ };
35
+ return [
36
+ (0, util_1.overload)((0, util_1.minAggregate)('string'), [value.param], (0, util_1.sql) `ARRAY_JOIN(ARRAY_AGG(${value.arg} ${orderBy}), ',')`, { supportsOrderBy: true, supportsLimit: false }),
37
+ (0, util_1.overload)((0, util_1.minAggregate)('string'), [value.param, separator.param], (0, util_1.sql) `ARRAY_JOIN(ARRAY_AGG(${value.arg} ${orderBy}), ${separator.arg})`, { supportsOrderBy: true, supportsLimit: false }),
38
+ ];
39
+ }
40
+ exports.fnStringAgg = fnStringAgg;
41
+ function fnStringAggDistinct() {
42
+ const value = (0, util_1.makeParam)('value', (0, util_1.maxScalar)('string'));
43
+ const separator = (0, util_1.makeParam)('separator', (0, util_1.literal)((0, util_1.maxScalar)('string')));
44
+ const orderBy = {
45
+ type: 'aggregate_order_by',
46
+ prefix: '',
47
+ suffix: '',
48
+ };
49
+ return [
50
+ (0, util_1.overload)((0, util_1.minAggregate)('string'), [value.param], (0, util_1.sql) `ARRAY_JOIN(ARRAY_AGG(DISTINCT ${value.arg} ${orderBy}), ',')`, { supportsOrderBy: true, supportsLimit: false }),
51
+ (0, util_1.overload)((0, util_1.minAggregate)('string'), [value.param, separator.param], (0, util_1.sql) `ARRAY_JOIN(ARRAY_AGG(DISTINCT ${value.arg} ${orderBy}), ${separator.arg})`, { supportsOrderBy: true, supportsLimit: false }),
52
+ ];
53
+ }
54
+ exports.fnStringAggDistinct = fnStringAggDistinct;
55
+ //# sourceMappingURL=string_agg.js.map
@@ -27,13 +27,31 @@ const functions_1 = require("../../functions");
27
27
  const trunc_1 = require("./trunc");
28
28
  const log_1 = require("./log");
29
29
  const ifnull_1 = require("./ifnull");
30
+ const is_inf_1 = require("./is_inf");
30
31
  const concat_1 = require("./concat");
31
32
  const byte_length_1 = require("./byte_length");
33
+ const string_agg_1 = require("./string_agg");
34
+ const chr_1 = require("./chr");
35
+ const starts_ends_with_1 = require("./starts_ends_with");
36
+ const div_1 = require("./div");
37
+ const repeat_1 = require("./repeat");
38
+ const reverse_1 = require("./reverse");
32
39
  exports.TRINO_FUNCTIONS = functions_1.FUNCTIONS.clone();
33
40
  exports.TRINO_FUNCTIONS.add('trunc', trunc_1.fnTrunc);
34
41
  exports.TRINO_FUNCTIONS.add('log', log_1.fnLog);
35
42
  exports.TRINO_FUNCTIONS.add('ifnull', ifnull_1.fnIfnull);
43
+ exports.TRINO_FUNCTIONS.add('is_inf', is_inf_1.fnIsInf);
36
44
  exports.TRINO_FUNCTIONS.add('byte_length', byte_length_1.fnByteLength);
37
45
  exports.TRINO_FUNCTIONS.add('concat', concat_1.fnConcat);
46
+ exports.TRINO_FUNCTIONS.add('string_agg', string_agg_1.fnStringAgg);
47
+ exports.TRINO_FUNCTIONS.add('string_agg_distinct', string_agg_1.fnStringAggDistinct);
48
+ exports.TRINO_FUNCTIONS.add('div', div_1.fnDiv);
49
+ exports.TRINO_FUNCTIONS.add('starts_with', starts_ends_with_1.fnStartsWith);
50
+ exports.TRINO_FUNCTIONS.add('ends_with', starts_ends_with_1.fnEndsWith);
51
+ exports.TRINO_FUNCTIONS.add('chr', chr_1.fnChr);
52
+ exports.TRINO_FUNCTIONS.add('ascii', chr_1.fnAscii);
53
+ exports.TRINO_FUNCTIONS.add('unicode', chr_1.fnUnicode);
54
+ exports.TRINO_FUNCTIONS.add('repeat', repeat_1.fnRepeat);
55
+ exports.TRINO_FUNCTIONS.add('reverse', reverse_1.fnReverse);
38
56
  exports.TRINO_FUNCTIONS.seal();
39
57
  //# sourceMappingURL=trino_functions.js.map
@@ -24,6 +24,8 @@ export declare class TrinoDialect extends Dialect {
24
24
  orderByClause: OrderByClauseType;
25
25
  nullMatchesFunctionSignature: boolean;
26
26
  supportsSelectReplace: boolean;
27
+ supportsComplexFilteredSources: boolean;
28
+ supportsTempTables: boolean;
27
29
  quoteTablePath(tablePath: string): string;
28
30
  sqlGroupSetTable(groupSetCount: number): string;
29
31
  dialectExpr(qi: QueryInfo, df: DialectFragment): Expr;
@@ -61,5 +63,6 @@ export declare class TrinoDialect extends Dialect {
61
63
  castToString(expression: string): string;
62
64
  concat(...values: string[]): string;
63
65
  sqlMakeUnnestKey(key: string, rowKey: string): string;
66
+ sqlStringAggDistinct(distinctKey: string, valueSQL: string, separatorSQL: string): string;
64
67
  validateTypeName(sqlType: string): boolean;
65
68
  }
@@ -78,6 +78,8 @@ class TrinoDialect extends dialect_1.Dialect {
78
78
  this.orderByClause = 'output_name';
79
79
  this.nullMatchesFunctionSignature = false;
80
80
  this.supportsSelectReplace = false;
81
+ this.supportsComplexFilteredSources = false;
82
+ this.supportsTempTables = false;
81
83
  // TODO(figutierrez): update.
82
84
  this.keywords = `
83
85
  ALL
@@ -275,7 +277,7 @@ class TrinoDialect extends dialect_1.Dialect {
275
277
  if (fieldName === '__row_id') {
276
278
  return `__row_id_from_${alias}`;
277
279
  }
278
- return `${alias}.${fieldName}`;
280
+ return `${alias}.${this.sqlMaybeQuoteIdentifier(fieldName)}`;
279
281
  }
280
282
  sqlUnnestPipelineHead(isSingleton, sourceSQLExpression) {
281
283
  let p = sourceSQLExpression;
@@ -347,7 +349,7 @@ ${(0, utils_1.indent)(sql)}
347
349
  }
348
350
  }
349
351
  const extracted = (0, malloy_types_1.mkExpr) `EXTRACT(${pgUnits} FROM ${extractFrom})`;
350
- return units === 'day_of_week' ? (0, malloy_types_1.mkExpr) `(${extracted}+1)` : extracted;
352
+ return units === 'day_of_week' ? (0, malloy_types_1.mkExpr) `mod(${extracted}+1,7)` : extracted;
351
353
  }
352
354
  sqlAlterTime(op, expr, n, timeframe) {
353
355
  if (timeframe === 'quarter') {
@@ -433,10 +435,10 @@ ${(0, utils_1.indent)(sql)}
433
435
  sample = this.defaultSampling;
434
436
  }
435
437
  if ((0, malloy_types_1.isSamplingRows)(sample)) {
436
- throw new Error("StandardSQL doesn't support sampling by rows only percent");
438
+ throw new Error("Trino doesn't support sampling by rows only percent");
437
439
  }
438
440
  else if ((0, malloy_types_1.isSamplingPercent)(sample)) {
439
- return `(SELECT * FROM ${tableSQL} TABLESAMPLE SYSTEM (${sample.percent} PERCENT))`;
441
+ return `(SELECT * FROM ${tableSQL} TABLESAMPLE SYSTEM (${sample.percent}))`;
440
442
  }
441
443
  }
442
444
  return tableSQL;
@@ -478,6 +480,10 @@ ${(0, utils_1.indent)(sql)}
478
480
  sqlMakeUnnestKey(key, rowKey) {
479
481
  return `CAST(${key} as VARCHAR) || 'x' || CAST(${rowKey} as VARCHAR)`;
480
482
  }
483
+ sqlStringAggDistinct(distinctKey, valueSQL, separatorSQL) {
484
+ return `
485
+ ARRAY_JOIN(TRANSFORM(ARRAY_AGG(DISTINCT ARRAY[CAST(${valueSQL} AS VARCHAR),CAST(${distinctKey} as VARCHAR)]), x -> x[1]),${separatorSQL.length > 0 ? separatorSQL : "','"})`;
486
+ }
481
487
  validateTypeName(sqlType) {
482
488
  // Letters: BIGINT
483
489
  // Numbers: INT8
@@ -334,16 +334,9 @@ class QueryField extends QueryNode {
334
334
  }
335
335
  const valueSQL = this.generateDimFragment(resultSet, context, value, state);
336
336
  const separatorSQL = separator
337
- ? ' ,' + this.generateDimFragment(resultSet, context, separator, state)
337
+ ? this.generateDimFragment(resultSet, context, separator, state)
338
338
  : '';
339
- const keyStart = '__STRING_AGG_KS__';
340
- const keyEnd = '__STRING_AGG_KE__';
341
- const distinctValueSQL = `concat('${keyStart}', ${distinctKey}, '${keyEnd}', ${valueSQL})`;
342
- return `REGEXP_REPLACE(
343
- STRING_AGG(DISTINCT ${distinctValueSQL}${separatorSQL}),
344
- '${keyStart}.*?${keyEnd}',
345
- ''
346
- )`;
339
+ return this.parent.dialect.sqlStringAggDistinct(distinctKey, valueSQL, separatorSQL);
347
340
  }
348
341
  getParamForArgIndex(params, argIndex) {
349
342
  const prevVariadic = params.slice(0, argIndex).find(p => p.isVariadic);
@@ -1995,6 +1988,9 @@ class QueryQuery extends QueryField {
1995
1988
  s += ` ${matrixOperation} JOIN ${structSQL} AS ${ji.alias}\n ON ${onCondition}${filters}\n`;
1996
1989
  }
1997
1990
  else {
1991
+ if (!this.parent.dialect.supportsComplexFilteredSources) {
1992
+ throw new Error('Cannot join a source with a filter on a joined source');
1993
+ }
1998
1994
  let select = `SELECT ${ji.alias}.*`;
1999
1995
  let joins = '';
2000
1996
  for (const childJoin of ji.children) {
@@ -2503,7 +2499,7 @@ class QueryQuery extends QueryField {
2503
2499
  field instanceof FieldInstanceField &&
2504
2500
  field.fieldUsage.type === 'result') {
2505
2501
  dialectFieldList.push({
2506
- type: field.type,
2502
+ type: field.f.fieldDef.type,
2507
2503
  sqlExpression: field.f.generateExpression(resultStruct),
2508
2504
  rawName: name,
2509
2505
  sqlOutputName: sqlName,
@@ -152,6 +152,8 @@ export declare function isSQLExpressionFragment(f: Fragment): f is SQLExpression
152
152
  export interface SpreadFragment {
153
153
  type: 'spread';
154
154
  e: Expr;
155
+ prefix: string | undefined;
156
+ suffix: string | undefined;
155
157
  }
156
158
  export declare function isSpreadFragment(f: Fragment): f is SpreadFragment;
157
159
  export interface FieldFragment {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.142-dev240411154213",
3
+ "version": "0.0.142-dev240413014741",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",