Skip to content

Commit b757175

Browse files
committed
fix: sqlAlias isn't used for pre-aggregation table names
1 parent fdeafb8 commit b757175

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,15 +1308,16 @@ class BaseQuery {
13081308
throw new Error('Not implemented');
13091309
}
13101310

1311-
aliasName(name) {
1311+
aliasName(name, isPreAggregationName) {
13121312
const path = name.split('.');
13131313
if (path[0] && this.cubeEvaluator.cubeExists(path[0]) && this.cubeEvaluator.cubeFromPath(path[0]).sqlAlias) {
13141314
const cubeName = path[0];
13151315
path.splice(0, 1);
13161316
path.unshift(this.cubeEvaluator.cubeFromPath(cubeName).sqlAlias);
13171317
name = this.cubeEvaluator.pathFromArray(path);
13181318
}
1319-
return inflection.underscore(name).replace(/\./g, '__');
1319+
// use single underscore for pre-aggregations to avoid fail of pre-aggregation name replace
1320+
return inflection.underscore(name).replace(/\./g, isPreAggregationName ? '_' : '__');
13201321
}
13211322

13221323
newSubQuery(options) {
@@ -1428,7 +1429,7 @@ class BaseQuery {
14281429
}
14291430

14301431
preAggregationTableName(cube, preAggregationName, skipSchema) {
1431-
return `${skipSchema ? '' : this.preAggregationSchema() && `${this.preAggregationSchema()}.`}${this.aliasName(`${cube}_${preAggregationName}`)}`;
1432+
return `${skipSchema ? '' : this.preAggregationSchema() && `${this.preAggregationSchema()}.`}${this.aliasName(`${cube}.${preAggregationName}`, true)}`;
14321433
}
14331434

14341435
preAggregationSchema() {

packages/cubejs-schema-compiler/test/PreAggregationsTest.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ describe('PreAggregations', function test() {
140140
sql: \`
141141
select * from visitor_checkins
142142
\`,
143+
144+
sqlAlias: 'vc',
143145
144146
measures: {
145147
count: {
@@ -572,6 +574,7 @@ describe('PreAggregations', function test() {
572574
console.log(preAggregationsDescription);
573575

574576
const queries = tempTablePreAggregations(preAggregationsDescription);
577+
preAggregationsDescription[1].loadSql[0].should.match(/vc_main/);
575578

576579
console.log(JSON.stringify(queries.concat(queryAndParams)));
577580

0 commit comments

Comments
 (0)