@malloydata/malloy 0.0.182-dev240911155850 → 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
|
@@ -59,7 +59,9 @@ export declare abstract class Dialect {
|
|
|
59
59
|
hasModOperator: boolean;
|
|
60
60
|
supportsLeftJoinUnnest: boolean;
|
|
61
61
|
supportsCountApprox: boolean;
|
|
62
|
-
abstract
|
|
62
|
+
abstract getDialectFunctionOverrides(): {
|
|
63
|
+
[name: string]: DialectFunctionOverloadDef[];
|
|
64
|
+
};
|
|
63
65
|
abstract getDialectFunctions(): {
|
|
64
66
|
[name: string]: DialectFunctionOverloadDef[];
|
|
65
67
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Dialect } from './dialect';
|
|
2
|
-
import { FunctionDef } from '../model/malloy_types';
|
|
3
2
|
export declare function getDialect(name: string): Dialect;
|
|
4
3
|
export declare function registerDialect(d: Dialect): void;
|
|
5
|
-
export declare function
|
|
4
|
+
export declare function getDialects(): Dialect[];
|
|
@@ -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.
|
|
25
|
+
exports.getDialects = exports.registerDialect = exports.getDialect = void 0;
|
|
26
26
|
const duckdb_1 = require("./duckdb");
|
|
27
27
|
const postgres_1 = require("./postgres");
|
|
28
28
|
const snowflake_1 = require("./snowflake");
|
|
@@ -41,83 +41,14 @@ function registerDialect(d) {
|
|
|
41
41
|
dialectMap.set(d.name, d);
|
|
42
42
|
}
|
|
43
43
|
exports.registerDialect = registerDialect;
|
|
44
|
+
function getDialects() {
|
|
45
|
+
return [...dialectMap.values()];
|
|
46
|
+
}
|
|
47
|
+
exports.getDialects = getDialects;
|
|
44
48
|
registerDialect(new postgres_1.PostgresDialect());
|
|
45
49
|
registerDialect(new standardsql_1.StandardSQLDialect());
|
|
46
50
|
registerDialect(new duckdb_1.DuckDBDialect());
|
|
47
51
|
registerDialect(new snowflake_1.SnowflakeDialect());
|
|
48
52
|
registerDialect(new trino_1.TrinoDialect());
|
|
49
53
|
registerDialect(new trino_1.PrestoDialect());
|
|
50
|
-
function paramsEqual(a, b) {
|
|
51
|
-
return (a.params.length === b.params.length &&
|
|
52
|
-
a.params.every((param, i) => {
|
|
53
|
-
const otherParam = b.params[i];
|
|
54
|
-
return (param.isVariadic === otherParam.isVariadic &&
|
|
55
|
-
param.name === otherParam.name &&
|
|
56
|
-
param.allowedTypes.length === otherParam.allowedTypes.length &&
|
|
57
|
-
param.allowedTypes.every(t => otherParam.allowedTypes.some(ot => t.dataType === ot.dataType &&
|
|
58
|
-
t.expressionType === ot.expressionType)));
|
|
59
|
-
}));
|
|
60
|
-
}
|
|
61
|
-
function paramsCompatible(a, b) {
|
|
62
|
-
// TODO detect when parameters are not exactly equal, but would cause collision issues...
|
|
63
|
-
return paramsEqual(a, b);
|
|
64
|
-
}
|
|
65
|
-
function returnEqual(a, b) {
|
|
66
|
-
return (a.returnType.dataType === b.returnType.dataType &&
|
|
67
|
-
a.returnType.expressionType === b.returnType.expressionType);
|
|
68
|
-
}
|
|
69
|
-
function getDialectFunction(name) {
|
|
70
|
-
const func = {
|
|
71
|
-
type: 'function',
|
|
72
|
-
name,
|
|
73
|
-
overloads: [],
|
|
74
|
-
};
|
|
75
|
-
let found = false;
|
|
76
|
-
for (const dialect of dialectMap.values()) {
|
|
77
|
-
const overloads = dialect.getGlobalFunctionDef(name);
|
|
78
|
-
if (overloads) {
|
|
79
|
-
for (const overload of overloads) {
|
|
80
|
-
let handled = false;
|
|
81
|
-
for (const existingOverload of func.overloads) {
|
|
82
|
-
if (!paramsCompatible(overload, existingOverload)) {
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
if (!paramsEqual(overload, existingOverload)) {
|
|
86
|
-
throw new Error('params are compatible but not equal');
|
|
87
|
-
}
|
|
88
|
-
if (!returnEqual(overload, existingOverload)) {
|
|
89
|
-
throw new Error('params match but return types differ!');
|
|
90
|
-
}
|
|
91
|
-
existingOverload.dialect[dialect.name] = {
|
|
92
|
-
e: overload.e,
|
|
93
|
-
supportsOrderBy: overload.supportsOrderBy,
|
|
94
|
-
defaultOrderByArgIndex: overload.defaultOrderByArgIndex,
|
|
95
|
-
supportsLimit: overload.supportsLimit,
|
|
96
|
-
};
|
|
97
|
-
handled = true;
|
|
98
|
-
}
|
|
99
|
-
if (!handled) {
|
|
100
|
-
func.overloads.push({
|
|
101
|
-
returnType: overload.returnType,
|
|
102
|
-
params: overload.params,
|
|
103
|
-
dialect: {
|
|
104
|
-
[dialect.name]: {
|
|
105
|
-
e: overload.e,
|
|
106
|
-
supportsOrderBy: overload.supportsOrderBy,
|
|
107
|
-
defaultOrderByArgIndex: overload.defaultOrderByArgIndex,
|
|
108
|
-
supportsLimit: overload.supportsLimit,
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
needsWindowOrderBy: overload.needsWindowOrderBy,
|
|
112
|
-
between: overload.between,
|
|
113
|
-
isSymmetric: overload.isSymmetric,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
found = true;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return found ? func : undefined;
|
|
121
|
-
}
|
|
122
|
-
exports.getDialectFunction = getDialectFunction;
|
|
123
54
|
//# sourceMappingURL=dialect_map.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
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.DUCKDB_DIALECT_FUNCTIONS = void 0;
|
|
10
|
+
const to_timestamp = {
|
|
11
|
+
takes: { 'epoch_seconds': 'number' },
|
|
12
|
+
returns: 'timestamp',
|
|
13
|
+
impl: { function: 'TO_TIMESTAMP' },
|
|
14
|
+
};
|
|
15
|
+
const count_approx = {
|
|
16
|
+
takes: { 'value': { dimension: 'any' } },
|
|
17
|
+
returns: { measure: 'number' },
|
|
18
|
+
impl: { function: 'APPROX_COUNT_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: 'STRING_AGG(${value}${order_by:})',
|
|
27
|
+
defaultOrderByArgIndex: 0,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
with_separator: {
|
|
31
|
+
takes: {
|
|
32
|
+
'value': { dimension: 'string' },
|
|
33
|
+
'separator': { literal: 'string' },
|
|
34
|
+
},
|
|
35
|
+
returns: { measure: 'string' },
|
|
36
|
+
supportsOrderBy: true,
|
|
37
|
+
impl: {
|
|
38
|
+
sql: 'STRING_AGG(${value}, ${separator}${order_by:})',
|
|
39
|
+
defaultOrderByArgIndex: 0,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const string_agg_distinct = {
|
|
44
|
+
default_separator: {
|
|
45
|
+
...string_agg['default_separator'],
|
|
46
|
+
isSymmetric: true,
|
|
47
|
+
impl: {
|
|
48
|
+
sql: 'STRING_AGG(DISTINCT ${value}${order_by:})',
|
|
49
|
+
defaultOrderByArgIndex: 0,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
with_separator: {
|
|
53
|
+
...string_agg['with_separator'],
|
|
54
|
+
isSymmetric: true,
|
|
55
|
+
impl: {
|
|
56
|
+
sql: 'STRING_AGG(DISTINCT ${value}, ${separator}${order_by:})',
|
|
57
|
+
defaultOrderByArgIndex: 0,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
exports.DUCKDB_DIALECT_FUNCTIONS = {
|
|
62
|
+
count_approx,
|
|
63
|
+
to_timestamp,
|
|
64
|
+
string_agg,
|
|
65
|
+
string_agg_distinct,
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=dialect_functions.js.map
|
|
@@ -49,7 +49,9 @@ export declare class DuckDBDialect extends PostgresBase {
|
|
|
49
49
|
sqlOrderBy(orderTerms: string[]): string;
|
|
50
50
|
sqlLiteralString(literal: string): string;
|
|
51
51
|
sqlLiteralRegexp(literal: string): string;
|
|
52
|
-
|
|
52
|
+
getDialectFunctionOverrides(): {
|
|
53
|
+
[name: string]: DialectFunctionOverloadDef[];
|
|
54
|
+
};
|
|
53
55
|
getDialectFunctions(): {
|
|
54
56
|
[name: string]: DialectFunctionOverloadDef[];
|
|
55
57
|
};
|
|
@@ -25,10 +25,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.DuckDBDialect = void 0;
|
|
26
26
|
const malloy_types_1 = require("../../model/malloy_types");
|
|
27
27
|
const utils_1 = require("../../model/utils");
|
|
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
|
// need to refactor runSQL to take a SQLBlock instead of just a sql string.
|
|
33
34
|
const hackSplitComment = '-- hack: split on this';
|
|
34
35
|
const duckDBToMalloyTypes = {
|
|
@@ -261,11 +262,11 @@ class DuckDBDialect extends pg_impl_1.PostgresBase {
|
|
|
261
262
|
sqlLiteralRegexp(literal) {
|
|
262
263
|
return "'" + literal.replace(/'/g, "''") + "'";
|
|
263
264
|
}
|
|
264
|
-
|
|
265
|
-
return functions_1.
|
|
265
|
+
getDialectFunctionOverrides() {
|
|
266
|
+
return (0, functions_1.expandOverrideMap)(function_overrides_1.DUCKDB_MALLOY_STANDARD_OVERLOADS);
|
|
266
267
|
}
|
|
267
268
|
getDialectFunctions() {
|
|
268
|
-
return dialect_functions_1.DUCKDB_DIALECT_FUNCTIONS;
|
|
269
|
+
return (0, functions_1.expandBlueprintMap)(dialect_functions_1.DUCKDB_DIALECT_FUNCTIONS);
|
|
269
270
|
}
|
|
270
271
|
malloyTypeToSQLType(malloyType) {
|
|
271
272
|
if (malloyType.type === 'number') {
|
|
@@ -0,0 +1,55 @@
|
|
|
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.DUCKDB_MALLOY_STANDARD_OVERLOADS = void 0;
|
|
10
|
+
function greatestOrLeastSQL(name) {
|
|
11
|
+
return ('CASE' +
|
|
12
|
+
' WHEN LEN(LIST_FILTER([${...values}], x -> x is null)) > 0' +
|
|
13
|
+
' THEN NULL' +
|
|
14
|
+
' ELSE ' +
|
|
15
|
+
name +
|
|
16
|
+
'(${...values})' +
|
|
17
|
+
' END');
|
|
18
|
+
}
|
|
19
|
+
exports.DUCKDB_MALLOY_STANDARD_OVERLOADS = {
|
|
20
|
+
byte_length: { sql: '(BIT_LENGTH(${value}) / 8)' },
|
|
21
|
+
div: {
|
|
22
|
+
sql: 'CASE WHEN ${dividend} / ${divisor} < 0 THEN CEIL(${dividend} / ${divisor}) ELSE FLOOR(${dividend} / ${divisor}) END',
|
|
23
|
+
},
|
|
24
|
+
ends_with: { sql: 'COALESCE(SUFFIX(${value}, ${suffix}), false)' },
|
|
25
|
+
greatest: { sql: greatestOrLeastSQL('GREATEST') },
|
|
26
|
+
is_inf: { sql: 'COALESCE(ISINF(${value}), false)' },
|
|
27
|
+
is_nan: { sql: 'COALESCE(ISNAN(${value}), false)' },
|
|
28
|
+
// DuckDB doesn't seem to have a log with base function, so we use the change of base
|
|
29
|
+
// forumla to implement it.
|
|
30
|
+
log: { sql: '(LN(${value}) / LN(${base}))' },
|
|
31
|
+
least: { sql: greatestOrLeastSQL('LEAST') },
|
|
32
|
+
rand: { function: 'RANDOM' },
|
|
33
|
+
replace: {
|
|
34
|
+
// In DuckDB we specifically need to say that the replacement should be global.
|
|
35
|
+
regular_expression: {
|
|
36
|
+
sql: "REGEXP_REPLACE(${value}, ${pattern}, ${replacement}, 'g')",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
// Trunc function doesn't exist in DuckDB, so we emulate it.
|
|
40
|
+
// For both overloads, we switch between CEIL and FLOOR based on the sign of the arugment
|
|
41
|
+
// For the overload with precision, we multiply by a power of 10 before rounding, then divide.
|
|
42
|
+
trunc: {
|
|
43
|
+
to_integer: {
|
|
44
|
+
sql: 'CASE WHEN ${value} < 0 THEN CEIL(${value}) ELSE FLOOR(${value}) END',
|
|
45
|
+
},
|
|
46
|
+
to_precision: {
|
|
47
|
+
sql: 'CASE WHEN ${value} < 0 THEN CEIL(${value} * POW(10, ${precision})) / POW(10, ${precision}) ELSE FLOOR(${value} * POW(10, ${precision})) / POW(10, ${precision}) END',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
// In DuckDB, `UNICODE('')` gives -1, rather than 0.
|
|
51
|
+
unicode: {
|
|
52
|
+
sql: "CASE WHEN ${value} = '' THEN 0 ELSE UNICODE(${value}) END",
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=function_overrides.js.map
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export type { DialectFunctionOverloadDef } from './util';
|
|
2
|
-
export {
|
|
2
|
+
export { expandBlueprintMap } from './util';
|
|
3
|
+
export { getMalloyStandardFunctions, expandOverrideMap, } from './malloy_standard_functions';
|
|
4
|
+
export type { MalloyStandardFunctionImplementations } from './malloy_standard_functions';
|
|
@@ -22,7 +22,10 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.
|
|
26
|
-
var
|
|
27
|
-
Object.defineProperty(exports, "
|
|
25
|
+
exports.expandOverrideMap = exports.getMalloyStandardFunctions = exports.expandBlueprintMap = void 0;
|
|
26
|
+
var util_1 = require("./util");
|
|
27
|
+
Object.defineProperty(exports, "expandBlueprintMap", { enumerable: true, get: function () { return util_1.expandBlueprintMap; } });
|
|
28
|
+
var malloy_standard_functions_1 = require("./malloy_standard_functions");
|
|
29
|
+
Object.defineProperty(exports, "getMalloyStandardFunctions", { enumerable: true, get: function () { return malloy_standard_functions_1.getMalloyStandardFunctions; } });
|
|
30
|
+
Object.defineProperty(exports, "expandOverrideMap", { enumerable: true, get: function () { return malloy_standard_functions_1.expandOverrideMap; } });
|
|
28
31
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { DefinitionBlueprint, DialectFunctionOverloadDef, ImplementationBlueprint } from './util';
|
|
2
|
+
type D = DefinitionBlueprint;
|
|
3
|
+
type I = ImplementationBlueprint;
|
|
4
|
+
type DefinitionsFor<T> = {
|
|
5
|
+
[key in keyof T]: D;
|
|
6
|
+
};
|
|
7
|
+
type ImplementationsFor<T> = {
|
|
8
|
+
[key in keyof T]?: I;
|
|
9
|
+
};
|
|
10
|
+
type DefinitionFor<T> = T extends D ? D : DefinitionsFor<T>;
|
|
11
|
+
type ImplementationFor<T> = T extends D ? I : ImplementationsFor<T>;
|
|
12
|
+
type DefinitionMap<T> = {
|
|
13
|
+
[key in keyof T]: DefinitionFor<T[key]>;
|
|
14
|
+
};
|
|
15
|
+
type ImplementationMap<T> = {
|
|
16
|
+
[key in keyof T]?: ImplementationFor<T[key]>;
|
|
17
|
+
};
|
|
18
|
+
type Standard = {
|
|
19
|
+
abs: D;
|
|
20
|
+
acos: D;
|
|
21
|
+
ascii: D;
|
|
22
|
+
asin: D;
|
|
23
|
+
atan2: D;
|
|
24
|
+
atan: D;
|
|
25
|
+
byte_length: D;
|
|
26
|
+
ceil: D;
|
|
27
|
+
chr: D;
|
|
28
|
+
coalesce: D;
|
|
29
|
+
concat: {
|
|
30
|
+
empty: D;
|
|
31
|
+
variadic: D;
|
|
32
|
+
};
|
|
33
|
+
cos: D;
|
|
34
|
+
div: D;
|
|
35
|
+
ends_with: D;
|
|
36
|
+
exp: D;
|
|
37
|
+
floor: D;
|
|
38
|
+
greatest: D;
|
|
39
|
+
ifnull: D;
|
|
40
|
+
is_inf: D;
|
|
41
|
+
is_nan: D;
|
|
42
|
+
least: D;
|
|
43
|
+
length: D;
|
|
44
|
+
ln: D;
|
|
45
|
+
log: D;
|
|
46
|
+
lower: D;
|
|
47
|
+
ltrim: {
|
|
48
|
+
whitespace: D;
|
|
49
|
+
characters: D;
|
|
50
|
+
};
|
|
51
|
+
nullif: D;
|
|
52
|
+
pi: D;
|
|
53
|
+
pow: D;
|
|
54
|
+
rand: D;
|
|
55
|
+
regexp_extract: D;
|
|
56
|
+
repeat: D;
|
|
57
|
+
replace: {
|
|
58
|
+
string: D;
|
|
59
|
+
regular_expression: D;
|
|
60
|
+
};
|
|
61
|
+
reverse: D;
|
|
62
|
+
round: {
|
|
63
|
+
to_integer: D;
|
|
64
|
+
to_precision: D;
|
|
65
|
+
};
|
|
66
|
+
rtrim: {
|
|
67
|
+
whitespace: D;
|
|
68
|
+
characters: D;
|
|
69
|
+
};
|
|
70
|
+
sign: D;
|
|
71
|
+
sin: D;
|
|
72
|
+
sqrt: D;
|
|
73
|
+
starts_with: D;
|
|
74
|
+
strpos: D;
|
|
75
|
+
substr: {
|
|
76
|
+
position_only: D;
|
|
77
|
+
with_length: D;
|
|
78
|
+
};
|
|
79
|
+
tan: D;
|
|
80
|
+
trim: {
|
|
81
|
+
whitespace: D;
|
|
82
|
+
characters: D;
|
|
83
|
+
};
|
|
84
|
+
trunc: {
|
|
85
|
+
to_integer: D;
|
|
86
|
+
to_precision: D;
|
|
87
|
+
};
|
|
88
|
+
unicode: D;
|
|
89
|
+
upper: D;
|
|
90
|
+
stddev: D;
|
|
91
|
+
avg_moving: {
|
|
92
|
+
preceding: D;
|
|
93
|
+
following: D;
|
|
94
|
+
};
|
|
95
|
+
first_value: D;
|
|
96
|
+
lag: {
|
|
97
|
+
bare: D;
|
|
98
|
+
with_offset: D;
|
|
99
|
+
with_default: D;
|
|
100
|
+
};
|
|
101
|
+
last_value: D;
|
|
102
|
+
lead: {
|
|
103
|
+
bare: D;
|
|
104
|
+
with_offset: D;
|
|
105
|
+
with_default: D;
|
|
106
|
+
};
|
|
107
|
+
max_cumulative: D;
|
|
108
|
+
max_window: D;
|
|
109
|
+
min_cumulative: D;
|
|
110
|
+
min_window: D;
|
|
111
|
+
rank: D;
|
|
112
|
+
row_number: D;
|
|
113
|
+
sum_cumulative: D;
|
|
114
|
+
sum_moving: {
|
|
115
|
+
preceding: D;
|
|
116
|
+
following: D;
|
|
117
|
+
};
|
|
118
|
+
sum_window: D;
|
|
119
|
+
sql_boolean: D;
|
|
120
|
+
sql_date: D;
|
|
121
|
+
sql_number: D;
|
|
122
|
+
sql_string: D;
|
|
123
|
+
sql_timestamp: D;
|
|
124
|
+
};
|
|
125
|
+
export type MalloyStandardFunctionDefinitions = DefinitionMap<Standard>;
|
|
126
|
+
export type MalloyStandardFunctionImplementations = ImplementationMap<Standard>;
|
|
127
|
+
export declare const MALLOY_STANDARD_FUNCTIONS: MalloyStandardFunctionDefinitions;
|
|
128
|
+
export declare function getMalloyStandardFunctions(): {
|
|
129
|
+
[name: string]: DialectFunctionOverloadDef[];
|
|
130
|
+
};
|
|
131
|
+
export declare function expandOverrideMap(overrides: MalloyStandardFunctionImplementations): {
|
|
132
|
+
[name: string]: DialectFunctionOverloadDef[];
|
|
133
|
+
};
|
|
134
|
+
export {};
|