Skip to content

Commit 9fff964

Browse files
committed
fix(schema-compiler): prevent member name collection from impacting joins
1 parent bc23173 commit 9fff964

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ export class BaseQuery {
344344
this.canUseNativeSqlPlannerPreAggregation = fullAggregateMeasures.multiStageMembers.length > 0;
345345
}
346346
this.queryLevelJoinHints = this.options.joinHints ?? [];
347+
this.collectAllMemberNames(); // Ensure member names are computed so that they are not lazily added during join computation
347348
this.prebuildJoin();
348349

349350
this.cubeAliasPrefix = this.options.cubeAliasPrefix;

packages/cubejs-schema-compiler/test/unit/base-query.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,52 @@ describe('SQL Generation', () => {
999999
/* expect(queryAndParams[0]).toContain('LEFT JOIN card2_tbl AS "cards_b" ON "cards_a".other_id = "cards_b".id');
10001000
expect(queryAndParams[0]).toContain('LEFT JOIN card3_tbl AS "cards_c" ON "cards_b".other_id = "cards_c".id'); */
10011001
});
1002+
1003+
it('Base joins - join hint cache', async () => {
1004+
// Create a schema with a segment that uses FILTER_PARAMS
1005+
const filterParamsCompilers = /** @type Compilers */ prepareJsCompiler([
1006+
createCubeSchema({
1007+
name: 'cardsA',
1008+
sqlTable: 'card_tbl',
1009+
joins: `{
1010+
cardsB: {
1011+
sql: \`\${CUBE}.other_id = \${cardsB}.id\`,
1012+
relationship: 'one_to_one'
1013+
},
1014+
}`
1015+
}).replace(`sql: \`\${CUBE}.location = 'San Francisco'\``, `sql: \`\${FILTER_PARAMS.cardsA.location.filter('location')}\``),
1016+
createCubeSchema({
1017+
name: 'cardsB',
1018+
sqlTable: 'card2_tbl',
1019+
}),
1020+
]);
1021+
await compilers.compiler.compile();
1022+
1023+
// First query requires a join
1024+
const queryWithJoin = new PostgresQuery(filterParamsCompilers, {
1025+
dimensions: [
1026+
'cardsA.id',
1027+
'cardsB.id',
1028+
],
1029+
segments: [
1030+
'cardsA.sfUsers',
1031+
],
1032+
});
1033+
const queryAndParamsWithJoin = queryWithJoin.buildSqlAndParams();
1034+
expect(queryAndParamsWithJoin[0]).toContain('LEFT JOIN card2_tbl AS "cards_b" ON "cards_a".other_id = "cards_b".id');
1035+
1036+
// Second query does not require a join and should not be impacted by the first query
1037+
const queryWithoutJoin = new PostgresQuery(filterParamsCompilers, {
1038+
dimensions: [
1039+
'cardsA.id',
1040+
],
1041+
segments: [
1042+
'cardsA.sfUsers',
1043+
],
1044+
});
1045+
const queryAndParamsWithoutJoin = queryWithoutJoin.buildSqlAndParams();
1046+
expect(queryAndParamsWithoutJoin[0]).not.toContain('JOIN');
1047+
});
10021048
});
10031049
describe('Common - JS', () => {
10041050
const compilers = /** @type Compilers */ prepareJsCompiler(

0 commit comments

Comments
 (0)