Skip to content

Commit 8ea7d4f

Browse files
Fix issue where joins were causing incorrect usage to be calculated
1 parent b6f1b4d commit 8ea7d4f

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

packages/malloy/src/model/composite_source_utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ function compositeFieldUsageWithoutNonCompositeFields(
398398
fields: compositeFieldUsage.fields.filter(f =>
399399
isCompositeField(sourceFieldsByName[f])
400400
),
401-
joinedUsage: compositeFieldUsage.joinedUsage,
401+
// Today it is not possible for a join to be composite, so we can safely throw
402+
// away all join usage here...; if we ever allow joins in composite source
403+
// inputs, then this will need to be updated to be the joinUsage with joins
404+
// that are not composite filtered out...
405+
joinedUsage: {},
402406
};
403407
}

test/src/databases/all/composite_sources.spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,45 @@ describe.each(runtimes.runtimeList)('%s', (databaseName, runtime) => {
266266
run: x -> { aggregate: foo; group_by: bar, arr.each }
267267
`).malloyResultMatches(runtime, {foo: 0});
268268
});
269+
it('complex nesting composite without join', async () => {
270+
await expect(`
271+
##! experimental.composite_sources
272+
source: state_facts is ${databaseName}.table('malloytest.state_facts')
273+
source: x is compose(
274+
compose(
275+
state_facts,
276+
state_facts extend {
277+
dimension: bar is 1
278+
}
279+
) extend {
280+
measure: foo is sum(0)
281+
},
282+
state_facts extend {
283+
measure: foo is sum(0) + 1
284+
dimension: bar is 2
285+
}
286+
)
287+
run: x -> { aggregate: foo; group_by: bar }
288+
`).malloyResultMatches(runtime, {foo: 0, bar: 1});
289+
});
290+
it('complex nesting composite with join', async () => {
291+
await expect(`
292+
##! experimental.composite_sources
293+
source: state_facts is ${databaseName}.table('malloytest.state_facts')
294+
source: x is compose(
295+
compose(
296+
state_facts,
297+
state_facts extend {
298+
dimension: the_state is 'CA'
299+
}
300+
),
301+
state_facts extend {
302+
dimension: the_state is 'IL'
303+
}
304+
) extend {
305+
join_one: state_facts on the_state = state_facts.state
306+
}
307+
run: x -> { group_by: state_facts.state }
308+
`).malloyResultMatches(runtime, {state: 'CA'});
309+
});
269310
});

0 commit comments

Comments
 (0)