Skip to content

Commit

Permalink
test: Add smoke tests for literals in grouped CubeScan
Browse files Browse the repository at this point in the history
  • Loading branch information
mcheshkov committed Dec 13, 2024
1 parent 76eec8b commit 9ce4579
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
67 changes: 67 additions & 0 deletions packages/cubejs-testing/test/smoke-cubesql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;';
Expand Down

0 comments on commit 9ce4579

Please sign in to comment.