Skip to content

Commit

Permalink
reverted back to dimensionSql()
Browse files Browse the repository at this point in the history
  • Loading branch information
KSDaemon committed Sep 15, 2024
1 parent bd449d8 commit 282b054
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions packages/cubejs-schema-compiler/src/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,14 @@ export class BaseQuery {
this.pushMemberNameForCollectionIfNecessary(cubeName, name);
}
const memberPathArray = [cubeName, name];
// Member path needs to be expanded to granularity if subPropertyName is provided.
// Without this: infinite recursion with maximum call stack size exceeded.
// During resolving within dimensionSql() the same symbol is pushed into the stack.
// This would not be needed when the subProperty evaluation will be here and no
// call to dimensionSql().
if (subPropertyName && symbol.type === 'time') {
memberPathArray.push('granularities', subPropertyName);
}
const memberPath = this.cubeEvaluator.pathFromArray(memberPathArray);
let type = memberExpressionType;
if (!type) {
Expand Down Expand Up @@ -2302,6 +2310,15 @@ export class BaseQuery {
'\',\'',
this.autoPrefixAndEvaluateSql(cubeName, symbol.longitude.sql, isMemberExpr)
]);
} else if (symbol.type === 'time' && subPropertyName) {
// TODO: Beware! memberExpression && shiftInterval are not supported with the current implementation.
// Ideally this should be implemented (at least partially) here + inside cube symbol evaluation logic.
// As now `dimensionSql()` is recursively calling `evaluateSymbolSql()` which is not good.
const td = this.newTimeDimension({
dimension: this.cubeEvaluator.pathFromArray([cubeName, name]),
granularity: subPropertyName
});
return td.dimensionSql();
} else {
let res = this.autoPrefixAndEvaluateSql(cubeName, symbol.sql, isMemberExpr);

Expand All @@ -2315,17 +2332,6 @@ export class BaseQuery {
) {
res = this.convertTz(res);
}

if (symbol.type === 'time' && subPropertyName) {
// Custom granularity
const granularity = new Granularity(this, {
dimension: memberPath,
granularity: subPropertyName
});

res = this.dimensionTimeGroupedColumn(res, granularity);
}

return res;
}
} else if (type === 'segment') {
Expand Down

0 comments on commit 282b054

Please sign in to comment.