@@ -507,8 +507,16 @@ export class PreAggregations {
507507 filterDimensionsSingleValueEqual =
508508 allValuesEq1 ( filterDimensionsSingleValueEqual ) ? new Set ( filterDimensionsSingleValueEqual ?. keys ( ) ) : null ;
509509
510+ // Build reverse query joins map, which is used for
511+ // rollupLambda and rollupJoin pre-aggs matching later
512+ const joinsMap : Record < string , string > = { } ;
513+ for ( const j of query . join . joins ) {
514+ joinsMap [ j . to ] = j . from ;
515+ }
516+
510517 return {
511- joinGraph : query . join ,
518+ joinGraphRoot : query . join . root ,
519+ joinsMap,
512520 sortedDimensions,
513521 sortedTimeDimensions,
514522 timeDimensions,
@@ -734,11 +742,33 @@ export class PreAggregations {
734742 if ( references . rollups . length > 0 ) {
735743 // In 'rollupJoin' / 'rollupLambda' pre-aggregations fullName members will be empty, because there are
736744 // no connections in the joinTree between cubes from different datasources
745+ // but joinGraph of the query has all the connections, necessary for serving the query,
746+ // so we use this information to complete the full paths of members from the root of the query
747+ // up to the pre-agg cube.
737748 dimsToMatch = references . dimensions ;
738749 timeDimsToMatch = references . timeDimensions ;
739750
751+ const buildPath = ( cube : string ) : string [ ] => {
752+ const path = [ cube ] ;
753+ const parentMap = transformedQuery . joinsMap ;
754+ while ( parentMap [ cube ] ) {
755+ cube = parentMap [ cube ] ;
756+ path . push ( cube ) ;
757+ }
758+ return path . reverse ( ) ;
759+ } ;
760+
740761 dimensionsMatch = ( dimensions , doBackAlias ) => {
741- const target = doBackAlias ? backAlias ( dimsToMatch ) : dimsToMatch ;
762+ let target = doBackAlias ? backAlias ( dimsToMatch ) : dimsToMatch ;
763+ target = target . map ( dim => {
764+ const [ cube , field ] = dim . split ( '.' ) ;
765+ if ( cube === transformedQuery . joinGraphRoot ) {
766+ return dim ;
767+ }
768+ const path = buildPath ( cube ) ;
769+ return `${ path . join ( '.' ) } .${ field } ` ;
770+ } ) ;
771+
742772 return dimensions . every ( d => target . includes ( d ) ) ;
743773 } ;
744774 } else {
0 commit comments