Skip to content

Commit 80b312f

Browse files
committed
fix: Merge back sqlAlias support
1 parent 3a16410 commit 80b312f

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,13 +1017,6 @@ class BaseQuery {
10171017
return this.evaluateSymbolSqlWithContext(fn, { cubeAliasPrefix });
10181018
}
10191019

1020-
// TODO merge fail. Remove sqlAlias us unused?
1021-
/*
1022-
cubeAlias(cube) {
1023-
return this.cubeAlias(this.cubeEvaluator.cubeFromPath(cube).sqlAlias || cube);
1024-
}
1025-
*/
1026-
10271020
cubeAlias(cubeName) {
10281021
const prefix = this.safeEvaluateSymbolContext().cubeAliasPrefix || this.cubeAliasPrefix;
10291022
return this.escapeColumnName(this.aliasName(`${prefix ? prefix + '__' : ''}${cubeName}`));
@@ -1239,6 +1232,13 @@ class BaseQuery {
12391232
}
12401233

12411234
aliasName(name) {
1235+
const path = name.split('.');
1236+
if (path[0] && this.cubeEvaluator.cubeExists(path[0]) && this.cubeEvaluator.cubeFromPath(path[0]).sqlAlias) {
1237+
const cubeName = path[0];
1238+
path.splice(0, 1);
1239+
path.unshift(this.cubeEvaluator.cubeFromPath(cubeName).sqlAlias);
1240+
name = this.cubeEvaluator.pathFromArray(path);
1241+
}
12421242
return inflection.underscore(name).replace(/\./g, '__');
12431243
}
12441244

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ describe('ClickHouse JoinGraph', function test() {
2828
\${USER_CONTEXT.sourceArray.filter(sourceArray => \`source in (\${sourceArray.join(',')})\`)}
2929
\`,
3030
31-
sqlAlias: 'visitors_table',
32-
3331
refreshKey: {
3432
sql: 'SELECT 1',
3533
},

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ describe('SQL Generation', function test() {
2828
\${USER_CONTEXT.sourceArray.filter(sourceArray => \`source in (\${sourceArray.join(',')})\`)}
2929
\`,
3030
31-
sqlAlias: 'visitors_table',
32-
3331
refreshKey: {
3432
sql: 'SELECT 1',
3533
},
@@ -288,6 +286,20 @@ describe('SQL Generation', function test() {
288286
}
289287
}
290288
})
289+
290+
cube('CubeWithVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName', {
291+
sql: \`
292+
select * from cards
293+
\`,
294+
295+
sqlAlias: 'cube_with_long_name',
296+
297+
measures: {
298+
count: {
299+
type: 'count'
300+
}
301+
}
302+
});
291303
`);
292304

293305
it('simple join', () => {
@@ -1400,4 +1412,18 @@ describe('SQL Generation', function test() {
14001412
}, {
14011413
"visitors__created_at_date": "2017-01-06T00:00:00.000Z"
14021414
}]));
1415+
1416+
it(
1417+
'sqlAlias',
1418+
() => runQueryTest({
1419+
measures: ['CubeWithVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName.count'],
1420+
dimensions: [],
1421+
timeDimensions: [],
1422+
timezone: 'America/Los_Angeles',
1423+
filters: [],
1424+
order: []
1425+
}, [
1426+
{ "cube_with_long_name__count": '3' }
1427+
])
1428+
);
14031429
});

0 commit comments

Comments
 (0)