From 282b054ed47bc98f21190cae2653608c26922c49 Mon Sep 17 00:00:00 2001 From: Konstantin Burkalev Date: Sun, 15 Sep 2024 22:44:12 +0300 Subject: [PATCH] reverted back to dimensionSql() --- .../src/adapter/BaseQuery.js | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js b/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js index 42a4eaf55bf07..62fe81b30b5ba 100644 --- a/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js +++ b/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js @@ -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) { @@ -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); @@ -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') {