Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(schema-compiler): Handle member expressions in keyDimensions #9083

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/cubejs-schema-compiler/src/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -1855,7 +1855,14 @@ export class BaseQuery {
keyDimensions(primaryKeyDimensions) {
// The same dimension with different granularities maybe requested, so it's not enough to filter only by dimension
return R.uniqBy(
(d) => `${d.dimension}${d.granularity ?? ''}`, this.dimensionsForSelect()
(d) => {
if (d.isMemberExpression) {
return d.dimension.definition;
}

return `${d.dimension}${d.granularity ?? ''}`;
},
this.dimensionsForSelect()
.concat(primaryKeyDimensions)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2974,6 +2974,63 @@ describe('SQL Generation', () => {
}]
));

// Subquery aggregation for multiplied measure (and any `keysSelect` for that matter)
// should pick up all dimensions, even through member expressions
it('multiplied sum with dimension member expressions', async () => runQueryTest(
{
measures: [
'visitors_visitors_checkins_view.revenue',
'visitors_visitors_checkins_view.visitor_checkins_count',
],
dimensions: [
{
// eslint-disable-next-line no-new-func
expression: new Function(
'visitors_visitors_checkins_view',
// eslint-disable-next-line no-template-curly-in-string
'return `LOWER(${visitors_visitors_checkins_view.source})`'
),
expressionName: 'lower_source',
// eslint-disable-next-line no-template-curly-in-string
definition: 'LOWER(${visitors_visitors_checkins_view.source})',
cubeName: 'visitors_visitors_checkins_view',
},
{
// eslint-disable-next-line no-new-func
expression: new Function(
'visitors_visitors_checkins_view',
// eslint-disable-next-line no-template-curly-in-string
'return `UPPER(${visitors_visitors_checkins_view.source})`'
),
expressionName: 'upper_source',
// eslint-disable-next-line no-template-curly-in-string
definition: 'UPPER(${visitors_visitors_checkins_view.source})',
cubeName: 'visitors_visitors_checkins_view',
},
],
},
[
{
lower_source: null,
upper_source: null,
visitors_visitors_checkins_view__revenue: '1400',
visitors_visitors_checkins_view__visitor_checkins_count: '0',
},
{
lower_source: 'google',
upper_source: 'GOOGLE',
visitors_visitors_checkins_view__revenue: '300',
visitors_visitors_checkins_view__visitor_checkins_count: '1',
},
{
lower_source: 'some',
upper_source: 'SOME',
visitors_visitors_checkins_view__revenue: '300',
visitors_visitors_checkins_view__visitor_checkins_count: '5',
},
]
));

// TODO not implemented
// it('multi stage bucketing', async () => runQueryTest(
// {
Expand Down
Loading