@malloydata/malloy 0.0.36-dev230524204158 → 0.0.36-dev230524224445
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.
|
@@ -32,15 +32,18 @@ class DefineQuery extends malloy_element_1.MalloyElement {
|
|
|
32
32
|
this.elementType = 'defineQuery';
|
|
33
33
|
}
|
|
34
34
|
execute(doc) {
|
|
35
|
+
const existing = doc.getEntry(this.name);
|
|
36
|
+
if (existing) {
|
|
37
|
+
this.log(`Query '${this.name}' is already defined, cannot redefine`);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
35
40
|
const entry = {
|
|
36
41
|
...this.queryDetails.query(),
|
|
37
42
|
type: 'query',
|
|
38
43
|
name: this.name,
|
|
39
44
|
location: this.location,
|
|
40
45
|
};
|
|
41
|
-
|
|
42
|
-
doc.setEntry(this.name, { entry, exported });
|
|
43
|
-
return undefined;
|
|
46
|
+
doc.setEntry(this.name, { entry, exported: true });
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
exports.DefineQuery = DefineQuery;
|
|
@@ -38,15 +38,12 @@ class ExprFilter extends expression_def_1.ExpressionDef {
|
|
|
38
38
|
getExpression(fs) {
|
|
39
39
|
const testList = this.filter.getFilterList(fs);
|
|
40
40
|
const resultExpr = this.expr.getExpression(fs);
|
|
41
|
-
for (const cond of testList) {
|
|
42
|
-
if ((0, malloy_types_1.expressionIsCalculation)(cond.expressionType)) {
|
|
43
|
-
this.filter.log('Cannot filter a field with an aggregate or analytical computation');
|
|
44
|
-
return (0, ast_utils_1.errorFor)('no filter on aggregate');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
41
|
if (resultExpr.expressionType === 'scalar') {
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
this.expr.log('Filtered expression requires an aggregate computation');
|
|
43
|
+
return resultExpr;
|
|
44
|
+
}
|
|
45
|
+
if (testList.find(cond => (0, malloy_types_1.expressionIsCalculation)(cond.expressionType))) {
|
|
46
|
+
this.filter.log('Cannot filter an expresion with an aggregate or analytical computation');
|
|
50
47
|
return resultExpr;
|
|
51
48
|
}
|
|
52
49
|
if (this.typeCheck(this.expr, { ...resultExpr, expressionType: 'scalar' })) {
|
|
@@ -216,6 +216,9 @@ describe('model statements', () => {
|
|
|
216
216
|
}
|
|
217
217
|
`));
|
|
218
218
|
});
|
|
219
|
+
test('errors on redefinition of query', () => {
|
|
220
|
+
expect('query: q1 is a -> { project: * }, q1 is a -> { project: * }').compileToFailWith("Query 'q1' is already defined, cannot redefine");
|
|
221
|
+
});
|
|
219
222
|
});
|
|
220
223
|
describe('explore properties', () => {
|
|
221
224
|
test('single dimension', modelOK('explore: aa is a { dimension: x is 1 }'));
|
|
@@ -682,6 +685,10 @@ describe('expressions', () => {
|
|
|
682
685
|
});
|
|
683
686
|
});
|
|
684
687
|
test('filtered measure', exprOK("acount {? astr = 'why?' }"));
|
|
688
|
+
test('correctly flags filtered scalar', () => {
|
|
689
|
+
const e = new test_translator_1.BetaExpression('ai { where: true }');
|
|
690
|
+
expect(e).compileToFailWith('Filtered expression requires an aggregate computation');
|
|
691
|
+
});
|
|
685
692
|
describe('aggregate forms', () => {
|
|
686
693
|
test('count', exprOK('count()'));
|
|
687
694
|
test('count distinct', exprOK('count(distinct astr)'));
|