@malloydata/malloy 0.0.81-dev230910215631 → 0.0.81

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.
@@ -76,18 +76,22 @@ class Filter extends malloy_element_1.ListOf {
76
76
  // Aggregates are ALSO checked at SQL generation time, but checking
77
77
  // here allows better reflection of errors back to user.
78
78
  if (this.havingClause !== undefined) {
79
- const needHaving = (0, malloy_types_1.expressionIsCalculation)(fExpr.expressionType);
79
+ const isAggregate = (0, malloy_types_1.expressionIsAggregate)(fExpr.expressionType);
80
+ const isAnalytic = (0, malloy_types_1.expressionIsAnalytic)(fExpr.expressionType);
80
81
  if (this.havingClause) {
81
- if (!needHaving) {
82
- oneElement.log('Aggregate or analytic expression expected in HAVING filter');
82
+ if (isAnalytic) {
83
+ oneElement.log('Analytic expressions are not allowed in `having:`');
83
84
  continue;
84
85
  }
85
86
  }
86
87
  else {
87
- if (needHaving) {
88
- oneElement.log('Aggregate or analytic expressions not allowed in WHERE');
88
+ if (isAnalytic) {
89
+ oneElement.log('Analytic expressions are not allowed in `where:`');
89
90
  continue;
90
91
  }
92
+ else if (isAggregate) {
93
+ oneElement.log('Aggregate expressions are not allowed in `where:`; use `having:`');
94
+ }
91
95
  }
92
96
  }
93
97
  checked.push(fExpr);
@@ -805,6 +805,15 @@ describe('query:', () => {
805
805
  }
806
806
  `).toTranslate();
807
807
  });
808
+ test('agg cannot be used in where', () => {
809
+ expect('query:ab->{ aggregate: acount; group_by: astr; where: acount > 10 }').translationToFailWith('Aggregate expressions are not allowed in `where:`; use `having:`');
810
+ });
811
+ test('analytic cannot be used in where', () => {
812
+ expect('query:ab->{ calculate: prevc is lag(count()); group_by: astr; where: prevc > 10 }').translationToFailWith("'prevc' is not defined");
813
+ });
814
+ test('analytic cannot be used in having', () => {
815
+ expect('query:ab->{ calculate: prevc is lag(count()); group_by: astr; having: prevc > 10 }').translationToFailWith('Analytic expressions are not allowed in `having:`');
816
+ });
808
817
  test('where single', () => {
809
818
  expect('query:a->{ group_by: astr; where: af > 10 }').toTranslate();
810
819
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.81-dev230910215631",
3
+ "version": "0.0.81",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",