Skip to content

Commit 8c37a40

Browse files
authored
fix: Ungrouped filtered count should contain CASE WHEN statement bu… (#7853)
* fix: Ungrouped filtered count should contain `CASE WHEN` statement but renders as `1` * Return always ones for count and fix tests
1 parent fa2a89b commit 8c37a40

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2005,7 +2005,7 @@ export class BaseQuery {
20052005
}
20062006
if (this.ungrouped) {
20072007
if (symbol.type === 'count' || symbol.type === 'countDistinct' || symbol.type === 'countDistinctApprox') {
2008-
return '1';
2008+
return evaluateSql === '*' ? '1' : this.caseWhenStatement([{ sql: `(${evaluateSql}) IS NOT NULL`, label: `1` }]);
20092009
} else {
20102010
return evaluateSql;
20112011
}

packages/cubejs-schema-compiler/test/integration/postgres/pre-aggregations.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,6 @@ describe('PreAggregations', () => {
20252025

20262026
expect(partitionInvalidateKeyQueries).toStrictEqual([]);
20272027
expect(loadSql[0]).not.toMatch(/GROUP BY/);
2028-
expect(loadSql[0]).toMatch(/1 `real_time_lambda_visitors__count`/);
2028+
expect(loadSql[0]).toMatch(/THEN 1 END `real_time_lambda_visitors__count`/);
20292029
}));
20302030
});

packages/cubejs-schema-compiler/test/integration/postgres/sql-generation.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,30 @@ describe('SQL Generation', () => {
14351435
}],
14361436
}, [{ reference_visitors__google_sourced_count: '1' }]));
14371437

1438+
it('ungrouped filtered count', () => runQueryTest({
1439+
measures: [
1440+
'visitor_checkins.google_sourced_checkins',
1441+
],
1442+
timezone: 'America/Los_Angeles',
1443+
order: [{
1444+
id: 'visitor_checkins.created_at',
1445+
}],
1446+
timeDimensions: [{
1447+
dimension: 'visitor_checkins.created_at',
1448+
granularity: 'day',
1449+
dateRange: ['2016-12-01', '2017-03-30'],
1450+
}],
1451+
ungrouped: true,
1452+
allowUngroupedWithoutPrimaryKey: true,
1453+
}, [
1454+
{ visitor_checkins__created_at_day: '2017-01-02T00:00:00.000Z', visitor_checkins__google_sourced_checkins: null },
1455+
{ visitor_checkins__created_at_day: '2017-01-03T00:00:00.000Z', visitor_checkins__google_sourced_checkins: null },
1456+
{ visitor_checkins__created_at_day: '2017-01-04T00:00:00.000Z', visitor_checkins__google_sourced_checkins: null },
1457+
{ visitor_checkins__created_at_day: '2017-01-04T00:00:00.000Z', visitor_checkins__google_sourced_checkins: null },
1458+
{ visitor_checkins__created_at_day: '2017-01-04T00:00:00.000Z', visitor_checkins__google_sourced_checkins: null },
1459+
{ visitor_checkins__created_at_day: '2017-01-05T00:00:00.000Z', visitor_checkins__google_sourced_checkins: 1 },
1460+
]));
1461+
14381462
it('builds geo dimension', () => runQueryTest({
14391463
dimensions: [
14401464
'visitors.location'

0 commit comments

Comments
 (0)