@@ -4,6 +4,7 @@ import { CubeSymbols } from '../compiler/CubeSymbols';
4
4
import { UserError } from '../compiler/UserError' ;
5
5
import { BaseQuery } from './BaseQuery' ;
6
6
import {
7
+ JoinEdge ,
7
8
PreAggregationDefinition ,
8
9
PreAggregationDefinitions ,
9
10
PreAggregationReferences ,
@@ -1042,6 +1043,22 @@ export class PreAggregations {
1042
1043
) ;
1043
1044
}
1044
1045
1046
+ private doesQueryAndPreAggJoinTreeMatch ( references : PreAggregationReferences ) : boolean {
1047
+ const { query } = this ;
1048
+ const preAggTree = references . joinTree || { joins : [ ] } ;
1049
+ const preAggEdges = new Set ( preAggTree . joins . map ( ( e : JoinEdge ) => `${ e . from } ->${ e . to } ` ) ) ;
1050
+ const queryTree = query . join ;
1051
+
1052
+ for ( const edge of queryTree . joins ) {
1053
+ const key = `${ edge . from } ->${ edge . to } ` ;
1054
+ if ( ! preAggEdges . has ( key ) ) {
1055
+ return false ;
1056
+ }
1057
+ }
1058
+
1059
+ return true ;
1060
+ }
1061
+
1045
1062
private evaluatedPreAggregationObj (
1046
1063
cube : string ,
1047
1064
preAggregationName : string ,
@@ -1053,7 +1070,7 @@ export class PreAggregations {
1053
1070
preAggregationName,
1054
1071
preAggregation,
1055
1072
cube,
1056
- canUsePreAggregation : canUsePreAggregation ( references ) ,
1073
+ canUsePreAggregation : canUsePreAggregation ( references ) && this . doesQueryAndPreAggJoinTreeMatch ( references ) ,
1057
1074
references,
1058
1075
preAggregationId : `${ cube } .${ preAggregationName } `
1059
1076
} ;
0 commit comments