From 13bd2f0bcbc85f93f7d841ad3a83cd6e0d03948f Mon Sep 17 00:00:00 2001 From: Alexandr Romanenko Date: Thu, 3 Apr 2025 19:40:15 +0200 Subject: [PATCH 1/2] fix(tesseract): Fix for multi fact queries --- .../src/adapter/BaseQuery.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js b/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js index 36120f50a1f03..221e99eb6301d 100644 --- a/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js +++ b/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js @@ -227,7 +227,7 @@ export class BaseQuery { dimensions: this.options.dimensions, timeDimensions: this.options.timeDimensions, filters: this.options.filters, - segments: this.options.segments, + egments: this.options.segments, order: this.options.order, contextSymbols: this.options.contextSymbols, timezone: this.options.timezone, @@ -307,12 +307,17 @@ export class BaseQuery { } prebuildJoin() { - /* if (!this.useNativeSqlPlanner) { We still need this join for the follback to preaggregation to work properly. This condition should be returned after the tesseract starts working with pre-aggregations + if (this.useNativeSqlPlanner) { // Tesseract doesn't require join to be prebuilt and there's a case where single join can't be built for multi-fact query + // But we need this join for a fallback when using pre-aggregations. So we’ll try to obtain the join but ignore any errors (which may occur if the query is a multi-fact one). + try { + this.join = this.joinGraph.buildJoin(this.allJoinHints); + } catch (e) { + // Ignore + } + } else { this.join = this.joinGraph.buildJoin(this.allJoinHints); - } */ - - this.join = this.joinGraph.buildJoin(this.allJoinHints); + } } cacheValue(key, fn, { contextPropNames, inputProps, cache } = {}) { @@ -391,7 +396,7 @@ export class BaseQuery { initUngrouped() { this.ungrouped = this.options.ungrouped; if (this.ungrouped) { - if (!this.options.allowUngroupedWithoutPrimaryKey) { + if (!this.options.allowUngroupedWithoutPrimaryKey && this.join) { const cubes = R.uniq([this.join.root].concat(this.join.joins.map(j => j.originalTo))); const primaryKeyNames = cubes.flatMap(c => this.primaryKeyNames(c)); const missingPrimaryKeys = primaryKeyNames.filter(key => !this.dimensions.find(d => d.dimension === key)); From 842f85900b75b1874d3d642062e3cb6fd7000e8f Mon Sep 17 00:00:00 2001 From: Alexandr Romanenko Date: Thu, 3 Apr 2025 19:43:06 +0200 Subject: [PATCH 2/2] fix --- packages/cubejs-schema-compiler/src/adapter/BaseQuery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js b/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js index 221e99eb6301d..8ec91a51fb1a3 100644 --- a/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js +++ b/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js @@ -227,7 +227,7 @@ export class BaseQuery { dimensions: this.options.dimensions, timeDimensions: this.options.timeDimensions, filters: this.options.filters, - egments: this.options.segments, + segments: this.options.segments, order: this.options.order, contextSymbols: this.options.contextSymbols, timezone: this.options.timezone,