@malloydata/malloy 0.0.39-dev230613161129 → 0.0.39
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 +9 -13
- package/dist/dialect/dialect.js +16 -3
- package/dist/dialect/dialect_map.d.ts +2 -0
- package/dist/dialect/dialect_map.js +61 -1
- package/dist/dialect/{duckdb.d.ts → duckdb/duckdb.d.ts} +8 -5
- package/dist/dialect/{duckdb.js → duckdb/duckdb.js} +21 -9
- package/dist/dialect/duckdb/functions/byte_length.d.ts +2 -0
- package/dist/dialect/duckdb/functions/byte_length.js +33 -0
- package/dist/dialect/duckdb/functions/div.d.ts +2 -0
- package/dist/dialect/duckdb/functions/div.js +38 -0
- package/dist/dialect/duckdb/functions/duckdb_functions.d.ts +1 -0
- package/dist/dialect/duckdb/functions/duckdb_functions.js +52 -0
- package/dist/dialect/duckdb/functions/ends_with.d.ts +2 -0
- package/dist/dialect/duckdb/functions/ends_with.js +35 -0
- package/dist/dialect/duckdb/functions/greatest_and_least.d.ts +3 -0
- package/dist/dialect/duckdb/functions/greatest_and_least.js +58 -0
- package/dist/dialect/duckdb/functions/index.d.ts +1 -0
- package/dist/dialect/duckdb/functions/index.js +28 -0
- package/dist/dialect/duckdb/functions/is_inf.d.ts +2 -0
- package/dist/dialect/duckdb/functions/is_inf.js +33 -0
- package/dist/dialect/duckdb/functions/is_nan.d.ts +2 -0
- package/dist/dialect/duckdb/functions/is_nan.js +33 -0
- package/dist/dialect/duckdb/functions/log.d.ts +2 -0
- package/dist/dialect/duckdb/functions/log.js +38 -0
- package/dist/dialect/duckdb/functions/rand.d.ts +2 -0
- package/dist/dialect/duckdb/functions/rand.js +31 -0
- package/dist/dialect/duckdb/functions/replace.d.ts +2 -0
- package/dist/dialect/duckdb/functions/replace.js +40 -0
- package/dist/dialect/duckdb/functions/trunc.d.ts +2 -0
- package/dist/dialect/duckdb/functions/trunc.js +39 -0
- package/dist/dialect/duckdb/functions/unicode.d.ts +2 -0
- package/dist/dialect/duckdb/functions/unicode.js +35 -0
- package/dist/dialect/duckdb/index.d.ts +1 -0
- package/dist/dialect/duckdb/index.js +40 -0
- package/dist/dialect/functions/all_functions.d.ts +8 -0
- package/dist/dialect/functions/all_functions.js +135 -0
- package/dist/dialect/functions/atan2.d.ts +2 -0
- package/dist/dialect/functions/atan2.js +33 -0
- package/dist/dialect/functions/avg_moving.d.ts +2 -0
- package/dist/dialect/functions/avg_moving.js +46 -0
- package/dist/dialect/functions/chr.d.ts +4 -0
- package/dist/dialect/functions/chr.js +45 -0
- package/dist/dialect/functions/coalesce.d.ts +2 -0
- package/dist/dialect/functions/coalesce.js +38 -0
- package/dist/dialect/functions/concat.d.ts +2 -0
- package/dist/dialect/functions/concat.js +38 -0
- package/dist/dialect/functions/div.d.ts +2 -0
- package/dist/dialect/functions/div.js +36 -0
- package/dist/dialect/functions/first_value_window.d.ts +3 -0
- package/dist/dialect/functions/first_value_window.js +49 -0
- package/dist/dialect/functions/function_map.d.ts +16 -0
- package/dist/dialect/functions/function_map.js +50 -0
- package/dist/dialect/functions/greatest_and_least.d.ts +3 -0
- package/dist/dialect/functions/greatest_and_least.js +44 -0
- package/dist/dialect/functions/ifnull.d.ts +2 -0
- package/dist/dialect/functions/ifnull.js +38 -0
- package/dist/dialect/functions/index.d.ts +2 -0
- package/dist/dialect/functions/index.js +28 -0
- package/dist/dialect/functions/is_inf.d.ts +2 -0
- package/dist/dialect/functions/is_inf.js +33 -0
- package/dist/dialect/functions/is_nan.d.ts +2 -0
- package/dist/dialect/functions/is_nan.js +33 -0
- package/dist/dialect/functions/lag.d.ts +2 -0
- package/dist/dialect/functions/lag.js +53 -0
- package/dist/dialect/functions/lead.d.ts +2 -0
- package/dist/dialect/functions/lead.js +50 -0
- package/dist/dialect/functions/length.d.ts +3 -0
- package/dist/dialect/functions/length.js +39 -0
- package/dist/dialect/functions/log.d.ts +2 -0
- package/dist/dialect/functions/log.js +35 -0
- package/dist/dialect/functions/lower.d.ts +2 -0
- package/dist/dialect/functions/lower.js +34 -0
- package/dist/dialect/functions/nullif.d.ts +2 -0
- package/dist/dialect/functions/nullif.js +42 -0
- package/dist/dialect/functions/pi.d.ts +2 -0
- package/dist/{lang/ast/types/type-desc.js → dialect/functions/pi.js} +7 -1
- package/dist/dialect/functions/pow.d.ts +2 -0
- package/dist/dialect/functions/pow.js +35 -0
- package/dist/dialect/functions/rand.d.ts +2 -0
- package/dist/dialect/functions/rand.js +31 -0
- package/dist/dialect/functions/rank.d.ts +2 -0
- package/dist/dialect/functions/rank.js +36 -0
- package/dist/dialect/functions/regexp_extract.d.ts +2 -0
- package/dist/dialect/functions/regexp_extract.js +41 -0
- package/dist/dialect/functions/repeat.d.ts +2 -0
- package/dist/dialect/functions/repeat.js +35 -0
- package/dist/dialect/functions/replace.d.ts +2 -0
- package/dist/dialect/functions/replace.js +42 -0
- package/dist/dialect/functions/reverse.d.ts +2 -0
- package/dist/dialect/functions/reverse.js +34 -0
- package/dist/dialect/functions/round.d.ts +2 -0
- package/dist/dialect/functions/round.js +40 -0
- package/dist/dialect/functions/row_number.d.ts +2 -0
- package/dist/dialect/functions/row_number.js +40 -0
- package/dist/dialect/functions/simple_numeric_functions.d.ts +15 -0
- package/dist/dialect/functions/simple_numeric_functions.js +60 -0
- package/dist/dialect/functions/starts_ends_with.d.ts +3 -0
- package/dist/dialect/functions/starts_ends_with.js +43 -0
- package/dist/dialect/functions/stddev.d.ts +2 -0
- package/dist/dialect/functions/stddev.js +34 -0
- package/dist/dialect/functions/strpos.d.ts +2 -0
- package/dist/dialect/functions/strpos.js +35 -0
- package/dist/dialect/functions/substr.d.ts +2 -0
- package/dist/dialect/functions/substr.js +37 -0
- package/dist/dialect/functions/sum_min_max_window.d.ts +7 -0
- package/dist/dialect/functions/sum_min_max_window.js +94 -0
- package/dist/dialect/functions/trim_functions.d.ts +4 -0
- package/dist/dialect/functions/trim_functions.js +42 -0
- package/dist/dialect/functions/trunc.d.ts +2 -0
- package/dist/dialect/functions/trunc.js +38 -0
- package/dist/dialect/functions/upper.d.ts +2 -0
- package/dist/dialect/functions/upper.js +34 -0
- package/dist/dialect/functions/util.d.ts +45 -0
- package/dist/dialect/functions/util.js +187 -0
- package/dist/dialect/index.d.ts +1 -1
- package/dist/dialect/index.js +2 -1
- package/dist/dialect/postgres/functions/byte_length.d.ts +2 -0
- package/dist/dialect/postgres/functions/byte_length.js +33 -0
- package/dist/dialect/postgres/functions/ends_with.d.ts +2 -0
- package/dist/dialect/postgres/functions/ends_with.js +38 -0
- package/dist/dialect/postgres/functions/greatest_and_least.d.ts +3 -0
- package/dist/dialect/postgres/functions/greatest_and_least.js +45 -0
- package/dist/dialect/postgres/functions/ifnull.d.ts +2 -0
- package/dist/dialect/postgres/functions/ifnull.js +40 -0
- package/dist/dialect/postgres/functions/index.d.ts +1 -0
- package/dist/dialect/postgres/functions/index.js +28 -0
- package/dist/dialect/postgres/functions/is_inf.d.ts +2 -0
- package/dist/dialect/postgres/functions/is_inf.js +34 -0
- package/dist/dialect/postgres/functions/is_nan.d.ts +2 -0
- package/dist/dialect/postgres/functions/is_nan.js +33 -0
- package/dist/dialect/postgres/functions/log.d.ts +2 -0
- package/dist/dialect/postgres/functions/log.js +37 -0
- package/dist/dialect/postgres/functions/postgres_functions.d.ts +1 -0
- package/dist/dialect/postgres/functions/postgres_functions.js +60 -0
- package/dist/dialect/postgres/functions/rand.d.ts +2 -0
- package/dist/dialect/postgres/functions/rand.js +31 -0
- package/dist/dialect/postgres/functions/regexp_extract.d.ts +2 -0
- package/dist/dialect/postgres/functions/regexp_extract.js +35 -0
- package/dist/dialect/postgres/functions/replace.d.ts +2 -0
- package/dist/dialect/postgres/functions/replace.js +40 -0
- package/dist/dialect/postgres/functions/round.d.ts +2 -0
- package/dist/dialect/postgres/functions/round.js +39 -0
- package/dist/dialect/postgres/functions/stddev.d.ts +2 -0
- package/dist/dialect/postgres/functions/stddev.js +37 -0
- package/dist/dialect/postgres/functions/substr.d.ts +2 -0
- package/dist/dialect/postgres/functions/substr.js +38 -0
- package/dist/dialect/postgres/functions/trunc.d.ts +2 -0
- package/dist/dialect/postgres/functions/trunc.js +40 -0
- package/dist/dialect/postgres/functions/unicode.d.ts +2 -0
- package/dist/dialect/postgres/functions/unicode.js +34 -0
- package/dist/dialect/postgres/index.d.ts +1 -0
- package/dist/dialect/postgres/index.js +40 -0
- package/dist/dialect/{postgres.d.ts → postgres/postgres.d.ts} +9 -5
- package/dist/dialect/{postgres.js → postgres/postgres.js} +24 -10
- package/dist/dialect/standardsql/functions/chr.d.ts +2 -0
- package/dist/dialect/standardsql/functions/chr.js +37 -0
- package/dist/dialect/standardsql/functions/index.d.ts +1 -0
- package/dist/dialect/standardsql/functions/index.js +28 -0
- package/dist/dialect/standardsql/functions/pi.d.ts +2 -0
- package/dist/dialect/standardsql/functions/pi.js +32 -0
- package/dist/dialect/standardsql/functions/standardsql_functions.d.ts +1 -0
- package/dist/dialect/standardsql/functions/standardsql_functions.js +33 -0
- package/dist/dialect/standardsql/index.d.ts +1 -0
- package/dist/dialect/standardsql/index.js +40 -0
- package/dist/dialect/{standardsql.d.ts → standardsql/standardsql.d.ts} +7 -4
- package/dist/dialect/{standardsql.js → standardsql/standardsql.js} +13 -11
- package/dist/index.d.ts +1 -1
- package/dist/lang/ast/ast-utils.js +1 -0
- package/dist/lang/ast/elements/define-query.js +1 -1
- package/dist/lang/ast/elements/import-statement.js +6 -1
- package/dist/lang/ast/executors/index-executor.d.ts +1 -1
- package/dist/lang/ast/executors/index-executor.js +2 -2
- package/dist/lang/ast/executors/project-executor.d.ts +1 -1
- package/dist/lang/ast/executors/project-executor.js +2 -2
- package/dist/lang/ast/executors/reduce-executor.d.ts +2 -4
- package/dist/lang/ast/executors/reduce-executor.js +8 -4
- package/dist/lang/ast/expressions/binary-boolean.d.ts +1 -1
- package/dist/lang/ast/expressions/binary-boolean.js +2 -0
- package/dist/lang/ast/expressions/constant-sub-expression.js +10 -0
- package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-aggregate-function.js +28 -2
- package/dist/lang/ast/expressions/expr-alternation-tree.js +1 -0
- package/dist/lang/ast/expressions/expr-cast.js +1 -0
- package/dist/lang/ast/expressions/expr-coalesce.d.ts +1 -1
- package/dist/lang/ast/expressions/expr-coalesce.js +1 -0
- package/dist/lang/ast/expressions/expr-count-distinct.d.ts +1 -1
- package/dist/lang/ast/expressions/expr-count.js +1 -0
- package/dist/lang/ast/expressions/expr-filter.d.ts +1 -1
- package/dist/lang/ast/expressions/expr-filter.js +1 -1
- package/dist/lang/ast/expressions/expr-func.d.ts +6 -1
- package/dist/lang/ast/expressions/expr-func.js +266 -16
- package/dist/lang/ast/expressions/expr-granular-time.d.ts +1 -1
- package/dist/lang/ast/expressions/expr-id-reference.js +12 -0
- package/dist/lang/ast/expressions/expr-logical-op.d.ts +1 -1
- package/dist/lang/ast/expressions/expr-max.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-min.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-not.d.ts +1 -1
- package/dist/lang/ast/expressions/expr-now.js +2 -0
- package/dist/lang/ast/expressions/expr-null.js +1 -0
- package/dist/lang/ast/expressions/expr-number.js +5 -1
- package/dist/lang/ast/expressions/expr-regex.js +4 -1
- package/dist/lang/ast/expressions/expr-string.js +1 -0
- package/dist/lang/ast/expressions/expr-time-extract.js +2 -0
- package/dist/lang/ast/expressions/expr-time.js +1 -0
- package/dist/lang/ast/expressions/expr-ungroup.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-ungroup.js +15 -7
- package/dist/lang/ast/expressions/for-range.d.ts +1 -1
- package/dist/lang/ast/expressions/pick-when.js +7 -0
- package/dist/lang/ast/expressions/range.js +1 -0
- package/dist/lang/ast/expressions/time-literal.js +9 -3
- package/dist/lang/ast/field-space/column-space-field.d.ts +1 -2
- package/dist/lang/ast/field-space/dynamic-space.js +6 -4
- package/dist/lang/ast/field-space/field-definition-value.d.ts +1 -1
- package/dist/lang/ast/field-space/project-field-space.d.ts +2 -2
- package/dist/lang/ast/field-space/project-field-space.js +12 -13
- package/dist/lang/ast/field-space/query-space-field.d.ts +1 -2
- package/dist/lang/ast/field-space/query-space-field.js +1 -1
- package/dist/lang/ast/field-space/query-spaces.d.ts +16 -2
- package/dist/lang/ast/field-space/query-spaces.js +175 -10
- package/dist/lang/ast/field-space/reference-field.d.ts +3 -2
- package/dist/lang/ast/field-space/reference-field.js +8 -1
- package/dist/lang/ast/field-space/rename-space-field.d.ts +1 -2
- package/dist/lang/ast/field-space/static-space.d.ts +4 -3
- package/dist/lang/ast/field-space/static-space.js +4 -0
- package/dist/lang/ast/field-space/struct-space-field-base.d.ts +1 -2
- package/dist/lang/ast/field-space/struct-space-field-base.js +1 -1
- package/dist/lang/ast/field-space/wild-space-field.d.ts +1 -2
- package/dist/lang/ast/fragtype-utils.d.ts +1 -1
- package/dist/lang/ast/fragtype-utils.js +4 -3
- package/dist/lang/ast/index.d.ts +1 -0
- package/dist/lang/ast/index.js +1 -0
- package/dist/lang/ast/query-items/field-declaration.d.ts +40 -4
- package/dist/lang/ast/query-items/field-declaration.js +102 -3
- package/dist/lang/ast/query-items/field-references.d.ts +44 -2
- package/dist/lang/ast/query-items/field-references.js +110 -2
- package/dist/lang/ast/query-items/typecheck_utils.d.ts +10 -0
- package/dist/lang/ast/query-items/typecheck_utils.js +177 -0
- package/dist/lang/ast/query-properties/aggregate.js +0 -6
- package/dist/lang/ast/query-properties/calculate.d.ts +5 -0
- package/dist/lang/ast/query-properties/calculate.js +33 -0
- package/dist/lang/ast/query-properties/dimmensions.js +0 -3
- package/dist/lang/ast/query-properties/filters.js +6 -3
- package/dist/lang/ast/query-properties/group-by.js +0 -6
- package/dist/lang/ast/query-properties/measures.js +0 -3
- package/dist/lang/ast/query-properties/nest-reference.d.ts +2 -0
- package/dist/lang/ast/query-properties/nest-reference.js +23 -0
- package/dist/lang/ast/query-properties/ordering.d.ts +1 -1
- package/dist/lang/ast/query-properties/ordering.js +18 -8
- package/dist/lang/ast/query-properties/qop-desc.js +8 -4
- package/dist/lang/ast/query-properties/top.js +20 -6
- package/dist/lang/ast/sources/named-source.js +4 -0
- package/dist/lang/ast/sources/sql-source.js +5 -1
- package/dist/lang/ast/time-utils.d.ts +1 -2
- package/dist/lang/ast/types/expr-result.d.ts +1 -2
- package/dist/lang/ast/types/expression-def.d.ts +3 -4
- package/dist/lang/ast/types/expression-def.js +10 -2
- package/dist/lang/ast/types/field-space.d.ts +7 -0
- package/dist/lang/ast/types/global-name-space.d.ts +12 -0
- package/dist/lang/ast/types/global-name-space.js +51 -0
- package/dist/lang/ast/types/malloy-element.d.ts +1 -0
- package/dist/lang/ast/types/malloy-element.js +15 -2
- package/dist/lang/ast/types/query-property.d.ts +1 -2
- package/dist/lang/ast/types/query-property.js +2 -0
- package/dist/lang/ast/types/space-entry.d.ts +1 -1
- package/dist/lang/ast/types/space-field.d.ts +1 -2
- package/dist/lang/ast/types/space-field.js +5 -1
- package/dist/lang/ast/types/space-param.d.ts +1 -2
- package/dist/lang/ast/types/space-param.js +10 -2
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +138 -135
- package/dist/lang/lib/Malloy/MalloyLexer.js +1135 -1103
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +252 -275
- package/dist/lang/lib/Malloy/MalloyParser.js +1753 -1905
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +40 -103
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +25 -64
- package/dist/lang/malloy-to-ast.d.ts +11 -7
- package/dist/lang/malloy-to-ast.js +90 -51
- package/dist/lang/parse-tree-walkers/document-symbol-walker.js +5 -2
- package/dist/lang/test/parse.spec.js +399 -18
- package/dist/lang/test/test-translator.d.ts +1 -0
- package/dist/lang/test/test-translator.js +5 -0
- package/dist/model/malloy_query.d.ts +13 -4
- package/dist/model/malloy_query.js +240 -76
- package/dist/model/malloy_types.d.ts +89 -18
- package/dist/model/malloy_types.js +88 -61
- package/dist/model/utils.d.ts +4 -0
- package/dist/model/utils.js +118 -1
- package/package.json +1 -1
- package/dist/lang/ast/types/type-desc.d.ts +0 -8
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.PostgresDialect = void 0;
|
|
26
|
-
const utils_1 = require("
|
|
27
|
-
const malloy_types_1 = require("
|
|
28
|
-
const
|
|
26
|
+
const utils_1 = require("../../model/utils");
|
|
27
|
+
const malloy_types_1 = require("../../model/malloy_types");
|
|
28
|
+
const functions_1 = require("./functions");
|
|
29
|
+
const dialect_1 = require("../dialect");
|
|
29
30
|
const castMap = {
|
|
30
31
|
'number': 'double precision',
|
|
31
32
|
'string': 'varchar',
|
|
@@ -63,12 +64,11 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
63
64
|
this.unnestWithNumbers = false;
|
|
64
65
|
this.defaultSampling = { rows: 50000 };
|
|
65
66
|
this.supportUnnestArrayAgg = true;
|
|
67
|
+
this.supportsAggDistinct = true;
|
|
66
68
|
this.supportsCTEinCoorelatedSubQueries = true;
|
|
67
69
|
this.dontUnionIndex = false;
|
|
68
70
|
this.supportsQualify = false;
|
|
69
|
-
this.
|
|
70
|
-
'concat': { returnType: 'string' },
|
|
71
|
-
};
|
|
71
|
+
this.globalFunctions = functions_1.POSTGRES_FUNCTIONS;
|
|
72
72
|
}
|
|
73
73
|
quoteTablePath(tablePath) {
|
|
74
74
|
return tablePath
|
|
@@ -218,7 +218,7 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
218
218
|
throw new Error('Not implemented Yet');
|
|
219
219
|
}
|
|
220
220
|
sqlNow() {
|
|
221
|
-
return (0, malloy_types_1.mkExpr) `
|
|
221
|
+
return (0, malloy_types_1.mkExpr) `LOCALTIMESTAMP`;
|
|
222
222
|
}
|
|
223
223
|
sqlTrunc(qi, sqlTime, units) {
|
|
224
224
|
// adjusting for monday/sunday weeks
|
|
@@ -292,9 +292,6 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
292
292
|
}
|
|
293
293
|
return `TIMESTAMP '${timeString}'`;
|
|
294
294
|
}
|
|
295
|
-
getFunctionInfo(functionName) {
|
|
296
|
-
return this.functionInfo[functionName];
|
|
297
|
-
}
|
|
298
295
|
sqlMeasureTime(from, to, units) {
|
|
299
296
|
let lVal = from.value;
|
|
300
297
|
let rVal = to.value;
|
|
@@ -317,6 +314,17 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
317
314
|
) a
|
|
318
315
|
)`;
|
|
319
316
|
}
|
|
317
|
+
// TODO this does not preserve the types of the arguments, meaning we have to hack
|
|
318
|
+
// around this in the definitions of functions that use this to cast back to the correct
|
|
319
|
+
// type (from text). See the postgres implementation of stddev.
|
|
320
|
+
sqlAggDistinct(key, values, func) {
|
|
321
|
+
return `(
|
|
322
|
+
SELECT ${func(values.map((v, i) => `(a::json->>'f${i + 2}')`))} as value
|
|
323
|
+
FROM (
|
|
324
|
+
SELECT UNNEST(array_agg(distinct row_to_json(row(${key},${values.join(',')}))::text)) a
|
|
325
|
+
) a
|
|
326
|
+
)`;
|
|
327
|
+
}
|
|
320
328
|
sqlSampleTable(tableSQL, sample) {
|
|
321
329
|
if (sample !== undefined) {
|
|
322
330
|
if ((0, malloy_types_1.isSamplingEnable)(sample) && sample.enable) {
|
|
@@ -337,6 +345,12 @@ class PostgresDialect extends dialect_1.Dialect {
|
|
|
337
345
|
sqlLiteralString(literal) {
|
|
338
346
|
return "'" + literal.replace(/'/g, "''") + "'";
|
|
339
347
|
}
|
|
348
|
+
sqlLiteralRegexp(literal) {
|
|
349
|
+
return "'" + literal.replace(/'/g, "''") + "'";
|
|
350
|
+
}
|
|
351
|
+
getGlobalFunctionDef(name) {
|
|
352
|
+
return functions_1.POSTGRES_FUNCTIONS.get(name);
|
|
353
|
+
}
|
|
340
354
|
}
|
|
341
355
|
exports.PostgresDialect = PostgresDialect;
|
|
342
356
|
//# sourceMappingURL=postgres.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.fnChr = void 0;
|
|
26
|
+
const util_1 = require("../../functions/util");
|
|
27
|
+
function fnChr() {
|
|
28
|
+
const value = (0, util_1.makeParam)('value', (0, util_1.anyExprType)('number'));
|
|
29
|
+
return [
|
|
30
|
+
(0, util_1.overload)((0, util_1.minScalar)('string'), [value.param],
|
|
31
|
+
// Need to explicitly have a case for when the arg is 0, to return ''
|
|
32
|
+
// Also, cannot compare literal null with = in BigQuery, so we wrap in an IFNULL
|
|
33
|
+
(0, util_1.sql) `CASE WHEN IFNULL(${value.arg}, 1) = 0 THEN '' ELSE CHR(${value.arg}) END`),
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
exports.fnChr = fnChr;
|
|
37
|
+
//# sourceMappingURL=chr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { STANDARDSQL_FUNCTIONS } from './standardsql_functions';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.STANDARDSQL_FUNCTIONS = void 0;
|
|
26
|
+
var standardsql_functions_1 = require("./standardsql_functions");
|
|
27
|
+
Object.defineProperty(exports, "STANDARDSQL_FUNCTIONS", { enumerable: true, get: function () { return standardsql_functions_1.STANDARDSQL_FUNCTIONS; } });
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.fnPi = void 0;
|
|
26
|
+
const util_1 = require("../../functions/util");
|
|
27
|
+
function fnPi() {
|
|
28
|
+
// There's no built-in PI function, but we can compute it easily.
|
|
29
|
+
return [(0, util_1.overload)((0, util_1.minScalar)('number'), [], (0, util_1.sql) `ACOS(-1)`)];
|
|
30
|
+
}
|
|
31
|
+
exports.fnPi = fnPi;
|
|
32
|
+
//# sourceMappingURL=pi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const STANDARDSQL_FUNCTIONS: import("../../functions/function_map").FunctionMap;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.STANDARDSQL_FUNCTIONS = void 0;
|
|
26
|
+
const functions_1 = require("../../functions");
|
|
27
|
+
const chr_1 = require("./chr");
|
|
28
|
+
const pi_1 = require("./pi");
|
|
29
|
+
exports.STANDARDSQL_FUNCTIONS = functions_1.FUNCTIONS.clone();
|
|
30
|
+
exports.STANDARDSQL_FUNCTIONS.add('pi', pi_1.fnPi);
|
|
31
|
+
exports.STANDARDSQL_FUNCTIONS.add('chr', chr_1.fnChr);
|
|
32
|
+
exports.STANDARDSQL_FUNCTIONS.seal();
|
|
33
|
+
//# sourceMappingURL=standardsql_functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './standardsql';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
27
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
28
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
29
|
+
}
|
|
30
|
+
Object.defineProperty(o, k2, desc);
|
|
31
|
+
}) : (function(o, m, k, k2) {
|
|
32
|
+
if (k2 === undefined) k2 = k;
|
|
33
|
+
o[k2] = m[k];
|
|
34
|
+
}));
|
|
35
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
__exportStar(require("./standardsql"), exports);
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Expr, ExtractUnit, Sampling, TimeValue, TimestampUnit, TypecastFragment } from '
|
|
2
|
-
import {
|
|
1
|
+
import { Expr, ExtractUnit, Sampling, TimeValue, TimestampUnit, TypecastFragment } from '../../model/malloy_types';
|
|
2
|
+
import { DialectFunctionOverloadDef } from '../functions';
|
|
3
|
+
import { Dialect, DialectFieldList, QueryInfo } from '../dialect';
|
|
3
4
|
export declare class StandardSQLDialect extends Dialect {
|
|
4
5
|
name: string;
|
|
5
6
|
defaultNumberType: string;
|
|
@@ -13,10 +14,10 @@ export declare class StandardSQLDialect extends Dialect {
|
|
|
13
14
|
enable: boolean;
|
|
14
15
|
};
|
|
15
16
|
supportUnnestArrayAgg: boolean;
|
|
17
|
+
supportsAggDistinct: boolean;
|
|
16
18
|
supportsCTEinCoorelatedSubQueries: boolean;
|
|
17
19
|
dontUnionIndex: boolean;
|
|
18
20
|
supportsQualify: boolean;
|
|
19
|
-
functionInfo: Record<string, FunctionInfo>;
|
|
20
21
|
quoteTablePath(tablePath: string): string;
|
|
21
22
|
sqlGroupSetTable(groupSetCount: number): string;
|
|
22
23
|
sqlAnyValue(groupSet: number, fieldName: string): string;
|
|
@@ -41,9 +42,11 @@ export declare class StandardSQLDialect extends Dialect {
|
|
|
41
42
|
sqlAlterTime(op: '+' | '-', expr: TimeValue, n: Expr, timeframe: TimestampUnit): Expr;
|
|
42
43
|
ignoreInProject(fieldName: string): boolean;
|
|
43
44
|
sqlCast(qi: QueryInfo, cast: TypecastFragment): Expr;
|
|
44
|
-
sqlRegexpMatch(expr: Expr, regexp:
|
|
45
|
+
sqlRegexpMatch(expr: Expr, regexp: Expr): Expr;
|
|
45
46
|
sqlLiteralTime(qi: QueryInfo, timeString: string, type: 'date' | 'timestamp', timezone: string | undefined): string;
|
|
46
47
|
sqlMeasureTime(from: TimeValue, to: TimeValue, units: string): Expr;
|
|
47
48
|
sqlSampleTable(tableSQL: string, sample: Sampling | undefined): string;
|
|
48
49
|
sqlLiteralString(literal: string): string;
|
|
50
|
+
sqlLiteralRegexp(literal: string): string;
|
|
51
|
+
getGlobalFunctionDef(name: string): DialectFunctionOverloadDef[] | undefined;
|
|
49
52
|
}
|
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.StandardSQLDialect = void 0;
|
|
26
|
-
const utils_1 = require("
|
|
27
|
-
const malloy_types_1 = require("
|
|
28
|
-
const
|
|
26
|
+
const utils_1 = require("../../model/utils");
|
|
27
|
+
const malloy_types_1 = require("../../model/malloy_types");
|
|
28
|
+
const functions_1 = require("./functions");
|
|
29
|
+
const dialect_1 = require("../dialect");
|
|
29
30
|
const castMap = {
|
|
30
31
|
'number': 'float64',
|
|
31
32
|
};
|
|
@@ -69,16 +70,10 @@ class StandardSQLDialect extends dialect_1.Dialect {
|
|
|
69
70
|
this.unnestWithNumbers = false;
|
|
70
71
|
this.defaultSampling = { enable: false };
|
|
71
72
|
this.supportUnnestArrayAgg = false;
|
|
73
|
+
this.supportsAggDistinct = false;
|
|
72
74
|
this.supportsCTEinCoorelatedSubQueries = false;
|
|
73
75
|
this.dontUnionIndex = true; // bigquery can't use a sample table more than once in a query.
|
|
74
76
|
this.supportsQualify = true;
|
|
75
|
-
// I think we want an optional list of parameters types that we force a cast to.
|
|
76
|
-
this.functionInfo = {
|
|
77
|
-
'timestamp_seconds': {
|
|
78
|
-
returnType: 'timestamp',
|
|
79
|
-
},
|
|
80
|
-
'concat': { returnType: 'string' },
|
|
81
|
-
};
|
|
82
77
|
this.keywords = `
|
|
83
78
|
ALL
|
|
84
79
|
AND
|
|
@@ -344,7 +339,7 @@ ${(0, utils_1.indent)(sql)}
|
|
|
344
339
|
return cast.expr;
|
|
345
340
|
}
|
|
346
341
|
sqlRegexpMatch(expr, regexp) {
|
|
347
|
-
return (0, malloy_types_1.mkExpr) `REGEXP_CONTAINS(${expr},
|
|
342
|
+
return (0, malloy_types_1.mkExpr) `REGEXP_CONTAINS(${expr}, ${regexp})`;
|
|
348
343
|
}
|
|
349
344
|
sqlLiteralTime(qi, timeString, type, timezone) {
|
|
350
345
|
if (type === 'date') {
|
|
@@ -412,6 +407,13 @@ ${(0, utils_1.indent)(sql)}
|
|
|
412
407
|
const noVirgule = literal.replace(/\\/g, '\\\\');
|
|
413
408
|
return "'" + noVirgule.replace(/'/g, "\\'") + "'";
|
|
414
409
|
}
|
|
410
|
+
sqlLiteralRegexp(literal) {
|
|
411
|
+
const noVirgule = literal.replace(/\\/g, '\\\\');
|
|
412
|
+
return "r'" + noVirgule.replace(/'/g, "\\'") + "'";
|
|
413
|
+
}
|
|
414
|
+
getGlobalFunctionDef(name) {
|
|
415
|
+
return functions_1.STANDARDSQL_FUNCTIONS.get(name);
|
|
416
|
+
}
|
|
415
417
|
}
|
|
416
418
|
exports.StandardSQLDialect = StandardSQLDialect;
|
|
417
419
|
//# sourceMappingURL=standardsql.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { QueryDataRow, Fragment, StructDef, StructRelationship, NamedStructDefs, MalloyQueryData, AtomicFieldType as AtomicFieldTypeInner, DateUnit, ExtractUnit, TimestampUnit, TimeFieldType, QueryData, FieldTypeDef, Expr, DialectFragment, TimeValue, FilterExpression, SQLBlock, FieldDef, FilteredAliasedName, PipeSegment, QueryFieldDef, TurtleDef, SearchValueMapResult, SearchIndexResult, ModelDef, Query, QueryRunStats, NamedQuery, NamedModelObject, ExpressionType, DocumentLocation, DocumentRange, DocumentPosition, } from './model';
|
|
1
|
+
export type { QueryDataRow, Fragment, StructDef, StructRelationship, NamedStructDefs, MalloyQueryData, AtomicFieldType as AtomicFieldTypeInner, DateUnit, ExtractUnit, TimestampUnit, TimeFieldType, QueryData, FieldTypeDef, Expr, DialectFragment, TimeValue, FilterExpression, SQLBlock, FieldDef, FilteredAliasedName, PipeSegment, QueryFieldDef, TurtleDef, SearchValueMapResult, SearchIndexResult, ModelDef, Query, QueryRunStats, NamedQuery, NamedModelObject, ExpressionType, FunctionDef, FunctionOverloadDef, FunctionParameterDef, ExpressionValueType, TypeDesc, FieldValueType, ExpressionTypeDesc, FunctionParamTypeDesc, DocumentLocation, DocumentRange, DocumentPosition, } from './model';
|
|
2
2
|
export { Segment, isFilteredAliasedName, flattenQuery, expressionIsCalculation, } from './model';
|
|
3
3
|
export { HighlightType, MalloyTranslator, } from './lang';
|
|
4
4
|
export type { LogMessage, TranslateResponse } from './lang';
|
|
@@ -34,7 +34,7 @@ class DefineQuery extends malloy_element_1.MalloyElement {
|
|
|
34
34
|
execute(doc) {
|
|
35
35
|
const existing = doc.getEntry(this.name);
|
|
36
36
|
if (existing) {
|
|
37
|
-
this.log(`
|
|
37
|
+
this.log(`'${this.name}' is already defined, cannot redefine`);
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
const entry = {
|
|
@@ -57,7 +57,12 @@ class ImportStatement extends malloy_element_1.MalloyElement {
|
|
|
57
57
|
return childNeeds;
|
|
58
58
|
}
|
|
59
59
|
for (const [importing, entry] of Object.entries(trans.getChildExports(this.fullURL))) {
|
|
60
|
-
doc.
|
|
60
|
+
if (doc.getEntry(importing)) {
|
|
61
|
+
this.log(`Cannot redefine '${importing}'`);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
doc.setEntry(importing, { entry, exported: false });
|
|
65
|
+
}
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
68
|
else if (src.status === 'error') {
|
|
@@ -12,7 +12,7 @@ export declare class IndexExecutor implements Executor {
|
|
|
12
12
|
sample?: Sampling;
|
|
13
13
|
resultFS: IndexFieldSpace;
|
|
14
14
|
inputFS: QueryInputSpace;
|
|
15
|
-
constructor(inputFS: FieldSpace);
|
|
15
|
+
constructor(inputFS: FieldSpace, refineThis: PipeSegment | undefined);
|
|
16
16
|
execute(qp: QueryProperty): void;
|
|
17
17
|
finalize(from: PipeSegment | undefined): PipeSegment;
|
|
18
18
|
}
|
|
@@ -30,9 +30,9 @@ const limit_1 = require("../query-properties/limit");
|
|
|
30
30
|
const sampling_1 = require("../query-properties/sampling");
|
|
31
31
|
const index_field_space_1 = require("../field-space/index-field-space");
|
|
32
32
|
class IndexExecutor {
|
|
33
|
-
constructor(inputFS) {
|
|
33
|
+
constructor(inputFS, refineThis) {
|
|
34
34
|
this.filters = [];
|
|
35
|
-
this.resultFS = new index_field_space_1.IndexFieldSpace(inputFS);
|
|
35
|
+
this.resultFS = new index_field_space_1.IndexFieldSpace(inputFS, refineThis);
|
|
36
36
|
this.inputFS = this.resultFS.exprSpace;
|
|
37
37
|
}
|
|
38
38
|
execute(qp) {
|
|
@@ -4,7 +4,7 @@ import { ProjectFieldSpace } from '../field-space/project-field-space';
|
|
|
4
4
|
import { QueryProperty } from '../types/query-property';
|
|
5
5
|
import { ReduceExecutor } from './reduce-executor';
|
|
6
6
|
export declare class ProjectExecutor extends ReduceExecutor {
|
|
7
|
-
getResultSpace(fs: FieldSpace): ProjectFieldSpace;
|
|
7
|
+
getResultSpace(fs: FieldSpace, refineThis: PipeSegment | undefined): ProjectFieldSpace;
|
|
8
8
|
execute(qp: QueryProperty): void;
|
|
9
9
|
finalize(fromSeg: PipeSegment | undefined): PipeSegment;
|
|
10
10
|
}
|
|
@@ -32,8 +32,8 @@ const project_statement_1 = require("../query-properties/project-statement");
|
|
|
32
32
|
const project_field_space_1 = require("../field-space/project-field-space");
|
|
33
33
|
const reduce_executor_1 = require("./reduce-executor");
|
|
34
34
|
class ProjectExecutor extends reduce_executor_1.ReduceExecutor {
|
|
35
|
-
getResultSpace(fs) {
|
|
36
|
-
return new project_field_space_1.ProjectFieldSpace(fs);
|
|
35
|
+
getResultSpace(fs, refineThis) {
|
|
36
|
+
return new project_field_space_1.ProjectFieldSpace(fs, refineThis);
|
|
37
37
|
}
|
|
38
38
|
execute(qp) {
|
|
39
39
|
if (qp instanceof project_statement_1.ProjectStatement) {
|
|
@@ -5,16 +5,14 @@ import { Top } from '../query-properties/top';
|
|
|
5
5
|
import { QueryProperty } from '../types/query-property';
|
|
6
6
|
import { Executor } from '../types/executor';
|
|
7
7
|
import { QueryInputSpace, QuerySpace } from '../field-space/query-spaces';
|
|
8
|
-
import { DynamicSpace } from '../field-space/dynamic-space';
|
|
9
8
|
export declare class ReduceExecutor implements Executor {
|
|
10
9
|
inputFS: QueryInputSpace;
|
|
11
10
|
resultFS: QuerySpace;
|
|
12
11
|
filters: FilterExpression[];
|
|
13
12
|
order?: Top | Ordering;
|
|
14
13
|
limit?: number;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
getResultSpace(fs: FieldSpace): QuerySpace;
|
|
14
|
+
constructor(baseFS: FieldSpace, refineThis: PipeSegment | undefined);
|
|
15
|
+
getResultSpace(fs: FieldSpace, refineThis: PipeSegment | undefined): QuerySpace;
|
|
18
16
|
execute(qp: QueryProperty): void;
|
|
19
17
|
refineFrom(from: PipeSegment | undefined, to: QuerySegment): void;
|
|
20
18
|
finalize(fromSeg: PipeSegment | undefined): PipeSegment;
|
|
@@ -36,15 +36,16 @@ const top_1 = require("../query-properties/top");
|
|
|
36
36
|
const nests_1 = require("../query-properties/nests");
|
|
37
37
|
const nest_1 = require("../query-properties/nest");
|
|
38
38
|
const query_spaces_1 = require("../field-space/query-spaces");
|
|
39
|
+
const calculate_1 = require("../query-properties/calculate");
|
|
39
40
|
const timezone_statement_1 = require("../source-properties/timezone-statement");
|
|
40
41
|
class ReduceExecutor {
|
|
41
|
-
constructor(baseFS) {
|
|
42
|
+
constructor(baseFS, refineThis) {
|
|
42
43
|
this.filters = [];
|
|
43
|
-
this.resultFS = this.getResultSpace(baseFS);
|
|
44
|
+
this.resultFS = this.getResultSpace(baseFS, refineThis);
|
|
44
45
|
this.inputFS = this.resultFS.exprSpace;
|
|
45
46
|
}
|
|
46
|
-
getResultSpace(fs) {
|
|
47
|
-
return new query_spaces_1.ReduceFieldSpace(fs);
|
|
47
|
+
getResultSpace(fs, refineThis) {
|
|
48
|
+
return new query_spaces_1.ReduceFieldSpace(fs, refineThis);
|
|
48
49
|
}
|
|
49
50
|
execute(qp) {
|
|
50
51
|
if (qp instanceof group_by_1.GroupBy ||
|
|
@@ -52,6 +53,9 @@ class ReduceExecutor {
|
|
|
52
53
|
qp instanceof nests_1.Nests) {
|
|
53
54
|
this.resultFS.addQueryItems(...qp.list);
|
|
54
55
|
}
|
|
56
|
+
else if (qp instanceof calculate_1.Calculate) {
|
|
57
|
+
this.resultFS.addQueryItems(...qp.list);
|
|
58
|
+
}
|
|
55
59
|
else if ((0, nest_1.isNestedQuery)(qp)) {
|
|
56
60
|
this.resultFS.addQueryItems(qp);
|
|
57
61
|
}
|
|
@@ -6,7 +6,7 @@ export declare abstract class BinaryBoolean<opType extends string> extends Expre
|
|
|
6
6
|
readonly op: opType;
|
|
7
7
|
readonly right: ExpressionDef;
|
|
8
8
|
elementType: string;
|
|
9
|
-
legalChildTypes: import("
|
|
9
|
+
legalChildTypes: import("../../../model/malloy_types").TypeDesc[];
|
|
10
10
|
constructor(left: ExpressionDef, op: opType, right: ExpressionDef);
|
|
11
11
|
getExpression(fs: FieldSpace): ExprValue;
|
|
12
12
|
}
|
|
@@ -41,9 +41,11 @@ class BinaryBoolean extends expression_def_1.ExpressionDef {
|
|
|
41
41
|
const left = this.left.getExpression(fs);
|
|
42
42
|
const right = this.right.getExpression(fs);
|
|
43
43
|
if (this.typeCheck(this.left, left) && this.typeCheck(this.right, right)) {
|
|
44
|
+
const evalSpace = (0, malloy_types_1.mergeEvalSpaces)(left.evalSpace, right.evalSpace);
|
|
44
45
|
return {
|
|
45
46
|
dataType: 'boolean',
|
|
46
47
|
expressionType: (0, malloy_types_1.maxExpressionType)(left.expressionType, right.expressionType),
|
|
48
|
+
evalSpace,
|
|
47
49
|
value: (0, utils_1.compose)(left.value, this.op, right.value),
|
|
48
50
|
};
|
|
49
51
|
}
|
|
@@ -43,12 +43,21 @@ class ConstantFieldSpace {
|
|
|
43
43
|
found: undefined,
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
+
entries() {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
entry() {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
46
52
|
dialectObj() {
|
|
47
53
|
return undefined;
|
|
48
54
|
}
|
|
49
55
|
whenComplete(step) {
|
|
50
56
|
step();
|
|
51
57
|
}
|
|
58
|
+
isQueryFieldSpace() {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
52
61
|
}
|
|
53
62
|
class DollarReference extends expression_def_1.ExpressionDef {
|
|
54
63
|
constructor(refType) {
|
|
@@ -61,6 +70,7 @@ class DollarReference extends expression_def_1.ExpressionDef {
|
|
|
61
70
|
dataType: this.refType,
|
|
62
71
|
value: [{ type: 'applyVal' }],
|
|
63
72
|
expressionType: 'scalar',
|
|
73
|
+
evalSpace: 'constant',
|
|
64
74
|
};
|
|
65
75
|
}
|
|
66
76
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { FieldValueType } from '../../../model/malloy_types';
|
|
1
2
|
import { FieldReference } from '../query-items/field-references';
|
|
2
3
|
import { ExprValue } from '../types/expr-value';
|
|
3
4
|
import { ExpressionDef } from '../types/expression-def';
|
|
4
5
|
import { FieldSpace } from '../types/field-space';
|
|
5
|
-
import { FieldValueType } from '../types/type-desc';
|
|
6
6
|
export declare abstract class ExprAggregateFunction extends ExpressionDef {
|
|
7
7
|
readonly func: string;
|
|
8
8
|
elementType: string;
|
|
9
9
|
source?: FieldReference;
|
|
10
10
|
expr?: ExpressionDef;
|
|
11
|
-
legalChildTypes: import("
|
|
11
|
+
legalChildTypes: import("../../../model/malloy_types").TypeDesc[];
|
|
12
12
|
constructor(func: string, expr?: ExpressionDef);
|
|
13
13
|
returns(_forExpression: ExprValue): FieldValueType;
|
|
14
14
|
getExpression(fs: FieldSpace): ExprValue;
|
|
@@ -25,6 +25,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.ExprAggregateFunction = void 0;
|
|
26
26
|
const malloy_types_1 = require("../../../model/malloy_types");
|
|
27
27
|
const ast_utils_1 = require("../ast-utils");
|
|
28
|
+
const query_spaces_1 = require("../field-space/query-spaces");
|
|
29
|
+
const reference_field_1 = require("../field-space/reference-field");
|
|
28
30
|
const struct_space_field_base_1 = require("../field-space/struct-space-field-base");
|
|
29
31
|
const fragtype_utils_1 = require("../fragtype-utils");
|
|
30
32
|
const expression_def_1 = require("../types/expression-def");
|
|
@@ -54,9 +56,28 @@ class ExprAggregateFunction extends expression_def_1.ExpressionDef {
|
|
|
54
56
|
exprVal = {
|
|
55
57
|
dataType: footType.dataType,
|
|
56
58
|
expressionType: footType.expressionType,
|
|
57
|
-
value: [
|
|
59
|
+
value: [
|
|
60
|
+
footType.evalSpace === 'output'
|
|
61
|
+
? {
|
|
62
|
+
type: 'outputField',
|
|
63
|
+
name: this.source.refString,
|
|
64
|
+
}
|
|
65
|
+
: {
|
|
66
|
+
type: 'field',
|
|
67
|
+
path: this.source.refString,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
evalSpace: footType.evalSpace,
|
|
58
71
|
};
|
|
59
|
-
|
|
72
|
+
// If you reference an output field as the foot, then we need to get the
|
|
73
|
+
// source from that field, rather than using the default source.
|
|
74
|
+
if (sourceFoot instanceof query_spaces_1.OutputSpaceEntry &&
|
|
75
|
+
sourceFoot.inputSpaceEntry instanceof reference_field_1.ReferenceField) {
|
|
76
|
+
structPath = sourceFoot.inputSpaceEntry.fieldRef.sourceString;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
structPath = this.source.sourceString;
|
|
80
|
+
}
|
|
60
81
|
}
|
|
61
82
|
else {
|
|
62
83
|
if (!(sourceFoot instanceof struct_space_field_base_1.StructSpaceFieldBase)) {
|
|
@@ -74,6 +95,10 @@ class ExprAggregateFunction extends expression_def_1.ExpressionDef {
|
|
|
74
95
|
this.log('Missing expression for aggregate function');
|
|
75
96
|
return (0, ast_utils_1.errorFor)('agggregate without expression');
|
|
76
97
|
}
|
|
98
|
+
if ((0, malloy_types_1.expressionIsAggregate)(exprVal.expressionType)) {
|
|
99
|
+
this.log('Aggregate expression cannot be aggregate');
|
|
100
|
+
return (0, ast_utils_1.errorFor)('reagggregate');
|
|
101
|
+
}
|
|
77
102
|
if (this.typeCheck(this.expr || this, {
|
|
78
103
|
...exprVal,
|
|
79
104
|
expressionType: 'scalar',
|
|
@@ -90,6 +115,7 @@ class ExprAggregateFunction extends expression_def_1.ExpressionDef {
|
|
|
90
115
|
dataType: this.returns(exprVal),
|
|
91
116
|
expressionType: 'aggregate',
|
|
92
117
|
value: [f],
|
|
118
|
+
evalSpace: 'output',
|
|
93
119
|
};
|
|
94
120
|
}
|
|
95
121
|
return (0, ast_utils_1.errorFor)('aggregate type check');
|
|
@@ -39,6 +39,7 @@ class ExprAlternationTree extends binary_boolean_1.BinaryBoolean {
|
|
|
39
39
|
return {
|
|
40
40
|
dataType: 'boolean',
|
|
41
41
|
expressionType: (0, malloy_types_1.maxExpressionType)(choice1.expressionType, choice2.expressionType),
|
|
42
|
+
evalSpace: (0, malloy_types_1.mergeEvalSpaces)(choice1.evalSpace, choice2.evalSpace),
|
|
42
43
|
value: (0, utils_1.compose)(choice1.value, this.op === '&' ? 'and' : 'or', choice2.value),
|
|
43
44
|
};
|
|
44
45
|
}
|