Skip to content

Commit 19cc9c1

Browse files
committed
implement join tree comparison
1 parent 8beb002 commit 19cc9c1

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/cubejs-schema-compiler/src/adapter/PreAggregations.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CubeSymbols } from '../compiler/CubeSymbols';
44
import { UserError } from '../compiler/UserError';
55
import { BaseQuery } from './BaseQuery';
66
import {
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

Comments
 (0)