From ff20b2dbe671ed6be0e02bd8952d13685ff40556 Mon Sep 17 00:00:00 2001 From: Paul Heinrichs Date: Tue, 19 Nov 2024 11:59:37 -0500 Subject: [PATCH 1/2] support join inheritance --- .../src/compiler/CubeSymbols.js | 13 +++- .../postgres/yaml-compiler.test.ts | 64 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/packages/cubejs-schema-compiler/src/compiler/CubeSymbols.js b/packages/cubejs-schema-compiler/src/compiler/CubeSymbols.js index ee8b0ab6e333f..798a15b2589fa 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..fd2d66d0a0196 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,70 @@ 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)); + [ + { + 'active_users.user_id': 1, + 'base_user_joins.second_prop': 2 + } + ]; + expect(res).toEqual( + [{ + active_users__user_id: 1, + base_user_joins__second_prop: 2 + }] + ); + }); + it('COMPILE_CONTEXT', async () => { const { compiler, joinGraph, cubeEvaluator } = prepareYamlCompiler(` cubes: From e36345813f518c81c49724c8fe9c8e982e502e51 Mon Sep 17 00:00:00 2001 From: Paul Heinrichs Date: Tue, 19 Nov 2024 12:18:32 -0500 Subject: [PATCH 2/2] remove JSON response object --- .../test/integration/postgres/yaml-compiler.test.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) 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 fd2d66d0a0196..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 @@ -532,12 +532,7 @@ cubes: const res = await dbRunner.testQuery(query.buildSqlAndParams()); console.log(JSON.stringify(res)); - [ - { - 'active_users.user_id': 1, - 'base_user_joins.second_prop': 2 - } - ]; + expect(res).toEqual( [{ active_users__user_id: 1,