From 1846a140af0377391b2ea2d6b89c4e4a61859bc3 Mon Sep 17 00:00:00 2001 From: Dehowe Feng <8065116+dehowef@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:06:52 -0700 Subject: [PATCH] Refactor Regression Tests for CASE statement (#1268) Added some new cases to CASE statement regression tests to capture cases that were not tested for before. Refactored existing test cases to improve readability --- regress/expected/expr.out | 72 +++++++++++++++++++++++++++++++-------- regress/sql/expr.sql | 43 +++++++++++++++++++---- 2 files changed, 94 insertions(+), 21 deletions(-) diff --git a/regress/expected/expr.out b/regress/expected/expr.out index 63d7a4826..d85b51de7 100644 --- a/regress/expected/expr.out +++ b/regress/expected/expr.out @@ -6352,32 +6352,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) @@ -6462,6 +6452,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 @@ -7281,9 +7322,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 ------------ diff --git a/regress/sql/expr.sql b/regress/sql/expr.sql index 326b22e5e..26acc1b38 100644 --- a/regress/sql/expr.sql +++ b/regress/sql/expr.sql @@ -2637,12 +2637,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 @@ -2688,6 +2686,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);