Skip to content

Commit 9440876

Browse files
committed
test: Add smoke tests for grouped joins
1 parent f391f53 commit 9440876

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-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: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,65 @@ filter_subq AS (
476476
expect(res.rows).toMatchSnapshot('select __user and literal in wrapper');
477477
});
478478

479+
test('join with grouped query', async () => {
480+
const query = `
481+
SELECT
482+
"Orders".status AS status,
483+
COUNT(*) AS count
484+
FROM
485+
"Orders"
486+
INNER JOIN
487+
(
488+
SELECT
489+
status,
490+
SUM(totalAmount)
491+
FROM
492+
"Orders"
493+
GROUP BY 1
494+
ORDER BY 2 DESC
495+
LIMIT 2
496+
) top_orders
497+
ON
498+
"Orders".status = top_orders.status
499+
GROUP BY 1
500+
ORDER BY 1
501+
`;
502+
503+
const res = await connection.query(query);
504+
// Expect only top statuses 2 by total amount: processed and shipped
505+
expect(res.rows).toMatchSnapshot('join grouped');
506+
});
507+
508+
test('join with filtered grouped query', async () => {
509+
const query = `
510+
SELECT
511+
"Orders".status AS status,
512+
COUNT(*) AS count
513+
FROM
514+
"Orders"
515+
INNER JOIN
516+
(
517+
SELECT
518+
status,
519+
SUM(totalAmount)
520+
FROM
521+
"Orders"
522+
WHERE
523+
status NOT IN ('shipped')
524+
GROUP BY 1
525+
ORDER BY 2 DESC
526+
LIMIT 2
527+
) top_orders
528+
ON
529+
"Orders".status = top_orders.status
530+
GROUP BY 1
531+
`;
532+
533+
const res = await connection.query(query);
534+
// Expect only top statuses 2 by total amount, with shipped filtered out: processed and new
535+
expect(res.rows).toMatchSnapshot('join grouped with filter');
536+
});
537+
479538
test('where segment is false', async () => {
480539
const query =
481540
'SELECT value AS val, * FROM "SegmentTest" WHERE segment_eq_1 IS FALSE ORDER BY value;';

0 commit comments

Comments
 (0)