Skip to content

Commit d0e8bc1

Browse files
committed
some code polish + throw error for loop detected
1 parent e158147 commit d0e8bc1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ export class BaseQuery {
488488
cnt++;
489489
}
490490

491+
if (cnt >= 10000) {
492+
throw new UserError('Can not construct joins for the query, potential loop detected');
493+
}
494+
491495
this.collectedJoinHints = R.uniq(constructJH());
492496
}
493497
return this.collectedJoinHints;
@@ -2489,13 +2493,10 @@ export class BaseQuery {
24892493
// In a join between Cube A and Cube B, sql() may reference members from other cubes.
24902494
// These referenced cubes must be added as join hints before Cube B to ensure correct SQL generation.
24912495
const targetCube = s.targetCubeName();
2492-
const { joinHints } = this.safeEvaluateSymbolContext();
2493-
let targetIdx = joinHints.findIndex(e => e === targetCube);
2494-
while (targetIdx > -1) {
2495-
joinHints.splice(targetIdx, 1);
2496-
targetIdx = joinHints.findIndex(e => e === targetCube);
2497-
}
2496+
let { joinHints } = this.safeEvaluateSymbolContext();
2497+
joinHints = joinHints.filter(e => e !== targetCube);
24982498
joinHints.push(targetCube);
2499+
this.safeEvaluateSymbolContext().joinHints = joinHints;
24992500

25002501
// Special processing is required when one cube extends another, because in this case
25012502
// cube names collected during joins evaluation might belong to ancestors which are out of scope of

0 commit comments

Comments
 (0)