Skip to content

Commit 8e58477

Browse files
committed
add tests
1 parent 533c767 commit 8e58477

File tree

1 file changed

+109
-1
lines changed

1 file changed

+109
-1
lines changed

packages/cubejs-schema-compiler/test/integration/postgres/pre-aggregations.test.ts

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,83 @@ describe('PreAggregations', () => {
599599
}
600600
]
601601
});
602-
`);
602+
603+
cube('cube_1', {
604+
sql: \`SELECT 1 as id, 'dim_1' as dim_1\`,
605+
606+
joins: {
607+
cube_2: {
608+
relationship: 'many_to_one',
609+
sql: \`\${CUBE.dim_1} = \${cube_2.dim_1}\`
610+
}
611+
},
612+
613+
dimensions: {
614+
id: {
615+
sql: 'id',
616+
type: 'string',
617+
primary_key: true
618+
},
619+
620+
dim_1: {
621+
sql: 'dim_1',
622+
type: 'string'
623+
},
624+
},
625+
626+
pre_aggregations: {
627+
aaa: {
628+
dimensions: [
629+
dim_1
630+
]
631+
},
632+
rollupJoin: {
633+
type: 'rollupJoin',
634+
dimensions: [
635+
dim_1,
636+
cube_2.dim_1,
637+
cube_2.dim_2 // XXX
638+
],
639+
rollups: [
640+
aaa,
641+
cube_2.bbb
642+
]
643+
}
644+
}
645+
});
646+
647+
cube('cube_2', {
648+
sql: \`SELECT 2 as id, 'dim_1' as dim_1, 'dim_2' as dim_2\`,
649+
650+
dimensions: {
651+
id: {
652+
sql: 'id',
653+
type: 'string',
654+
primary_key: true
655+
},
656+
657+
dim_1: {
658+
sql: 'dim_1',
659+
type: 'string'
660+
},
661+
662+
dim_2: {
663+
sql: 'dim_2',
664+
type: 'string'
665+
},
666+
},
667+
668+
pre_aggregations: {
669+
bbb: {
670+
dimensions: [
671+
dim_1,
672+
dim_2,
673+
]
674+
}
675+
}
676+
});
677+
678+
`);
603679

604680
it('simple pre-aggregation', async () => {
605681
await compiler.compile();
@@ -2773,4 +2849,36 @@ describe('PreAggregations', () => {
27732849
expect(loadSql[0]).not.toMatch(/GROUP BY/);
27742850
expect(loadSql[0]).toMatch(/THEN 1 END `real_time_lambda_visitors__count`/);
27752851
});
2852+
2853+
it('rollupJoin pre-aggregation', async () => {
2854+
await compiler.compile();
2855+
2856+
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
2857+
dimensions: ['cube_1.dim_1', 'cube_2.dim_2'],
2858+
timezone: 'America/Los_Angeles',
2859+
preAggregationsSchema: ''
2860+
});
2861+
2862+
const queryAndParams = query.buildSqlAndParams();
2863+
console.log(queryAndParams);
2864+
const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription();
2865+
console.log(preAggregationsDescription);
2866+
expect(preAggregationsDescription.length).toBe(2);
2867+
const aaa = preAggregationsDescription.find(p => p.preAggregationId === 'cube_1.aaa');
2868+
const bbb = preAggregationsDescription.find(p => p.preAggregationId === 'cube_2.bbb');
2869+
expect(aaa).toBeDefined();
2870+
expect(bbb).toBeDefined();
2871+
2872+
expect(query.preAggregations?.preAggregationForQuery?.canUsePreAggregation).toEqual(true);
2873+
expect(query.preAggregations?.preAggregationForQuery?.preAggregationName).toEqual('rollupJoin');
2874+
2875+
return dbRunner.evaluateQueryWithPreAggregations(query).then(res => {
2876+
expect(res).toEqual(
2877+
[{
2878+
cube_1__dim_1: 'dim_1',
2879+
cube_2__dim_2: 'dim_2',
2880+
}]
2881+
);
2882+
});
2883+
});
27762884
});

0 commit comments

Comments
 (0)