Skip to content

Commit

Permalink
Fix issue where array.each messed up composite caluclations (#2043)
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherswenson authored Dec 12, 2024
1 parent f7ba72a commit 94f98d0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
24 changes: 24 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 @@ -191,5 +191,29 @@ describe('composite sources', () => {
run: foo(param is 2) -> { group_by: y }
`).toTranslate();
});
test('array.each is okay', () => {
expect(`
##! experimental { composite_sources }
source: foo is compose(
a extend { dimension: x is 1 },
a extend { dimension: y is 2 }
) extend {
dimension: arr is [1, 2, 3]
}
run: foo -> { group_by: y, arr.each }
`).toTranslate();
});
test('timevalue extract okay', () => {
expect(`
##! experimental { composite_sources }
source: foo is compose(
a extend { dimension: x is 1 },
a extend { dimension: y is 2 }
) extend {
dimension: time is now
}
run: foo -> { group_by: y, time.day }
`).toTranslate();
});
});
});
5 changes: 4 additions & 1 deletion packages/malloy/src/model/composite_source_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,13 @@ function _resolveCompositeSources(
error: {code: 'composite_source_not_defined', data: {path: newPath}},
};
}
if (!isJoined(join) || !isSourceDef(join)) {
if (!isJoined(join)) {
return {
error: {code: 'composite_source_not_a_join', data: {path: newPath}},
};
} else if (!isSourceDef(join)) {
// Non-source join, like an array, skip it (no need to resolve)
continue;
}
const resolved = _resolveCompositeSources(
newPath,
Expand Down
13 changes: 13 additions & 0 deletions test/src/databases/all/composite_sources.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,17 @@ describe.each(runtimes.runtimeList)('%s', (databaseName, runtime) => {
run: x -> { select: * }
`).malloyResultMatches(runtime, {foo: 1});
});
it('composite with each', async () => {
await expect(`
##! experimental.composite_sources
source: state_facts is ${databaseName}.table('malloytest.state_facts')
source: x is compose(
state_facts extend { measure: foo is sum(0); dimension: bar is 1 },
state_facts extend { measure: foo is count() }
) extend {
dimension: arr is [1, 2, 3]
}
run: x -> { aggregate: foo; group_by: bar, arr.each }
`).malloyResultMatches(runtime, {foo: 0});
});
});

0 comments on commit 94f98d0

Please sign in to comment.