diff --git a/packages/cubejs-testing/test/__snapshots__/smoke-cubesql.test.ts.snap b/packages/cubejs-testing/test/__snapshots__/smoke-cubesql.test.ts.snap index f027d7904b85a..fe01e2340efa8 100644 --- a/packages/cubejs-testing/test/__snapshots__/smoke-cubesql.test.ts.snap +++ b/packages/cubejs-testing/test/__snapshots__/smoke-cubesql.test.ts.snap @@ -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 { diff --git a/packages/cubejs-testing/test/smoke-cubesql.test.ts b/packages/cubejs-testing/test/smoke-cubesql.test.ts index ab816da2ecf28..0d1595956bdf0 100644 --- a/packages/cubejs-testing/test/smoke-cubesql.test.ts +++ b/packages/cubejs-testing/test/smoke-cubesql.test.ts @@ -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;';