Skip to content

Commit

Permalink
fix(schema-compiler): Handle member expressions in keyDimensions
Browse files Browse the repository at this point in the history
If dimension is member expression, `d.dimension` would be object, and key would be '[object Object]' string, so separate dimensions would have same key, and all but one will be eliminated
  • Loading branch information
mcheshkov committed Jan 9, 2025
1 parent ee826e1 commit d2e4a27
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
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

0 comments on commit d2e4a27

Please sign in to comment.