@@ -675,6 +675,120 @@ describe('PreAggregations', () => {
675675 }
676676 });
677677
678+ cube('cube_x', {
679+ sql: \`SELECT 1 as id, 'dim_x' as dim_x\`,
680+
681+ joins: {
682+ cube_y: {
683+ relationship: 'many_to_one',
684+ sql: \`\${CUBE.dim_x} = \${cube_y.dim_x}\`
685+ }
686+ },
687+
688+ dimensions: {
689+ id: {
690+ sql: 'id',
691+ type: 'string',
692+ primary_key: true
693+ },
694+
695+ dim_x: {
696+ sql: 'dim_x',
697+ type: 'string'
698+ },
699+ },
700+
701+ pre_aggregations: {
702+ xxx: {
703+ dimensions: [
704+ dim_x
705+ ]
706+ },
707+ rollupJoinThreeCubes: {
708+ type: 'rollupJoin',
709+ dimensions: [
710+ dim_x,
711+ cube_y.dim_y,
712+ cube_z.dim_z
713+ ],
714+ rollups: [
715+ xxx,
716+ cube_y.yyy,
717+ cube_z.zzz
718+ ]
719+ }
720+ }
721+ });
722+
723+ cube('cube_y', {
724+ sql: \`SELECT 2 as id, 'dim_x' as dim_x, 'dim_y' as dim_y\`,
725+
726+ joins: {
727+ cube_z: {
728+ relationship: 'many_to_one',
729+ sql: \`\${CUBE.dim_y} = \${cube_z.dim_y}\`
730+ }
731+ },
732+
733+ dimensions: {
734+ id: {
735+ sql: 'id',
736+ type: 'string',
737+ primary_key: true
738+ },
739+
740+ dim_x: {
741+ sql: 'dim_x',
742+ type: 'string'
743+ },
744+
745+ dim_y: {
746+ sql: 'dim_y',
747+ type: 'string'
748+ },
749+ },
750+
751+ pre_aggregations: {
752+ yyy: {
753+ dimensions: [
754+ dim_x,
755+ dim_y,
756+ ]
757+ }
758+ }
759+ });
760+
761+ cube('cube_z', {
762+ sql: \`SELECT 3 as id, 'dim_y' as dim_y, 'dim_z' as dim_z\`,
763+
764+ dimensions: {
765+ id: {
766+ sql: 'id',
767+ type: 'string',
768+ primary_key: true
769+ },
770+
771+ dim_y: {
772+ sql: 'dim_y',
773+ type: 'string'
774+ },
775+
776+ dim_z: {
777+ sql: 'dim_z',
778+ type: 'string'
779+ },
780+ },
781+
782+ pre_aggregations: {
783+ zzz: {
784+ dimensions: [
785+ dim_y,
786+ dim_z,
787+ ]
788+ }
789+ }
790+ });
791+
678792 ` ) ;
679793
680794 it ( 'simple pre-aggregation' , async ( ) => {
@@ -2881,4 +2995,39 @@ describe('PreAggregations', () => {
28812995 ) ;
28822996 } ) ;
28832997 } ) ;
2998+
2999+ it ( 'rollupJoin pre-aggregation with three cubes' , async ( ) => {
3000+ await compiler . compile ( ) ;
3001+
3002+ const query = new PostgresQuery ( { joinGraph, cubeEvaluator, compiler } , {
3003+ dimensions : [ 'cube_x.dim_x' , 'cube_y.dim_y' , 'cube_z.dim_z' ] ,
3004+ timezone : 'America/Los_Angeles' ,
3005+ preAggregationsSchema : ''
3006+ } ) ;
3007+
3008+ const queryAndParams = query . buildSqlAndParams ( ) ;
3009+ console . log ( queryAndParams ) ;
3010+ const preAggregationsDescription : any = query . preAggregations ?. preAggregationsDescription ( ) ;
3011+ console . log ( preAggregationsDescription ) ;
3012+ expect ( preAggregationsDescription . length ) . toBe ( 3 ) ;
3013+ const xxx = preAggregationsDescription . find ( p => p . preAggregationId === 'cube_x.xxx' ) ;
3014+ const yyy = preAggregationsDescription . find ( p => p . preAggregationId === 'cube_y.yyy' ) ;
3015+ const zzz = preAggregationsDescription . find ( p => p . preAggregationId === 'cube_z.zzz' ) ;
3016+ expect ( xxx ) . toBeDefined ( ) ;
3017+ expect ( yyy ) . toBeDefined ( ) ;
3018+ expect ( zzz ) . toBeDefined ( ) ;
3019+
3020+ expect ( query . preAggregations ?. preAggregationForQuery ?. canUsePreAggregation ) . toEqual ( true ) ;
3021+ expect ( query . preAggregations ?. preAggregationForQuery ?. preAggregationName ) . toEqual ( 'rollupJoinThreeCubes' ) ;
3022+
3023+ return dbRunner . evaluateQueryWithPreAggregations ( query ) . then ( res => {
3024+ expect ( res ) . toEqual (
3025+ [ {
3026+ cube_x__dim_x : 'dim_x' ,
3027+ cube_y__dim_y : 'dim_y' ,
3028+ cube_z__dim_z : 'dim_z' ,
3029+ } ]
3030+ ) ;
3031+ } ) ;
3032+ } ) ;
28843033} ) ;
0 commit comments