Skip to content

Commit 0889d02

Browse files
committed
fix(schema-compiler): fix Maximum call stack size exceeded if FILTER_PARAMS are used inside dimensions/measures
1 parent 8e815c2 commit 0889d02

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,14 @@ export class BaseQuery {
22402240
this.safeEvaluateSymbolContext().memberChildren[parentMember].push(memberPath);
22412241
}
22422242
}
2243+
2244+
// This is a special recursion guard that might happen sometimes, like
2245+
// during alias members collection which invokes sql evaluation of all members
2246+
// when FILTER_PARAMS is proxied for SQL evaluation.
2247+
if (parentMember === memberPath && this.safeEvaluateSymbolContext().aliasGathering) {
2248+
return '';
2249+
}
2250+
22432251
this.safeEvaluateSymbolContext().currentMember = memberPath;
22442252
try {
22452253
if (type === 'measure') {
@@ -3882,6 +3890,12 @@ export class BaseQuery {
38823890
// collectFrom() -> traverseSymbol() -> evaluateSymbolSql() ->
38833891
// evaluateSql() -> resolveSymbolsCall() -> cubeReferenceProxy->toString() ->
38843892
// evaluateSymbolSql() -> evaluateSql()... -> and got here again
3893+
//
3894+
// When FILTER_PARAMS is used in dimension/measure SQL - we also hit recursive loop:
3895+
// allBackAliasMembersExceptSegments() -> collectFrom() -> traverseSymbol() -> evaluateSymbolSql() ->
3896+
// autoPrefixAndEvaluateSql() -> evaluateSql() -> filterProxyFromAllFilters->Proxy->toString()
3897+
// and so on...
3898+
// For this case there is a recursion guard added to this.evaluateSymbolSql()
38853899
const aliases = allFilters ?
38863900
allFilters
38873901
.map(v => (v.query ? v.query.allBackAliasMembersExceptSegments() : {}))
@@ -3932,8 +3946,10 @@ export class BaseQuery {
39323946
const query = this;
39333947
return members.map(
39343948
member => {
3935-
const collectedMembers = query
3936-
.collectFrom([member], query.collectMemberNamesFor.bind(query), 'collectMemberNamesFor');
3949+
const collectedMembers = query.evaluateSymbolSqlWithContext(
3950+
() => query.collectFrom([member], query.collectMemberNamesFor.bind(query), 'collectMemberNamesFor'),
3951+
{ aliasGathering: true }
3952+
);
39373953
const memberPath = member.expressionPath();
39383954
let nonAliasSeen = false;
39393955
return collectedMembers

0 commit comments

Comments
 (0)