diff --git a/packages/cubejs-schema-compiler/src/compiler/CubeSymbols.js b/packages/cubejs-schema-compiler/src/compiler/CubeSymbols.js index 28c99383ae1fc..06c3d84eaebab 100644 --- a/packages/cubejs-schema-compiler/src/compiler/CubeSymbols.js +++ b/packages/cubejs-schema-compiler/src/compiler/CubeSymbols.js @@ -65,6 +65,7 @@ export class CubeSymbols { let measures; let dimensions; let segments; + let joins; const cubeObject = Object.assign({ allDefinitions(type) { @@ -106,7 +107,17 @@ export class CubeSymbols { }, set segments(v) { // Dont allow to modify - } + }, + + get joins() { + if (!joins) { + joins = this.allDefinitions('joins'); + } + return joins; + }, + set joins(v) { + // Dont allow to modify + }, }, cubeDefinition); if (cubeDefinition.extends) { diff --git a/packages/cubejs-schema-compiler/test/integration/postgres/yaml-compiler.test.ts b/packages/cubejs-schema-compiler/test/integration/postgres/yaml-compiler.test.ts index bd829ce6ff840..bff701ca595df 100644 --- a/packages/cubejs-schema-compiler/test/integration/postgres/yaml-compiler.test.ts +++ b/packages/cubejs-schema-compiler/test/integration/postgres/yaml-compiler.test.ts @@ -482,6 +482,65 @@ cubes: ); }); + it('should correctly handle extensions with joins', async () => { + const { compiler, joinGraph, cubeEvaluator } = prepareYamlCompiler(` + cubes: + - name: base_users + sql: "SELECT 1" + + dimensions: + - name: time + sql: "{CUBE}.timestamp" + type: time + - name: user_id + sql: "user_id" + type: number + primary_key: true + public: true + + joins: + - name: base_user_joins + sql: "{CUBE}.user_id = {base_user_joins}.user_id" + relationship: one_to_one + + - name: base_user_joins + sql: "SELECT 1 as user_id, 2 as second_prop" + + dimensions: + - name: user_id + sql: "user_id" + type: number + primary_key: true + - name: second_prop + sql: "second_prop" + type: number + + - name: active_users + sql: "SELECT 1 as user_id, '2022-01-01' as timestamp" + extends: base_users + + `, { yamlExtension: true }); + await compiler.compile(); + + const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, { + measures: [], + dimensions: ['active_users.user_id', 'active_users.second_prop'], + timezone: 'UTC' + }); + + console.log(query.buildSqlAndParams()); + + const res = await dbRunner.testQuery(query.buildSqlAndParams()); + console.log(JSON.stringify(res)); + + expect(res).toEqual( + [{ + active_users__user_id: 1, + base_user_joins__second_prop: 2 + }] + ); + }); + it('COMPILE_CONTEXT', async () => { const { compiler, joinGraph, cubeEvaluator } = prepareYamlCompiler(` cubes: