Skip to content

Commit

Permalink
test: Add smoke tests for grouped joins
Browse files Browse the repository at this point in the history
  • Loading branch information
mcheshkov committed Dec 18, 2024
1 parent 16fb906 commit 18417aa
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,32 @@ Array [
]
`;

exports[`SQL API Postgres (Data) join with filtered grouped query: join grouped with filter 1`] = `
Array [
Object {
"count": "2",
"status": "processed",
},
Object {
"count": "2",
"status": "new",
},
]
`;

exports[`SQL API Postgres (Data) join with grouped query: join grouped 1`] = `
Array [
Object {
"count": "2",
"status": "processed",
},
Object {
"count": "1",
"status": "shipped",
},
]
`;

exports[`SQL API Postgres (Data) metabase max number: metabase max number 1`] = `
Array [
Object {
Expand Down
59 changes: 59 additions & 0 deletions packages/cubejs-testing/test/smoke-cubesql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,65 @@ filter_subq AS (
expect(res.rows).toMatchSnapshot('select __user and literal in wrapper');
});

test('join with grouped query', async () => {
const query = `
SELECT
"Orders".status AS status,
COUNT(*) AS count
FROM
"Orders"
INNER JOIN
(
SELECT
status,
SUM(totalAmount)
FROM
"Orders"
GROUP BY 1
ORDER BY 2 DESC
LIMIT 2
) top_orders
ON
"Orders".status = top_orders.status
GROUP BY 1
ORDER BY 1
`;

const res = await connection.query(query);
// Expect only top statuses 2 by total amount: processed and shipped
expect(res.rows).toMatchSnapshot('join grouped');
});

test('join with filtered grouped query', async () => {
const query = `
SELECT
"Orders".status AS status,
COUNT(*) AS count
FROM
"Orders"
INNER JOIN
(
SELECT
status,
SUM(totalAmount)
FROM
"Orders"
WHERE
status NOT IN ('shipped')
GROUP BY 1
ORDER BY 2 DESC
LIMIT 2
) top_orders
ON
"Orders".status = top_orders.status
GROUP BY 1
`;

const res = await connection.query(query);
// Expect only top statuses 2 by total amount, with shipped filtered out: processed and new
expect(res.rows).toMatchSnapshot('join grouped with filter');
});

test('where segment is false', async () => {
const query =
'SELECT value AS val, * FROM "SegmentTest" WHERE segment_eq_1 IS FALSE ORDER BY value;';
Expand Down

0 comments on commit 18417aa

Please sign in to comment.