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 ae9fc2de07c05..9c9484ffb845d 100644 --- a/packages/cubejs-testing/test/__snapshots__/smoke-cubesql.test.ts.snap +++ b/packages/cubejs-testing/test/__snapshots__/smoke-cubesql.test.ts.snap @@ -232,6 +232,71 @@ Array [ ] `; +exports[`SQL API Postgres (Data) select __user and literal grouped under wrapper: select __user and literal in wrapper 1`] = ` +Array [ + Object { + "my_literal": "1", + "my_status": "new", + "my_user": null, + }, + Object { + "my_literal": "1", + "my_status": "processed", + "my_user": null, + }, + Object { + "my_literal": "1", + "my_status": "shipped", + "my_user": null, + }, +] +`; + +exports[`SQL API Postgres (Data) select __user and literal grouped: select __user and literal 1`] = ` +Array [ + Object { + "Int64(2)": "2", + "__cubeJoinField": null, + "id": 1, + "my_literal": "1", + "my_status": "new", + "my_user": null, + }, + Object { + "Int64(2)": "2", + "__cubeJoinField": null, + "id": 2, + "my_literal": "1", + "my_status": "new", + "my_user": null, + }, + Object { + "Int64(2)": "2", + "__cubeJoinField": null, + "id": 3, + "my_literal": "1", + "my_status": "processed", + "my_user": null, + }, + Object { + "Int64(2)": "2", + "__cubeJoinField": null, + "id": 4, + "my_literal": "1", + "my_status": "processed", + "my_user": null, + }, + Object { + "Int64(2)": "2", + "__cubeJoinField": null, + "id": 5, + "my_literal": "1", + "my_status": "shipped", + "my_user": null, + }, +] +`; + exports[`SQL API Postgres (Data) select null in subquery with streaming 1`] = ` Array [ Object { diff --git a/packages/cubejs-testing/test/smoke-cubesql.test.ts b/packages/cubejs-testing/test/smoke-cubesql.test.ts index 0833ed85b40c3..a11befeffe44a 100644 --- a/packages/cubejs-testing/test/smoke-cubesql.test.ts +++ b/packages/cubejs-testing/test/smoke-cubesql.test.ts @@ -404,6 +404,73 @@ describe('SQL API', () => { expect(res.rows).toEqual([{ max: null }]); }); + test('select __user and literal grouped', async () => { + const query = ` + SELECT + status AS my_status, + __user AS my_user, + 1 AS my_literal, + -- Columns without aliases should also work + id, + __cubeJoinField, + 2 + FROM + Orders + GROUP BY 1,2,3,4,5,6 + ORDER BY 1,2,3,4,5,6 + `; + + const res = await connection.query(query); + expect(res.rows).toMatchSnapshot('select __user and literal'); + }); + + test('select __user and literal grouped under wrapper', async () => { + const query = ` + WITH +-- This subquery should be represented as CubeScan(ungrouped=false) inside CubeScanWrapper +cube_scan_subq AS ( + SELECT + status AS my_status, + __user AS my_user, + 1 AS my_literal, + -- Columns without aliases should also work + id, + __cubeJoinField, + 2 + FROM Orders + GROUP BY 1,2,3,4,5,6 +), +filter_subq AS ( + SELECT + status status_filter + FROM Orders + GROUP BY + status_filter +) + SELECT + -- Should use SELECT * here to reference columns without aliases. + -- But it's broken ATM in DF, initial plan contains \`Projection: ... #__subquery-0.logs_content_filter\` on top, but it should not be there + -- TODO fix it + my_status, + my_user, + my_literal + FROM cube_scan_subq + WHERE + -- This subquery filter should trigger wrapping of whole query + my_status IN ( + SELECT + status_filter + FROM filter_subq + ) + GROUP BY 1,2,3 + ORDER BY 1,2,3 + ; + `; + + const res = await connection.query(query); + expect(res.rows).toMatchSnapshot('select __user and literal in wrapper'); + }); + test('where segment is false', async () => { const query = 'SELECT value AS val, * FROM "SegmentTest" WHERE segment_eq_1 IS FALSE ORDER BY value;';