Skip to content

Commit b14bf54

Browse files
committed
more tests
1 parent 862f4f5 commit b14bf54

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

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

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,111 @@ describe('PreAggregations', () => {
789789
}
790790
});
791791
792+
cube('cube_a', {
793+
sql: \`SELECT 1 as id, 'dim_a' as dim_a\`,
794+
795+
joins: {
796+
cube_b: {
797+
relationship: 'many_to_one',
798+
sql: \`\${CUBE.dim_a} = \${cube_b.dim_a}\`
799+
}
800+
},
801+
802+
dimensions: {
803+
id: {
804+
sql: 'id',
805+
type: 'string',
806+
primary_key: true
807+
},
808+
809+
dim_a: {
810+
sql: 'dim_a',
811+
type: 'string'
812+
},
813+
},
814+
815+
pre_aggregations: {
816+
aaa_rollup: {
817+
dimensions: [
818+
dim_a
819+
]
820+
},
821+
rollupJoinAB: {
822+
type: 'rollupJoin',
823+
dimensions: [
824+
dim_a,
825+
cube_b.dim_b,
826+
cube_c.dim_c
827+
],
828+
rollups: [
829+
aaa_rollup,
830+
cube_b.bbb_rollup
831+
]
832+
}
833+
}
834+
});
835+
836+
cube('cube_b', {
837+
sql: \`SELECT 2 as id, 'dim_a' as dim_a, 'dim_b' as dim_b\`,
838+
839+
joins: {
840+
cube_c: {
841+
relationship: 'many_to_one',
842+
sql: \`\${CUBE.dim_b} = \${cube_c.dim_b}\`
843+
}
844+
},
845+
846+
dimensions: {
847+
id: {
848+
sql: 'id',
849+
type: 'string',
850+
primary_key: true
851+
},
852+
853+
dim_a: {
854+
sql: 'dim_a',
855+
type: 'string'
856+
},
857+
858+
dim_b: {
859+
sql: 'dim_b',
860+
type: 'string'
861+
},
862+
},
863+
864+
pre_aggregations: {
865+
bbb_rollup: {
866+
dimensions: [
867+
dim_a,
868+
dim_b,
869+
cube_c.dim_c
870+
]
871+
}
872+
}
873+
});
874+
875+
cube('cube_c', {
876+
sql: \`SELECT 3 as id, 'dim_b' as dim_b, 'dim_c' as dim_c\`,
877+
878+
dimensions: {
879+
id: {
880+
sql: 'id',
881+
type: 'string',
882+
primary_key: true
883+
},
884+
885+
dim_b: {
886+
sql: 'dim_b',
887+
type: 'string'
888+
},
889+
890+
dim_c: {
891+
sql: 'dim_c',
892+
type: 'string'
893+
},
894+
}
895+
});
896+
792897
`);
793898

794899
it('simple pre-aggregation', async () => {
@@ -3030,4 +3135,37 @@ describe('PreAggregations', () => {
30303135
);
30313136
});
30323137
});
3138+
3139+
it('rollupJoin pre-aggregation with nested joins (A->B->C)', async () => {
3140+
await compiler.compile();
3141+
3142+
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
3143+
dimensions: ['cube_a.dim_a', 'cube_b.dim_b', 'cube_c.dim_c'],
3144+
timezone: 'America/Los_Angeles',
3145+
preAggregationsSchema: ''
3146+
});
3147+
3148+
const queryAndParams = query.buildSqlAndParams();
3149+
console.log(queryAndParams);
3150+
const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription();
3151+
console.log(preAggregationsDescription);
3152+
expect(preAggregationsDescription.length).toBe(2);
3153+
const aaa = preAggregationsDescription.find(p => p.preAggregationId === 'cube_a.aaa_rollup');
3154+
const bbb = preAggregationsDescription.find(p => p.preAggregationId === 'cube_b.bbb_rollup');
3155+
expect(aaa).toBeDefined();
3156+
expect(bbb).toBeDefined();
3157+
3158+
expect(query.preAggregations?.preAggregationForQuery?.canUsePreAggregation).toEqual(true);
3159+
expect(query.preAggregations?.preAggregationForQuery?.preAggregationName).toEqual('rollupJoinAB');
3160+
3161+
return dbRunner.evaluateQueryWithPreAggregations(query).then(res => {
3162+
expect(res).toEqual(
3163+
[{
3164+
cube_a__dim_a: 'dim_a',
3165+
cube_b__dim_b: 'dim_b',
3166+
cube_c__dim_c: 'dim_c',
3167+
}]
3168+
);
3169+
});
3170+
});
30333171
});

0 commit comments

Comments
 (0)