Skip to content
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
17 changes: 16 additions & 1 deletion packages/cubejs-schema-compiler/src/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,22 @@ export class BaseQuery {
const memberDef = member.definition();
// TODO can addGroupBy replaced by something else?
if (memberDef.addGroupByReferences) {
queryContext = { ...queryContext, dimensions: R.uniq(queryContext.dimensions.concat(memberDef.addGroupByReferences)) };
const dims = memberDef.addGroupByReferences.reduce((acc, cur) => {
const pathArr = cur.split('.');
// addGroupBy may include time dimension with granularity
// But we don't need it as time dimension
if (pathArr.length > 2) {
pathArr.splice(2, 0, 'granularities');
acc.push(pathArr.join('.'));
} else {
acc.push(cur);
}
return acc;
}, []);
queryContext = {
...queryContext,
dimensions: R.uniq(queryContext.dimensions.concat(dims)),
};
}
if (memberDef.timeShiftReferences?.length) {
let { commonTimeShift } = queryContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ export class CubeSymbols {
return cubeEvaluator.pathFromArray(fullPath(cubeEvaluator.joinHints(), [referencedCube, name]));
}, {
// eslint-disable-next-line no-shadow
sqlResolveFn: (symbol, currentCube, n) => cubeEvaluator.pathFromArray(fullPath(cubeEvaluator.joinHints(), [currentCube, n])),
sqlResolveFn: (symbol, currentCube, refProperty, propertyName) => cubeEvaluator.pathFromArray(fullPath(cubeEvaluator.joinHints(), [currentCube, refProperty, ...(propertyName ? [propertyName] : [])])),
// eslint-disable-next-line no-shadow
cubeAliasFn: (currentCube) => cubeEvaluator.pathFromArray(fullPath(cubeEvaluator.joinHints(), [currentCube])),
collectJoinHints: options.collectJoinHints,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ describe('SQL Generation', () => {
type: 'sum',
add_group_by: [visitors.created_at],
},
revenue_sum_group_by_granularity: {
multi_stage: true,
sql: \`\${revenue}\`,
type: 'number',
add_group_by: [visitors.created_at.month],
},
revenue_rank: {
multi_stage: true,
type: \`rank\`,
Expand Down Expand Up @@ -3458,6 +3464,33 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
}]
));

it('multi stage revenue_sum_group_by_granularity and group by td with granularity', async () => runQueryTest(
{
measures: ['visitors.revenue_sum_group_by_granularity'],
dimensions: ['visitors.source'],
order: [{
id: 'visitors.source'
}],
timezone: 'UTC',
},
[{
visitors__revenue_sum_group_by_granularity: '300',
visitors__source: 'google',
},
{
visitors__revenue_sum_group_by_granularity: '300',
visitors__source: 'some',
},
{
visitors__revenue_sum_group_by_granularity: '900',
visitors__source: null,
},
{
visitors__revenue_sum_group_by_granularity: '500',
visitors__source: null,
}]
));

it('multi stage complex graph with time dimension no granularity', async () => runQueryTest(
{
measures: ['visitors.adjusted_rank_sum', 'visitors.visitor_revenue'],
Expand Down
Loading