@malloydata/malloy 0.0.177-dev240828173040 → 0.0.177-dev240829030921
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 +23 -13
- package/dist/dialect/dialect.js +33 -27
- package/dist/dialect/duckdb/duckdb.d.ts +7 -11
- package/dist/dialect/duckdb/duckdb.js +34 -100
- package/dist/dialect/duckdb/functions/greatest_and_least.js +5 -12
- package/dist/dialect/functions/concat.js +1 -1
- package/dist/dialect/functions/greatest_and_least.js +1 -1
- package/dist/dialect/functions/simple_numeric_functions.js +1 -1
- package/dist/dialect/functions/sql.js +5 -15
- package/dist/dialect/functions/string_agg.js +2 -2
- package/dist/dialect/functions/trim_functions.js +2 -2
- package/dist/dialect/functions/util.d.ts +6 -9
- package/dist/dialect/functions/util.js +29 -38
- package/dist/dialect/index.d.ts +1 -1
- package/dist/dialect/index.js +1 -2
- package/dist/dialect/pg_impl.d.ts +15 -0
- package/dist/dialect/pg_impl.js +91 -0
- package/dist/dialect/postgres/functions/greatest_and_least.js +1 -3
- package/dist/dialect/postgres/functions/string_agg.js +2 -2
- package/dist/dialect/postgres/postgres.d.ts +7 -11
- package/dist/dialect/postgres/postgres.js +29 -92
- package/dist/dialect/snowflake/functions/string_agg.js +2 -2
- package/dist/dialect/snowflake/snowflake.d.ts +9 -9
- package/dist/dialect/snowflake/snowflake.js +41 -48
- package/dist/dialect/standardsql/functions/string_agg.js +4 -4
- package/dist/dialect/standardsql/standardsql.d.ts +9 -9
- package/dist/dialect/standardsql/standardsql.js +56 -51
- package/dist/dialect/trino/functions/concat.js +1 -1
- package/dist/dialect/trino/functions/string_agg.js +2 -2
- package/dist/dialect/trino/trino.d.ts +11 -12
- package/dist/dialect/trino/trino.js +59 -83
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -4
- package/dist/lang/ast/ast-utils.d.ts +1 -1
- package/dist/lang/ast/ast-utils.js +2 -2
- package/dist/lang/ast/expressions/apply.js +1 -2
- package/dist/lang/ast/expressions/binary-boolean.d.ts +2 -1
- package/dist/lang/ast/expressions/binary-boolean.js +6 -3
- package/dist/lang/ast/expressions/binary-numeric.d.ts +2 -1
- package/dist/lang/ast/expressions/boolean.js +1 -1
- package/dist/lang/ast/expressions/constant-expression.d.ts +3 -3
- package/dist/lang/ast/expressions/constant-expression.js +0 -23
- package/dist/lang/ast/expressions/expr-aggregate-function.js +24 -34
- package/dist/lang/ast/expressions/expr-alternation-tree.d.ts +6 -3
- package/dist/lang/ast/expressions/expr-alternation-tree.js +10 -5
- package/dist/lang/ast/expressions/expr-cast.js +1 -2
- package/dist/lang/ast/expressions/expr-coalesce.js +4 -1
- package/dist/lang/ast/expressions/expr-compare.d.ts +3 -3
- package/dist/lang/ast/expressions/expr-count-distinct.js +1 -1
- package/dist/lang/ast/expressions/expr-count.js +3 -3
- package/dist/lang/ast/expressions/expr-func.js +15 -18
- package/dist/lang/ast/expressions/expr-granular-time.js +8 -10
- package/dist/lang/ast/expressions/expr-id-reference.js +2 -2
- package/dist/lang/ast/expressions/expr-minus.js +5 -4
- package/dist/lang/ast/expressions/expr-not.js +1 -1
- package/dist/lang/ast/expressions/expr-now.js +1 -6
- package/dist/lang/ast/expressions/expr-null.js +1 -1
- package/dist/lang/ast/expressions/expr-number.js +1 -1
- package/dist/lang/ast/expressions/expr-parens.js +1 -1
- package/dist/lang/ast/expressions/expr-props.js +4 -7
- package/dist/lang/ast/expressions/expr-regex.js +1 -3
- package/dist/lang/ast/expressions/expr-string.js +1 -7
- package/dist/lang/ast/expressions/expr-time-extract.js +12 -16
- package/dist/lang/ast/expressions/expr-time.d.ts +2 -2
- package/dist/lang/ast/expressions/expr-time.js +4 -6
- package/dist/lang/ast/expressions/expr-ungroup.js +2 -2
- package/dist/lang/ast/expressions/for-range.d.ts +2 -1
- package/dist/lang/ast/expressions/function-ordering.js +5 -5
- package/dist/lang/ast/expressions/partial-compare.d.ts +3 -3
- package/dist/lang/ast/expressions/pick-when.js +24 -8
- package/dist/lang/ast/expressions/range.d.ts +2 -1
- package/dist/lang/ast/expressions/range.js +4 -2
- package/dist/lang/ast/expressions/time-literal.d.ts +4 -3
- package/dist/lang/ast/expressions/time-literal.js +5 -10
- package/dist/lang/ast/expressions/top-by.js +1 -2
- package/dist/lang/ast/expressions/utils.d.ts +3 -12
- package/dist/lang/ast/expressions/utils.js +8 -56
- package/dist/lang/ast/field-space/reference-field.js +1 -1
- package/dist/lang/ast/index.d.ts +1 -1
- package/dist/lang/ast/index.js +1 -1
- package/dist/lang/ast/query-builders/index-builder.d.ts +2 -2
- package/dist/lang/ast/query-builders/reduce-builder.d.ts +2 -2
- package/dist/lang/ast/query-items/field-declaration.js +1 -5
- package/dist/lang/ast/query-properties/filters.d.ts +3 -3
- package/dist/lang/ast/query-properties/filters.js +6 -5
- package/dist/lang/ast/query-properties/top.js +1 -2
- package/dist/lang/ast/source-elements/refined-source.js +1 -1
- package/dist/lang/ast/source-properties/joins.js +11 -10
- package/dist/lang/ast/time-utils.d.ts +5 -7
- package/dist/lang/ast/time-utils.js +17 -57
- package/dist/lang/ast/types/binary_operators.d.ts +9 -0
- package/dist/lang/ast/types/binary_operators.js +28 -0
- package/dist/lang/ast/types/expr-result.d.ts +3 -3
- package/dist/lang/ast/types/expression-def.d.ts +4 -3
- package/dist/lang/ast/types/expression-def.js +43 -50
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +0 -11
- package/dist/lang/lib/Malloy/MalloyParser.js +803 -858
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +0 -13
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +0 -8
- package/dist/lang/malloy-to-ast.d.ts +0 -1
- package/dist/lang/malloy-to-ast.js +0 -4
- package/dist/lang/test/expressions.spec.js +42 -86
- package/dist/lang/test/field-symbols.spec.js +8 -6
- package/dist/lang/test/literals.spec.js +6 -6
- package/dist/lang/test/model_serialization.spec.js +5 -5
- package/dist/lang/test/test-translator.js +9 -7
- package/dist/malloy.d.ts +3 -3
- package/dist/malloy.js +1 -1
- package/dist/model/index.d.ts +1 -1
- package/dist/model/index.js +2 -1
- package/dist/model/malloy_query.d.ts +24 -19
- package/dist/model/malloy_query.js +272 -244
- package/dist/model/malloy_types.d.ts +224 -205
- package/dist/model/malloy_types.js +19 -98
- package/dist/model/utils.d.ts +10 -3
- package/dist/model/utils.js +84 -219
- package/package.json +1 -1
- package/dist/lang/ast/types/comparison.d.ts +0 -11
- package/dist/lang/ast/types/comparison.js +0 -41
- package/dist/lang/ast/types/equality.d.ts +0 -7
- package/dist/lang/ast/types/equality.js +0 -37
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StructDef } from '../../../model/malloy_types';
|
|
2
|
+
import { BinaryMalloyOperator } from '../types/binary_operators';
|
|
2
3
|
import { ExprValue } from '../types/expr-value';
|
|
3
4
|
import { ExpressionDef } from '../types/expression-def';
|
|
4
5
|
import { FieldSpace, QueryFieldSpace } from '../types/field-space';
|
|
@@ -22,7 +23,6 @@ export declare class ConstantExpression extends ExpressionDef {
|
|
|
22
23
|
getExpression(_fs: FieldSpace): ExprValue;
|
|
23
24
|
private get constantFs();
|
|
24
25
|
constantValue(): ExprValue;
|
|
25
|
-
|
|
26
|
-
apply(fs: FieldSpace, op: string, expr: ExpressionDef): ExprValue;
|
|
26
|
+
apply(fs: FieldSpace, op: BinaryMalloyOperator, expr: ExpressionDef): ExprValue;
|
|
27
27
|
requestExpression(fs: FieldSpace): ExprValue | undefined;
|
|
28
28
|
}
|
|
@@ -23,10 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.ConstantExpression = exports.ConstantFieldSpace = void 0;
|
|
26
|
-
const comparison_1 = require("../types/comparison");
|
|
27
26
|
const expression_def_1 = require("../types/expression-def");
|
|
28
|
-
const expr_compare_1 = require("./expr-compare");
|
|
29
|
-
const utils_1 = require("./utils");
|
|
30
27
|
class ConstantFieldSpace {
|
|
31
28
|
constructor() {
|
|
32
29
|
this.type = 'fieldSpace';
|
|
@@ -57,21 +54,6 @@ class ConstantFieldSpace {
|
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
56
|
exports.ConstantFieldSpace = ConstantFieldSpace;
|
|
60
|
-
class DollarReference extends expression_def_1.ExpressionDef {
|
|
61
|
-
constructor(refType) {
|
|
62
|
-
super();
|
|
63
|
-
this.refType = refType;
|
|
64
|
-
this.elementType = '$';
|
|
65
|
-
}
|
|
66
|
-
getExpression(_fs) {
|
|
67
|
-
return {
|
|
68
|
-
dataType: this.refType,
|
|
69
|
-
value: [{ type: 'applyVal' }],
|
|
70
|
-
expressionType: 'scalar',
|
|
71
|
-
evalSpace: 'constant',
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
57
|
class ConstantExpression extends expression_def_1.ExpressionDef {
|
|
76
58
|
constructor(expr) {
|
|
77
59
|
super({ expr: expr });
|
|
@@ -90,11 +72,6 @@ class ConstantExpression extends expression_def_1.ExpressionDef {
|
|
|
90
72
|
constantValue() {
|
|
91
73
|
return this.expr.getExpression(this.constantFs);
|
|
92
74
|
}
|
|
93
|
-
constantCondition(type) {
|
|
94
|
-
const compareAndContrast = new expr_compare_1.ExprCompare(new DollarReference(type), comparison_1.Comparison.EqualTo, this.expr);
|
|
95
|
-
const application = compareAndContrast.getExpression(this.constantFs);
|
|
96
|
-
return { ...application, value: (0, utils_1.compressExpr)(application.value) };
|
|
97
|
-
}
|
|
98
75
|
apply(fs, op, expr) {
|
|
99
76
|
return this.expr.apply(fs, op, expr);
|
|
100
77
|
}
|
|
@@ -68,17 +68,9 @@ class ExprAggregateFunction extends expression_def_1.ExpressionDef {
|
|
|
68
68
|
exprVal = {
|
|
69
69
|
dataType: footType.dataType,
|
|
70
70
|
expressionType: footType.expressionType,
|
|
71
|
-
value:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
type: 'outputField',
|
|
75
|
-
name: this.source.refString,
|
|
76
|
-
}
|
|
77
|
-
: {
|
|
78
|
-
type: 'field',
|
|
79
|
-
path: this.source.path,
|
|
80
|
-
},
|
|
81
|
-
],
|
|
71
|
+
value: footType.evalSpace === 'output'
|
|
72
|
+
? { node: 'outputField', name: this.source.refString }
|
|
73
|
+
: { node: 'field', path: this.source.path },
|
|
82
74
|
evalSpace: footType.evalSpace,
|
|
83
75
|
};
|
|
84
76
|
structPath = this.source.path;
|
|
@@ -140,7 +132,7 @@ class ExprAggregateFunction extends expression_def_1.ExpressionDef {
|
|
|
140
132
|
expressionType: 'scalar',
|
|
141
133
|
})) {
|
|
142
134
|
const f = {
|
|
143
|
-
|
|
135
|
+
node: 'aggregate',
|
|
144
136
|
function: this.func,
|
|
145
137
|
e: exprVal.value,
|
|
146
138
|
};
|
|
@@ -150,7 +142,7 @@ class ExprAggregateFunction extends expression_def_1.ExpressionDef {
|
|
|
150
142
|
return {
|
|
151
143
|
dataType: this.returns(exprVal),
|
|
152
144
|
expressionType: 'aggregate',
|
|
153
|
-
value:
|
|
145
|
+
value: f,
|
|
154
146
|
evalSpace: 'output',
|
|
155
147
|
};
|
|
156
148
|
}
|
|
@@ -164,7 +156,7 @@ class ExprAggregateFunction extends expression_def_1.ExpressionDef {
|
|
|
164
156
|
if (this.source) {
|
|
165
157
|
const lookup = this.source.getField(fs);
|
|
166
158
|
if (lookup.found) {
|
|
167
|
-
const sfd =
|
|
159
|
+
const sfd = { node: 'field', path: this.source.path };
|
|
168
160
|
result.push(...getJoinUsage(fs, sfd));
|
|
169
161
|
}
|
|
170
162
|
}
|
|
@@ -226,31 +218,29 @@ function getJoinUsage(fs, expr) {
|
|
|
226
218
|
throw new Error('expected a field def or struct');
|
|
227
219
|
}
|
|
228
220
|
};
|
|
229
|
-
(0, utils_1.exprWalk)(expr
|
|
230
|
-
if (
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (def.def.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
result.push(...defUsage.map(r => [...def.relationship, ...r]));
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
result.push(def.relationship);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
else if (frag.type === 'source-reference') {
|
|
244
|
-
if (frag.path) {
|
|
245
|
-
const def = lookup(fs, frag.path);
|
|
246
|
-
result.push(def.relationship);
|
|
221
|
+
for (const frag of (0, utils_1.exprWalk)(expr)) {
|
|
222
|
+
if (frag.node === 'field') {
|
|
223
|
+
const def = lookup(fs, frag.path);
|
|
224
|
+
if (def.def.type !== 'struct' && def.def.type !== 'turtle') {
|
|
225
|
+
if (def.def.e) {
|
|
226
|
+
const defUsage = getJoinUsage(def.fs, def.def.e);
|
|
227
|
+
result.push(...defUsage.map(r => [...def.relationship, ...r]));
|
|
247
228
|
}
|
|
248
229
|
else {
|
|
249
|
-
result.push(
|
|
230
|
+
result.push(def.relationship);
|
|
250
231
|
}
|
|
251
232
|
}
|
|
252
233
|
}
|
|
253
|
-
|
|
234
|
+
else if (frag.node === 'source-reference') {
|
|
235
|
+
if (frag.path) {
|
|
236
|
+
const def = lookup(fs, frag.path);
|
|
237
|
+
result.push(def.relationship);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
result.push([]);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
254
244
|
return result;
|
|
255
245
|
}
|
|
256
246
|
function getJoinUsagePaths(sourceRelationship, joinUsage) {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { ExprValue } from '../types/expr-value';
|
|
2
|
-
import { BinaryBoolean } from './binary-boolean';
|
|
3
2
|
import { FieldSpace } from '../types/field-space';
|
|
4
3
|
import { ExpressionDef } from '../types/expression-def';
|
|
5
|
-
|
|
4
|
+
import { BinaryMalloyOperator } from '../types/binary_operators';
|
|
5
|
+
export declare class ExprAlternationTree extends ExpressionDef {
|
|
6
|
+
readonly left: ExpressionDef;
|
|
7
|
+
readonly op: '|' | '&';
|
|
8
|
+
readonly right: ExpressionDef;
|
|
6
9
|
elementType: string;
|
|
7
10
|
constructor(left: ExpressionDef, op: '|' | '&', right: ExpressionDef);
|
|
8
|
-
apply(fs: FieldSpace, applyOp:
|
|
11
|
+
apply(fs: FieldSpace, applyOp: BinaryMalloyOperator, expr: ExpressionDef): ExprValue;
|
|
9
12
|
requestExpression(_fs: FieldSpace): ExprValue | undefined;
|
|
10
13
|
getExpression(_fs: FieldSpace): ExprValue;
|
|
11
14
|
}
|
|
@@ -25,11 +25,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.ExprAlternationTree = void 0;
|
|
26
26
|
const malloy_types_1 = require("../../../model/malloy_types");
|
|
27
27
|
const ast_utils_1 = require("../ast-utils");
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
class ExprAlternationTree extends binary_boolean_1.BinaryBoolean {
|
|
28
|
+
const expression_def_1 = require("../types/expression-def");
|
|
29
|
+
class ExprAlternationTree extends expression_def_1.ExpressionDef {
|
|
31
30
|
constructor(left, op, right) {
|
|
32
|
-
super(left,
|
|
31
|
+
super({ left, right });
|
|
32
|
+
this.left = left;
|
|
33
|
+
this.op = op;
|
|
34
|
+
this.right = right;
|
|
33
35
|
this.elementType = 'alternation';
|
|
34
36
|
this.elementType = `${op}alternation${op}`;
|
|
35
37
|
}
|
|
@@ -40,7 +42,10 @@ class ExprAlternationTree extends binary_boolean_1.BinaryBoolean {
|
|
|
40
42
|
dataType: 'boolean',
|
|
41
43
|
expressionType: (0, malloy_types_1.maxExpressionType)(choice1.expressionType, choice2.expressionType),
|
|
42
44
|
evalSpace: (0, malloy_types_1.mergeEvalSpaces)(choice1.evalSpace, choice2.evalSpace),
|
|
43
|
-
value:
|
|
45
|
+
value: {
|
|
46
|
+
node: this.op === '&' ? 'and' : 'or',
|
|
47
|
+
kids: { left: choice1.value, right: choice2.value },
|
|
48
|
+
},
|
|
44
49
|
};
|
|
45
50
|
}
|
|
46
51
|
requestExpression(_fs) {
|
|
@@ -25,7 +25,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.ExprCast = void 0;
|
|
26
26
|
const time_utils_1 = require("../time-utils");
|
|
27
27
|
const expression_def_1 = require("../types/expression-def");
|
|
28
|
-
const utils_1 = require("./utils");
|
|
29
28
|
class ExprCast extends expression_def_1.ExpressionDef {
|
|
30
29
|
constructor(expr, castType, safe = false) {
|
|
31
30
|
super({ expr: expr });
|
|
@@ -58,7 +57,7 @@ class ExprCast extends expression_def_1.ExpressionDef {
|
|
|
58
57
|
return {
|
|
59
58
|
dataType,
|
|
60
59
|
expressionType: expr.expressionType,
|
|
61
|
-
value: (0,
|
|
60
|
+
value: (0, time_utils_1.castTo)(this.castType, expr.value, expr.dataType, this.safe),
|
|
62
61
|
evalSpace: expr.evalSpace,
|
|
63
62
|
};
|
|
64
63
|
}
|
|
@@ -55,7 +55,10 @@ class ExprCoalesce extends expression_def_1.ExpressionDef {
|
|
|
55
55
|
...whenNull,
|
|
56
56
|
dataType: maybeNull.dataType === 'error' ? whenNull.dataType : maybeNull.dataType,
|
|
57
57
|
expressionType: (0, model_1.maxExpressionType)(maybeNull.expressionType, whenNull.expressionType),
|
|
58
|
-
value:
|
|
58
|
+
value: {
|
|
59
|
+
node: 'coalesce',
|
|
60
|
+
kids: { left: maybeNull.value, right: whenNull.value },
|
|
61
|
+
},
|
|
59
62
|
evalSpace: (0, model_1.mergeEvalSpaces)(maybeNull.evalSpace, whenNull.evalSpace),
|
|
60
63
|
};
|
|
61
64
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CompareMalloyOperator } from '../types/binary_operators';
|
|
2
2
|
import { ExprValue } from '../types/expr-value';
|
|
3
3
|
import { ExpressionDef } from '../types/expression-def';
|
|
4
4
|
import { FieldSpace } from '../types/field-space';
|
|
5
5
|
import { BinaryBoolean } from './binary-boolean';
|
|
6
|
-
export declare class ExprCompare extends BinaryBoolean<
|
|
6
|
+
export declare class ExprCompare extends BinaryBoolean<CompareMalloyOperator> {
|
|
7
7
|
elementType: string;
|
|
8
|
-
constructor(left: ExpressionDef, op:
|
|
8
|
+
constructor(left: ExpressionDef, op: CompareMalloyOperator, right: ExpressionDef);
|
|
9
9
|
getExpression(fs: FieldSpace): ExprValue;
|
|
10
10
|
}
|
|
@@ -27,7 +27,7 @@ const fragtype_utils_1 = require("../fragtype-utils");
|
|
|
27
27
|
const expr_aggregate_function_1 = require("./expr-aggregate-function");
|
|
28
28
|
class ExprCountDistinct extends expr_aggregate_function_1.ExprAggregateFunction {
|
|
29
29
|
constructor(expr) {
|
|
30
|
-
super('
|
|
30
|
+
super('distinct', expr);
|
|
31
31
|
this.legalChildTypes = [fragtype_utils_1.FT.numberT, fragtype_utils_1.FT.stringT, fragtype_utils_1.FT.dateT, fragtype_utils_1.FT.timestampT];
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -39,9 +39,9 @@ class ExprCount extends expr_aggregate_function_1.ExprAggregateFunction {
|
|
|
39
39
|
}
|
|
40
40
|
getExpression(_fs) {
|
|
41
41
|
const ret = {
|
|
42
|
-
|
|
42
|
+
node: 'aggregate',
|
|
43
43
|
function: 'count',
|
|
44
|
-
e:
|
|
44
|
+
e: { node: '' },
|
|
45
45
|
};
|
|
46
46
|
if (this.source) {
|
|
47
47
|
ret.structPath = this.source.path;
|
|
@@ -49,7 +49,7 @@ class ExprCount extends expr_aggregate_function_1.ExprAggregateFunction {
|
|
|
49
49
|
return {
|
|
50
50
|
dataType: 'number',
|
|
51
51
|
expressionType: 'aggregate',
|
|
52
|
-
value:
|
|
52
|
+
value: ret,
|
|
53
53
|
evalSpace: 'output',
|
|
54
54
|
};
|
|
55
55
|
}
|
|
@@ -28,7 +28,7 @@ const ast_utils_1 = require("../ast-utils");
|
|
|
28
28
|
const struct_space_field_base_1 = require("../field-space/struct-space-field-base");
|
|
29
29
|
const expression_def_1 = require("../types/expression-def");
|
|
30
30
|
const field_space_1 = require("../types/field-space");
|
|
31
|
-
const utils_1 = require("
|
|
31
|
+
const utils_1 = require("../../../model/utils");
|
|
32
32
|
class ExprFunc extends expression_def_1.ExpressionDef {
|
|
33
33
|
constructor(name, args, isRaw, rawType, source) {
|
|
34
34
|
super({ args: args });
|
|
@@ -67,14 +67,14 @@ class ExprFunc extends expression_def_1.ExpressionDef {
|
|
|
67
67
|
else {
|
|
68
68
|
collectType = expr.dataType;
|
|
69
69
|
}
|
|
70
|
-
funcCall.push(
|
|
70
|
+
funcCall.push(expr.value);
|
|
71
71
|
}
|
|
72
72
|
funcCall.push(')');
|
|
73
73
|
const dataType = (_b = (_a = this.rawType) !== null && _a !== void 0 ? _a : collectType) !== null && _b !== void 0 ? _b : 'number';
|
|
74
74
|
return {
|
|
75
75
|
dataType,
|
|
76
76
|
expressionType,
|
|
77
|
-
value: (0, utils_1.
|
|
77
|
+
value: (0, utils_1.composeSQLExpr)(funcCall),
|
|
78
78
|
evalSpace: (0, malloy_types_1.mergeEvalSpaces)(...argExprsWithoutImplicit.map(e => e.evalSpace)),
|
|
79
79
|
};
|
|
80
80
|
}
|
|
@@ -104,7 +104,7 @@ class ExprFunc extends expression_def_1.ExpressionDef {
|
|
|
104
104
|
implicitExpr = {
|
|
105
105
|
dataType: footType.dataType,
|
|
106
106
|
expressionType: footType.expressionType,
|
|
107
|
-
value:
|
|
107
|
+
value: { node: 'field', path: this.source.path },
|
|
108
108
|
evalSpace: footType.evalSpace,
|
|
109
109
|
};
|
|
110
110
|
structPath = this.source.path.slice(0, -1);
|
|
@@ -175,14 +175,14 @@ class ExprFunc extends expression_def_1.ExpressionDef {
|
|
|
175
175
|
return (0, ast_utils_1.errorFor)('cannot call with source');
|
|
176
176
|
}
|
|
177
177
|
const frag = {
|
|
178
|
-
|
|
178
|
+
node: 'function_call',
|
|
179
179
|
overload,
|
|
180
180
|
name: this.name,
|
|
181
|
-
args: argExprs.map(x => x.value),
|
|
181
|
+
kids: { args: argExprs.map(x => x.value) },
|
|
182
182
|
expressionType,
|
|
183
183
|
structPath,
|
|
184
184
|
};
|
|
185
|
-
let funcCall =
|
|
185
|
+
let funcCall = frag;
|
|
186
186
|
const dialect = (_e = fs.dialectObj()) === null || _e === void 0 ? void 0 : _e.name;
|
|
187
187
|
const dialectOverload = dialect ? overload.dialect[dialect] : undefined;
|
|
188
188
|
// TODO add in an error if you use an asymmetric function in BQ
|
|
@@ -204,7 +204,7 @@ class ExprFunc extends expression_def_1.ExpressionDef {
|
|
|
204
204
|
const allObs = props.orderBys.flatMap(orderBy => isAnalytic
|
|
205
205
|
? orderBy.getAnalyticOrderBy(fs)
|
|
206
206
|
: orderBy.getAggregateOrderBy(fs, allowExpression));
|
|
207
|
-
frag.orderBy = allObs;
|
|
207
|
+
frag.kids.orderBy = allObs;
|
|
208
208
|
}
|
|
209
209
|
else {
|
|
210
210
|
props.orderBys[0].log(`Function \`${this.name}\` does not support \`order_by\``);
|
|
@@ -251,14 +251,11 @@ class ExprFunc extends expression_def_1.ExpressionDef {
|
|
|
251
251
|
return (0, ast_utils_1.errorFor)('sql_function used without enabling');
|
|
252
252
|
}
|
|
253
253
|
const str = argExprs[0].value;
|
|
254
|
-
if (str.
|
|
255
|
-
typeof str[0] === 'string' ||
|
|
256
|
-
str[0].type !== 'dialect' ||
|
|
257
|
-
str[0].function !== 'stringLiteral') {
|
|
254
|
+
if (str.node !== 'stringLiteral') {
|
|
258
255
|
this.log(`Invalid string literal for \`${func.name}\``);
|
|
259
256
|
}
|
|
260
257
|
else {
|
|
261
|
-
const literal = str
|
|
258
|
+
const literal = str.literal;
|
|
262
259
|
const parts = parseSQLInterpolation(literal);
|
|
263
260
|
const unsupportedInterpolations = parts
|
|
264
261
|
.filter(part => part.type === 'interpolation' && part.name.includes('.'))
|
|
@@ -278,7 +275,7 @@ class ExprFunc extends expression_def_1.ExpressionDef {
|
|
|
278
275
|
expr.push(part.value);
|
|
279
276
|
}
|
|
280
277
|
else if (part.name === 'TABLE') {
|
|
281
|
-
expr.push({
|
|
278
|
+
expr.push({ node: 'source-reference' });
|
|
282
279
|
}
|
|
283
280
|
else {
|
|
284
281
|
const name = new field_space_1.FieldName(part.name);
|
|
@@ -289,14 +286,14 @@ class ExprFunc extends expression_def_1.ExpressionDef {
|
|
|
289
286
|
return (0, ast_utils_1.errorFor)('invalid interpolated field');
|
|
290
287
|
}
|
|
291
288
|
if (result.found.refType === 'parameter') {
|
|
292
|
-
expr.push({
|
|
289
|
+
expr.push({ node: 'parameter', path: [part.name] });
|
|
293
290
|
}
|
|
294
291
|
else {
|
|
295
|
-
expr.push({
|
|
292
|
+
expr.push({ node: 'field', path: [part.name] });
|
|
296
293
|
}
|
|
297
294
|
}
|
|
298
295
|
}
|
|
299
|
-
funcCall =
|
|
296
|
+
funcCall = (0, utils_1.composeSQLExpr)(expr);
|
|
300
297
|
}
|
|
301
298
|
}
|
|
302
299
|
if (type.dataType === 'any') {
|
|
@@ -317,7 +314,7 @@ class ExprFunc extends expression_def_1.ExpressionDef {
|
|
|
317
314
|
return {
|
|
318
315
|
dataType: type.dataType,
|
|
319
316
|
expressionType,
|
|
320
|
-
value:
|
|
317
|
+
value: funcCall,
|
|
321
318
|
evalSpace,
|
|
322
319
|
};
|
|
323
320
|
}
|
|
@@ -59,14 +59,11 @@ class ExprGranularTime extends expression_def_1.ExpressionDef {
|
|
|
59
59
|
timeframe: timeframe,
|
|
60
60
|
};
|
|
61
61
|
if (this.truncate) {
|
|
62
|
-
tsVal.value =
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
units: timeframe,
|
|
68
|
-
},
|
|
69
|
-
];
|
|
62
|
+
tsVal.value = {
|
|
63
|
+
node: 'trunc',
|
|
64
|
+
e: { ...exprVal.value, dataType: exprVal.dataType },
|
|
65
|
+
units: timeframe,
|
|
66
|
+
};
|
|
70
67
|
}
|
|
71
68
|
return tsVal;
|
|
72
69
|
}
|
|
@@ -102,13 +99,14 @@ class ExprGranularTime extends expression_def_1.ExpressionDef {
|
|
|
102
99
|
// }
|
|
103
100
|
toRange(fs) {
|
|
104
101
|
const begin = this.getExpression(fs);
|
|
102
|
+
const one = { node: 'numberLiteral', literal: '1' };
|
|
105
103
|
if (begin.dataType === 'timestamp') {
|
|
106
104
|
const beginTS = expr_time_1.ExprTime.fromValue('timestamp', begin);
|
|
107
|
-
const endTS = new expr_time_1.ExprTime('timestamp', (0, time_utils_1.timeOffset)('timestamp', begin.value, '+',
|
|
105
|
+
const endTS = new expr_time_1.ExprTime('timestamp', (0, time_utils_1.timeOffset)('timestamp', begin.value, '+', one, this.units), begin.expressionType);
|
|
108
106
|
return new range_1.Range(beginTS, endTS);
|
|
109
107
|
}
|
|
110
108
|
const beginDate = new expr_time_1.ExprTime('date', begin.value, begin.expressionType);
|
|
111
|
-
const endAt = (0, time_utils_1.timeOffset)('date', begin.value, '+',
|
|
109
|
+
const endAt = (0, time_utils_1.timeOffset)('date', begin.value, '+', one, this.units);
|
|
112
110
|
const endDate = new expr_time_1.ExprTime('date', endAt, begin.expressionType);
|
|
113
111
|
return new range_1.Range(beginDate, endDate);
|
|
114
112
|
}
|
|
@@ -44,10 +44,10 @@ class ExprIdReference extends expression_def_1.ExpressionDef {
|
|
|
44
44
|
return {
|
|
45
45
|
...td,
|
|
46
46
|
evalSpace: td.evalSpace === 'constant' ? 'constant' : 'output',
|
|
47
|
-
value:
|
|
47
|
+
value: { node: 'outputField', name: this.refString },
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
-
const value =
|
|
50
|
+
const value = { node: def.found.refType, path: this.fieldReference.path };
|
|
51
51
|
// We think that aggregates are more 'output' like, but maybe we will reconsider that...
|
|
52
52
|
const evalSpace = (0, malloy_types_1.expressionIsAggregate)(td.expressionType)
|
|
53
53
|
? 'output'
|
|
@@ -36,10 +36,11 @@ class ExprMinus extends expression_def_1.ExpressionDef {
|
|
|
36
36
|
getExpression(fs) {
|
|
37
37
|
const expr = this.expr.getExpression(fs);
|
|
38
38
|
if (fragtype_utils_1.FT.typeIn(expr, this.legalChildTypes)) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
return {
|
|
40
|
+
...expr,
|
|
41
|
+
dataType: 'number',
|
|
42
|
+
value: { node: 'unary-', e: expr.value },
|
|
43
|
+
};
|
|
43
44
|
}
|
|
44
45
|
return (0, ast_utils_1.errorFor)('negate requires number');
|
|
45
46
|
}
|
|
@@ -35,12 +35,7 @@ class ExprNow extends expression_def_1.ExpressionDef {
|
|
|
35
35
|
expressionType: 'scalar',
|
|
36
36
|
// `now` is considered to be a constant, at least in the dialects we support today
|
|
37
37
|
evalSpace: 'constant',
|
|
38
|
-
value:
|
|
39
|
-
{
|
|
40
|
-
type: 'dialect',
|
|
41
|
-
function: 'now',
|
|
42
|
-
},
|
|
43
|
-
],
|
|
38
|
+
value: { node: 'now' },
|
|
44
39
|
};
|
|
45
40
|
}
|
|
46
41
|
}
|
|
@@ -38,7 +38,7 @@ class ExprNumber extends expression_def_1.ExpressionDef {
|
|
|
38
38
|
return {
|
|
39
39
|
...fragtype_utils_1.FT.numberT,
|
|
40
40
|
evalSpace: 'literal',
|
|
41
|
-
value:
|
|
41
|
+
value: { node: 'numberLiteral', literal: this.n },
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -35,7 +35,7 @@ class ExprParens extends expression_def_1.ExpressionDef {
|
|
|
35
35
|
}
|
|
36
36
|
getExpression(fs) {
|
|
37
37
|
const subExpr = this.expr.getExpression(fs);
|
|
38
|
-
return { ...subExpr, value:
|
|
38
|
+
return { ...subExpr, value: { node: '()', e: subExpr.value } };
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
exports.ExprParens = ExprParens;
|
|
@@ -57,13 +57,10 @@ class ExprProps extends expression_def_1.ExpressionDef {
|
|
|
57
57
|
if (this.typeCheck(this.expr, { ...expr, expressionType: 'scalar' })) {
|
|
58
58
|
return {
|
|
59
59
|
...expr,
|
|
60
|
-
value:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
filterList,
|
|
65
|
-
},
|
|
66
|
-
],
|
|
60
|
+
value: {
|
|
61
|
+
node: 'filteredExpr',
|
|
62
|
+
kids: { e: expr.value, filterList },
|
|
63
|
+
},
|
|
67
64
|
};
|
|
68
65
|
}
|
|
69
66
|
this.expr.log(`Cannot filter '${expr.dataType}' data`);
|
|
@@ -34,9 +34,7 @@ class ExprRegEx extends expression_def_1.ExpressionDef {
|
|
|
34
34
|
return {
|
|
35
35
|
dataType: 'regular expression',
|
|
36
36
|
expressionType: 'scalar',
|
|
37
|
-
value:
|
|
38
|
-
{ type: 'dialect', function: 'regexpLiteral', literal: this.regex },
|
|
39
|
-
],
|
|
37
|
+
value: { node: 'regexpLiteral', literal: this.regex },
|
|
40
38
|
evalSpace: 'literal',
|
|
41
39
|
};
|
|
42
40
|
}
|
|
@@ -34,13 +34,7 @@ class ExprString extends expression_def_1.ExpressionDef {
|
|
|
34
34
|
getExpression(_fs) {
|
|
35
35
|
return {
|
|
36
36
|
...fragtype_utils_1.FT.stringT,
|
|
37
|
-
value:
|
|
38
|
-
{
|
|
39
|
-
type: 'dialect',
|
|
40
|
-
function: 'stringLiteral',
|
|
41
|
-
literal: this.value,
|
|
42
|
-
},
|
|
43
|
-
],
|
|
37
|
+
value: { node: 'stringLiteral', literal: this.value },
|
|
44
38
|
evalSpace: 'literal',
|
|
45
39
|
};
|
|
46
40
|
}
|
|
@@ -107,15 +107,14 @@ class ExprTimeExtract extends expression_def_1.ExpressionDef {
|
|
|
107
107
|
dataType: 'number',
|
|
108
108
|
expressionType,
|
|
109
109
|
evalSpace,
|
|
110
|
-
value:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
right: { valueType, value: last.value },
|
|
110
|
+
value: {
|
|
111
|
+
node: 'timeDiff',
|
|
112
|
+
units: extractTo,
|
|
113
|
+
kids: {
|
|
114
|
+
left: { ...first.value, dataType: valueType },
|
|
115
|
+
right: { ...last.value, dataType: valueType },
|
|
117
116
|
},
|
|
118
|
-
|
|
117
|
+
},
|
|
119
118
|
};
|
|
120
119
|
}
|
|
121
120
|
else {
|
|
@@ -125,14 +124,11 @@ class ExprTimeExtract extends expression_def_1.ExpressionDef {
|
|
|
125
124
|
dataType: 'number',
|
|
126
125
|
expressionType: argV.expressionType,
|
|
127
126
|
evalSpace: argV.evalSpace,
|
|
128
|
-
value:
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
units: extractTo,
|
|
134
|
-
},
|
|
135
|
-
],
|
|
127
|
+
value: {
|
|
128
|
+
node: 'extract',
|
|
129
|
+
e: { ...argV.value, dataType: argV.dataType },
|
|
130
|
+
units: extractTo,
|
|
131
|
+
},
|
|
136
132
|
};
|
|
137
133
|
}
|
|
138
134
|
if (argV.dataType !== 'error') {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Expr, ExpressionType, TimeFieldType } from '../../../model/malloy_types';
|
|
2
2
|
import { FieldSpace } from '../types/field-space';
|
|
3
3
|
import { ExprValue } from '../types/expr-value';
|
|
4
4
|
import { ExpressionDef } from '../types/expression-def';
|
|
5
5
|
export declare class ExprTime extends ExpressionDef {
|
|
6
6
|
elementType: string;
|
|
7
7
|
readonly translationValue: ExprValue;
|
|
8
|
-
constructor(timeType: TimeFieldType, value:
|
|
8
|
+
constructor(timeType: TimeFieldType, value: Expr, expressionType?: ExpressionType);
|
|
9
9
|
getExpression(_fs: FieldSpace): ExprValue;
|
|
10
10
|
static fromValue(timeType: TimeFieldType, expr: ExprValue): ExprTime;
|
|
11
11
|
}
|