Skip to content

Commit 53dcf73

Browse files
committed
next attempt to make allJoinHints work
1 parent a8182dc commit 53dcf73

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

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

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,10 @@ export class BaseQuery {
418418
*/
419419
get allJoinHints() {
420420
if (!this.collectedJoinHints) {
421-
let joinHints = this.collectJoinHints();
422-
// let joinHints = this.collectJoinHintsFromMembers(this.allMembersConcat(false));
421+
// let joinHints = this.collectJoinHints();
422+
const allMembersJoinHints = this.collectJoinHintsFromMembers(this.allMembersConcat(false));
423+
const customSubQueryJoinHints = this.collectJoinHintsFromMembers(this.joinMembersFromCustomSubQuery());
424+
let joinMembersJoinHints = this.collectJoinHintsFromMembers(this.joinMembersFromJoin());
423425

424426
// One cube may join the other cube via transitive joined cubes,
425427
// members from which are referenced in the join `on` clauses.
@@ -428,16 +430,28 @@ export class BaseQuery {
428430

429431
const prevJoins = this.join;
430432

431-
let newJoin = this.joinGraph.buildJoin([...this.queryLevelJoinHints, ...joinHints]);
433+
let newJoin = this.joinGraph.buildJoin([
434+
...this.queryLevelJoinHints,
435+
...allMembersJoinHints,
436+
...joinMembersJoinHints,
437+
...customSubQueryJoinHints,
438+
]);
432439
while (!R.equals(this.join, newJoin)) {
433440
this.join = newJoin;
434-
joinHints = R.uniq([joinHints[0], ...this.collectJoinHintsFromMembers(this.joinMembersFromJoin()), ...joinHints]);
435-
newJoin = this.joinGraph.buildJoin([...this.queryLevelJoinHints, ...joinHints]);
441+
joinMembersJoinHints = this.collectJoinHintsFromMembers(this.joinMembersFromJoin());
442+
newJoin = this.joinGraph.buildJoin([
443+
...this.queryLevelJoinHints,
444+
...allMembersJoinHints,
445+
...joinMembersJoinHints,
446+
...customSubQueryJoinHints,
447+
]);
436448
}
437449

438450
this.collectedJoinHints = [
439451
...this.queryLevelJoinHints,
440-
...joinHints,
452+
...allMembersJoinHints,
453+
...joinMembersJoinHints,
454+
...customSubQueryJoinHints,
441455
];
442456

443457
this.join = prevJoins;
@@ -2455,7 +2469,17 @@ export class BaseQuery {
24552469
* @returns {Array<Array<string>>}
24562470
*/
24572471
collectJoinHints(excludeTimeDimensions = false) {
2458-
const customSubQueryJoinMembers = this.customSubQueryJoins.map(j => {
2472+
const membersToCollectFrom = [
2473+
...this.allMembersConcat(excludeTimeDimensions),
2474+
...this.joinMembersFromJoin(),
2475+
...this.joinMembersFromCustomSubQuery(),
2476+
];
2477+
2478+
return this.collectJoinHintsFromMembers(membersToCollectFrom);
2479+
}
2480+
2481+
joinMembersFromCustomSubQuery() {
2482+
return this.customSubQueryJoins.map(j => {
24592483
const res = {
24602484
path: () => null,
24612485
cube: () => this.cubeEvaluator.cubeFromPath(j.on.cubeName),
@@ -2469,14 +2493,6 @@ export class BaseQuery {
24692493
getMembers: () => [res],
24702494
};
24712495
});
2472-
2473-
const membersToCollectFrom = [
2474-
...this.allMembersConcat(excludeTimeDimensions),
2475-
...this.joinMembersFromJoin(),
2476-
...customSubQueryJoinMembers,
2477-
];
2478-
2479-
return this.collectJoinHintsFromMembers(membersToCollectFrom);
24802496
}
24812497

24822498
joinMembersFromJoin() {

0 commit comments

Comments
 (0)