Skip to content

Commit 0914e1e

Browse files
authored
fix(schema-compiler): Fix pre-aggregation for time dimension matching (#9669)
1 parent bca2362 commit 0914e1e

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2403,7 +2403,7 @@ export class BaseQuery {
24032403
*/
24042404
collectCubeNames() {
24052405
return this.collectFromMembers(
2406-
[],
2406+
false,
24072407
this.collectCubeNamesFor.bind(this),
24082408
'collectCubeNamesFor'
24092409
);

packages/cubejs-schema-compiler/test/unit/pre-aggregations.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,62 @@ describe('pre-aggregations', () => {
450450
expect(preAggregationsDescription[0].invalidateKeyQueries[0][1]).toEqual(['__FROM_PARTITION_RANGE', '__TO_PARTITION_RANGE']);
451451
});
452452

453+
it('pre-aggregation match for only td query', async () => {
454+
const { compiler, cubeEvaluator, joinGraph } = prepareYamlCompiler(
455+
createSchemaYaml({
456+
cubes: [
457+
{
458+
name: 'orders',
459+
sql_table: 'orders',
460+
measures: [{
461+
name: 'count',
462+
type: 'count',
463+
}],
464+
dimensions: [
465+
{
466+
name: 'created_at',
467+
sql: 'created_at',
468+
type: 'time',
469+
},
470+
{
471+
name: 'status',
472+
sql: 'status',
473+
type: 'string',
474+
}
475+
],
476+
preAggregations: [
477+
{
478+
name: 'simple',
479+
measures: ['count'],
480+
dimensions: ['status'],
481+
timeDimension: 'CUBE.created_at',
482+
granularity: 'day',
483+
},
484+
]
485+
}
486+
]
487+
})
488+
);
489+
490+
await compiler.compile();
491+
492+
// It's important to provide a queryFactory, as it triggers flow
493+
// with paramAllocator reset in BaseQuery->newSubQueryForCube()
494+
const queryFactory = new QueryFactory({ orders: PostgresQuery });
495+
496+
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
497+
timeDimensions: [{
498+
dimension: 'orders.created_at',
499+
granularity: 'day',
500+
}],
501+
queryFactory
502+
});
503+
504+
const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription();
505+
expect(preAggregationsDescription.length).toEqual(1);
506+
expect(preAggregationsDescription[0].preAggregationId).toEqual('orders.simple');
507+
});
508+
453509
describe('rollup with multiplied measure', () => {
454510
let compiler;
455511
let cubeEvaluator;

0 commit comments

Comments
 (0)