@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
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.overload = exports.minAnalytic = exports.minAggregate = exports.minScalar = exports.maxAnalytic = exports.maxUngroupedAggregate = exports.anyExprType = exports.maxAggregate = exports.maxScalar = exports.makeParam = exports.param = exports.
|
|
25
|
+
exports.expandOverrideMapFromBase = exports.expandBlueprintMap = exports.overload = exports.minAnalytic = exports.minAggregate = exports.minScalar = exports.maxAnalytic = exports.maxUngroupedAggregate = exports.anyExprType = exports.maxAggregate = exports.maxScalar = exports.makeParam = exports.param = exports.variadicParam = exports.literal = exports.output = exports.constant = exports.sql = exports.spread = exports.arg = void 0;
|
|
26
26
|
function arg(name) {
|
|
27
27
|
return { node: 'function_parameter', name };
|
|
28
28
|
}
|
|
@@ -80,14 +80,14 @@ function literal(type) {
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
exports.literal = literal;
|
|
83
|
-
function
|
|
83
|
+
function variadicParam(name, ...allowedTypes) {
|
|
84
84
|
return {
|
|
85
85
|
name,
|
|
86
86
|
isVariadic: true,
|
|
87
87
|
allowedTypes,
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
|
-
exports.
|
|
90
|
+
exports.variadicParam = variadicParam;
|
|
91
91
|
/**
|
|
92
92
|
* Prefer `makeParam` for future function definitions
|
|
93
93
|
*/
|
|
@@ -181,4 +181,258 @@ function overload(returnType, params, e, options) {
|
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
183
|
exports.overload = overload;
|
|
184
|
+
function removeGeneric(type, generic) {
|
|
185
|
+
if (typeof type === 'string') {
|
|
186
|
+
return type;
|
|
187
|
+
}
|
|
188
|
+
if (type.generic !== (generic === null || generic === void 0 ? void 0 : generic.name)) {
|
|
189
|
+
throw new Error(`Cannot expand generic name ${type.generic}`);
|
|
190
|
+
}
|
|
191
|
+
return generic.type;
|
|
192
|
+
}
|
|
193
|
+
function expandReturnTypeBlueprint(blueprint, generic) {
|
|
194
|
+
if (typeof blueprint === 'string') {
|
|
195
|
+
return minScalar(blueprint);
|
|
196
|
+
}
|
|
197
|
+
else if ('generic' in blueprint) {
|
|
198
|
+
return minScalar(removeGeneric(blueprint, generic));
|
|
199
|
+
}
|
|
200
|
+
else if ('literal' in blueprint) {
|
|
201
|
+
return literal(minScalar(removeGeneric(blueprint.literal, generic)));
|
|
202
|
+
}
|
|
203
|
+
else if ('constant' in blueprint) {
|
|
204
|
+
return constant(minScalar(removeGeneric(blueprint.constant, generic)));
|
|
205
|
+
}
|
|
206
|
+
else if ('dimension' in blueprint) {
|
|
207
|
+
return minScalar(removeGeneric(blueprint.dimension, generic));
|
|
208
|
+
}
|
|
209
|
+
else if ('measure' in blueprint) {
|
|
210
|
+
return minAggregate(removeGeneric(blueprint.measure, generic));
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
return minAnalytic(removeGeneric(blueprint.calculation, generic));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function isTypeDescBlueprint(blueprint) {
|
|
217
|
+
return (typeof blueprint === 'string' ||
|
|
218
|
+
'generic' in blueprint ||
|
|
219
|
+
'literal' in blueprint ||
|
|
220
|
+
'constant' in blueprint ||
|
|
221
|
+
'dimension' in blueprint ||
|
|
222
|
+
'measure' in blueprint ||
|
|
223
|
+
'calculation' in blueprint);
|
|
224
|
+
}
|
|
225
|
+
function extractParamTypeBlueprints(blueprint) {
|
|
226
|
+
if (isTypeDescBlueprint(blueprint)) {
|
|
227
|
+
return [blueprint];
|
|
228
|
+
}
|
|
229
|
+
else if (Array.isArray(blueprint)) {
|
|
230
|
+
return blueprint;
|
|
231
|
+
}
|
|
232
|
+
else if (isTypeDescBlueprint(blueprint.variadic)) {
|
|
233
|
+
return [blueprint.variadic];
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
return blueprint.variadic;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function expandParamTypeBlueprint(blueprint, generic) {
|
|
240
|
+
if (typeof blueprint === 'string') {
|
|
241
|
+
return anyExprType(blueprint);
|
|
242
|
+
}
|
|
243
|
+
else if ('generic' in blueprint) {
|
|
244
|
+
return anyExprType(removeGeneric(blueprint, generic));
|
|
245
|
+
}
|
|
246
|
+
else if ('literal' in blueprint) {
|
|
247
|
+
return literal(maxScalar(removeGeneric(blueprint.literal, generic)));
|
|
248
|
+
}
|
|
249
|
+
else if ('constant' in blueprint) {
|
|
250
|
+
return constant(maxScalar(removeGeneric(blueprint.constant, generic)));
|
|
251
|
+
}
|
|
252
|
+
else if ('dimension' in blueprint) {
|
|
253
|
+
return maxScalar(removeGeneric(blueprint.dimension, generic));
|
|
254
|
+
}
|
|
255
|
+
else if ('measure' in blueprint) {
|
|
256
|
+
return maxAggregate(removeGeneric(blueprint.measure, generic));
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
return maxAnalytic(removeGeneric(blueprint.calculation, generic));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function expandParamTypeBlueprints(blueprints, generic) {
|
|
263
|
+
return blueprints.map(blueprint => expandParamTypeBlueprint(blueprint, generic));
|
|
264
|
+
}
|
|
265
|
+
function isVariadicParamBlueprint(blueprint) {
|
|
266
|
+
return typeof blueprint !== 'string' && 'variadic' in blueprint;
|
|
267
|
+
}
|
|
268
|
+
function expandParamBlueprint(name, blueprint, generic) {
|
|
269
|
+
return {
|
|
270
|
+
name,
|
|
271
|
+
allowedTypes: expandParamTypeBlueprints(extractParamTypeBlueprints(blueprint), generic),
|
|
272
|
+
isVariadic: isVariadicParamBlueprint(blueprint),
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function expandParamsBlueprints(blueprints, generic) {
|
|
276
|
+
const paramsArray = Object.entries(blueprints);
|
|
277
|
+
return paramsArray.map(blueprint => expandParamBlueprint(blueprint[0], blueprint[1], generic));
|
|
278
|
+
}
|
|
279
|
+
function expandBlueprintSqlInterpolation(sql) {
|
|
280
|
+
const src = [];
|
|
281
|
+
const args = [];
|
|
282
|
+
let current = sql;
|
|
283
|
+
while (current.length > 0) {
|
|
284
|
+
const start = current.indexOf('${');
|
|
285
|
+
if (start === -1) {
|
|
286
|
+
src.push(current);
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
const left = current.slice(0, start);
|
|
290
|
+
current = current.slice(start);
|
|
291
|
+
const end = current.indexOf('}');
|
|
292
|
+
if (end === -1) {
|
|
293
|
+
src.push(left + current);
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
const arg = current.slice(2, end);
|
|
297
|
+
current = current.slice(end + 1);
|
|
298
|
+
const isSpread = arg.startsWith('...');
|
|
299
|
+
const isSpecial = arg.endsWith(':');
|
|
300
|
+
const name = isSpread ? arg.slice(3) : isSpecial ? arg.slice(0, -1) : arg;
|
|
301
|
+
const param = { node: 'function_parameter', name };
|
|
302
|
+
src.push(left);
|
|
303
|
+
// TODO validate that there is a param with this name?
|
|
304
|
+
if (isSpread) {
|
|
305
|
+
args.push({ node: 'spread', e: param, prefix: '', suffix: '' });
|
|
306
|
+
}
|
|
307
|
+
else if (isSpecial && name === 'order_by') {
|
|
308
|
+
args.push({ node: 'aggregate_order_by' });
|
|
309
|
+
}
|
|
310
|
+
else if (isSpecial && name === 'limit') {
|
|
311
|
+
args.push({ node: 'aggregate_limit' });
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
args.push(param);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const node = {
|
|
318
|
+
node: 'genericSQLExpr',
|
|
319
|
+
kids: { args },
|
|
320
|
+
src,
|
|
321
|
+
};
|
|
322
|
+
return node;
|
|
323
|
+
}
|
|
324
|
+
function makeParamReplacement(name, blueprint) {
|
|
325
|
+
if (isVariadicParamBlueprint(blueprint)) {
|
|
326
|
+
return {
|
|
327
|
+
node: 'spread',
|
|
328
|
+
e: { node: 'function_parameter', name },
|
|
329
|
+
prefix: '',
|
|
330
|
+
suffix: '',
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
return { node: 'function_parameter', name };
|
|
334
|
+
}
|
|
335
|
+
function expandBlueprintFunction(name, blueprint) {
|
|
336
|
+
const takesArray = Object.entries(blueprint.takes);
|
|
337
|
+
const numCommas = takesArray.length > 0 ? takesArray.length - 1 : 0;
|
|
338
|
+
return {
|
|
339
|
+
node: 'genericSQLExpr',
|
|
340
|
+
kids: {
|
|
341
|
+
args: takesArray.map(param => makeParamReplacement(param[0], param[1])),
|
|
342
|
+
},
|
|
343
|
+
src: [`${name}(`, ...Array(numCommas).fill(','), ')'],
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
function expendImplExprBlueprint(blueprint) {
|
|
347
|
+
if ('sql' in blueprint.impl) {
|
|
348
|
+
return expandBlueprintSqlInterpolation(blueprint.impl.sql);
|
|
349
|
+
}
|
|
350
|
+
else if ('expr' in blueprint.impl) {
|
|
351
|
+
return blueprint.impl.expr;
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
return expandBlueprintFunction(blueprint.impl.function, blueprint);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function expandImplBlueprint(blueprint) {
|
|
358
|
+
return {
|
|
359
|
+
e: expendImplExprBlueprint(blueprint),
|
|
360
|
+
between: blueprint.impl.between,
|
|
361
|
+
needsWindowOrderBy: blueprint.impl.needsWindowOrderBy,
|
|
362
|
+
defaultOrderByArgIndex: blueprint.impl.defaultOrderByArgIndex,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function expandOneBlueprint(blueprint, generic) {
|
|
366
|
+
return {
|
|
367
|
+
returnType: expandReturnTypeBlueprint(blueprint.returns, generic),
|
|
368
|
+
params: expandParamsBlueprints(blueprint.takes, generic),
|
|
369
|
+
isSymmetric: blueprint.isSymmetric,
|
|
370
|
+
supportsOrderBy: blueprint.supportsOrderBy,
|
|
371
|
+
supportsLimit: blueprint.supportsLimit,
|
|
372
|
+
...expandImplBlueprint(blueprint),
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function expandBlueprint(blueprint) {
|
|
376
|
+
if (blueprint.generic !== undefined) {
|
|
377
|
+
const name = blueprint.generic[0];
|
|
378
|
+
return blueprint.generic[1].map(type => expandOneBlueprint(blueprint, { name, type }));
|
|
379
|
+
}
|
|
380
|
+
return [expandOneBlueprint(blueprint)];
|
|
381
|
+
}
|
|
382
|
+
function isDefinitionBlueprint(blueprint) {
|
|
383
|
+
return 'takes' in blueprint && 'returns' in blueprint && 'impl' in blueprint;
|
|
384
|
+
}
|
|
385
|
+
function isImplementationBlueprint(blueprint) {
|
|
386
|
+
return 'function' in blueprint || 'sql' in blueprint || 'expr' in blueprint;
|
|
387
|
+
}
|
|
388
|
+
function expandOverloadedBlueprint(blueprint) {
|
|
389
|
+
if (isDefinitionBlueprint(blueprint)) {
|
|
390
|
+
return expandBlueprint(blueprint);
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
return Object.values(blueprint).flatMap(overload => expandBlueprint(overload));
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
function expandBlueprintMap(blueprints) {
|
|
397
|
+
const map = {};
|
|
398
|
+
for (const name in blueprints) {
|
|
399
|
+
map[name] = expandOverloadedBlueprint(blueprints[name]);
|
|
400
|
+
}
|
|
401
|
+
return map;
|
|
402
|
+
}
|
|
403
|
+
exports.expandBlueprintMap = expandBlueprintMap;
|
|
404
|
+
function expandImplementationBlueprint(base, impl) {
|
|
405
|
+
return expandBlueprint({ ...base, impl });
|
|
406
|
+
}
|
|
407
|
+
function expandOverloadedOverrideBlueprint(name, base, blueprint) {
|
|
408
|
+
if (isImplementationBlueprint(blueprint)) {
|
|
409
|
+
if (!isDefinitionBlueprint(base)) {
|
|
410
|
+
throw new Error(`Malformed function override: ${name}. Attempt to override multiple overloads with a single overload (missing: ${Object.keys(base)})`);
|
|
411
|
+
}
|
|
412
|
+
return expandImplementationBlueprint(base, blueprint);
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
if (isDefinitionBlueprint(base)) {
|
|
416
|
+
throw new Error(`Malformed function override: ${name}. Attempt to override a single overload with multiple overloads (extraneous: ${Object.keys(blueprint)})`);
|
|
417
|
+
}
|
|
418
|
+
return Object.entries(blueprint).flatMap(([overloadName, overload]) => {
|
|
419
|
+
const baseOverload = base[overloadName];
|
|
420
|
+
if (baseOverload === undefined) {
|
|
421
|
+
throw new Error(`Malformed function override: ${name}. No overload named ${overloadName}`);
|
|
422
|
+
}
|
|
423
|
+
return expandImplementationBlueprint(baseOverload, overload);
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
function expandOverrideMapFromBase(base, overrides) {
|
|
428
|
+
const map = {};
|
|
429
|
+
for (const name in overrides) {
|
|
430
|
+
if (!(name in base)) {
|
|
431
|
+
throw new Error(`Malformed function override: ${name}. No such function in Malloy standard`);
|
|
432
|
+
}
|
|
433
|
+
map[name] = expandOverloadedOverrideBlueprint(name, base[name], overrides[name]);
|
|
434
|
+
}
|
|
435
|
+
return map;
|
|
436
|
+
}
|
|
437
|
+
exports.expandOverrideMapFromBase = expandOverrideMapFromBase;
|
|
184
438
|
//# sourceMappingURL=util.js.map
|
package/dist/dialect/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type { DialectFunctionOverloadDef } from './functions/util';
|
|
2
|
-
export { arg, anyExprType, makeParam, overload, minScalar, minAggregate, maxScalar, spread, param,
|
|
1
|
+
export type { DialectFunctionOverloadDef, DefinitionBlueprint, DefinitionBlueprintMap, OverloadedDefinitionBlueprint, } from './functions/util';
|
|
2
|
+
export { arg, anyExprType, makeParam, overload, minScalar, minAggregate, maxScalar, spread, param, variadicParam, literal, sql, } from './functions/util';
|
|
3
3
|
export { Dialect, qtz } from './dialect';
|
|
4
4
|
export type { DialectFieldList, QueryInfo } from './dialect';
|
|
5
5
|
export { StandardSQLDialect } from './standardsql';
|
|
@@ -7,5 +7,6 @@ export { PostgresDialect } from './postgres';
|
|
|
7
7
|
export { DuckDBDialect } from './duckdb';
|
|
8
8
|
export { SnowflakeDialect } from './snowflake';
|
|
9
9
|
export { TrinoDialect } from './trino';
|
|
10
|
-
export { getDialect, registerDialect
|
|
11
|
-
export {
|
|
10
|
+
export { getDialect, registerDialect } from './dialect_map';
|
|
11
|
+
export { getMalloyStandardFunctions } from './functions';
|
|
12
|
+
export type { MalloyStandardFunctionImplementations } from './functions';
|
package/dist/dialect/index.js
CHANGED
|
@@ -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.getMalloyStandardFunctions = exports.registerDialect = exports.getDialect = exports.TrinoDialect = exports.SnowflakeDialect = exports.DuckDBDialect = exports.PostgresDialect = exports.StandardSQLDialect = exports.qtz = exports.Dialect = exports.sql = exports.literal = exports.variadicParam = exports.param = exports.spread = exports.maxScalar = exports.minAggregate = exports.minScalar = exports.overload = exports.makeParam = exports.anyExprType = exports.arg = void 0;
|
|
26
26
|
var util_1 = require("./functions/util");
|
|
27
27
|
Object.defineProperty(exports, "arg", { enumerable: true, get: function () { return util_1.arg; } });
|
|
28
28
|
Object.defineProperty(exports, "anyExprType", { enumerable: true, get: function () { return util_1.anyExprType; } });
|
|
@@ -33,7 +33,7 @@ Object.defineProperty(exports, "minAggregate", { enumerable: true, get: function
|
|
|
33
33
|
Object.defineProperty(exports, "maxScalar", { enumerable: true, get: function () { return util_1.maxScalar; } });
|
|
34
34
|
Object.defineProperty(exports, "spread", { enumerable: true, get: function () { return util_1.spread; } });
|
|
35
35
|
Object.defineProperty(exports, "param", { enumerable: true, get: function () { return util_1.param; } });
|
|
36
|
-
Object.defineProperty(exports, "
|
|
36
|
+
Object.defineProperty(exports, "variadicParam", { enumerable: true, get: function () { return util_1.variadicParam; } });
|
|
37
37
|
Object.defineProperty(exports, "literal", { enumerable: true, get: function () { return util_1.literal; } });
|
|
38
38
|
Object.defineProperty(exports, "sql", { enumerable: true, get: function () { return util_1.sql; } });
|
|
39
39
|
var dialect_1 = require("./dialect");
|
|
@@ -52,7 +52,6 @@ Object.defineProperty(exports, "TrinoDialect", { enumerable: true, get: function
|
|
|
52
52
|
var dialect_map_1 = require("./dialect_map");
|
|
53
53
|
Object.defineProperty(exports, "getDialect", { enumerable: true, get: function () { return dialect_map_1.getDialect; } });
|
|
54
54
|
Object.defineProperty(exports, "registerDialect", { enumerable: true, get: function () { return dialect_map_1.registerDialect; } });
|
|
55
|
-
Object.defineProperty(exports, "getDialectFunction", { enumerable: true, get: function () { return dialect_map_1.getDialectFunction; } });
|
|
56
55
|
var functions_1 = require("./functions");
|
|
57
|
-
Object.defineProperty(exports, "
|
|
56
|
+
Object.defineProperty(exports, "getMalloyStandardFunctions", { enumerable: true, get: function () { return functions_1.getMalloyStandardFunctions; } });
|
|
58
57
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
const string_agg = {
|
|
11
|
+
default_separator: {
|
|
12
|
+
takes: { 'value': { dimension: 'string' } },
|
|
13
|
+
returns: { measure: 'string' },
|
|
14
|
+
supportsOrderBy: true,
|
|
15
|
+
impl: { sql: "STRING_AGG(${value}, ','${order_by:})" },
|
|
16
|
+
},
|
|
17
|
+
with_separator: {
|
|
18
|
+
takes: {
|
|
19
|
+
'value': { dimension: 'string' },
|
|
20
|
+
'separator': { literal: 'string' },
|
|
21
|
+
},
|
|
22
|
+
returns: { measure: 'string' },
|
|
23
|
+
supportsOrderBy: true,
|
|
24
|
+
impl: { sql: 'STRING_AGG(${value}, ${separator}${order_by:})' },
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
const string_agg_distinct = {
|
|
28
|
+
default_separator: {
|
|
29
|
+
...string_agg['default_separator'],
|
|
30
|
+
isSymmetric: true,
|
|
31
|
+
supportsOrderBy: 'only_default',
|
|
32
|
+
impl: {
|
|
33
|
+
sql: "STRING_AGG(DISTINCT ${value}, ','${order_by:})",
|
|
34
|
+
defaultOrderByArgIndex: 0,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
with_separator: {
|
|
38
|
+
...string_agg['with_separator'],
|
|
39
|
+
isSymmetric: true,
|
|
40
|
+
supportsOrderBy: 'only_default',
|
|
41
|
+
impl: {
|
|
42
|
+
sql: 'STRING_AGG(DISTINCT ${value}, ${separator}${order_by:})',
|
|
43
|
+
defaultOrderByArgIndex: 0,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
exports.POSTGRES_DIALECT_FUNCTIONS = {
|
|
48
|
+
string_agg,
|
|
49
|
+
string_agg_distinct,
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=dialect_functions.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
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_MALLOY_STANDARD_OVERLOADS = void 0;
|
|
10
|
+
function greatestOrLeastSQL(name) {
|
|
11
|
+
return ('CASE WHEN NUM_NULLS(${...values}) > 0 THEN NULL ELSE ' +
|
|
12
|
+
name +
|
|
13
|
+
'(${...values}) END');
|
|
14
|
+
}
|
|
15
|
+
exports.POSTGRES_MALLOY_STANDARD_OVERLOADS = {
|
|
16
|
+
byte_length: { function: 'OCTET_LENGTH' },
|
|
17
|
+
// There's no ENDS_WITH function in Postgres, so we do a hacky check that the last
|
|
18
|
+
// N characters, where N is the length of the suffix, are equal to the suffix.
|
|
19
|
+
ends_with: {
|
|
20
|
+
sql: 'COALESCE(RIGHT(${value}, LENGTH(${suffix})) = ${suffix}, false)',
|
|
21
|
+
},
|
|
22
|
+
greatest: { sql: greatestOrLeastSQL('GREATEST') },
|
|
23
|
+
least: { sql: greatestOrLeastSQL('LEAST') },
|
|
24
|
+
// Postgres doesn't have an IFNULL function, so we use COALESCE, which is equivalent.
|
|
25
|
+
ifnull: { sql: 'COALESCE(${value}, ${default})' },
|
|
26
|
+
is_inf: {
|
|
27
|
+
sql: "COALESCE(${value} = DOUBLE PRECISION 'Infinity' OR ${value} = DOUBLE PRECISION '-Infinity', false)",
|
|
28
|
+
},
|
|
29
|
+
is_nan: { sql: "COALESCE(${value} = NUMERIC 'NaN', false)" },
|
|
30
|
+
// Parameter order is backwards in Postgres.
|
|
31
|
+
log: { sql: 'LOG(${base}, ${value})' },
|
|
32
|
+
rand: { function: 'RANDOM' },
|
|
33
|
+
regexp_extract: { function: 'SUBSTRING' },
|
|
34
|
+
replace: {
|
|
35
|
+
// In Postgres we specifically need to say that the replacement should be global.
|
|
36
|
+
regular_expression: {
|
|
37
|
+
sql: "REGEXP_REPLACE(${value}, ${pattern}, ${replacement}, 'g')",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
// Postgres doesn't let you ROUND a FLOAT to a particular number of decimal places,
|
|
41
|
+
// so we cast to NUMERIC first...
|
|
42
|
+
// TODO it would be nice not to have to do this cast if it was already NUMERIC type...
|
|
43
|
+
round: {
|
|
44
|
+
to_integer: { sql: 'ROUND((${value})::NUMERIC)' },
|
|
45
|
+
to_precision: { sql: 'ROUND((${value})::NUMERIC, ${precision})' },
|
|
46
|
+
},
|
|
47
|
+
// TODO this is a bit of a hack in order to make the arrayAggUnnest work for Postgres,
|
|
48
|
+
// as we don't currently have a good way of doing this while preserving types
|
|
49
|
+
stddev: { sql: 'STDDEV(${value}::DOUBLE PRECISION)' },
|
|
50
|
+
substr: {
|
|
51
|
+
position_only: {
|
|
52
|
+
sql: 'SUBSTR(${value}, CASE WHEN ${position} < 0 THEN LENGTH(${value}) + ${position} + 1 ELSE ${position} END)',
|
|
53
|
+
},
|
|
54
|
+
with_length: {
|
|
55
|
+
sql: 'SUBSTR(${value}, CASE WHEN ${position} < 0 THEN LENGTH(${value}) + ${position} + 1 ELSE ${position} END, ${length})',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
// Postgres doesn't let you TRUNC a FLOAT with a precision, so we cast to NUMERIC first
|
|
59
|
+
// Also, TRUNC(NULL) doesn't compile because PG doesn't know the type of NULL, so we cast to
|
|
60
|
+
// NUMERIC there too...
|
|
61
|
+
// TODO Maybe there's a way we don't have to cast to NUMERIC.
|
|
62
|
+
trunc: {
|
|
63
|
+
to_integer: {
|
|
64
|
+
sql: 'TRUNC(${value}::NUMERIC)',
|
|
65
|
+
},
|
|
66
|
+
to_precision: {
|
|
67
|
+
sql: 'TRUNC((${value}::NUMERIC), ${precision})',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
// Aparently the ASCII function also works for unicode code points...
|
|
71
|
+
unicode: { function: 'ASCII' },
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=function_overrides.js.map
|
|
@@ -20,7 +20,6 @@ export declare class PostgresDialect extends PostgresBase {
|
|
|
20
20
|
supportsSafeCast: boolean;
|
|
21
21
|
dontUnionIndex: boolean;
|
|
22
22
|
supportsQualify: boolean;
|
|
23
|
-
globalFunctions: import("../functions/function_map").FunctionMap;
|
|
24
23
|
supportsNesting: boolean;
|
|
25
24
|
experimental: boolean;
|
|
26
25
|
readsNestedData: boolean;
|
|
@@ -53,7 +52,9 @@ export declare class PostgresDialect extends PostgresBase {
|
|
|
53
52
|
sqlOrderBy(orderTerms: string[]): string;
|
|
54
53
|
sqlLiteralString(literal: string): string;
|
|
55
54
|
sqlLiteralRegexp(literal: string): string;
|
|
56
|
-
|
|
55
|
+
getDialectFunctionOverrides(): {
|
|
56
|
+
[name: string]: DialectFunctionOverloadDef[];
|
|
57
|
+
};
|
|
57
58
|
getDialectFunctions(): {
|
|
58
59
|
[name: string]: DialectFunctionOverloadDef[];
|
|
59
60
|
};
|
|
@@ -25,9 +25,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.PostgresDialect = 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 pg_impl_1 = require("../pg_impl");
|
|
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 pgMakeIntervalMap = {
|
|
32
33
|
'year': 'years',
|
|
33
34
|
'month': 'months',
|
|
@@ -88,7 +89,6 @@ class PostgresDialect extends pg_impl_1.PostgresBase {
|
|
|
88
89
|
this.supportsSafeCast = false;
|
|
89
90
|
this.dontUnionIndex = false;
|
|
90
91
|
this.supportsQualify = false;
|
|
91
|
-
this.globalFunctions = functions_1.POSTGRES_FUNCTIONS;
|
|
92
92
|
this.supportsNesting = true;
|
|
93
93
|
this.experimental = false;
|
|
94
94
|
this.readsNestedData = false;
|
|
@@ -319,11 +319,11 @@ class PostgresDialect extends pg_impl_1.PostgresBase {
|
|
|
319
319
|
sqlLiteralRegexp(literal) {
|
|
320
320
|
return "'" + literal.replace(/'/g, "''") + "'";
|
|
321
321
|
}
|
|
322
|
-
|
|
323
|
-
return functions_1.
|
|
322
|
+
getDialectFunctionOverrides() {
|
|
323
|
+
return (0, functions_1.expandOverrideMap)(function_overrides_1.POSTGRES_MALLOY_STANDARD_OVERLOADS);
|
|
324
324
|
}
|
|
325
325
|
getDialectFunctions() {
|
|
326
|
-
return dialect_functions_1.POSTGRES_DIALECT_FUNCTIONS;
|
|
326
|
+
return (0, functions_1.expandBlueprintMap)(dialect_functions_1.POSTGRES_DIALECT_FUNCTIONS);
|
|
327
327
|
}
|
|
328
328
|
malloyTypeToSQLType(malloyType) {
|
|
329
329
|
if (malloyType.type === 'number') {
|
|
@@ -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.SNOWFLAKE_DIALECT_FUNCTIONS = void 0;
|
|
10
|
+
const util_1 = require("../functions/util");
|
|
11
|
+
const order_by = {
|
|
12
|
+
node: 'aggregate_order_by',
|
|
13
|
+
prefix: ' WITHIN GROUP(',
|
|
14
|
+
suffix: ')',
|
|
15
|
+
};
|
|
16
|
+
const string_agg = {
|
|
17
|
+
default_separator: {
|
|
18
|
+
takes: { 'value': { dimension: 'string' } },
|
|
19
|
+
returns: { measure: 'string' },
|
|
20
|
+
supportsOrderBy: true,
|
|
21
|
+
impl: {
|
|
22
|
+
expr: (0, util_1.sql) `LISTAGG(${(0, util_1.arg)('value')}, ',')${order_by}`,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
with_separator: {
|
|
26
|
+
takes: {
|
|
27
|
+
'value': { dimension: 'string' },
|
|
28
|
+
'separator': { literal: 'string' },
|
|
29
|
+
},
|
|
30
|
+
returns: { measure: 'string' },
|
|
31
|
+
supportsOrderBy: true,
|
|
32
|
+
impl: {
|
|
33
|
+
expr: (0, util_1.sql) `LISTAGG(${(0, util_1.arg)('value')}, ${(0, util_1.arg)('separator')})${order_by}`,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const string_agg_distinct = {
|
|
38
|
+
default_separator: {
|
|
39
|
+
...string_agg['default_separator'],
|
|
40
|
+
isSymmetric: true,
|
|
41
|
+
impl: {
|
|
42
|
+
expr: (0, util_1.sql) `LISTAGG(DISTINCT ${(0, util_1.arg)('value')}, ',')${order_by}`,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
with_separator: {
|
|
46
|
+
...string_agg['with_separator'],
|
|
47
|
+
isSymmetric: true,
|
|
48
|
+
impl: {
|
|
49
|
+
expr: (0, util_1.sql) `LISTAGG(DISTINCT ${(0, util_1.arg)('value')}, ${(0, util_1.arg)('separator')})${order_by}`,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
exports.SNOWFLAKE_DIALECT_FUNCTIONS = {
|
|
54
|
+
string_agg,
|
|
55
|
+
string_agg_distinct,
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=dialect_functions.js.map
|
|
@@ -0,0 +1,39 @@
|
|
|
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_MALLOY_STANDARD_OVERLOADS = void 0;
|
|
10
|
+
exports.SNOWFLAKE_MALLOY_STANDARD_OVERLOADS = {
|
|
11
|
+
// Need to explicitly have a case for when the arg is 0, to return ''
|
|
12
|
+
chr: { sql: "COALESCE(CHR(${value}), '')" },
|
|
13
|
+
// in Snowflake division is always a float division, so we need this conversion
|
|
14
|
+
div: {
|
|
15
|
+
sql: 'CASE WHEN DIV0(${dividend}, ${divisor}) < 0 THEN CEIL(DIV0(${dividend}, ${divisor})) ELSE FLOOR(DIV0(${dividend}, ${divisor})) END',
|
|
16
|
+
},
|
|
17
|
+
is_inf: {
|
|
18
|
+
sql: "COALESCE(${value} = 'inf'::FLOAT OR ${value} = '-inf'::FLOAT, false)",
|
|
19
|
+
},
|
|
20
|
+
is_nan: { sql: "COALESCE(${value} = 'NAN'::FLOAT, false)" },
|
|
21
|
+
length: { function: 'LENGTH' },
|
|
22
|
+
byte_length: { sql: 'CEIL(BIT_LENGTH(${value}) / 8)' },
|
|
23
|
+
// Snowflake takes base first, then value.
|
|
24
|
+
log: { sql: 'LOG(${base}, ${value})' },
|
|
25
|
+
rand: { sql: 'UNIFORM(0::FLOAT, 1::FLOAT, RANDOM())' },
|
|
26
|
+
regexp_extract: { sql: "REGEXP_SUBSTR(${value}, ${pattern}, 1, 1, 'e')" },
|
|
27
|
+
starts_with: { sql: 'COALESCE(STARTSWITH(${value}, ${prefix}), false)' },
|
|
28
|
+
ends_with: { sql: 'COALESCE(ENDSWITH(${value}, ${suffix}), false)' },
|
|
29
|
+
strpos: { sql: 'POSITION(${search_string}, ${test_string})' },
|
|
30
|
+
trunc: {
|
|
31
|
+
to_integer: {
|
|
32
|
+
sql: 'CASE WHEN ${value} < 0 THEN CEIL(${value}) ELSE FLOOR(${value}) END',
|
|
33
|
+
},
|
|
34
|
+
to_precision: {
|
|
35
|
+
sql: 'CASE WHEN ${value} < 0 THEN CEIL(${value} * POW(10, ${precision})) / POW(10, ${precision}) ELSE FLOOR(${value} * POW(10, ${precision})) / POW(10, ${precision}) END',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=function_overrides.js.map
|
|
@@ -15,7 +15,6 @@ export declare class SnowflakeDialect extends Dialect {
|
|
|
15
15
|
defaultSampling: {
|
|
16
16
|
rows: number;
|
|
17
17
|
};
|
|
18
|
-
globalFunctions: import("../functions/function_map").FunctionMap;
|
|
19
18
|
unnestWithNumbers: boolean;
|
|
20
19
|
supportUnnestArrayAgg: boolean;
|
|
21
20
|
supportsAggDistinct: boolean;
|
|
@@ -57,7 +56,9 @@ export declare class SnowflakeDialect extends Dialect {
|
|
|
57
56
|
sqlOrderBy(orderTerms: string[]): string;
|
|
58
57
|
sqlLiteralString(literal: string): string;
|
|
59
58
|
sqlLiteralRegexp(literal: string): string;
|
|
60
|
-
|
|
59
|
+
getDialectFunctionOverrides(): {
|
|
60
|
+
[name: string]: DialectFunctionOverloadDef[];
|
|
61
|
+
};
|
|
61
62
|
getDialectFunctions(): {
|
|
62
63
|
[name: string]: DialectFunctionOverloadDef[];
|
|
63
64
|
};
|