@@ -507,8 +507,18 @@ 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+ if ( query . join ) {
514+ for ( const j of query . join . joins ) {
515+ joinsMap [ j . to ] = j . from ;
516+ }
517+ }
518+
510519 return {
511- joinGraph : query . join ,
520+ joinGraphRoot : query . join ?. root ,
521+ joinsMap,
512522 sortedDimensions,
513523 sortedTimeDimensions,
514524 timeDimensions,
@@ -734,11 +744,33 @@ export class PreAggregations {
734744 if ( references . rollups . length > 0 ) {
735745 // In 'rollupJoin' / 'rollupLambda' pre-aggregations fullName members will be empty, because there are
736746 // no connections in the joinTree between cubes from different datasources
747+ // but joinGraph of the query has all the connections, necessary for serving the query,
748+ // so we use this information to complete the full paths of members from the root of the query
749+ // up to the pre-agg cube.
737750 dimsToMatch = references . dimensions ;
738751 timeDimsToMatch = references . timeDimensions ;
739752
753+ const buildPath = ( cube : string ) : string [ ] => {
754+ const path = [ cube ] ;
755+ const parentMap = transformedQuery . joinsMap ;
756+ while ( parentMap [ cube ] ) {
757+ cube = parentMap [ cube ] ;
758+ path . push ( cube ) ;
759+ }
760+ return path . reverse ( ) ;
761+ } ;
762+
740763 dimensionsMatch = ( dimensions , doBackAlias ) => {
741- const target = doBackAlias ? backAlias ( dimsToMatch ) : dimsToMatch ;
764+ let target = doBackAlias ? backAlias ( dimsToMatch ) : dimsToMatch ;
765+ target = target . map ( dim => {
766+ const [ cube , field ] = dim . split ( '.' ) ;
767+ if ( cube === transformedQuery . joinGraphRoot ) {
768+ return dim ;
769+ }
770+ const path = buildPath ( cube ) ;
771+ return `${ path . join ( '.' ) } .${ field } ` ;
772+ } ) ;
773+
742774 return dimensions . every ( d => target . includes ( d ) ) ;
743775 } ;
744776 } else {
0 commit comments