Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Regression Tests for CASE statement (#1268) #1319

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 57 additions & 15 deletions regress/expected/expr.out
Original file line number Diff line number Diff line change
Expand Up @@ -6236,32 +6236,22 @@ NOTICE: graph "case_statement" has been created

(1 row)

SELECT * FROM cypher('case_statement', $$CREATE ({i: 1, j: null})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 1, i: 1, j: null})-[:connected_to {id: 1, k:0}]->({id: 2, i: 'a', j: 'b'})$$) AS (result agtype);
result
--------
(0 rows)

SELECT * FROM cypher('case_statement', $$CREATE ({i: 'a', j: 'b'})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 3, i: 0, j: 1})-[:connected_to {id: 2, k:1}]->({id: 4, i: true, j: false})$$) AS (result agtype);
result
--------
(0 rows)

SELECT * FROM cypher('case_statement', $$CREATE ({i: 0, j: 1})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 5, i: [], j: [0,1,2]})$$) AS (result agtype);
result
--------
(0 rows)

SELECT * FROM cypher('case_statement', $$CREATE ({i: true, j: false})$$) AS (result agtype);
result
--------
(0 rows)

SELECT * FROM cypher('case_statement', $$CREATE ({i: [], j: [0,1,2]})$$) AS (result agtype);
result
--------
(0 rows)

SELECT * FROM cypher('case_statement', $$CREATE ({i: {}, j: {i:1}})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 6, i: {}, j: {i:1}})$$) AS (result agtype);
result
--------
(0 rows)
Expand Down Expand Up @@ -6346,6 +6336,57 @@ $$ ) AS (j agtype, case_statement agtype);
{"i": 1} | {"i": 1}
(6 rows)

--CASE agtype_vertex WHEN value THEN result END
SELECT * FROM cypher('case_statement', $$
MATCH (n)
RETURN CASE n
WHEN null THEN 'should not return me'
WHEN 'agtype_string' THEN 'wrong'
WHEN n THEN n
ELSE 'no n'
END
$$ ) AS (case_statement agtype);
case_statement
------------------------------------------------------------------------------------------------
{"id": 281474976710657, "label": "", "properties": {"i": 1, "id": 1}}::vertex
{"id": 281474976710658, "label": "", "properties": {"i": "a", "j": "b", "id": 2}}::vertex
{"id": 281474976710659, "label": "", "properties": {"i": 0, "j": 1, "id": 3}}::vertex
{"id": 281474976710660, "label": "", "properties": {"i": true, "j": false, "id": 4}}::vertex
{"id": 281474976710661, "label": "", "properties": {"i": [], "j": [0, 1, 2], "id": 5}}::vertex
{"id": 281474976710662, "label": "", "properties": {"i": {}, "j": {"i": 1}, "id": 6}}::vertex
(6 rows)

--CASE with match and edges
SELECT * FROM cypher('case_statement', $$
MATCH (n)-[e]->(m)
RETURN CASE
WHEN null THEN 'should not return me'
WHEN n.i = 1 THEN n
WHEN n.i = 0 THEN m
ELSE 'none'
END
$$ ) AS (case_statement agtype);
case_statement
----------------------------------------------------------------------------------------------
{"id": 281474976710657, "label": "", "properties": {"i": 1, "id": 1}}::vertex
{"id": 281474976710660, "label": "", "properties": {"i": true, "j": false, "id": 4}}::vertex
(2 rows)

SELECT * FROM cypher('case_statement', $$
MATCH (n)-[e]->(m)
RETURN CASE
WHEN null THEN 'should not return me'
WHEN e.k = 1 THEN e
WHEN e.k = 0 THEN e
ELSE 'none'
END
$$ ) AS (case_statement agtype);
case_statement
-------------------------------------------------------------------------------------------------------------------------------------------------
{"id": 844424930131969, "label": "connected_to", "end_id": 281474976710658, "start_id": 281474976710657, "properties": {"k": 0, "id": 1}}::edge
{"id": 844424930131970, "label": "connected_to", "end_id": 281474976710660, "start_id": 281474976710659, "properties": {"k": 1, "id": 2}}::edge
(2 rows)

-- RETURN * and (u)--(v) optional forms
SELECT create_graph('opt_forms');
NOTICE: graph "opt_forms" has been created
Expand Down Expand Up @@ -7204,9 +7245,10 @@ NOTICE: graph "VLE" has been dropped
(1 row)

SELECT * FROM drop_graph('case_statement', true);
NOTICE: drop cascades to 2 other objects
NOTICE: drop cascades to 3 other objects
DETAIL: drop cascades to table case_statement._ag_label_vertex
drop cascades to table case_statement._ag_label_edge
drop cascades to table case_statement.connected_to
NOTICE: graph "case_statement" has been dropped
drop_graph
------------
Expand Down
43 changes: 37 additions & 6 deletions regress/sql/expr.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2593,12 +2593,10 @@ $$) AS (i agtype);

--CASE
SELECT create_graph('case_statement');
SELECT * FROM cypher('case_statement', $$CREATE ({i: 1, j: null})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({i: 'a', j: 'b'})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({i: 0, j: 1})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({i: true, j: false})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({i: [], j: [0,1,2]})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({i: {}, j: {i:1}})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 1, i: 1, j: null})-[:connected_to {id: 1, k:0}]->({id: 2, i: 'a', j: 'b'})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 3, i: 0, j: 1})-[:connected_to {id: 2, k:1}]->({id: 4, i: true, j: false})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 5, i: [], j: [0,1,2]})$$) AS (result agtype);
SELECT * FROM cypher('case_statement', $$CREATE ({id: 6, i: {}, j: {i:1}})$$) AS (result agtype);

--standalone case & edge cases
--base case
Expand Down Expand Up @@ -2644,6 +2642,39 @@ SELECT * FROM cypher('case_statement', $$
END
$$ ) AS (j agtype, case_statement agtype);

--CASE agtype_vertex WHEN value THEN result END
SELECT * FROM cypher('case_statement', $$
MATCH (n)
RETURN CASE n
WHEN null THEN 'should not return me'
WHEN 'agtype_string' THEN 'wrong'
WHEN n THEN n
ELSE 'no n'
END
$$ ) AS (case_statement agtype);

--CASE with match and edges
SELECT * FROM cypher('case_statement', $$
MATCH (n)-[e]->(m)
RETURN CASE
WHEN null THEN 'should not return me'
WHEN n.i = 1 THEN n
WHEN n.i = 0 THEN m
ELSE 'none'
END
$$ ) AS (case_statement agtype);

SELECT * FROM cypher('case_statement', $$
MATCH (n)-[e]->(m)
RETURN CASE
WHEN null THEN 'should not return me'
WHEN e.k = 1 THEN e
WHEN e.k = 0 THEN e
ELSE 'none'
END
$$ ) AS (case_statement agtype);


-- RETURN * and (u)--(v) optional forms
SELECT create_graph('opt_forms');
SELECT * FROM cypher('opt_forms', $$CREATE ({i:1})-[:KNOWS]->({i:2})<-[:KNOWS]-({i:3})$$)AS (result agtype);
Expand Down