@@ -749,8 +749,15 @@ export class PreAggregations {
749749 // but joinGraph of the query has all the connections, necessary for serving the query,
750750 // so we use this information to complete the full paths of members from the root of the query
751751 // up to the pre-agg cube.
752- dimsToMatch = references . dimensions ;
753- timeDimsToMatch = references . timeDimensions ;
752+ // We use references from the underlying pre-aggregations, filtered with members existing in the root
753+ // pre-aggregation itself.
754+
755+ dimsToMatch = references . rollupsReferences
756+ . flatMap ( rolRef => rolRef . fullNameDimensions )
757+ . filter ( d => references . dimensions . some ( rd => d . endsWith ( rd ) ) ) ;
758+ timeDimsToMatch = references . rollupsReferences
759+ . flatMap ( rolRef => rolRef . fullNameTimeDimensions )
760+ . filter ( d => references . timeDimensions . some ( rd => d . dimension . endsWith ( rd . dimension ) ) ) ;
754761
755762 const buildPath = ( cube : string ) : string [ ] => {
756763 const path = [ cube ] ;
@@ -765,12 +772,12 @@ export class PreAggregations {
765772 dimensionsMatch = ( dimensions , doBackAlias ) => {
766773 let target = doBackAlias ? backAlias ( dimsToMatch ) : dimsToMatch ;
767774 target = target . map ( dim => {
768- const [ cube , field ] = dim . split ( '.' ) ;
775+ const [ cube , ... restPath ] = dim . split ( '.' ) ;
769776 if ( cube === transformedQuery . joinGraphRoot ) {
770777 return dim ;
771778 }
772779 const path = buildPath ( cube ) ;
773- return `${ path . join ( '.' ) } .${ field } ` ;
780+ return `${ path . join ( '.' ) } .${ restPath . join ( '.' ) } ` ;
774781 } ) ;
775782
776783 return dimensions . every ( d => target . includes ( d ) ) ;
@@ -1084,7 +1091,9 @@ export class PreAggregations {
10841091 preAggregationName,
10851092 preAggregation,
10861093 cube,
1087- canUsePreAggregation : canUsePreAggregation ( references ) ,
1094+ // For rollupJoin and rollupLambda we need to pass references of the underlying rollups
1095+ // to canUsePreAggregation fn, which are collected later;
1096+ canUsePreAggregation : preAggregation . type === 'rollup' ? canUsePreAggregation ( references ) : false ,
10881097 references,
10891098 preAggregationId : `${ cube } .${ preAggregationName } `
10901099 } ;
@@ -1102,8 +1111,12 @@ export class PreAggregations {
11021111 ) ;
11031112 }
11041113 ) ;
1114+ preAggregationsToJoin . forEach ( preAgg => {
1115+ references . rollupsReferences . push ( preAgg . references ) ;
1116+ } ) ;
11051117 return {
11061118 ...preAggObj ,
1119+ canUsePreAggregation : canUsePreAggregation ( references ) ,
11071120 preAggregationsToJoin,
11081121 rollupJoin : this . buildRollupJoin ( preAggObj , preAggregationsToJoin )
11091122 } ;
@@ -1150,8 +1163,12 @@ export class PreAggregations {
11501163 PreAggregations . memberNameMismatchValidation ( preAggObj , referencedPreAggregation , 'dimensions' ) ;
11511164 PreAggregations . memberNameMismatchValidation ( preAggObj , referencedPreAggregation , 'timeDimensions' ) ;
11521165 } ) ;
1166+ referencedPreAggregations . forEach ( preAgg => {
1167+ references . rollupsReferences . push ( preAgg . references ) ;
1168+ } ) ;
11531169 return {
11541170 ...preAggObj ,
1171+ canUsePreAggregation : canUsePreAggregation ( references ) ,
11551172 referencedPreAggregations,
11561173 } ;
11571174 } else {
0 commit comments