Skip to content

Commit 3d7c1e1

Browse files
committed
fix buildRollupJoin()
1 parent 0db02fc commit 3d7c1e1

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -977,16 +977,9 @@ export class PreAggregations {
977977
return this.query.cacheValue(
978978
['buildRollupJoin', JSON.stringify(preAggObj), JSON.stringify(preAggObjsToJoin)],
979979
() => {
980-
// It's important to build join graph not only using the pre-agg members, but also
981-
// taking into account all explicit underlying rollup pre-aggregation joins, because
982-
// otherwise the built join tree might differ from the actual pre-aggregation.
983-
const preAggJoinsJoinHints = preAggObj.references.rollupsReferences.map(
984-
this.collectJoinHintsFromRollupReferences
985-
).flat();
986-
987-
const builtJoinTree = this.query.joinGraph.buildJoin(
988-
preAggJoinsJoinHints.concat(this.cubesFromPreAggregation(preAggObj))
989-
);
980+
// It's not enough to call buildJoin() directly on cubesFromPreAggregation()
981+
// because transitive joins won't be collected in that case.
982+
const builtJoinTree = this.query.joinTreeForHints(this.cubesHintsFromPreAggregation(preAggObj), true);
990983

991984
if (!builtJoinTree) {
992985
throw new UserError(`Can't build join tree for pre-aggregation ${preAggObj.cube}.${preAggObj.preAggregationName}`);
@@ -997,9 +990,7 @@ export class PreAggregations {
997990
// TODO join hints?
998991
const existingJoins = preAggObjsToJoin
999992
.map(p => this.resolveJoinMembers(
1000-
this.query.joinGraph.buildJoin(
1001-
this.collectJoinHintsFromRollupReferences(p.references).concat(this.cubesFromPreAggregation(p))
1002-
)!
993+
this.query.joinTreeForHints(this.cubesHintsFromPreAggregation(p), true)
1003994
))
1004995
.flat();
1005996

@@ -1074,11 +1065,11 @@ export class PreAggregations {
10741065
});
10751066
}
10761067

1077-
private cubesFromPreAggregation(preAggObj: PreAggregationForQuery): string[] {
1068+
private cubesHintsFromPreAggregation(preAggObj: PreAggregationForQuery): string[][] {
10781069
return R.uniq(
1079-
preAggObj.references.measures.map(m => this.query.cubeEvaluator.parsePath('measures', this.query.cubeEvaluator.memberShortNameFromPath(m))).concat(
1080-
preAggObj.references.dimensions.map(m => this.query.cubeEvaluator.parsePathAnyType(this.query.cubeEvaluator.memberShortNameFromPath(m)))
1081-
).map(p => p[0])
1070+
preAggObj.references.measures.concat(
1071+
preAggObj.references.dimensions
1072+
).map(p => p.split('.').slice(0, -1))
10821073
);
10831074
}
10841075

0 commit comments

Comments
 (0)