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

Fix issue #975 Invalid reuse of variables in CREATE clause #977

Merged
merged 1 commit into from
Jun 9, 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
144 changes: 136 additions & 8 deletions regress/expected/cypher_create.out
Original file line number Diff line number Diff line change
Expand Up @@ -499,25 +499,25 @@ SELECT * FROM cypher('cypher_create', $$
CREATE (a {test:1})-[:e_var]->()
$$) as (a agtype);
ERROR: previously declared nodes in a create clause cannot have properties
LINE 1: SELECT * FROM cypher('cypher_create', $$
^
LINE 4: CREATE (a {test:1})-[:e_var]->()
^
-- Var 'a' cannot change labels
SELECT * FROM cypher('cypher_create', $$
MATCH (a:n_var)
WHERE a.name = 'Node A'
CREATE (a:new_label)-[:e_var]->()
$$) as (a agtype);
ERROR: previously declared variables cannot have a label
LINE 1: SELECT * FROM cypher('cypher_create', $$
^
LINE 4: CREATE (a:new_label)-[:e_var]->()
^
SELECT * FROM cypher('cypher_create', $$
MATCH (a:n_var)-[b]-()
WHERE a.name = 'Node A'
CREATE (a)-[b:e_var]->()
$$) as (a agtype);
ERROR: variable b already exists
LINE 1: SELECT * FROM cypher('cypher_create', $$
^
LINE 4: CREATE (a)-[b:e_var]->()
^
-- A valid single vertex path
SELECT * FROM cypher('cypher_create', $$
CREATE p=(a)
Expand Down Expand Up @@ -578,7 +578,7 @@ SELECT * FROM cypher('cypher_create', $$
$$) as (a agtype);
ERROR: label existing_elabel is for edges, not vertices
LINE 2: CREATE (a:existing_elabel { id: 5})
^
^
--
-- check the cypher CREATE clause inside an INSERT INTO
--
Expand Down Expand Up @@ -641,12 +641,137 @@ SELECT * FROM cypher('cypher_create', $$ MATCH (a:Part) RETURN a $$) as (a agtyp

END;
--
-- variable reuse
--
-- Valid variable reuse
SELECT * FROM cypher('cypher_create', $$
CREATE (p)-[a:new]->(p)
RETURN p,a,p
$$) as (n1 agtype, e agtype, n2 agtype);
n1 | e | n2
----------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------
{"id": 281474976710681, "label": "", "properties": {}}::vertex | {"id": 3940649673949185, "label": "new", "end_id": 281474976710681, "start_id": 281474976710681, "properties": {}}::edge | {"id": 281474976710681, "label": "", "properties": {}}::vertex
(1 row)

SELECT * FROM cypher('cypher_create', $$
CREATE (p:node)-[e:new]->(p)
RETURN p,e,p
$$) as (n1 agtype, e agtype, n2 agtype);
n1 | e | n2
---------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------
{"id": 4222124650659841, "label": "node", "properties": {}}::vertex | {"id": 3940649673949186, "label": "new", "end_id": 4222124650659841, "start_id": 4222124650659841, "properties": {}}::edge | {"id": 4222124650659841, "label": "node", "properties": {}}::vertex
(1 row)

SELECT * FROM cypher('cypher_create', $$
CREATE (p)
CREATE (p)-[a:new]->(p)
RETURN p,a,p
$$) as (n1 agtype, e agtype, n2 agtype);
n1 | e | n2
----------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------
{"id": 281474976710682, "label": "", "properties": {}}::vertex | {"id": 3940649673949187, "label": "new", "end_id": 281474976710682, "start_id": 281474976710682, "properties": {}}::edge | {"id": 281474976710682, "label": "", "properties": {}}::vertex
(1 row)

SELECT * FROM cypher('cypher_create', $$
CREATE (p:n1)
CREATE (p)-[a:new]->(p)
RETURN p,a,p
$$) as (n1 agtype, e agtype, n2 agtype);
n1 | e | n2
-------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------
{"id": 4503599627370497, "label": "n1", "properties": {}}::vertex | {"id": 3940649673949188, "label": "new", "end_id": 4503599627370497, "start_id": 4503599627370497, "properties": {}}::edge | {"id": 4503599627370497, "label": "n1", "properties": {}}::vertex
(1 row)

SELECT * FROM cypher('cypher_create', $$
MATCH (p:node)
CREATE (p)-[a:new]->(p)
RETURN p,a,p
$$) as (n1 agtype, e agtype, n2 agtype);
n1 | e | n2
---------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------
{"id": 4222124650659841, "label": "node", "properties": {}}::vertex | {"id": 3940649673949189, "label": "new", "end_id": 4222124650659841, "start_id": 4222124650659841, "properties": {}}::edge | {"id": 4222124650659841, "label": "node", "properties": {}}::vertex
(1 row)

-- Invalid variable reuse
SELECT * FROM cypher('cypher_create', $$
CREATE (p)-[a:new]->(p {n0:'n1'})
$$) as (a agtype);
ERROR: previously declared nodes in a create clause cannot have properties
LINE 2: CREATE (p)-[a:new]->(p {n0:'n1'})
^
SELECT * FROM cypher('cypher_create', $$
CREATE (p:n0)-[a:new]->(p:n1)
$$) as (a agtype);
ERROR: previously declared variables cannot have a label
LINE 2: CREATE (p:n0)-[a:new]->(p:n1)
^
SELECT * FROM cypher('cypher_create', $$
CREATE p=(p)
$$) as (a agtype);
ERROR: variable "p" already exists
LINE 2: CREATE p=(p)
^
SELECT * FROM cypher('cypher_create', $$
CREATE p=() CREATE (p)
$$) as (a agtype);
ERROR: agtype must resolve to a vertex
SELECT * FROM cypher('cypher_create', $$
CREATE p=(a)-[p:b]->(a)
$$) as (a agtype);
ERROR: variable "p" already exists
LINE 2: CREATE p=(a)-[p:b]->(a)
^
SELECT * FROM cypher('cypher_create', $$
CREATE p=(a)-[:new]->(p)
$$) as (a agtype);
ERROR: variable "p" already exists
LINE 2: CREATE p=(a)-[:new]->(p)
^
SELECT * FROM cypher('cypher_create', $$
MATCH (p) CREATE p=()
$$) as (a agtype);
ERROR: variable "p" already exists
LINE 2: MATCH (p) CREATE p=()
^
SELECT * FROM cypher('cypher_create', $$
MATCH (p) CREATE p=(p)
$$) as (a agtype);
ERROR: variable "p" already exists
LINE 2: MATCH (p) CREATE p=(p)
^
SELECT * FROM cypher('cypher_create', $$
MATCH (p) CREATE (a)-[p:b]->(a)
$$) as (a agtype);
ERROR: variable p already exists
LINE 2: MATCH (p) CREATE (a)-[p:b]->(a)
^
SELECT * FROM cypher('cypher_create', $$
CREATE (a)-[e:new]->(p)-[e]->(a)
$$) as (a agtype);
ERROR: relationships must be specify a label in CREATE.
LINE 2: CREATE (a)-[e:new]->(p)-[e]->(a)
^
SELECT * FROM cypher('cypher_create', $$
CREATE (a)-[e:new]->(p)
CREATE (p)-[e:new]->(a)
$$) as (a agtype);
ERROR: variable e already exists
LINE 3: CREATE (p)-[e:new]->(a)
^
SELECT * FROM cypher('cypher_create', $$
MATCH (a)-[e:new]->(p)
CREATE (p)-[e:new]->(a)
$$) as (a agtype);
ERROR: variable e already exists
LINE 3: CREATE (p)-[e:new]->(a)
^
--
-- Clean up
--
DROP TABLE simple_path;
DROP FUNCTION create_test;
SELECT drop_graph('cypher_create', true);
NOTICE: drop cascades to 13 other objects
NOTICE: drop cascades to 16 other objects
DETAIL: drop cascades to table cypher_create._ag_label_vertex
drop cascades to table cypher_create._ag_label_edge
drop cascades to table cypher_create.v
Expand All @@ -660,6 +785,9 @@ drop cascades to table cypher_create.existing_vlabel
drop cascades to table cypher_create.existing_elabel
drop cascades to table cypher_create.knows
drop cascades to table cypher_create."Part"
drop cascades to table cypher_create.new
drop cascades to table cypher_create.node
drop cascades to table cypher_create.n1
NOTICE: graph "cypher_create" has been dropped
drop_graph
------------
Expand Down
30 changes: 15 additions & 15 deletions regress/expected/cypher_match.out
Original file line number Diff line number Diff line change
Expand Up @@ -508,43 +508,43 @@ SELECT * FROM cypher('cypher_match', $$
$$) AS (a agtype);
ERROR: multiple labels for variable 'a' are not supported
LINE 2: MATCH (a)-[]-()-[]-(a:v1) RETURN a
^
^
SELECT * FROM cypher('cypher_match', $$
MATCH (a)-[]-(a:v2)-[]-(a) RETURN a
$$) AS (a agtype);
ERROR: multiple labels for variable 'a' are not supported
LINE 2: MATCH (a)-[]-(a:v2)-[]-(a) RETURN a
^
^
SELECT * FROM cypher('cypher_match', $$
MATCH (a)-[]-(a:v1) RETURN a
$$) AS (a agtype);
ERROR: multiple labels for variable 'a' are not supported
LINE 2: MATCH (a)-[]-(a:v1) RETURN a
^
^
SELECT * FROM cypher('cypher_match', $$
MATCH (a)-[]-(a)-[]-(a:v1) RETURN a
$$) AS (a agtype);
ERROR: multiple labels for variable 'a' are not supported
LINE 2: MATCH (a)-[]-(a)-[]-(a:v1) RETURN a
^
^
SELECT * FROM cypher('cypher_match', $$
MATCH (a)-[]-(a)-[]-(a:invalid_label) RETURN a
$$) AS (a agtype);
ERROR: multiple labels for variable 'a' are not supported
LINE 2: MATCH (a)-[]-(a)-[]-(a:invalid_label) RETURN a
^
^
SELECT * FROM cypher('cypher_match', $$
MATCH (a) MATCH (a:v1) RETURN a
$$) AS (a agtype);
ERROR: multiple labels for variable 'a' are not supported
LINE 2: MATCH (a) MATCH (a:v1) RETURN a
^
^
SELECT * FROM cypher('cypher_match', $$
MATCH (a) MATCH (a:invalid_label) RETURN a
$$) AS (a agtype);
ERROR: multiple labels for variable 'a' are not supported
LINE 2: MATCH (a) MATCH (a:invalid_label) RETURN a
^
^
SELECT * FROM cypher('cypher_match', $$
MATCH (a:v1)-[]-()-[a]-() RETURN a
$$) AS (a agtype);
Expand Down Expand Up @@ -718,8 +718,8 @@ SELECT * FROM cypher('cypher_match', $$
MATCH (r1:invalid)-[]->(r1)-[]->(r1)-[]->(r1:invalids) return r1
$$) AS (r1 agtype);
ERROR: multiple labels for variable 'r1' are not supported
LINE 2: MATCH (r1:invalid)-[]->(r1)-[]->(r1)-[]->(r1:invali...
^
LINE 2: ... MATCH (r1:invalid)-[]->(r1)-[]->(r1)-[]->(r1:invalid...
^
SELECT * FROM cypher('cypher_match', $$
MATCH (r1:invalid)-[]->(r1)-[]->(r1)-[]->(r1)-[r1]->() return r1
$$) AS (r1 agtype);
Expand All @@ -732,25 +732,25 @@ SELECT * FROM cypher('cypher_match', $$
$$) AS (r1 agtype);
ERROR: multiple labels for variable 'r1' are not supported
LINE 2: MATCH (r1:e1), (r1:e2) return r1
^
^
SELECT * FROM cypher('cypher_match', $$
MATCH (r1:invalid), (r1:e2) return r1
$$) AS (r1 agtype);
ERROR: multiple labels for variable 'r1' are not supported
LINE 2: MATCH (r1:invalid), (r1:e2) return r1
^
^
SELECT * FROM cypher('cypher_match', $$
MATCH (r1:e1), (r1:invalid) return r1
$$) AS (r1 agtype);
ERROR: multiple labels for variable 'r1' are not supported
LINE 2: MATCH (r1:e1), (r1:invalid) return r1
^
^
SELECT * FROM cypher('cypher_match', $$
MATCH (r1:e1), (r1), (r1:invalid) return r1
$$) AS (r1 agtype);
ERROR: multiple labels for variable 'r1' are not supported
LINE 2: MATCH (r1:e1), (r1), (r1:invalid) return r1
^
^
SELECT * FROM cypher('cypher_match', $$
MATCH (r0)-[r0]->() MATCH ()-[]->() RETURN r0
$$) AS (r0 agtype);
Expand All @@ -768,7 +768,7 @@ SELECT * FROM cypher('cypher_match', $$
$$) AS (r0 agtype);
ERROR: variable 'r0' is for a edge
LINE 2: MATCH ()-[r0]->() MATCH ()-[]->(r0) RETURN r0
^
^
SELECT * FROM cypher('cypher_match', $$
MATCH ()-[r0:e1]->() MATCH ()-[r0:e2]->() RETURN r0
$$) AS (r0 agtype);
Expand Down Expand Up @@ -1083,7 +1083,7 @@ SELECT * FROM cypher('cypher_match',
AS (u agtype, e agtype, v agtype);
ERROR: variable `x` does not exist
LINE 2: $$MATCH (u)-[e]->(v) WHERE EXISTS((u)-[e]->(x)) RETURN u, e...
^
^
--
-- Tests for EXISTS(property)
--
Expand Down
86 changes: 86 additions & 0 deletions regress/sql/cypher_create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,92 @@ SELECT * FROM cypher('cypher_create', $$ CREATE (a:Part {part_num: '673'}) $$) a
SELECT * FROM cypher('cypher_create', $$ MATCH (a:Part) RETURN a $$) as (a agtype);
END;

--
-- variable reuse
--

-- Valid variable reuse

SELECT * FROM cypher('cypher_create', $$
CREATE (p)-[a:new]->(p)
RETURN p,a,p
$$) as (n1 agtype, e agtype, n2 agtype);

SELECT * FROM cypher('cypher_create', $$
CREATE (p:node)-[e:new]->(p)
RETURN p,e,p
$$) as (n1 agtype, e agtype, n2 agtype);

SELECT * FROM cypher('cypher_create', $$
CREATE (p)
CREATE (p)-[a:new]->(p)
RETURN p,a,p
$$) as (n1 agtype, e agtype, n2 agtype);

SELECT * FROM cypher('cypher_create', $$
CREATE (p:n1)
CREATE (p)-[a:new]->(p)
RETURN p,a,p
$$) as (n1 agtype, e agtype, n2 agtype);

SELECT * FROM cypher('cypher_create', $$
MATCH (p:node)
CREATE (p)-[a:new]->(p)
RETURN p,a,p
$$) as (n1 agtype, e agtype, n2 agtype);

-- Invalid variable reuse

SELECT * FROM cypher('cypher_create', $$
CREATE (p)-[a:new]->(p {n0:'n1'})
$$) as (a agtype);

SELECT * FROM cypher('cypher_create', $$
CREATE (p:n0)-[a:new]->(p:n1)
$$) as (a agtype);

SELECT * FROM cypher('cypher_create', $$
CREATE p=(p)
$$) as (a agtype);

SELECT * FROM cypher('cypher_create', $$
CREATE p=() CREATE (p)
$$) as (a agtype);

SELECT * FROM cypher('cypher_create', $$
CREATE p=(a)-[p:b]->(a)
$$) as (a agtype);

SELECT * FROM cypher('cypher_create', $$
CREATE p=(a)-[:new]->(p)
$$) as (a agtype);

SELECT * FROM cypher('cypher_create', $$
MATCH (p) CREATE p=()
$$) as (a agtype);

SELECT * FROM cypher('cypher_create', $$
MATCH (p) CREATE p=(p)
$$) as (a agtype);

SELECT * FROM cypher('cypher_create', $$
MATCH (p) CREATE (a)-[p:b]->(a)
$$) as (a agtype);

SELECT * FROM cypher('cypher_create', $$
CREATE (a)-[e:new]->(p)-[e]->(a)
jrgemignani marked this conversation as resolved.
Show resolved Hide resolved
$$) as (a agtype);

SELECT * FROM cypher('cypher_create', $$
CREATE (a)-[e:new]->(p)
CREATE (p)-[e:new]->(a)
$$) as (a agtype);

SELECT * FROM cypher('cypher_create', $$
MATCH (a)-[e:new]->(p)
CREATE (p)-[e:new]->(a)
jrgemignani marked this conversation as resolved.
Show resolved Hide resolved
$$) as (a agtype);

--
-- Clean up
--
Expand Down
Loading