diff --git a/packages/cubejs-testing-drivers/fixtures/athena.json b/packages/cubejs-testing-drivers/fixtures/athena.json index db56c019feaed..a453044d8b32d 100644 --- a/packages/cubejs-testing-drivers/fixtures/athena.json +++ b/packages/cubejs-testing-drivers/fixtures/athena.json @@ -155,6 +155,8 @@ "SQL API: Nested Rollup", "SQL API: Rollup with aliases", "SQL API: Rollup over exprs", - "SQL API: Nested Rollup with aliases" + "SQL API: Nested Rollup with aliases", + "SQL API: Nested Rollup over asterisk", + "SQL API: Extended nested Rollup over asterisk" ] } diff --git a/packages/cubejs-testing-drivers/fixtures/bigquery.json b/packages/cubejs-testing-drivers/fixtures/bigquery.json index c5acb3f381154..b9bdad4afa400 100644 --- a/packages/cubejs-testing-drivers/fixtures/bigquery.json +++ b/packages/cubejs-testing-drivers/fixtures/bigquery.json @@ -160,6 +160,8 @@ "---------------------------------------", "SQL API: reuse params", "SQL API: Complex Rollup", - "SQL API: Rollup with aliases" + "SQL API: Rollup with aliases", + "SQL API: Nested Rollup over asterisk", + "SQL API: Extended nested Rollup over asterisk" ] } diff --git a/packages/cubejs-testing-drivers/fixtures/databricks-jdbc.json b/packages/cubejs-testing-drivers/fixtures/databricks-jdbc.json index 0247dffbeae83..f4fcfbd47746e 100644 --- a/packages/cubejs-testing-drivers/fixtures/databricks-jdbc.json +++ b/packages/cubejs-testing-drivers/fixtures/databricks-jdbc.json @@ -161,6 +161,8 @@ "SKIPPED SQL API (Need work)", "---------------------------------------", "SQL API: Nested Rollup", - "SQL API: Nested Rollup with aliases" + "SQL API: Nested Rollup with aliases", + "SQL API: Nested Rollup over asteriks", + "SQL API: Extended nested Rollup over asterisk" ] } diff --git a/packages/cubejs-testing-drivers/fixtures/mssql.json b/packages/cubejs-testing-drivers/fixtures/mssql.json index 523964fd3409a..acf415f5d2775 100644 --- a/packages/cubejs-testing-drivers/fixtures/mssql.json +++ b/packages/cubejs-testing-drivers/fixtures/mssql.json @@ -144,6 +144,8 @@ "SQL API: Nested Rollup", "SQL API: Rollup with aliases", "SQL API: Rollup over exprs", - "SQL API: Nested Rollup with aliases" + "SQL API: Nested Rollup with aliases", + "SQL API: Nested Rollup over asterisk", + "SQL API: Extended nested Rollup over asterisk" ] } diff --git a/packages/cubejs-testing-drivers/fixtures/mysql.json b/packages/cubejs-testing-drivers/fixtures/mysql.json index 4d3a1e565ca86..7744d214b22e3 100644 --- a/packages/cubejs-testing-drivers/fixtures/mysql.json +++ b/packages/cubejs-testing-drivers/fixtures/mysql.json @@ -136,6 +136,8 @@ "SQL API: Nested Rollup", "SQL API: Rollup with aliases", "SQL API: Rollup over exprs", - "SQL API: Nested Rollup with aliases" + "SQL API: Nested Rollup with aliases", + "SQL API: Nested Rollup over asterisk", + "SQL API: Extended nested Rollup over asterisk" ] } diff --git a/packages/cubejs-testing-drivers/src/tests/testQueries.ts b/packages/cubejs-testing-drivers/src/tests/testQueries.ts index dc353a1b75587..9ba02b50ee88c 100644 --- a/packages/cubejs-testing-drivers/src/tests/testQueries.ts +++ b/packages/cubejs-testing-drivers/src/tests/testQueries.ts @@ -1771,5 +1771,39 @@ from `); expect(res.rows).toMatchSnapshot('nested_rollup_with_aliases'); }); + executePg('SQL API: Nested Rollup over asterisk', async (connection) => { + const res = await connection.query(` + select rowId as "row", orderId as "order", orderDate as "date", sum(count) + from ( + select * + from + "ECommerce" as "ECommerce" + ) a + group by + ROLLUP(1, 2, 3) + order by 1, 2, 3 + + `); + expect(res.rows).toMatchSnapshot('nested_rollup_over_asterisk'); + }); + executePg('SQL API: Extended nested Rollup over asterisk', async (connection) => { + const res = await connection.query(` + select * from ( + select * from ( + select rowId as "row", orderId as "order", sum(count) + from ( + select * + from + "ECommerce" as "ECommerce" + ) a + group by + ROLLUP(row, order) + ORDER BY "rowId" ASC NULLS FIRST, "orderId" ASC NULLS FIRST OFFSET 0 ROWS FETCH FIRST 100 ROWS ONLY + ) q1 + ) q2 limit 100 + + `); + expect(res.rows).toMatchSnapshot('extended_nested_rollup_over_asterisk'); + }); }); } diff --git a/packages/cubejs-testing-drivers/test/__snapshots__/postgres-full.test.ts.snap b/packages/cubejs-testing-drivers/test/__snapshots__/postgres-full.test.ts.snap index e726f0eab4145..7b9fc1e9d74d4 100644 --- a/packages/cubejs-testing-drivers/test/__snapshots__/postgres-full.test.ts.snap +++ b/packages/cubejs-testing-drivers/test/__snapshots__/postgres-full.test.ts.snap @@ -1797,6 +1797,1259 @@ Array [ ] `; +exports[`Queries with the @cubejs-backend/postgres-driver SQL API: Extended nested Rollup over asterisk: extended_nested_rollup_over_asterisk 1`] = ` +Array [ + Object { + "SUM(a.count)": "1", + "order": "CA-2017-145142", + "row": 523, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 523, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-107503", + "row": 849, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 849, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-118437", + "row": 1013, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 1013, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-139661", + "row": 1494, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 1494, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-133648", + "row": 1995, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 1995, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-138422", + "row": 2329, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 2329, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-140949", + "row": 2455, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 2455, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-149048", + "row": 2595, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 2595, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-112515", + "row": 2655, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 2655, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-123372", + "row": 2661, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 2661, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-134915", + "row": 2952, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 2952, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-131492", + "row": 3059, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 3059, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-131492", + "row": 3060, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 3060, + }, + Object { + "SUM(a.count)": "1", + "order": "US-2017-132297", + "row": 3083, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 3083, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-102554", + "row": 3448, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 3448, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-144568", + "row": 3717, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 3717, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-123001", + "row": 3934, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 3934, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-100811", + "row": 4012, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 4012, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-124296", + "row": 4031, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 4031, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-115546", + "row": 4161, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 4161, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-120327", + "row": 4227, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 4227, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-143567", + "row": 4882, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 4882, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-145653", + "row": 5220, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 5220, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-147333", + "row": 5277, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 5277, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-145772", + "row": 6125, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 6125, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-145660", + "row": 6205, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 6205, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-102379", + "row": 6272, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 6272, + }, + Object { + "SUM(a.count)": "1", + "order": "US-2017-133361", + "row": 6459, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 6459, + }, + Object { + "SUM(a.count)": "1", + "order": "US-2017-124779", + "row": 6651, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 6651, + }, + Object { + "SUM(a.count)": "1", + "order": "US-2017-141677", + "row": 7174, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 7174, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-109183", + "row": 7293, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 7293, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-112172", + "row": 7310, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 7310, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-135069", + "row": 7425, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 7425, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-151799", + "row": 7698, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 7698, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-150091", + "row": 8425, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 8425, + }, + Object { + "SUM(a.count)": "1", + "order": "US-2017-119319", + "row": 8621, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 8621, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-163265", + "row": 8673, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 8673, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-119284", + "row": 8697, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 8697, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-126928", + "row": 8878, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 8878, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-105620", + "row": 8958, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 8958, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-102925", + "row": 9473, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 9473, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-116127", + "row": 9584, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 9584, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-160633", + "row": 9618, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 9618, + }, + Object { + "SUM(a.count)": "1", + "order": "CA-2017-160633", + "row": 9619, + }, + Object { + "SUM(a.count)": "1", + "order": null, + "row": 9619, + }, + Object { + "SUM(a.count)": "44", + "order": null, + "row": null, + }, +] +`; + +exports[`Queries with the @cubejs-backend/postgres-driver SQL API: Nested Rollup over asterisk: nested_rollup_over_asterisk 1`] = ` +Array [ + Object { + "SUM(a.count)": "1", + "date": 2020-01-23T00:00:00.000Z, + "order": "CA-2017-145142", + "row": 523, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-145142", + "row": 523, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 523, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-01-01T00:00:00.000Z, + "order": "CA-2017-107503", + "row": 849, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-107503", + "row": 849, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 849, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-06-17T00:00:00.000Z, + "order": "CA-2017-118437", + "row": 1013, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-118437", + "row": 1013, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 1013, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-10-30T00:00:00.000Z, + "order": "CA-2017-139661", + "row": 1494, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-139661", + "row": 1494, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 1494, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-06-25T00:00:00.000Z, + "order": "CA-2017-133648", + "row": 1995, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-133648", + "row": 1995, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 1995, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-09-23T00:00:00.000Z, + "order": "CA-2017-138422", + "row": 2329, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-138422", + "row": 2329, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 2329, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-03-17T00:00:00.000Z, + "order": "CA-2017-140949", + "row": 2455, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-140949", + "row": 2455, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 2455, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-05-13T00:00:00.000Z, + "order": "CA-2017-149048", + "row": 2595, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-149048", + "row": 2595, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 2595, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-09-17T00:00:00.000Z, + "order": "CA-2017-112515", + "row": 2655, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-112515", + "row": 2655, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 2655, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-11-28T00:00:00.000Z, + "order": "CA-2017-123372", + "row": 2661, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-123372", + "row": 2661, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 2661, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-11-12T00:00:00.000Z, + "order": "CA-2017-134915", + "row": 2952, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-134915", + "row": 2952, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 2952, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-10-19T00:00:00.000Z, + "order": "CA-2017-131492", + "row": 3059, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-131492", + "row": 3059, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 3059, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-10-19T00:00:00.000Z, + "order": "CA-2017-131492", + "row": 3060, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-131492", + "row": 3060, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 3060, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-05-27T00:00:00.000Z, + "order": "US-2017-132297", + "row": 3083, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "US-2017-132297", + "row": 3083, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 3083, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-06-11T00:00:00.000Z, + "order": "CA-2017-102554", + "row": 3448, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-102554", + "row": 3448, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 3448, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-05-29T00:00:00.000Z, + "order": "CA-2017-144568", + "row": 3717, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-144568", + "row": 3717, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 3717, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-09-02T00:00:00.000Z, + "order": "CA-2017-123001", + "row": 3934, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-123001", + "row": 3934, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 3934, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-11-21T00:00:00.000Z, + "order": "CA-2017-100811", + "row": 4012, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-100811", + "row": 4012, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 4012, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-12-24T00:00:00.000Z, + "order": "CA-2017-124296", + "row": 4031, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-124296", + "row": 4031, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 4031, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-05-14T00:00:00.000Z, + "order": "CA-2017-115546", + "row": 4161, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-115546", + "row": 4161, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 4161, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-11-11T00:00:00.000Z, + "order": "CA-2017-120327", + "row": 4227, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-120327", + "row": 4227, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 4227, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-11-02T00:00:00.000Z, + "order": "CA-2017-143567", + "row": 4882, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-143567", + "row": 4882, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 4882, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-09-01T00:00:00.000Z, + "order": "CA-2017-145653", + "row": 5220, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-145653", + "row": 5220, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 5220, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-12-14T00:00:00.000Z, + "order": "CA-2017-147333", + "row": 5277, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-147333", + "row": 5277, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 5277, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-06-03T00:00:00.000Z, + "order": "CA-2017-145772", + "row": 6125, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-145772", + "row": 6125, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 6125, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-12-01T00:00:00.000Z, + "order": "CA-2017-145660", + "row": 6205, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-145660", + "row": 6205, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 6205, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-12-02T00:00:00.000Z, + "order": "CA-2017-102379", + "row": 6272, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-102379", + "row": 6272, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 6272, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-05-14T00:00:00.000Z, + "order": "US-2017-133361", + "row": 6459, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "US-2017-133361", + "row": 6459, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 6459, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-09-08T00:00:00.000Z, + "order": "US-2017-124779", + "row": 6651, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "US-2017-124779", + "row": 6651, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 6651, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-03-26T00:00:00.000Z, + "order": "US-2017-141677", + "row": 7174, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "US-2017-141677", + "row": 7174, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 7174, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-12-04T00:00:00.000Z, + "order": "CA-2017-109183", + "row": 7293, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-109183", + "row": 7293, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 7293, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-06-10T00:00:00.000Z, + "order": "CA-2017-112172", + "row": 7310, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-112172", + "row": 7310, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 7310, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-04-10T00:00:00.000Z, + "order": "CA-2017-135069", + "row": 7425, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-135069", + "row": 7425, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 7425, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-12-14T00:00:00.000Z, + "order": "CA-2017-151799", + "row": 7698, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-151799", + "row": 7698, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 7698, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-10-12T00:00:00.000Z, + "order": "CA-2017-150091", + "row": 8425, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-150091", + "row": 8425, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 8425, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-11-06T00:00:00.000Z, + "order": "US-2017-119319", + "row": 8621, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "US-2017-119319", + "row": 8621, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 8621, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-02-16T00:00:00.000Z, + "order": "CA-2017-163265", + "row": 8673, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-163265", + "row": 8673, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 8673, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-06-15T00:00:00.000Z, + "order": "CA-2017-119284", + "row": 8697, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-119284", + "row": 8697, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 8697, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-09-17T00:00:00.000Z, + "order": "CA-2017-126928", + "row": 8878, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-126928", + "row": 8878, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 8878, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-12-25T00:00:00.000Z, + "order": "CA-2017-105620", + "row": 8958, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-105620", + "row": 8958, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 8958, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-11-05T00:00:00.000Z, + "order": "CA-2017-102925", + "row": 9473, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-102925", + "row": 9473, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 9473, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-06-25T00:00:00.000Z, + "order": "CA-2017-116127", + "row": 9584, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-116127", + "row": 9584, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 9584, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-11-16T00:00:00.000Z, + "order": "CA-2017-160633", + "row": 9618, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-160633", + "row": 9618, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 9618, + }, + Object { + "SUM(a.count)": "1", + "date": 2020-11-16T00:00:00.000Z, + "order": "CA-2017-160633", + "row": 9619, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": "CA-2017-160633", + "row": 9619, + }, + Object { + "SUM(a.count)": "1", + "date": null, + "order": null, + "row": 9619, + }, + Object { + "SUM(a.count)": "44", + "date": null, + "order": null, + "row": null, + }, +] +`; + exports[`Queries with the @cubejs-backend/postgres-driver SQL API: Nested Rollup with aliases: nested_rollup_with_aliases 1`] = ` Array [ Object { diff --git a/rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs b/rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs index 275f67a168cb9..37ed5d10ebf67 100644 --- a/rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs +++ b/rust/cubesql/cubesql/src/compile/engine/df/wrapper.rs @@ -627,10 +627,11 @@ impl CubeScanWrapperNode { subqueries_sql.clone(), ) .await?; + let flat_group_expr = extract_exprlist_from_groupping_set(&group_expr); let (group_by, sql) = Self::generate_column_expr( plan.clone(), schema.clone(), - extract_exprlist_from_groupping_set(&group_expr), + flat_group_expr.clone(), sql, generator.clone(), &column_remapping, @@ -779,7 +780,7 @@ impl CubeScanWrapperNode { projection[i].clone() }) }).or_else(|| { - group_expr + flat_group_expr .iter() .find_position(|e| { expr_name(e, &schema).map(|n| &n == &col_name).unwrap_or(false) @@ -791,7 +792,7 @@ impl CubeScanWrapperNode { col_name, projection_expr, aggr_expr, - group_expr + flat_group_expr )) })?; Ok(vec![ diff --git a/rust/cubesql/cubesql/src/compile/mod.rs b/rust/cubesql/cubesql/src/compile/mod.rs index dcd67f564d269..bc9a33437bac9 100644 --- a/rust/cubesql/cubesql/src/compile/mod.rs +++ b/rust/cubesql/cubesql/src/compile/mod.rs @@ -20149,6 +20149,31 @@ ORDER BY "source"."str0" ASC let _physical_plan = query_plan.as_physical_plan().await.unwrap(); } + #[tokio::test] + async fn test_wrapper_group_by_rollup_nested_from_asterisk() { + if !Rewriter::sql_push_down_enabled() { + return; + } + init_logger(); + + let query_plan = convert_select_to_query_plan( + "SELECT customer_gender, notes, avg(avgPrice) from (SELECT * FROM KibanaSampleDataEcommerce) b GROUP BY ROLLUP(1, 2) ORDER BY 1" + .to_string(), + DatabaseProtocol::PostgreSQL, + ) + .await; + + let logical_plan = query_plan.as_logical_plan(); + let sql = logical_plan + .find_cube_scan_wrapper() + .wrapped_sql + .unwrap() + .sql; + assert!(sql.contains("Rollup")); + + let _physical_plan = query_plan.as_physical_plan().await.unwrap(); + } + #[tokio::test] async fn test_wrapper_group_by_rollup_nested_with_aliases() { if !Rewriter::sql_push_down_enabled() {