@malloydata/malloy 0.0.182-dev240911142514 → 0.0.182-dev240911163224
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/dialect/dialect.d.ts +3 -1
- package/dist/dialect/dialect_map.d.ts +1 -2
- package/dist/dialect/dialect_map.js +5 -74
- package/dist/dialect/duckdb/dialect_functions.d.ts +2 -0
- package/dist/dialect/duckdb/dialect_functions.js +67 -0
- package/dist/dialect/duckdb/duckdb.d.ts +3 -1
- package/dist/dialect/duckdb/duckdb.js +6 -5
- package/dist/dialect/duckdb/function_overrides.d.ts +2 -0
- package/dist/dialect/duckdb/function_overrides.js +55 -0
- package/dist/dialect/functions/index.d.ts +3 -1
- package/dist/dialect/functions/index.js +6 -3
- package/dist/dialect/functions/malloy_standard_functions.d.ts +134 -0
- package/dist/dialect/functions/malloy_standard_functions.js +612 -0
- package/dist/dialect/functions/util.d.ts +78 -2
- package/dist/dialect/functions/util.js +257 -3
- package/dist/dialect/index.d.ts +5 -4
- package/dist/dialect/index.js +3 -4
- package/dist/dialect/postgres/dialect_functions.d.ts +2 -0
- package/dist/dialect/postgres/dialect_functions.js +51 -0
- package/dist/dialect/postgres/function_overrides.d.ts +2 -0
- package/dist/dialect/postgres/function_overrides.js +73 -0
- package/dist/dialect/postgres/postgres.d.ts +3 -2
- package/dist/dialect/postgres/postgres.js +6 -6
- package/dist/dialect/snowflake/dialect_functions.d.ts +2 -0
- package/dist/dialect/snowflake/dialect_functions.js +57 -0
- package/dist/dialect/snowflake/function_overrides.d.ts +2 -0
- package/dist/dialect/snowflake/function_overrides.js +39 -0
- package/dist/dialect/snowflake/snowflake.d.ts +3 -2
- package/dist/dialect/snowflake/snowflake.js +6 -6
- package/dist/dialect/standardsql/dialect_functions.d.ts +2 -0
- package/dist/dialect/standardsql/dialect_functions.js +65 -0
- package/dist/dialect/standardsql/function_overrides.d.ts +2 -0
- package/dist/dialect/standardsql/function_overrides.js +17 -0
- package/dist/dialect/standardsql/standardsql.d.ts +3 -1
- package/dist/dialect/standardsql/standardsql.js +6 -5
- package/dist/dialect/trino/dialect_functions.d.ts +2 -0
- package/dist/dialect/trino/dialect_functions.js +63 -0
- package/dist/dialect/trino/function_overrides.d.ts +2 -0
- package/dist/dialect/trino/function_overrides.js +50 -0
- package/dist/dialect/trino/trino.d.ts +3 -1
- package/dist/dialect/trino/trino.js +6 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -4
- package/dist/lang/ast/expressions/expr-func.js +25 -29
- package/dist/lang/ast/types/dialect-name-space.js +5 -5
- package/dist/lang/ast/types/global-name-space.d.ts +4 -2
- package/dist/lang/ast/types/global-name-space.js +59 -6
- package/dist/model/malloy_query.d.ts +1 -1
- package/dist/model/malloy_query.js +7 -6
- package/dist/model/malloy_types.d.ts +7 -7
- package/package.json +1 -1
- package/dist/dialect/duckdb/functions/byte_length.d.ts +0 -2
- package/dist/dialect/duckdb/functions/byte_length.js +0 -33
- package/dist/dialect/duckdb/functions/count_approx.d.ts +0 -2
- package/dist/dialect/duckdb/functions/count_approx.js +0 -20
- package/dist/dialect/duckdb/functions/dialect_functions.d.ts +0 -4
- package/dist/dialect/duckdb/functions/dialect_functions.js +0 -16
- package/dist/dialect/duckdb/functions/div.d.ts +0 -2
- package/dist/dialect/duckdb/functions/div.js +0 -38
- package/dist/dialect/duckdb/functions/duckdb_functions.d.ts +0 -1
- package/dist/dialect/duckdb/functions/duckdb_functions.js +0 -54
- package/dist/dialect/duckdb/functions/ends_with.d.ts +0 -2
- package/dist/dialect/duckdb/functions/ends_with.js +0 -35
- package/dist/dialect/duckdb/functions/greatest_and_least.d.ts +0 -3
- package/dist/dialect/duckdb/functions/greatest_and_least.js +0 -51
- package/dist/dialect/duckdb/functions/index.d.ts +0 -1
- package/dist/dialect/duckdb/functions/index.js +0 -28
- package/dist/dialect/duckdb/functions/is_inf.d.ts +0 -2
- package/dist/dialect/duckdb/functions/is_inf.js +0 -33
- package/dist/dialect/duckdb/functions/is_nan.d.ts +0 -2
- package/dist/dialect/duckdb/functions/is_nan.js +0 -33
- package/dist/dialect/duckdb/functions/log.d.ts +0 -2
- package/dist/dialect/duckdb/functions/log.js +0 -38
- package/dist/dialect/duckdb/functions/rand.d.ts +0 -2
- package/dist/dialect/duckdb/functions/rand.js +0 -31
- package/dist/dialect/duckdb/functions/replace.d.ts +0 -2
- package/dist/dialect/duckdb/functions/replace.js +0 -40
- package/dist/dialect/duckdb/functions/trunc.d.ts +0 -2
- package/dist/dialect/duckdb/functions/trunc.js +0 -39
- package/dist/dialect/duckdb/functions/unicode.d.ts +0 -2
- package/dist/dialect/duckdb/functions/unicode.js +0 -35
- package/dist/dialect/functions/all_functions.d.ts +0 -8
- package/dist/dialect/functions/all_functions.js +0 -146
- package/dist/dialect/functions/atan2.d.ts +0 -2
- package/dist/dialect/functions/atan2.js +0 -33
- package/dist/dialect/functions/avg_moving.d.ts +0 -2
- package/dist/dialect/functions/avg_moving.js +0 -46
- package/dist/dialect/functions/chr.d.ts +0 -4
- package/dist/dialect/functions/chr.js +0 -45
- package/dist/dialect/functions/coalesce.d.ts +0 -2
- package/dist/dialect/functions/coalesce.js +0 -38
- package/dist/dialect/functions/concat.d.ts +0 -2
- package/dist/dialect/functions/concat.js +0 -38
- package/dist/dialect/functions/div.d.ts +0 -2
- package/dist/dialect/functions/div.js +0 -36
- package/dist/dialect/functions/first_value_window.d.ts +0 -3
- package/dist/dialect/functions/first_value_window.js +0 -49
- package/dist/dialect/functions/function_map.d.ts +0 -16
- package/dist/dialect/functions/function_map.js +0 -72
- package/dist/dialect/functions/greatest_and_least.d.ts +0 -3
- package/dist/dialect/functions/greatest_and_least.js +0 -44
- package/dist/dialect/functions/ifnull.d.ts +0 -2
- package/dist/dialect/functions/ifnull.js +0 -38
- package/dist/dialect/functions/is_inf.d.ts +0 -2
- package/dist/dialect/functions/is_inf.js +0 -33
- package/dist/dialect/functions/is_nan.d.ts +0 -2
- package/dist/dialect/functions/is_nan.js +0 -33
- package/dist/dialect/functions/lag.d.ts +0 -2
- package/dist/dialect/functions/lag.js +0 -53
- package/dist/dialect/functions/lead.d.ts +0 -2
- package/dist/dialect/functions/lead.js +0 -50
- package/dist/dialect/functions/length.d.ts +0 -3
- package/dist/dialect/functions/length.js +0 -40
- package/dist/dialect/functions/log.d.ts +0 -2
- package/dist/dialect/functions/log.js +0 -35
- package/dist/dialect/functions/lower.d.ts +0 -2
- package/dist/dialect/functions/lower.js +0 -34
- package/dist/dialect/functions/nullif.d.ts +0 -2
- package/dist/dialect/functions/nullif.js +0 -42
- package/dist/dialect/functions/pi.d.ts +0 -2
- package/dist/dialect/functions/pi.js +0 -31
- package/dist/dialect/functions/pow.d.ts +0 -2
- package/dist/dialect/functions/pow.js +0 -35
- package/dist/dialect/functions/rand.d.ts +0 -2
- package/dist/dialect/functions/rand.js +0 -31
- package/dist/dialect/functions/rank.d.ts +0 -2
- package/dist/dialect/functions/rank.js +0 -36
- package/dist/dialect/functions/regexp_extract.d.ts +0 -2
- package/dist/dialect/functions/regexp_extract.js +0 -41
- package/dist/dialect/functions/repeat.d.ts +0 -2
- package/dist/dialect/functions/repeat.js +0 -35
- package/dist/dialect/functions/replace.d.ts +0 -2
- package/dist/dialect/functions/replace.js +0 -42
- package/dist/dialect/functions/reverse.d.ts +0 -2
- package/dist/dialect/functions/reverse.js +0 -34
- package/dist/dialect/functions/round.d.ts +0 -2
- package/dist/dialect/functions/round.js +0 -40
- package/dist/dialect/functions/row_number.d.ts +0 -2
- package/dist/dialect/functions/row_number.js +0 -40
- package/dist/dialect/functions/simple_numeric_functions.d.ts +0 -15
- package/dist/dialect/functions/simple_numeric_functions.js +0 -60
- package/dist/dialect/functions/sql.d.ts +0 -6
- package/dist/dialect/functions/sql.js +0 -52
- package/dist/dialect/functions/starts_ends_with.d.ts +0 -3
- package/dist/dialect/functions/starts_ends_with.js +0 -43
- package/dist/dialect/functions/stddev.d.ts +0 -2
- package/dist/dialect/functions/stddev.js +0 -34
- package/dist/dialect/functions/string_agg.d.ts +0 -3
- package/dist/dialect/functions/string_agg.js +0 -55
- package/dist/dialect/functions/strpos.d.ts +0 -2
- package/dist/dialect/functions/strpos.js +0 -35
- package/dist/dialect/functions/substr.d.ts +0 -2
- package/dist/dialect/functions/substr.js +0 -37
- package/dist/dialect/functions/sum_min_max_window.d.ts +0 -7
- package/dist/dialect/functions/sum_min_max_window.js +0 -94
- package/dist/dialect/functions/sum_moving.d.ts +0 -2
- package/dist/dialect/functions/sum_moving.js +0 -43
- package/dist/dialect/functions/trim_functions.d.ts +0 -4
- package/dist/dialect/functions/trim_functions.js +0 -42
- package/dist/dialect/functions/trunc.d.ts +0 -2
- package/dist/dialect/functions/trunc.js +0 -38
- package/dist/dialect/functions/upper.d.ts +0 -2
- package/dist/dialect/functions/upper.js +0 -34
- package/dist/dialect/postgres/functions/byte_length.d.ts +0 -2
- package/dist/dialect/postgres/functions/byte_length.js +0 -33
- package/dist/dialect/postgres/functions/dialect_functions.d.ts +0 -4
- package/dist/dialect/postgres/functions/dialect_functions.js +0 -11
- package/dist/dialect/postgres/functions/ends_with.d.ts +0 -2
- package/dist/dialect/postgres/functions/ends_with.js +0 -38
- package/dist/dialect/postgres/functions/greatest_and_least.d.ts +0 -3
- package/dist/dialect/postgres/functions/greatest_and_least.js +0 -43
- package/dist/dialect/postgres/functions/ifnull.d.ts +0 -2
- package/dist/dialect/postgres/functions/ifnull.js +0 -40
- package/dist/dialect/postgres/functions/index.d.ts +0 -1
- package/dist/dialect/postgres/functions/index.js +0 -28
- package/dist/dialect/postgres/functions/is_inf.d.ts +0 -2
- package/dist/dialect/postgres/functions/is_inf.js +0 -34
- package/dist/dialect/postgres/functions/is_nan.d.ts +0 -2
- package/dist/dialect/postgres/functions/is_nan.js +0 -33
- package/dist/dialect/postgres/functions/log.d.ts +0 -2
- package/dist/dialect/postgres/functions/log.js +0 -37
- package/dist/dialect/postgres/functions/postgres_functions.d.ts +0 -1
- package/dist/dialect/postgres/functions/postgres_functions.js +0 -63
- package/dist/dialect/postgres/functions/rand.d.ts +0 -2
- package/dist/dialect/postgres/functions/rand.js +0 -31
- package/dist/dialect/postgres/functions/regexp_extract.d.ts +0 -2
- package/dist/dialect/postgres/functions/regexp_extract.js +0 -35
- package/dist/dialect/postgres/functions/replace.d.ts +0 -2
- package/dist/dialect/postgres/functions/replace.js +0 -40
- package/dist/dialect/postgres/functions/round.d.ts +0 -2
- package/dist/dialect/postgres/functions/round.js +0 -39
- package/dist/dialect/postgres/functions/stddev.d.ts +0 -2
- package/dist/dialect/postgres/functions/stddev.js +0 -37
- package/dist/dialect/postgres/functions/string_agg.d.ts +0 -3
- package/dist/dialect/postgres/functions/string_agg.js +0 -55
- package/dist/dialect/postgres/functions/substr.d.ts +0 -2
- package/dist/dialect/postgres/functions/substr.js +0 -38
- package/dist/dialect/postgres/functions/trunc.d.ts +0 -2
- package/dist/dialect/postgres/functions/trunc.js +0 -40
- package/dist/dialect/postgres/functions/unicode.d.ts +0 -2
- package/dist/dialect/postgres/functions/unicode.js +0 -34
- package/dist/dialect/snowflake/functions/chr.d.ts +0 -2
- package/dist/dialect/snowflake/functions/chr.js +0 -36
- package/dist/dialect/snowflake/functions/dialect_functions.d.ts +0 -4
- package/dist/dialect/snowflake/functions/dialect_functions.js +0 -11
- package/dist/dialect/snowflake/functions/div.d.ts +0 -2
- package/dist/dialect/snowflake/functions/div.js +0 -37
- package/dist/dialect/snowflake/functions/index.d.ts +0 -1
- package/dist/dialect/snowflake/functions/index.js +0 -28
- package/dist/dialect/snowflake/functions/is_inf.d.ts +0 -2
- package/dist/dialect/snowflake/functions/is_inf.js +0 -34
- package/dist/dialect/snowflake/functions/is_nan.d.ts +0 -2
- package/dist/dialect/snowflake/functions/is_nan.js +0 -33
- package/dist/dialect/snowflake/functions/length.d.ts +0 -3
- package/dist/dialect/snowflake/functions/length.js +0 -39
- package/dist/dialect/snowflake/functions/log.d.ts +0 -2
- package/dist/dialect/snowflake/functions/log.js +0 -37
- package/dist/dialect/snowflake/functions/rand.d.ts +0 -2
- package/dist/dialect/snowflake/functions/rand.js +0 -33
- package/dist/dialect/snowflake/functions/regexp_extract.d.ts +0 -2
- package/dist/dialect/snowflake/functions/regexp_extract.js +0 -35
- package/dist/dialect/snowflake/functions/snowflake_functions.d.ts +0 -1
- package/dist/dialect/snowflake/functions/snowflake_functions.js +0 -56
- package/dist/dialect/snowflake/functions/starts_ends_with.d.ts +0 -3
- package/dist/dialect/snowflake/functions/starts_ends_with.js +0 -43
- package/dist/dialect/snowflake/functions/string_agg.d.ts +0 -3
- package/dist/dialect/snowflake/functions/string_agg.js +0 -55
- package/dist/dialect/snowflake/functions/strpos.d.ts +0 -2
- package/dist/dialect/snowflake/functions/strpos.js +0 -35
- package/dist/dialect/snowflake/functions/trunc.d.ts +0 -2
- package/dist/dialect/snowflake/functions/trunc.js +0 -39
- package/dist/dialect/standardsql/functions/chr.d.ts +0 -2
- package/dist/dialect/standardsql/functions/chr.js +0 -37
- package/dist/dialect/standardsql/functions/dialect_functions.d.ts +0 -4
- package/dist/dialect/standardsql/functions/dialect_functions.js +0 -16
- package/dist/dialect/standardsql/functions/index.d.ts +0 -1
- package/dist/dialect/standardsql/functions/index.js +0 -28
- package/dist/dialect/standardsql/functions/pi.d.ts +0 -2
- package/dist/dialect/standardsql/functions/pi.js +0 -32
- package/dist/dialect/standardsql/functions/standardsql_functions.d.ts +0 -1
- package/dist/dialect/standardsql/functions/standardsql_functions.js +0 -36
- package/dist/dialect/standardsql/functions/string_agg.d.ts +0 -3
- package/dist/dialect/standardsql/functions/string_agg.js +0 -59
- package/dist/dialect/trino/functions/byte_length.d.ts +0 -2
- package/dist/dialect/trino/functions/byte_length.js +0 -33
- package/dist/dialect/trino/functions/chr.d.ts +0 -4
- package/dist/dialect/trino/functions/chr.js +0 -45
- package/dist/dialect/trino/functions/concat.d.ts +0 -2
- package/dist/dialect/trino/functions/concat.js +0 -38
- package/dist/dialect/trino/functions/count_approx.d.ts +0 -2
- package/dist/dialect/trino/functions/count_approx.js +0 -20
- package/dist/dialect/trino/functions/dialect_functions.d.ts +0 -4
- package/dist/dialect/trino/functions/dialect_functions.js +0 -16
- package/dist/dialect/trino/functions/div.d.ts +0 -2
- package/dist/dialect/trino/functions/div.js +0 -36
- package/dist/dialect/trino/functions/ifnull.d.ts +0 -2
- package/dist/dialect/trino/functions/ifnull.js +0 -40
- package/dist/dialect/trino/functions/index.d.ts +0 -1
- package/dist/dialect/trino/functions/index.js +0 -28
- package/dist/dialect/trino/functions/is_inf.d.ts +0 -2
- package/dist/dialect/trino/functions/is_inf.js +0 -33
- package/dist/dialect/trino/functions/log.d.ts +0 -2
- package/dist/dialect/trino/functions/log.js +0 -37
- package/dist/dialect/trino/functions/repeat.d.ts +0 -2
- package/dist/dialect/trino/functions/repeat.js +0 -35
- package/dist/dialect/trino/functions/reverse.d.ts +0 -2
- package/dist/dialect/trino/functions/reverse.js +0 -34
- package/dist/dialect/trino/functions/starts_ends_with.d.ts +0 -3
- package/dist/dialect/trino/functions/starts_ends_with.js +0 -43
- package/dist/dialect/trino/functions/string_agg.d.ts +0 -3
- package/dist/dialect/trino/functions/string_agg.js +0 -55
- package/dist/dialect/trino/functions/trino_functions.d.ts +0 -1
- package/dist/dialect/trino/functions/trino_functions.js +0 -59
- package/dist/dialect/trino/functions/trunc.d.ts +0 -2
- package/dist/dialect/trino/functions/trunc.js +0 -39
|
@@ -25,9 +25,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.SnowflakeDialect = void 0;
|
|
26
26
|
const utils_1 = require("../../model/utils");
|
|
27
27
|
const malloy_types_1 = require("../../model/malloy_types");
|
|
28
|
-
const functions_1 = require("
|
|
28
|
+
const functions_1 = require("../functions");
|
|
29
29
|
const dialect_1 = require("../dialect");
|
|
30
|
-
const dialect_functions_1 = require("./
|
|
30
|
+
const dialect_functions_1 = require("./dialect_functions");
|
|
31
|
+
const function_overrides_1 = require("./function_overrides");
|
|
31
32
|
const extractionMap = {
|
|
32
33
|
'day_of_week': 'dayofweek',
|
|
33
34
|
'day_of_year': 'dayofyear',
|
|
@@ -86,7 +87,6 @@ class SnowflakeDialect extends dialect_1.Dialect {
|
|
|
86
87
|
this.supportsSafeCast = true;
|
|
87
88
|
this.supportsNesting = true;
|
|
88
89
|
this.defaultSampling = { rows: 50000 };
|
|
89
|
-
this.globalFunctions = functions_1.SNOWFLAKE_FUNCTIONS;
|
|
90
90
|
// NOTE: safely setting all these to false for now
|
|
91
91
|
// more many be implemented in future
|
|
92
92
|
this.unnestWithNumbers = false;
|
|
@@ -366,11 +366,11 @@ ${(0, utils_1.indent)(sql)}
|
|
|
366
366
|
const noVirgule = literal.replace(/\\/g, '\\\\');
|
|
367
367
|
return "'" + noVirgule.replace(/'/g, "\\'") + "'";
|
|
368
368
|
}
|
|
369
|
-
|
|
370
|
-
return functions_1.
|
|
369
|
+
getDialectFunctionOverrides() {
|
|
370
|
+
return (0, functions_1.expandOverrideMap)(function_overrides_1.SNOWFLAKE_MALLOY_STANDARD_OVERLOADS);
|
|
371
371
|
}
|
|
372
372
|
getDialectFunctions() {
|
|
373
|
-
return dialect_functions_1.SNOWFLAKE_DIALECT_FUNCTIONS;
|
|
373
|
+
return (0, functions_1.expandBlueprintMap)(dialect_functions_1.SNOWFLAKE_DIALECT_FUNCTIONS);
|
|
374
374
|
}
|
|
375
375
|
malloyTypeToSQLType(malloyType) {
|
|
376
376
|
if (malloyType.type === 'number') {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.STANDARDSQL_DIALECT_FUNCTIONS = void 0;
|
|
10
|
+
const date_from_unix_date = {
|
|
11
|
+
takes: { 'unix_date': 'number' },
|
|
12
|
+
returns: 'date',
|
|
13
|
+
impl: { function: 'DATE_FROM_UNIX_DATE' },
|
|
14
|
+
};
|
|
15
|
+
const string_agg = {
|
|
16
|
+
'default_separator': {
|
|
17
|
+
takes: { 'value': { dimension: 'string' } },
|
|
18
|
+
returns: { measure: 'string' },
|
|
19
|
+
supportsOrderBy: true,
|
|
20
|
+
supportsLimit: true,
|
|
21
|
+
impl: {
|
|
22
|
+
sql: 'STRING_AGG(${value}${order_by:}${limit:})',
|
|
23
|
+
defaultOrderByArgIndex: 0,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
'with_separator': {
|
|
27
|
+
takes: {
|
|
28
|
+
'value': { dimension: 'string' },
|
|
29
|
+
'separator': { literal: 'string' },
|
|
30
|
+
},
|
|
31
|
+
returns: { measure: 'string' },
|
|
32
|
+
supportsOrderBy: true,
|
|
33
|
+
supportsLimit: true,
|
|
34
|
+
impl: {
|
|
35
|
+
sql: 'STRING_AGG(${value}, ${separator}${order_by:}${limit:})',
|
|
36
|
+
defaultOrderByArgIndex: 0,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
const string_agg_distinct = {
|
|
41
|
+
'default_separator': {
|
|
42
|
+
...string_agg['default_separator'],
|
|
43
|
+
isSymmetric: true,
|
|
44
|
+
supportsOrderBy: 'only_default',
|
|
45
|
+
impl: {
|
|
46
|
+
sql: 'STRING_AGG(DISTINCT ${value}${order_by:}${limit:})',
|
|
47
|
+
defaultOrderByArgIndex: 0,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
'with_separator': {
|
|
51
|
+
...string_agg['with_separator'],
|
|
52
|
+
isSymmetric: true,
|
|
53
|
+
supportsOrderBy: 'only_default',
|
|
54
|
+
impl: {
|
|
55
|
+
sql: 'STRING_AGG(DISTINCT ${value}, ${separator}${order_by:}${limit:})',
|
|
56
|
+
defaultOrderByArgIndex: 0,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
exports.STANDARDSQL_DIALECT_FUNCTIONS = {
|
|
61
|
+
date_from_unix_date,
|
|
62
|
+
string_agg,
|
|
63
|
+
string_agg_distinct,
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=dialect_functions.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.STANDARDSQL_MALLOY_STANDARD_OVERLOADS = void 0;
|
|
10
|
+
exports.STANDARDSQL_MALLOY_STANDARD_OVERLOADS = {
|
|
11
|
+
chr: {
|
|
12
|
+
sql: "CASE WHEN IFNULL(${value}, 1) = 0 THEN '' ELSE CHR(${value}) END",
|
|
13
|
+
},
|
|
14
|
+
// There's no built-in PI function, but we can compute it easily.
|
|
15
|
+
pi: { sql: 'ACOS(-1)' },
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=function_overrides.js.map
|
|
@@ -53,7 +53,9 @@ export declare class StandardSQLDialect extends Dialect {
|
|
|
53
53
|
sqlSampleTable(tableSQL: string, sample: Sampling | undefined): string;
|
|
54
54
|
sqlLiteralString(literal: string): string;
|
|
55
55
|
sqlLiteralRegexp(literal: string): string;
|
|
56
|
-
|
|
56
|
+
getDialectFunctionOverrides(): {
|
|
57
|
+
[name: string]: DialectFunctionOverloadDef[];
|
|
58
|
+
};
|
|
57
59
|
getDialectFunctions(): {
|
|
58
60
|
[name: string]: DialectFunctionOverloadDef[];
|
|
59
61
|
};
|
|
@@ -25,9 +25,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.StandardSQLDialect = void 0;
|
|
26
26
|
const utils_1 = require("../../model/utils");
|
|
27
27
|
const malloy_types_1 = require("../../model/malloy_types");
|
|
28
|
-
const functions_1 = require("
|
|
28
|
+
const functions_1 = require("../functions");
|
|
29
29
|
const dialect_1 = require("../dialect");
|
|
30
|
-
const dialect_functions_1 = require("./
|
|
30
|
+
const dialect_functions_1 = require("./dialect_functions");
|
|
31
|
+
const function_overrides_1 = require("./function_overrides");
|
|
31
32
|
// These are the units that "TIMESTAMP_ADD" "TIMESTAMP_DIFF" accept
|
|
32
33
|
function timestampMeasureable(units) {
|
|
33
34
|
return [
|
|
@@ -441,11 +442,11 @@ ${(0, utils_1.indent)(sql)}
|
|
|
441
442
|
const noVirgule = literal.replace(/\\/g, '\\\\');
|
|
442
443
|
return "'" + noVirgule.replace(/'/g, "\\'") + "'";
|
|
443
444
|
}
|
|
444
|
-
|
|
445
|
-
return functions_1.
|
|
445
|
+
getDialectFunctionOverrides() {
|
|
446
|
+
return (0, functions_1.expandOverrideMap)(function_overrides_1.STANDARDSQL_MALLOY_STANDARD_OVERLOADS);
|
|
446
447
|
}
|
|
447
448
|
getDialectFunctions() {
|
|
448
|
-
return dialect_functions_1.STANDARDSQL_DIALECT_FUNCTIONS;
|
|
449
|
+
return (0, functions_1.expandBlueprintMap)(dialect_functions_1.STANDARDSQL_DIALECT_FUNCTIONS);
|
|
449
450
|
}
|
|
450
451
|
malloyTypeToSQLType(malloyType) {
|
|
451
452
|
if (malloyType.type === 'number') {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TRINO_DIALECT_FUNCTIONS = void 0;
|
|
10
|
+
const from_unixtime = {
|
|
11
|
+
takes: { 'unixtime': 'number' },
|
|
12
|
+
returns: 'timestamp',
|
|
13
|
+
impl: { function: 'FROM_UNIXTIME' },
|
|
14
|
+
};
|
|
15
|
+
const count_approx = {
|
|
16
|
+
takes: { 'value': { dimension: 'any' } },
|
|
17
|
+
returns: { measure: 'number' },
|
|
18
|
+
impl: { function: 'APPROX_DISTINCT' },
|
|
19
|
+
};
|
|
20
|
+
const string_agg = {
|
|
21
|
+
default_separator: {
|
|
22
|
+
takes: { 'value': { dimension: 'string' } },
|
|
23
|
+
returns: { measure: 'string' },
|
|
24
|
+
supportsOrderBy: true,
|
|
25
|
+
impl: {
|
|
26
|
+
sql: "ARRAY_JOIN(ARRAY_AGG(${value} ${order_by:}), ',')",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
with_separator: {
|
|
30
|
+
takes: {
|
|
31
|
+
'value': { dimension: 'string' },
|
|
32
|
+
'separator': { literal: 'string' },
|
|
33
|
+
},
|
|
34
|
+
returns: { measure: 'string' },
|
|
35
|
+
supportsOrderBy: true,
|
|
36
|
+
impl: {
|
|
37
|
+
sql: 'ARRAY_JOIN(ARRAY_AGG(${value} ${order_by:}), ${separator})',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const string_agg_distinct = {
|
|
42
|
+
default_separator: {
|
|
43
|
+
...string_agg['default_separator'],
|
|
44
|
+
isSymmetric: true,
|
|
45
|
+
impl: {
|
|
46
|
+
sql: "ARRAY_JOIN(ARRAY_AGG(DISTINCT ${value} ${order_by:}), ',')",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
with_separator: {
|
|
50
|
+
...string_agg['with_separator'],
|
|
51
|
+
isSymmetric: true,
|
|
52
|
+
impl: {
|
|
53
|
+
sql: 'ARRAY_JOIN(ARRAY_AGG(DISTINCT ${value} ${order_by:}), ${separator})',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
exports.TRINO_DIALECT_FUNCTIONS = {
|
|
58
|
+
count_approx,
|
|
59
|
+
from_unixtime,
|
|
60
|
+
string_agg,
|
|
61
|
+
string_agg_distinct,
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=dialect_functions.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TRINO_MALLOY_STANDARD_OVERLOADS = void 0;
|
|
10
|
+
const util_1 = require("../functions/util");
|
|
11
|
+
exports.TRINO_MALLOY_STANDARD_OVERLOADS = {
|
|
12
|
+
byte_length: { sql: '(LENGTH(CAST(${value} AS VARBINARY)))' },
|
|
13
|
+
chr: { sql: "CASE WHEN ${value} = 0 THEN '' ELSE CHR(${value}) END" },
|
|
14
|
+
ascii: { sql: "CODEPOINT(NULLIF(CAST(${value} as VARCHAR(1)),''))" },
|
|
15
|
+
unicode: { sql: "CODEPOINT(NULLIF(CAST(${value} as VARCHAR(1)),''))" },
|
|
16
|
+
concat: {
|
|
17
|
+
variadic: {
|
|
18
|
+
// Using `expr` definition because each spread argument needs to be cast
|
|
19
|
+
expr: (0, util_1.sql) `CONCAT(${(0, util_1.spread)((0, util_1.arg)('values'), 'CAST(', 'AS VARCHAR)')})`,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
div: { sql: 'FLOOR(${dividend} / ${divisor})' },
|
|
23
|
+
ifnull: { sql: 'COALESCE(${value}, ${default})' },
|
|
24
|
+
is_inf: { sql: 'COALESCE(IS_INFINITE(${value}), false)' },
|
|
25
|
+
// Trino has it but Presto doesn't
|
|
26
|
+
// TODO only apply this override for Presto, not Trino
|
|
27
|
+
log: { sql: '(LN(${value}) / LN(${base}))' },
|
|
28
|
+
repeat: {
|
|
29
|
+
sql: "ARRAY_JOIN(REPEAT(${value}, CASE WHEN ${value} IS NOT NULL THEN ${count} END),'')",
|
|
30
|
+
},
|
|
31
|
+
reverse: {
|
|
32
|
+
sql: 'REVERSE(CAST(${value} AS VARCHAR))',
|
|
33
|
+
},
|
|
34
|
+
starts_with: { sql: 'COALESCE(STARTS_WITH(${value}, ${prefix}), false)' },
|
|
35
|
+
ends_with: {
|
|
36
|
+
sql: 'COALESCE(STARTS_WITH(REVERSE(CAST(${value} AS VARCHAR)), REVERSE(CAST(${suffix} AS VARCHAR))), false)',
|
|
37
|
+
},
|
|
38
|
+
// Trunc function doesn't exist in Trino, so we emulate it.
|
|
39
|
+
// For both overloads, we switch between CEIL and FLOOR based on the sign of the arugment
|
|
40
|
+
// For the overload with precision, we multiply by a power of 10 before rounding, then divide.
|
|
41
|
+
trunc: {
|
|
42
|
+
to_integer: {
|
|
43
|
+
sql: 'CASE WHEN ${value} < 0 THEN CEIL(${value}) ELSE FLOOR(${value}) END',
|
|
44
|
+
},
|
|
45
|
+
to_precision: {
|
|
46
|
+
sql: 'CASE WHEN ${value} < 0 THEN CEIL(${value} * POW(10, ${precision})) / POW(10, ${precision}) ELSE FLOOR(${value} * POW(10, ${precision})) / POW(10, ${precision}) END',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=function_overrides.js.map
|
|
@@ -58,7 +58,9 @@ export declare class TrinoDialect extends PostgresBase {
|
|
|
58
58
|
sqlSampleTable(tableSQL: string, sample: Sampling | undefined): string;
|
|
59
59
|
sqlLiteralString(literal: string): string;
|
|
60
60
|
sqlLiteralRegexp(literal: string): string;
|
|
61
|
-
|
|
61
|
+
getDialectFunctionOverrides(): {
|
|
62
|
+
[name: string]: DialectFunctionOverloadDef[];
|
|
63
|
+
};
|
|
62
64
|
getDialectFunctions(): {
|
|
63
65
|
[name: string]: DialectFunctionOverloadDef[];
|
|
64
66
|
};
|
|
@@ -25,10 +25,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.PrestoDialect = exports.TrinoDialect = void 0;
|
|
26
26
|
const utils_1 = require("../../model/utils");
|
|
27
27
|
const malloy_types_1 = require("../../model/malloy_types");
|
|
28
|
-
const functions_1 = require("
|
|
28
|
+
const functions_1 = require("../functions");
|
|
29
29
|
const dialect_1 = require("../dialect");
|
|
30
30
|
const pg_impl_1 = require("../pg_impl");
|
|
31
|
-
const dialect_functions_1 = require("./
|
|
31
|
+
const dialect_functions_1 = require("./dialect_functions");
|
|
32
|
+
const function_overrides_1 = require("./function_overrides");
|
|
32
33
|
// These are the units that "TIMESTAMP_ADD" "TIMESTAMP_DIFF" accept
|
|
33
34
|
function timestampMeasureable(units) {
|
|
34
35
|
return [
|
|
@@ -417,12 +418,11 @@ ${(0, utils_1.indent)(sql)}
|
|
|
417
418
|
sqlLiteralRegexp(literal) {
|
|
418
419
|
return "'" + literal.replace(/'/g, "''") + "'";
|
|
419
420
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return functions_1.TRINO_FUNCTIONS.get(name);
|
|
421
|
+
getDialectFunctionOverrides() {
|
|
422
|
+
return (0, functions_1.expandOverrideMap)(function_overrides_1.TRINO_MALLOY_STANDARD_OVERLOADS);
|
|
423
423
|
}
|
|
424
424
|
getDialectFunctions() {
|
|
425
|
-
return dialect_functions_1.TRINO_DIALECT_FUNCTIONS;
|
|
425
|
+
return (0, functions_1.expandBlueprintMap)(dialect_functions_1.TRINO_DIALECT_FUNCTIONS);
|
|
426
426
|
}
|
|
427
427
|
malloyTypeToSQLType(malloyType) {
|
|
428
428
|
if (malloyType.type === 'number') {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { DuckDBDialect, StandardSQLDialect, PostgresDialect, SnowflakeDialect, registerDialect, arg, qtz, overload, minScalar, anyExprType, minAggregate, maxScalar, sql, makeParam, param,
|
|
2
|
-
export type { DialectFieldList, DialectFunctionOverloadDef, QueryInfo, } from './dialect';
|
|
1
|
+
export { DuckDBDialect, StandardSQLDialect, PostgresDialect, SnowflakeDialect, registerDialect, arg, qtz, overload, minScalar, anyExprType, minAggregate, maxScalar, sql, makeParam, param, variadicParam, literal, spread, Dialect, } from './dialect';
|
|
2
|
+
export type { DialectFieldList, DialectFunctionOverloadDef, QueryInfo, MalloyStandardFunctionImplementations, DefinitionBlueprint, DefinitionBlueprintMap, OverloadedDefinitionBlueprint, } from './dialect';
|
|
3
3
|
export type { QueryDataRow, StructDef, StructRelationship, NamedStructDefs, MalloyQueryData, AtomicFieldType as AtomicFieldTypeInner, DateUnit, ExtractUnit, TimestampUnit, TimeFieldType, QueryData, QueryValue, FieldTypeDef, Expr, FilterCondition, SQLBlock, FieldAtomicDef, FieldDef, PipeSegment, QueryFieldDef, IndexFieldDef, TurtleDef, SearchValueMapResult, SearchIndexResult, ModelDef, Query, QueryResult, QueryRunStats, NamedQuery, NamedModelObject, ExpressionType, FunctionDef, FunctionOverloadDef, FunctionParameterDef, ExpressionValueType, TypeDesc, FieldValueType, ExpressionTypeDesc, FunctionParamTypeDesc, DocumentLocation, DocumentRange, DocumentPosition, Sampling, Annotation, FieldAtomicTypeDef, SQLBlockStructDef, } from './model';
|
|
4
4
|
export { Segment, isSamplingEnable, isSamplingPercent, isSamplingRows, expressionIsCalculation, indent, composeSQLExpr, } from './model';
|
|
5
5
|
export { MalloyTranslator, } from './lang';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Explore = exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.Result = exports.PreparedResult = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = exports.Malloy = exports.Model = exports.MalloyTranslator = exports.composeSQLExpr = exports.indent = exports.expressionIsCalculation = exports.isSamplingRows = exports.isSamplingPercent = exports.isSamplingEnable = exports.Segment = exports.
|
|
4
|
-
exports.Tag =
|
|
3
|
+
exports.toAsyncGenerator = exports.Explore = exports.DataWriter = exports.Parse = exports.JSONWriter = exports.CSVWriter = exports.QueryMaterializer = exports.Result = exports.PreparedResult = exports.TimestampTimeframe = exports.DateTimeframe = exports.SourceRelationship = exports.JoinRelationship = exports.MalloyError = exports.FixedConnectionMap = exports.InMemoryURLReader = exports.EmptyURLReader = exports.SingleConnectionRuntime = exports.ConnectionRuntime = exports.AtomicFieldType = exports.Runtime = exports.Malloy = exports.Model = exports.MalloyTranslator = exports.composeSQLExpr = exports.indent = exports.expressionIsCalculation = exports.isSamplingRows = exports.isSamplingPercent = exports.isSamplingEnable = exports.Segment = exports.Dialect = exports.spread = exports.literal = exports.variadicParam = exports.param = exports.makeParam = exports.sql = exports.maxScalar = exports.minAggregate = exports.anyExprType = exports.minScalar = exports.overload = exports.qtz = exports.arg = exports.registerDialect = exports.SnowflakeDialect = exports.PostgresDialect = exports.StandardSQLDialect = exports.DuckDBDialect = void 0;
|
|
4
|
+
exports.Tag = void 0;
|
|
5
5
|
/*
|
|
6
6
|
* Copyright 2023 Google LLC
|
|
7
7
|
*
|
|
@@ -40,11 +40,10 @@ Object.defineProperty(exports, "maxScalar", { enumerable: true, get: function ()
|
|
|
40
40
|
Object.defineProperty(exports, "sql", { enumerable: true, get: function () { return dialect_1.sql; } });
|
|
41
41
|
Object.defineProperty(exports, "makeParam", { enumerable: true, get: function () { return dialect_1.makeParam; } });
|
|
42
42
|
Object.defineProperty(exports, "param", { enumerable: true, get: function () { return dialect_1.param; } });
|
|
43
|
-
Object.defineProperty(exports, "
|
|
43
|
+
Object.defineProperty(exports, "variadicParam", { enumerable: true, get: function () { return dialect_1.variadicParam; } });
|
|
44
44
|
Object.defineProperty(exports, "literal", { enumerable: true, get: function () { return dialect_1.literal; } });
|
|
45
45
|
Object.defineProperty(exports, "spread", { enumerable: true, get: function () { return dialect_1.spread; } });
|
|
46
46
|
Object.defineProperty(exports, "Dialect", { enumerable: true, get: function () { return dialect_1.Dialect; } });
|
|
47
|
-
Object.defineProperty(exports, "FUNCTIONS", { enumerable: true, get: function () { return dialect_1.FUNCTIONS; } });
|
|
48
47
|
var model_1 = require("./model");
|
|
49
48
|
// Used in Composer Demo
|
|
50
49
|
Object.defineProperty(exports, "Segment", { enumerable: true, get: function () { return model_1.Segment; } });
|
|
@@ -196,39 +196,33 @@ class ExprFunc extends expression_def_1.ExpressionDef {
|
|
|
196
196
|
structPath,
|
|
197
197
|
};
|
|
198
198
|
let funcCall = frag;
|
|
199
|
-
const dialectOverload = dialect ? overload.dialect[dialect] : undefined;
|
|
200
199
|
// TODO add in an error if you use an asymmetric function in BQ
|
|
201
200
|
// and the function uses joins
|
|
202
201
|
// TODO add in an error if you use an illegal join pattern
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const isAnalytic = (0, malloy_types_1.expressionIsAnalytic)(overload.returnType.expressionType);
|
|
209
|
-
if (!isAnalytic) {
|
|
210
|
-
if (!this.inExperiment('aggregate_order_by', true)) {
|
|
211
|
-
props.orderBys[0].log('Enable experiment `aggregate_order_by` to use `order_by` with an aggregate function');
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
if (dialectOverload.supportsOrderBy || isAnalytic) {
|
|
215
|
-
const allowExpression = dialectOverload.supportsOrderBy !== 'only_default';
|
|
216
|
-
const allObs = props.orderBys.flatMap(orderBy => isAnalytic
|
|
217
|
-
? orderBy.getAnalyticOrderBy(fs)
|
|
218
|
-
: orderBy.getAggregateOrderBy(fs, allowExpression));
|
|
219
|
-
frag.kids.orderBy = allObs;
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
props.orderBys[0].log(`Function \`${this.name}\` does not support \`order_by\``);
|
|
202
|
+
if ((props === null || props === void 0 ? void 0 : props.orderBys) && props.orderBys.length > 0) {
|
|
203
|
+
const isAnalytic = (0, malloy_types_1.expressionIsAnalytic)(overload.returnType.expressionType);
|
|
204
|
+
if (!isAnalytic) {
|
|
205
|
+
if (!this.inExperiment('aggregate_order_by', true)) {
|
|
206
|
+
props.orderBys[0].log('Enable experiment `aggregate_order_by` to use `order_by` with an aggregate function');
|
|
223
207
|
}
|
|
224
208
|
}
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
209
|
+
if (overload.supportsOrderBy || isAnalytic) {
|
|
210
|
+
const allowExpression = overload.supportsOrderBy !== 'only_default';
|
|
211
|
+
const allObs = props.orderBys.flatMap(orderBy => isAnalytic
|
|
212
|
+
? orderBy.getAnalyticOrderBy(fs)
|
|
213
|
+
: orderBy.getAggregateOrderBy(fs, allowExpression));
|
|
214
|
+
frag.kids.orderBy = allObs;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
props.orderBys[0].log(`Function \`${this.name}\` does not support \`order_by\``);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if ((props === null || props === void 0 ? void 0 : props.limit) !== undefined) {
|
|
221
|
+
if (overload.supportsLimit) {
|
|
222
|
+
frag.limit = props.limit.limit;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
this.log(`Function ${this.name} does not support limit`);
|
|
232
226
|
}
|
|
233
227
|
}
|
|
234
228
|
if ((props === null || props === void 0 ? void 0 : props.partitionBys) && props.partitionBys.length > 0) {
|
|
@@ -377,7 +371,9 @@ function findOverload(func, args) {
|
|
|
377
371
|
(paramT.evalSpace === 'constant' &&
|
|
378
372
|
(arg.evalSpace === 'input' || arg.evalSpace === 'output')) ||
|
|
379
373
|
// Error if output is required but arg is input
|
|
380
|
-
|
|
374
|
+
// TODO: Assumption that calculations cannot take input things
|
|
375
|
+
((0, malloy_types_1.expressionIsAnalytic)(overload.returnType.expressionType) &&
|
|
376
|
+
arg.evalSpace === 'input')) {
|
|
381
377
|
evalSpaceErrors.push({
|
|
382
378
|
argIndex,
|
|
383
379
|
param,
|
|
@@ -23,17 +23,17 @@ class DialectNameSpace {
|
|
|
23
23
|
return {
|
|
24
24
|
returnType: overload.returnType,
|
|
25
25
|
params: overload.params,
|
|
26
|
+
supportsOrderBy: overload.supportsOrderBy,
|
|
27
|
+
supportsLimit: overload.supportsLimit,
|
|
28
|
+
isSymmetric: overload.isSymmetric,
|
|
26
29
|
dialect: {
|
|
27
30
|
[dialect.name]: {
|
|
28
31
|
e: overload.e,
|
|
29
|
-
supportsOrderBy: overload.supportsOrderBy,
|
|
30
32
|
defaultOrderByArgIndex: overload.defaultOrderByArgIndex,
|
|
31
|
-
|
|
33
|
+
between: overload.between,
|
|
34
|
+
needsWindowOrderBy: overload.needsWindowOrderBy,
|
|
32
35
|
},
|
|
33
36
|
},
|
|
34
|
-
needsWindowOrderBy: overload.needsWindowOrderBy,
|
|
35
|
-
between: overload.between,
|
|
36
|
-
isSymmetric: overload.isSymmetric,
|
|
37
37
|
};
|
|
38
38
|
}),
|
|
39
39
|
});
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { FunctionDef } from '../../../model';
|
|
1
2
|
import { ModelEntry } from './model-entry';
|
|
2
3
|
import { NameSpace } from './name-space';
|
|
3
4
|
/**
|
|
4
|
-
* We may want to remove this in the future...
|
|
5
|
-
*
|
|
6
5
|
* This is a global namespace which exists in the root of all Documents
|
|
7
6
|
* and includes SQL function definitions.
|
|
8
7
|
*/
|
|
9
8
|
export declare class GlobalNameSpace implements NameSpace {
|
|
9
|
+
entries: Map<string, FunctionDef>;
|
|
10
|
+
constructor();
|
|
10
11
|
getEntry(name: string): ModelEntry | undefined;
|
|
11
12
|
setEntry(_name: string, _value: ModelEntry, _exported: boolean): void;
|
|
12
13
|
}
|
|
14
|
+
export declare function getDialectFunctions(): Map<string, FunctionDef>;
|
|
@@ -22,19 +22,19 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.GlobalNameSpace = void 0;
|
|
25
|
+
exports.getDialectFunctions = exports.GlobalNameSpace = void 0;
|
|
26
|
+
const dialect_1 = require("../../../dialect");
|
|
26
27
|
const dialect_map_1 = require("../../../dialect/dialect_map");
|
|
27
28
|
/**
|
|
28
|
-
* We may want to remove this in the future...
|
|
29
|
-
*
|
|
30
29
|
* This is a global namespace which exists in the root of all Documents
|
|
31
30
|
* and includes SQL function definitions.
|
|
32
31
|
*/
|
|
33
32
|
class GlobalNameSpace {
|
|
33
|
+
constructor() {
|
|
34
|
+
this.entries = getDialectFunctions();
|
|
35
|
+
}
|
|
34
36
|
getEntry(name) {
|
|
35
|
-
|
|
36
|
-
// overloads on every usage
|
|
37
|
-
const func = (0, dialect_map_1.getDialectFunction)(name);
|
|
37
|
+
const func = this.entries.get(name);
|
|
38
38
|
if (func === undefined) {
|
|
39
39
|
return undefined;
|
|
40
40
|
}
|
|
@@ -48,4 +48,57 @@ class GlobalNameSpace {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
exports.GlobalNameSpace = GlobalNameSpace;
|
|
51
|
+
function paramsEqual(a, b) {
|
|
52
|
+
return (a.params.length === b.params.length &&
|
|
53
|
+
a.params.every((param, i) => {
|
|
54
|
+
const otherParam = b.params[i];
|
|
55
|
+
return (param.isVariadic === otherParam.isVariadic &&
|
|
56
|
+
param.name === otherParam.name &&
|
|
57
|
+
param.allowedTypes.length === otherParam.allowedTypes.length &&
|
|
58
|
+
param.allowedTypes.every(t => otherParam.allowedTypes.some(ot => t.dataType === ot.dataType &&
|
|
59
|
+
t.expressionType === ot.expressionType)));
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
function getDialectFunctions() {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
const baseImplementations = (0, dialect_1.getMalloyStandardFunctions)();
|
|
65
|
+
const dialectOverrides = {};
|
|
66
|
+
const dialects = (0, dialect_map_1.getDialects)();
|
|
67
|
+
for (const dialect of dialects) {
|
|
68
|
+
dialectOverrides[dialect.name] = dialect.getDialectFunctionOverrides();
|
|
69
|
+
}
|
|
70
|
+
const functions = new Map();
|
|
71
|
+
for (const name in baseImplementations) {
|
|
72
|
+
const baseOverloads = baseImplementations[name];
|
|
73
|
+
const func = {
|
|
74
|
+
type: 'function',
|
|
75
|
+
name,
|
|
76
|
+
overloads: [],
|
|
77
|
+
};
|
|
78
|
+
for (const baseOverload of baseOverloads) {
|
|
79
|
+
const overload = {
|
|
80
|
+
returnType: baseOverload.returnType,
|
|
81
|
+
params: baseOverload.params,
|
|
82
|
+
dialect: {},
|
|
83
|
+
supportsOrderBy: baseOverload.supportsOrderBy,
|
|
84
|
+
supportsLimit: baseOverload.supportsLimit,
|
|
85
|
+
isSymmetric: baseOverload.isSymmetric,
|
|
86
|
+
};
|
|
87
|
+
for (const dialect of dialects) {
|
|
88
|
+
const overloads = (_a = dialectOverrides[dialect.name][name]) !== null && _a !== void 0 ? _a : [];
|
|
89
|
+
const dialectOverload = (_b = overloads.find(o => paramsEqual(o, overload))) !== null && _b !== void 0 ? _b : baseOverload;
|
|
90
|
+
overload.dialect[dialect.name] = {
|
|
91
|
+
e: dialectOverload.e,
|
|
92
|
+
needsWindowOrderBy: dialectOverload.needsWindowOrderBy,
|
|
93
|
+
between: dialectOverload.between,
|
|
94
|
+
defaultOrderByArgIndex: dialectOverload.defaultOrderByArgIndex,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
func.overloads.push(overload);
|
|
98
|
+
}
|
|
99
|
+
functions.set(name, func);
|
|
100
|
+
}
|
|
101
|
+
return functions;
|
|
102
|
+
}
|
|
103
|
+
exports.getDialectFunctions = getDialectFunctions;
|
|
51
104
|
//# sourceMappingURL=global-name-space.js.map
|
|
@@ -87,7 +87,7 @@ declare class QueryField extends QueryNode {
|
|
|
87
87
|
generateCountFragment(resultSet: FieldInstanceResult, context: QueryStruct, expr: AggregateExpr, state: GenerateState): string;
|
|
88
88
|
generateSourceReference(resultSet: FieldInstanceResult, context: QueryStruct, expr: SourceReferenceNode): string;
|
|
89
89
|
getAnalyticPartitions(resultStruct: FieldInstanceResult, extraPartitionFields?: string[]): string[];
|
|
90
|
-
generateAnalyticFragment(resultStruct: FieldInstanceResult, context: QueryStruct, expr: Expr, overload: FunctionOverloadDef, state: GenerateState, args: Expr[], partitionByFields?: string[], funcOrdering?: string): string;
|
|
90
|
+
generateAnalyticFragment(dialect: string, resultStruct: FieldInstanceResult, context: QueryStruct, expr: Expr, overload: FunctionOverloadDef, state: GenerateState, args: Expr[], partitionByFields?: string[], funcOrdering?: string): string;
|
|
91
91
|
generatePickSQL(pf: PickExpr): string;
|
|
92
92
|
exprToSQL(resultSet: FieldInstanceResult, context: QueryStruct, exprToTranslate: Expr, state?: GenerateState): string;
|
|
93
93
|
getExpr(): Expr;
|
|
@@ -445,7 +445,7 @@ class QueryField extends QueryNode {
|
|
|
445
445
|
const extraPartitions = ((_c = frag.partitionBy) !== null && _c !== void 0 ? _c : []).map(outputName => {
|
|
446
446
|
return `(${resultSet.getField(outputName).getAnalyticalSQL(false)})`;
|
|
447
447
|
});
|
|
448
|
-
return this.generateAnalyticFragment(resultSet, context, funcCall, overload, state, args, extraPartitions, orderBySql);
|
|
448
|
+
return this.generateAnalyticFragment(context.dialect.name, resultSet, context, funcCall, overload, state, args, extraPartitions, orderBySql);
|
|
449
449
|
}
|
|
450
450
|
return this.exprToSQL(resultSet, context, funcCall, state);
|
|
451
451
|
}
|
|
@@ -614,7 +614,7 @@ class QueryField extends QueryNode {
|
|
|
614
614
|
}
|
|
615
615
|
return ret;
|
|
616
616
|
}
|
|
617
|
-
generateAnalyticFragment(resultStruct, context, expr, overload, state, args, partitionByFields, funcOrdering) {
|
|
617
|
+
generateAnalyticFragment(dialect, resultStruct, context, expr, overload, state, args, partitionByFields, funcOrdering) {
|
|
618
618
|
const isComplex = resultStruct.root().isComplexQuery;
|
|
619
619
|
const partitionFields = this.getAnalyticPartitions(resultStruct, partitionByFields);
|
|
620
620
|
const allPartitions = [
|
|
@@ -625,7 +625,8 @@ class QueryField extends QueryNode {
|
|
|
625
625
|
? `PARTITION BY ${allPartitions.join(', ')}`
|
|
626
626
|
: '';
|
|
627
627
|
let orderBy = funcOrdering !== null && funcOrdering !== void 0 ? funcOrdering : '';
|
|
628
|
-
|
|
628
|
+
const dialectOverload = overload.dialect[dialect];
|
|
629
|
+
if (!funcOrdering && dialectOverload.needsWindowOrderBy) {
|
|
629
630
|
// calculate the ordering.
|
|
630
631
|
const obSQL = [];
|
|
631
632
|
let orderingField;
|
|
@@ -662,10 +663,10 @@ class QueryField extends QueryNode {
|
|
|
662
663
|
}
|
|
663
664
|
}
|
|
664
665
|
let between = '';
|
|
665
|
-
if (
|
|
666
|
+
if (dialectOverload.between) {
|
|
666
667
|
const [preceding, following] = [
|
|
667
|
-
|
|
668
|
-
|
|
668
|
+
dialectOverload.between.preceding,
|
|
669
|
+
dialectOverload.between.following,
|
|
669
670
|
].map(value => {
|
|
670
671
|
if (value === -1) {
|
|
671
672
|
return 'UNBOUNDED';
|