@malloydata/malloy 0.0.180-dev240906180931 → 0.0.180-dev240906195755
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 -0
- package/dist/dialect/duckdb/duckdb.d.ts +3 -0
- package/dist/dialect/duckdb/duckdb.js +4 -0
- package/dist/dialect/duckdb/functions/dialect_functions.d.ts +4 -0
- package/dist/dialect/duckdb/functions/dialect_functions.js +16 -0
- package/dist/dialect/postgres/functions/dialect_functions.d.ts +4 -0
- package/dist/dialect/postgres/functions/dialect_functions.js +11 -0
- package/dist/dialect/postgres/postgres.d.ts +3 -0
- package/dist/dialect/postgres/postgres.js +4 -0
- package/dist/dialect/snowflake/functions/dialect_functions.d.ts +4 -0
- package/dist/dialect/snowflake/functions/dialect_functions.js +11 -0
- package/dist/dialect/snowflake/snowflake.d.ts +3 -0
- package/dist/dialect/snowflake/snowflake.js +4 -0
- package/dist/dialect/standardsql/functions/dialect_functions.d.ts +4 -0
- package/dist/dialect/standardsql/functions/dialect_functions.js +16 -0
- package/dist/dialect/standardsql/standardsql.d.ts +3 -0
- package/dist/dialect/standardsql/standardsql.js +4 -0
- package/dist/dialect/trino/functions/dialect_functions.d.ts +4 -0
- package/dist/dialect/trino/functions/dialect_functions.js +16 -0
- package/dist/dialect/trino/trino.d.ts +3 -0
- package/dist/dialect/trino/trino.js +4 -0
- package/dist/lang/ast/expressions/expr-func.d.ts +1 -0
- package/dist/lang/ast/expressions/expr-func.js +26 -14
- package/dist/lang/ast/types/dialect-name-space.d.ts +12 -0
- package/dist/lang/ast/types/dialect-name-space.js +57 -0
- package/dist/lang/ast/types/malloy-element.d.ts +3 -0
- package/dist/lang/ast/types/malloy-element.js +15 -0
- package/dist/lang/test/query.spec.js +12 -0
- package/package.json +1 -1
|
@@ -60,6 +60,9 @@ export declare abstract class Dialect {
|
|
|
60
60
|
supportsLeftJoinUnnest: boolean;
|
|
61
61
|
supportsCountApprox: boolean;
|
|
62
62
|
abstract getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
|
|
63
|
+
abstract getDialectFunctions(): {
|
|
64
|
+
[name: string]: DialectFunctionOverloadDef[];
|
|
65
|
+
};
|
|
63
66
|
abstract quoteTablePath(tablePath: string): string;
|
|
64
67
|
abstract sqlGroupSetTable(groupSetCount: number): string;
|
|
65
68
|
abstract sqlAnyValue(groupSet: number, fieldName: string): string;
|
|
@@ -50,6 +50,9 @@ export declare class DuckDBDialect extends PostgresBase {
|
|
|
50
50
|
sqlLiteralString(literal: string): string;
|
|
51
51
|
sqlLiteralRegexp(literal: string): string;
|
|
52
52
|
getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
|
|
53
|
+
getDialectFunctions(): {
|
|
54
|
+
[name: string]: DialectFunctionOverloadDef[];
|
|
55
|
+
};
|
|
53
56
|
malloyTypeToSQLType(malloyType: FieldAtomicTypeDef): string;
|
|
54
57
|
sqlTypeToMalloyType(sqlType: string): FieldAtomicTypeDef | undefined;
|
|
55
58
|
castToString(expression: string): string;
|
|
@@ -28,6 +28,7 @@ const utils_1 = require("../../model/utils");
|
|
|
28
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("./functions/dialect_functions");
|
|
31
32
|
// need to refactor runSQL to take a SQLBlock instead of just a sql string.
|
|
32
33
|
const hackSplitComment = '-- hack: split on this';
|
|
33
34
|
const duckDBToMalloyTypes = {
|
|
@@ -263,6 +264,9 @@ class DuckDBDialect extends pg_impl_1.PostgresBase {
|
|
|
263
264
|
getGlobalFunctionDef(name) {
|
|
264
265
|
return functions_1.DUCKDB_FUNCTIONS.get(name);
|
|
265
266
|
}
|
|
267
|
+
getDialectFunctions() {
|
|
268
|
+
return dialect_functions_1.DUCKDB_DIALECT_FUNCTIONS;
|
|
269
|
+
}
|
|
266
270
|
malloyTypeToSQLType(malloyType) {
|
|
267
271
|
if (malloyType.type === 'number') {
|
|
268
272
|
if (malloyType.numberType === 'integer') {
|
|
@@ -0,0 +1,16 @@
|
|
|
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 util_1 = require("../../functions/util");
|
|
11
|
+
exports.DUCKDB_DIALECT_FUNCTIONS = {
|
|
12
|
+
to_timestamp: [
|
|
13
|
+
(0, util_1.overload)((0, util_1.minScalar)('timestamp'), [(0, util_1.param)('epoch_seconds', (0, util_1.anyExprType)('number'))], (0, util_1.sql) `TO_TIMESTAMP(${(0, util_1.arg)('epoch_seconds')})`),
|
|
14
|
+
],
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=dialect_functions.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
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.POSTGRES_DIALECT_FUNCTIONS = void 0;
|
|
10
|
+
exports.POSTGRES_DIALECT_FUNCTIONS = {};
|
|
11
|
+
//# sourceMappingURL=dialect_functions.js.map
|
|
@@ -53,6 +53,9 @@ export declare class PostgresDialect extends PostgresBase {
|
|
|
53
53
|
sqlLiteralString(literal: string): string;
|
|
54
54
|
sqlLiteralRegexp(literal: string): string;
|
|
55
55
|
getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
|
|
56
|
+
getDialectFunctions(): {
|
|
57
|
+
[name: string]: DialectFunctionOverloadDef[];
|
|
58
|
+
};
|
|
56
59
|
malloyTypeToSQLType(malloyType: FieldAtomicTypeDef): string;
|
|
57
60
|
sqlTypeToMalloyType(sqlType: string): FieldAtomicTypeDef | undefined;
|
|
58
61
|
castToString(expression: string): string;
|
|
@@ -27,6 +27,7 @@ const utils_1 = require("../../model/utils");
|
|
|
27
27
|
const malloy_types_1 = require("../../model/malloy_types");
|
|
28
28
|
const functions_1 = require("./functions");
|
|
29
29
|
const pg_impl_1 = require("../pg_impl");
|
|
30
|
+
const dialect_functions_1 = require("./functions/dialect_functions");
|
|
30
31
|
const pgMakeIntervalMap = {
|
|
31
32
|
'year': 'years',
|
|
32
33
|
'month': 'months',
|
|
@@ -320,6 +321,9 @@ class PostgresDialect extends pg_impl_1.PostgresBase {
|
|
|
320
321
|
getGlobalFunctionDef(name) {
|
|
321
322
|
return functions_1.POSTGRES_FUNCTIONS.get(name);
|
|
322
323
|
}
|
|
324
|
+
getDialectFunctions() {
|
|
325
|
+
return dialect_functions_1.POSTGRES_DIALECT_FUNCTIONS;
|
|
326
|
+
}
|
|
323
327
|
malloyTypeToSQLType(malloyType) {
|
|
324
328
|
if (malloyType.type === 'number') {
|
|
325
329
|
if (malloyType.numberType === 'integer') {
|
|
@@ -0,0 +1,11 @@
|
|
|
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.SNOWFLAKE_DIALECT_FUNCTIONS = void 0;
|
|
10
|
+
exports.SNOWFLAKE_DIALECT_FUNCTIONS = {};
|
|
11
|
+
//# sourceMappingURL=dialect_functions.js.map
|
|
@@ -57,6 +57,9 @@ export declare class SnowflakeDialect extends Dialect {
|
|
|
57
57
|
sqlLiteralString(literal: string): string;
|
|
58
58
|
sqlLiteralRegexp(literal: string): string;
|
|
59
59
|
getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
|
|
60
|
+
getDialectFunctions(): {
|
|
61
|
+
[name: string]: DialectFunctionOverloadDef[];
|
|
62
|
+
};
|
|
60
63
|
malloyTypeToSQLType(malloyType: FieldAtomicTypeDef): string;
|
|
61
64
|
sqlTypeToMalloyType(sqlType: string): FieldAtomicTypeDef | undefined;
|
|
62
65
|
castToString(expression: string): string;
|
|
@@ -27,6 +27,7 @@ const utils_1 = require("../../model/utils");
|
|
|
27
27
|
const malloy_types_1 = require("../../model/malloy_types");
|
|
28
28
|
const functions_1 = require("./functions");
|
|
29
29
|
const dialect_1 = require("../dialect");
|
|
30
|
+
const dialect_functions_1 = require("./functions/dialect_functions");
|
|
30
31
|
const extractionMap = {
|
|
31
32
|
'day_of_week': 'dayofweek',
|
|
32
33
|
'day_of_year': 'dayofyear',
|
|
@@ -367,6 +368,9 @@ ${(0, utils_1.indent)(sql)}
|
|
|
367
368
|
getGlobalFunctionDef(name) {
|
|
368
369
|
return functions_1.SNOWFLAKE_FUNCTIONS.get(name);
|
|
369
370
|
}
|
|
371
|
+
getDialectFunctions() {
|
|
372
|
+
return dialect_functions_1.SNOWFLAKE_DIALECT_FUNCTIONS;
|
|
373
|
+
}
|
|
370
374
|
malloyTypeToSQLType(malloyType) {
|
|
371
375
|
if (malloyType.type === 'number') {
|
|
372
376
|
if (malloyType.numberType === 'integer') {
|
|
@@ -0,0 +1,16 @@
|
|
|
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 util_1 = require("../../functions/util");
|
|
11
|
+
exports.STANDARDSQL_DIALECT_FUNCTIONS = {
|
|
12
|
+
date_from_unix_date: [
|
|
13
|
+
(0, util_1.overload)((0, util_1.minScalar)('date'), [(0, util_1.param)('unix_date', (0, util_1.anyExprType)('number'))], (0, util_1.sql) `DATE_FROM_UNIX_DATE(${(0, util_1.arg)('unix_date')})`),
|
|
14
|
+
],
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=dialect_functions.js.map
|
|
@@ -54,6 +54,9 @@ export declare class StandardSQLDialect extends Dialect {
|
|
|
54
54
|
sqlLiteralString(literal: string): string;
|
|
55
55
|
sqlLiteralRegexp(literal: string): string;
|
|
56
56
|
getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
|
|
57
|
+
getDialectFunctions(): {
|
|
58
|
+
[name: string]: DialectFunctionOverloadDef[];
|
|
59
|
+
};
|
|
57
60
|
malloyTypeToSQLType(malloyType: FieldAtomicTypeDef): string;
|
|
58
61
|
sqlTypeToMalloyType(sqlType: string): FieldAtomicTypeDef | undefined;
|
|
59
62
|
castToString(expression: string): string;
|
|
@@ -27,6 +27,7 @@ const utils_1 = require("../../model/utils");
|
|
|
27
27
|
const malloy_types_1 = require("../../model/malloy_types");
|
|
28
28
|
const functions_1 = require("./functions");
|
|
29
29
|
const dialect_1 = require("../dialect");
|
|
30
|
+
const dialect_functions_1 = require("./functions/dialect_functions");
|
|
30
31
|
// These are the units that "TIMESTAMP_ADD" "TIMESTAMP_DIFF" accept
|
|
31
32
|
function timestampMeasureable(units) {
|
|
32
33
|
return [
|
|
@@ -443,6 +444,9 @@ ${(0, utils_1.indent)(sql)}
|
|
|
443
444
|
getGlobalFunctionDef(name) {
|
|
444
445
|
return functions_1.STANDARDSQL_FUNCTIONS.get(name);
|
|
445
446
|
}
|
|
447
|
+
getDialectFunctions() {
|
|
448
|
+
return dialect_functions_1.STANDARDSQL_DIALECT_FUNCTIONS;
|
|
449
|
+
}
|
|
446
450
|
malloyTypeToSQLType(malloyType) {
|
|
447
451
|
if (malloyType.type === 'number') {
|
|
448
452
|
if (malloyType.numberType === 'integer') {
|
|
@@ -0,0 +1,16 @@
|
|
|
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 util_1 = require("../../functions/util");
|
|
11
|
+
exports.TRINO_DIALECT_FUNCTIONS = {
|
|
12
|
+
from_unixtime: [
|
|
13
|
+
(0, util_1.overload)((0, util_1.minScalar)('timestamp'), [(0, util_1.param)('unixtime', (0, util_1.anyExprType)('number'))], (0, util_1.sql) `FROM_UNIXTIME(${(0, util_1.arg)('unixtime')})`),
|
|
14
|
+
],
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=dialect_functions.js.map
|
|
@@ -59,6 +59,9 @@ export declare class TrinoDialect extends PostgresBase {
|
|
|
59
59
|
sqlLiteralString(literal: string): string;
|
|
60
60
|
sqlLiteralRegexp(literal: string): string;
|
|
61
61
|
getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
|
|
62
|
+
getDialectFunctions(): {
|
|
63
|
+
[name: string]: DialectFunctionOverloadDef[];
|
|
64
|
+
};
|
|
62
65
|
malloyTypeToSQLType(malloyType: FieldAtomicTypeDef): string;
|
|
63
66
|
sqlTypeToMalloyType(_sqlType: string): FieldAtomicTypeDef | undefined;
|
|
64
67
|
castToString(expression: string): string;
|
|
@@ -28,6 +28,7 @@ const malloy_types_1 = require("../../model/malloy_types");
|
|
|
28
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("./functions/dialect_functions");
|
|
31
32
|
// These are the units that "TIMESTAMP_ADD" "TIMESTAMP_DIFF" accept
|
|
32
33
|
function timestampMeasureable(units) {
|
|
33
34
|
return [
|
|
@@ -420,6 +421,9 @@ ${(0, utils_1.indent)(sql)}
|
|
|
420
421
|
// TODO: implement
|
|
421
422
|
return functions_1.TRINO_FUNCTIONS.get(name);
|
|
422
423
|
}
|
|
424
|
+
getDialectFunctions() {
|
|
425
|
+
return dialect_functions_1.TRINO_DIALECT_FUNCTIONS;
|
|
426
|
+
}
|
|
423
427
|
malloyTypeToSQLType(malloyType) {
|
|
424
428
|
if (malloyType.type === 'number') {
|
|
425
429
|
if (malloyType.numberType === 'integer') {
|
|
@@ -18,6 +18,7 @@ export declare class ExprFunc extends ExpressionDef {
|
|
|
18
18
|
canSupportOrderBy(): boolean;
|
|
19
19
|
canSupportLimit(): boolean;
|
|
20
20
|
getExpression(fs: FieldSpace): ExprValue;
|
|
21
|
+
private findFunctionDef;
|
|
21
22
|
getPropsExpression(fs: FieldSpace, props?: {
|
|
22
23
|
partitionBys?: PartitionBy[];
|
|
23
24
|
orderBys?: FunctionOrdering[];
|
|
@@ -52,8 +52,30 @@ class ExprFunc extends expression_def_1.ExpressionDef {
|
|
|
52
52
|
getExpression(fs) {
|
|
53
53
|
return this.getPropsExpression(fs);
|
|
54
54
|
}
|
|
55
|
+
findFunctionDef(dialect) {
|
|
56
|
+
var _a, _b, _c;
|
|
57
|
+
// TODO this makes functions case-insensitive. This is weird that this is the only place
|
|
58
|
+
// where case insensitivity is thing.
|
|
59
|
+
const normalizedName = this.name.toLowerCase();
|
|
60
|
+
const dialectFunc = dialect
|
|
61
|
+
? (_b = (_a = this.getDialectNamespace(dialect)) === null || _a === void 0 ? void 0 : _a.getEntry(normalizedName)) === null || _b === void 0 ? void 0 : _b.entry
|
|
62
|
+
: undefined;
|
|
63
|
+
const func = dialectFunc !== null && dialectFunc !== void 0 ? dialectFunc : (_c = this.modelEntry(normalizedName)) === null || _c === void 0 ? void 0 : _c.entry;
|
|
64
|
+
if (func === undefined) {
|
|
65
|
+
this.log(`Unknown function '${this.name}'. Use '${this.name}!(...)' to call a SQL function directly.`);
|
|
66
|
+
return { found: undefined, error: 'unknown function' };
|
|
67
|
+
}
|
|
68
|
+
else if (func.type !== 'function') {
|
|
69
|
+
this.log(`Cannot call '${this.name}', which is of type ${func.type}`);
|
|
70
|
+
return { found: undefined, error: 'called non function' };
|
|
71
|
+
}
|
|
72
|
+
if (func.name !== this.name) {
|
|
73
|
+
this.log(`Case insensitivity for function names is deprecated, use '${func.name}' instead`, 'warn');
|
|
74
|
+
}
|
|
75
|
+
return { found: func, error: undefined };
|
|
76
|
+
}
|
|
55
77
|
getPropsExpression(fs, props) {
|
|
56
|
-
var _a, _b, _c, _d
|
|
78
|
+
var _a, _b, _c, _d;
|
|
57
79
|
const argExprsWithoutImplicit = this.args.map(arg => arg.getExpression(fs));
|
|
58
80
|
if (this.isRaw) {
|
|
59
81
|
let expressionType = 'scalar';
|
|
@@ -78,19 +100,10 @@ class ExprFunc extends expression_def_1.ExpressionDef {
|
|
|
78
100
|
evalSpace: (0, malloy_types_1.mergeEvalSpaces)(...argExprsWithoutImplicit.map(e => e.evalSpace)),
|
|
79
101
|
};
|
|
80
102
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const func = (_c = this.modelEntry(this.name.toLowerCase())) === null || _c === void 0 ? void 0 : _c.entry;
|
|
103
|
+
const dialect = (_c = fs.dialectObj()) === null || _c === void 0 ? void 0 : _c.name;
|
|
104
|
+
const { found: func, error } = this.findFunctionDef(dialect);
|
|
84
105
|
if (func === undefined) {
|
|
85
|
-
|
|
86
|
-
return (0, ast_utils_1.errorFor)('unknown function');
|
|
87
|
-
}
|
|
88
|
-
else if (func.type !== 'function') {
|
|
89
|
-
this.log(`Cannot call '${this.name}', which is of type ${func.type}`);
|
|
90
|
-
return (0, ast_utils_1.errorFor)('called non function');
|
|
91
|
-
}
|
|
92
|
-
if (func.name !== this.name) {
|
|
93
|
-
this.log(`Case insensitivity for function names is deprecated, use '${func.name}' instead`, 'warn');
|
|
106
|
+
return (0, ast_utils_1.errorFor)(error);
|
|
94
107
|
}
|
|
95
108
|
// Find the 'implicit argument' for aggregate functions called like `some_join.some_field.agg(...args)`
|
|
96
109
|
// where the full arg list is `(some_field, ...args)`.
|
|
@@ -183,7 +196,6 @@ class ExprFunc extends expression_def_1.ExpressionDef {
|
|
|
183
196
|
structPath,
|
|
184
197
|
};
|
|
185
198
|
let funcCall = frag;
|
|
186
|
-
const dialect = (_e = fs.dialectObj()) === null || _e === void 0 ? void 0 : _e.name;
|
|
187
199
|
const dialectOverload = dialect ? overload.dialect[dialect] : undefined;
|
|
188
200
|
// TODO add in an error if you use an asymmetric function in BQ
|
|
189
201
|
// and the function uses joins
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Dialect } from '../../../dialect';
|
|
2
|
+
import { ModelEntry } from './model-entry';
|
|
3
|
+
import { NameSpace } from './name-space';
|
|
4
|
+
/**
|
|
5
|
+
* This is the dialect namespace, which sits below the global namespace.
|
|
6
|
+
*/
|
|
7
|
+
export declare class DialectNameSpace implements NameSpace {
|
|
8
|
+
private entries;
|
|
9
|
+
constructor(dialect: Dialect);
|
|
10
|
+
getEntry(name: string): ModelEntry | undefined;
|
|
11
|
+
setEntry(_name: string, _value: ModelEntry, _exported: boolean): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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.DialectNameSpace = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* This is the dialect namespace, which sits below the global namespace.
|
|
12
|
+
*/
|
|
13
|
+
class DialectNameSpace {
|
|
14
|
+
constructor(dialect) {
|
|
15
|
+
this.entries = new Map();
|
|
16
|
+
const dialectFunctions = dialect.getDialectFunctions();
|
|
17
|
+
for (const name in dialectFunctions) {
|
|
18
|
+
const overloads = dialectFunctions[name];
|
|
19
|
+
this.entries.set(name, {
|
|
20
|
+
type: 'function',
|
|
21
|
+
name,
|
|
22
|
+
overloads: overloads.map(overload => {
|
|
23
|
+
return {
|
|
24
|
+
returnType: overload.returnType,
|
|
25
|
+
params: overload.params,
|
|
26
|
+
dialect: {
|
|
27
|
+
[dialect.name]: {
|
|
28
|
+
e: overload.e,
|
|
29
|
+
supportsOrderBy: overload.supportsOrderBy,
|
|
30
|
+
defaultOrderByArgIndex: overload.defaultOrderByArgIndex,
|
|
31
|
+
supportsLimit: overload.supportsLimit,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
needsWindowOrderBy: overload.needsWindowOrderBy,
|
|
35
|
+
between: overload.between,
|
|
36
|
+
isSymmetric: overload.isSymmetric,
|
|
37
|
+
};
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
getEntry(name) {
|
|
43
|
+
const func = this.entries.get(name);
|
|
44
|
+
if (func === undefined) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
entry: func,
|
|
49
|
+
exported: false,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
setEntry(_name, _value, _exported) {
|
|
53
|
+
throw new Error('The dialect namespace is immutable!');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.DialectNameSpace = DialectNameSpace;
|
|
57
|
+
//# sourceMappingURL=dialect-name-space.js.map
|
|
@@ -27,6 +27,7 @@ export declare abstract class MalloyElement {
|
|
|
27
27
|
get code(): string;
|
|
28
28
|
protected document(): Document | undefined;
|
|
29
29
|
protected namespace(): NameSpace | undefined;
|
|
30
|
+
getDialectNamespace(dialectName: string): NameSpace | undefined;
|
|
30
31
|
modelEntry(reference: string | ModelEntryReference): ModelEntry | undefined;
|
|
31
32
|
private xlate?;
|
|
32
33
|
/**
|
|
@@ -140,5 +141,7 @@ export declare class Document extends MalloyElement implements NameSpace {
|
|
|
140
141
|
* @returns The error message or undefined
|
|
141
142
|
*/
|
|
142
143
|
checkExperimentalDialect(me: MalloyElement, dialect: string): void;
|
|
144
|
+
private readonly dialectNameSpaces;
|
|
145
|
+
getDialectNamespace(dialectName: string): NameSpace | undefined;
|
|
143
146
|
}
|
|
144
147
|
export {};
|
|
@@ -26,6 +26,7 @@ exports.Document = exports.DocStatementList = exports.ListOf = exports.isDocStat
|
|
|
26
26
|
const dialect_1 = require("../../../dialect");
|
|
27
27
|
const malloy_types_1 = require("../../../model/malloy_types");
|
|
28
28
|
const tags_1 = require("../../../tags");
|
|
29
|
+
const dialect_name_space_1 = require("./dialect-name-space");
|
|
29
30
|
const global_name_space_1 = require("./global-name-space");
|
|
30
31
|
const noteable_1 = require("./noteable");
|
|
31
32
|
const uuid_1 = require("uuid");
|
|
@@ -100,6 +101,10 @@ class MalloyElement {
|
|
|
100
101
|
}
|
|
101
102
|
throw new Error('INTERNAL ERROR: Translation without document scope');
|
|
102
103
|
}
|
|
104
|
+
getDialectNamespace(dialectName) {
|
|
105
|
+
var _a;
|
|
106
|
+
return (_a = this.document()) === null || _a === void 0 ? void 0 : _a.getDialectNamespace(dialectName);
|
|
107
|
+
}
|
|
103
108
|
modelEntry(reference) {
|
|
104
109
|
var _a;
|
|
105
110
|
const key = reference instanceof ModelEntryReference ? reference.name : reference;
|
|
@@ -434,6 +439,7 @@ class Document extends MalloyElement {
|
|
|
434
439
|
this.annotation = {};
|
|
435
440
|
this.experiments = new tags_1.Tag({});
|
|
436
441
|
this.modelAnnotationTodoList = [];
|
|
442
|
+
this.dialectNameSpaces = new Map();
|
|
437
443
|
this.statements = new DocStatementList(statements);
|
|
438
444
|
this.has({ statements: statements });
|
|
439
445
|
}
|
|
@@ -567,6 +573,15 @@ class Document extends MalloyElement {
|
|
|
567
573
|
me.log(`Requires compiler flag '##! experimental.dialect.${dialect}'`, 'error');
|
|
568
574
|
}
|
|
569
575
|
}
|
|
576
|
+
getDialectNamespace(dialectName) {
|
|
577
|
+
if (this.dialectNameSpaces.has(dialectName)) {
|
|
578
|
+
return this.dialectNameSpaces.get(dialectName);
|
|
579
|
+
}
|
|
580
|
+
const dialect = (0, dialect_1.getDialect)(dialectName);
|
|
581
|
+
const ns = new dialect_name_space_1.DialectNameSpace(dialect);
|
|
582
|
+
this.dialectNameSpaces.set(dialectName, ns);
|
|
583
|
+
return ns;
|
|
584
|
+
}
|
|
570
585
|
}
|
|
571
586
|
exports.Document = Document;
|
|
572
587
|
//# sourceMappingURL=malloy-element.js.map
|
|
@@ -593,6 +593,18 @@ describe('query:', () => {
|
|
|
593
593
|
calculate: a is lag(big_i)
|
|
594
594
|
}`).toTranslate();
|
|
595
595
|
});
|
|
596
|
+
describe('dialect functions', () => {
|
|
597
|
+
test('can use function enabled in this dialect (standardsql)', () => {
|
|
598
|
+
expect(`run: a -> {
|
|
599
|
+
group_by: d is date_from_unix_date(1000)
|
|
600
|
+
}`).toTranslate();
|
|
601
|
+
});
|
|
602
|
+
test('cannot use function enabled in a different dialect (duckdb)', () => {
|
|
603
|
+
expect(`run: a -> {
|
|
604
|
+
group_by: ts is to_timestamp(1000)
|
|
605
|
+
}`).translationToFailWith(/Unknown function/);
|
|
606
|
+
});
|
|
607
|
+
});
|
|
596
608
|
});
|
|
597
609
|
describe('qops', () => {
|
|
598
610
|
test('group by single', () => {
|