Skip to content

Commit 4d2fa3f

Browse files
committed
test: Add COALESCE + IS NOT NULL join pushdown smoke test
1 parent 3f7c5d9 commit 4d2fa3f

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

packages/cubejs-testing/test/__snapshots__/smoke-cubesql.test.ts.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ Array [
7070
]
7171
`;
7272

73+
exports[`SQL API Postgres (Data) join with grouped query on coalesce: join grouped on coalesce 1`] = `
74+
Array [
75+
Object {
76+
"count": "2",
77+
"status": "processed",
78+
},
79+
Object {
80+
"count": "1",
81+
"status": "shipped",
82+
},
83+
]
84+
`;
85+
7386
exports[`SQL API Postgres (Data) join with grouped query: join grouped 1`] = `
7487
Array [
7588
Object {

packages/cubejs-testing/test/smoke-cubesql.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,36 @@ filter_subq AS (
535535
expect(res.rows).toMatchSnapshot('join grouped with filter');
536536
});
537537

538+
test('join with grouped query on coalesce', async () => {
539+
const query = `
540+
SELECT
541+
"Orders".status AS status,
542+
COUNT(*) AS count
543+
FROM
544+
"Orders"
545+
INNER JOIN
546+
(
547+
SELECT
548+
status,
549+
SUM(totalAmount)
550+
FROM
551+
"Orders"
552+
GROUP BY 1
553+
ORDER BY 2 DESC
554+
LIMIT 2
555+
) top_orders
556+
ON
557+
(COALESCE("Orders".status, '') = COALESCE(top_orders.status, '')) AND
558+
(("Orders".status IS NOT NULL) = (top_orders.status IS NOT NULL))
559+
GROUP BY 1
560+
ORDER BY 1
561+
`;
562+
563+
const res = await connection.query(query);
564+
// Expect only top statuses 2 by total amount: processed and shipped
565+
expect(res.rows).toMatchSnapshot('join grouped on coalesce');
566+
});
567+
538568
test('where segment is false', async () => {
539569
const query =
540570
'SELECT value AS val, * FROM "SegmentTest" WHERE segment_eq_1 IS FALSE ORDER BY value;';

0 commit comments

Comments
 (0)