Skip to content

Commit

Permalink
fix: SQL push down expressions incorrectly cache used cube names
Browse files Browse the repository at this point in the history
  • Loading branch information
paveltiunov committed Sep 28, 2023
1 parent 1d1d4f0 commit c5f0b03
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/cubejs-schema-compiler/src/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ class BaseQuery {
R.map(s => (
(cache || this.compilerCache).cache(
['collectFrom', methodName].concat(
s.path() ? [s.path().join('.')] : [s.cube().name, s.expressionName || s.definition().sql]
s.path() ? [s.path().join('.')] : [s.cube().name, s.expression?.toString() || s.expressionName || s.definition().sql]
),
() => fn(() => this.traverseSymbol(s))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1969,4 +1969,34 @@ describe('SQL Generation', () => {
});
});
});

it('expression cube name cache', async () => {
await runQueryTest(
{
dimensions: [{
// eslint-disable-next-line no-new-func,no-template-curly-in-string
expression: new Function('visitors', 'return `CASE WHEN ${visitors.id} > 10 THEN 10 ELSE 0 END`'),
expressionName: 'visitors.id_case',
// eslint-disable-next-line no-template-curly-in-string
definition: 'CASE WHEN ${visitors.id} > 10 THEN 10 ELSE 0 END',
cubeName: 'visitors'
}],
},
[{ visitors__id_case: 0 }]
);

await runQueryTest(
{
dimensions: [{
// eslint-disable-next-line no-new-func,no-template-curly-in-string
expression: new Function('visitor_checkins', 'return `CASE WHEN ${visitor_checkins.id} > 10 THEN 10 ELSE 0 END`'),
expressionName: 'visitors.id_case',
// eslint-disable-next-line no-template-curly-in-string
definition: 'CASE WHEN ${visitor_checkins.id} > 10 THEN 10 ELSE 0 END',
cubeName: 'visitors'
}],
},
[{ visitors__id_case: 0 }]
);
});
});

0 comments on commit c5f0b03

Please sign in to comment.