Skip to content

Commit 12bb2e3

Browse files
committed
udpat traversing to change the ancestors to the original cube hinting
1 parent 8e41b1e commit 12bb2e3

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ export class BaseQuery {
418418
*/
419419
get allJoinHints() {
420420
if (!this.collectedJoinHints) {
421-
// let joinHints = this.collectJoinHints();
421+
// this.collectedJoinHints = this.collectJoinHints();
422422
const allMembersJoinHints = this.collectJoinHintsFromMembers(this.allMembersConcat(false));
423423
const customSubQueryJoinHints = this.collectJoinHintsFromMembers(this.joinMembersFromCustomSubQuery());
424424
let joinMembersJoinHints = this.collectJoinHintsFromMembers(this.joinMembersFromJoin());
@@ -436,7 +436,7 @@ export class BaseQuery {
436436
...joinMembersJoinHints,
437437
...customSubQueryJoinHints,
438438
]);
439-
while (!R.equals(this.join, newJoin)) {
439+
while (newJoin?.joins.length > 0 && !R.equals(this.join, newJoin)) {
440440
this.join = newJoin;
441441
joinMembersJoinHints = this.collectJoinHintsFromMembers(this.joinMembersFromJoin());
442442
newJoin = this.joinGraph.buildJoin([
@@ -2462,6 +2462,26 @@ export class BaseQuery {
24622462
targetIdx = joinHints.findIndex(e => e === targetCube);
24632463
}
24642464
joinHints.push(targetCube);
2465+
2466+
// Special processing is required when one cube extends another, because in this case
2467+
// cube names collected during joins evaluation might belong to ancestors which are out of scope of
2468+
// the current query and thus will lead to `Can't find join path to join cubes` error.
2469+
// To work around this we change the all ancestors cube names in collected join hints to the original one.
2470+
if (s.cube().extends) {
2471+
const cubeName = s.cube().name;
2472+
let parentCube = this.cubeEvaluator.resolveSymbolsCall(s.cube().extends, (name) => this.cubeEvaluator.cubeFromPath(name));
2473+
while (parentCube) {
2474+
// eslint-disable-next-line no-loop-func
2475+
joinHints.forEach((item, index, array) => {
2476+
if (item === parentCube.name) {
2477+
array[index] = cubeName;
2478+
}
2479+
});
2480+
parentCube = parentCube.extends ?
2481+
this.cubeEvaluator.resolveSymbolsCall(parentCube.extends, (name) => this.cubeEvaluator.cubeFromPath(name))
2482+
: null;
2483+
}
2484+
}
24652485
}
24662486
return res;
24672487
}

0 commit comments

Comments
 (0)