@@ -4,6 +4,7 @@ import { CubeSymbols } from '../compiler/CubeSymbols';
44import { UserError } from '../compiler/UserError' ;
55import { BaseQuery } from './BaseQuery' ;
66import {
7+ JoinEdge ,
78 PreAggregationDefinition ,
89 PreAggregationDefinitions ,
910 PreAggregationReferences ,
@@ -1042,6 +1043,22 @@ export class PreAggregations {
10421043 ) ;
10431044 }
10441045
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+
10451062 private evaluatedPreAggregationObj (
10461063 cube : string ,
10471064 preAggregationName : string ,
@@ -1053,7 +1070,7 @@ export class PreAggregations {
10531070 preAggregationName,
10541071 preAggregation,
10551072 cube,
1056- canUsePreAggregation : canUsePreAggregation ( references ) ,
1073+ canUsePreAggregation : canUsePreAggregation ( references ) && this . doesQueryAndPreAggJoinTreeMatch ( references ) ,
10571074 references,
10581075 preAggregationId : `${ cube } .${ preAggregationName } `
10591076 } ;
0 commit comments