Skip to content

Commit

Permalink
Fix issue where filtered aggregates did not have composite usage of t…
Browse files Browse the repository at this point in the history
…he filter expressions involved (#2062)
  • Loading branch information
christopherswenson authored Dec 20, 2024
1 parent eba240c commit 74801a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/malloy/src/lang/ast/expressions/expr-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {ExpressionDef} from '../types/expression-def';
import {FieldPropStatement} from '../types/field-prop-statement';
import {FieldSpace} from '../types/field-space';
import {ExprFunc} from './expr-func';
import {mergeCompositeFieldUsage} from '../../../model/composite_source_utils';

export class ExprProps extends ExpressionDef {
elementType = 'expression with props';
Expand Down Expand Up @@ -77,6 +78,10 @@ export class ExprProps extends ExpressionDef {
if (this.typeCheck(this.expr, {...expr, expressionType: 'scalar'})) {
return {
...expr,
compositeFieldUsage: mergeCompositeFieldUsage(
expr.compositeFieldUsage,
...filterList.map(f => f.compositeFieldUsage)
),
value: {
node: 'filteredExpr',
kids: {e: expr.value, filterList},
Expand Down
6 changes: 6 additions & 0 deletions packages/malloy/src/lang/test/composite-field-usage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('composite sources', () => {
source: x is compose(ab, ab) extend {
dimension: aif is ai + af
measure: ss is ai.sum()
measure: saiaf is ai.sum() { where: af > 1 }
}
source: y is compose(ab, ab) extend {
Expand Down Expand Up @@ -94,6 +95,11 @@ describe('composite sources', () => {
const mexpr = makeExprFunc(m.translator.modelDef, 'x');
expect(mexpr`ss`).hasCompositeUsage(paths([['ai']]));
});

test('measure with filter defined in composite source', () => {
const mexpr = makeExprFunc(m.translator.modelDef, 'x');
expect(mexpr`saiaf`).hasCompositeUsage(paths([['ai'], ['af']]));
});
});

describe('composite source resolution and validation', () => {
Expand Down

0 comments on commit 74801a0

Please sign in to comment.