Skip to content

Commit

Permalink
chore: dont check dimension if there is no dataRange
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr committed Nov 24, 2023
1 parent e80eee1 commit e4a8841
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,16 @@ export class PreAggregations {

const matchedTimeDimension = preAggregation.partitionGranularity && !this.hasCumulativeMeasures &&
this.query.timeDimensions.find(td => {
if (td.dimension === foundPreAggregation.references.timeDimensions[0].dimension && td.dateRange) {
if (!td.dateRange) {
return false;

Check warning on line 158 in packages/cubejs-schema-compiler/src/adapter/PreAggregations.js

View check run for this annotation

Codecov / codecov/patch

packages/cubejs-schema-compiler/src/adapter/PreAggregations.js#L158

Added line #L158 was not covered by tests
}

if (td.dimension === foundPreAggregation.references.timeDimensions[0].dimension) {
return true;
}

const parent = this.query.cubeEvaluator.byPath('dimensions', td.expressionPath());

Check warning on line 165 in packages/cubejs-schema-compiler/src/adapter/PreAggregations.js

View check run for this annotation

Codecov / codecov/patch

packages/cubejs-schema-compiler/src/adapter/PreAggregations.js#L165

Added line #L165 was not covered by tests
if (parent?.aliasMember === foundPreAggregation.references.timeDimensions[0].dimension && td.dateRange) {
if (parent?.aliasMember === foundPreAggregation.references.timeDimensions[0].dimension) {
return true;

Check warning on line 167 in packages/cubejs-schema-compiler/src/adapter/PreAggregations.js

View check run for this annotation

Codecov / codecov/patch

packages/cubejs-schema-compiler/src/adapter/PreAggregations.js#L167

Added line #L167 was not covered by tests
}

Expand Down
14 changes: 14 additions & 0 deletions packages/cubejs-schema-compiler/src/compiler/CubeEvaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,22 @@ export class CubeEvaluator extends CubeSymbols {
return cubeAndName[0];
}

/**
* @param {measures|dimensions|segments} type
* @param {string} path
* @returns boolean
*/
isInstanceOfType(type, path) {
const cubeAndName = Array.isArray(path) ? path : path.split('.');
return this.evaluatedCubes[cubeAndName[0]] &&
this.evaluatedCubes[cubeAndName[0]][type] &&
this.evaluatedCubes[cubeAndName[0]][type][cubeAndName[1]];
}

/**
* @param {string} path
* @returns {*}
*/
byPathAnyType(path) {
const type = ['measures', 'dimensions', 'segments'].find(t => this.isInstanceOfType(t, path));

Expand All @@ -325,6 +334,11 @@ export class CubeEvaluator extends CubeSymbols {
return this.byPath(type, path);
}

/**
* @param {measures|dimensions|segments} type
* @param {string} path
* @returns {*}
*/
byPath(type, path) {
if (!type) {
throw new Error(`Type can't be undefined for '${path}'`);
Expand Down

0 comments on commit e4a8841

Please sign in to comment.