Skip to content

Commit 26820f6

Browse files
committed
test: Add smoke tests for grouped joins
1 parent aadde65 commit 26820f6

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,32 @@ Array [
5757
]
5858
`;
5959

60+
exports[`SQL API Postgres (Data) join with filtered grouped query: join grouped with filter 1`] = `
61+
Array [
62+
Object {
63+
"count": "2",
64+
"status": "processed",
65+
},
66+
Object {
67+
"count": "2",
68+
"status": "new",
69+
},
70+
]
71+
`;
72+
73+
exports[`SQL API Postgres (Data) join with grouped query: join grouped 1`] = `
74+
Array [
75+
Object {
76+
"count": "2",
77+
"status": "processed",
78+
},
79+
Object {
80+
"count": "1",
81+
"status": "shipped",
82+
},
83+
]
84+
`;
85+
6086
exports[`SQL API Postgres (Data) metabase max number: metabase max number 1`] = `
6187
Array [
6288
Object {

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,64 @@ describe('SQL API', () => {
404404
expect(res.rows).toEqual([{ max: null }]);
405405
});
406406

407+
test('join with grouped query', async () => {
408+
const query = `
409+
SELECT
410+
"Orders".status AS status,
411+
COUNT(*) AS count
412+
FROM
413+
"Orders"
414+
INNER JOIN
415+
(
416+
SELECT
417+
status,
418+
SUM(totalAmount)
419+
FROM
420+
"Orders"
421+
GROUP BY 1
422+
ORDER BY 2 DESC
423+
LIMIT 2
424+
) top_orders
425+
ON
426+
"Orders".status = top_orders.status
427+
GROUP BY 1
428+
`;
429+
430+
const res = await connection.query(query);
431+
// Expect only top statuses 2 by total amount: processed and shipped
432+
expect(res.rows).toMatchSnapshot('join grouped');
433+
});
434+
435+
test('join with filtered grouped query', async () => {
436+
const query = `
437+
SELECT
438+
"Orders".status AS status,
439+
COUNT(*) AS count
440+
FROM
441+
"Orders"
442+
INNER JOIN
443+
(
444+
SELECT
445+
status,
446+
SUM(totalAmount)
447+
FROM
448+
"Orders"
449+
WHERE
450+
status NOT IN ('shipped')
451+
GROUP BY 1
452+
ORDER BY 2 DESC
453+
LIMIT 2
454+
) top_orders
455+
ON
456+
"Orders".status = top_orders.status
457+
GROUP BY 1
458+
`;
459+
460+
const res = await connection.query(query);
461+
// Expect only top statuses 2 by total amount, with shipped filtered out: processed and new
462+
expect(res.rows).toMatchSnapshot('join grouped with filter');
463+
});
464+
407465
test('where segment is false', async () => {
408466
const query =
409467
'SELECT value AS val, * FROM "SegmentTest" WHERE segment_eq_1 IS FALSE ORDER BY value;';

0 commit comments

Comments
 (0)