You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by de...@apache.org on 2021/06/16 23:56:36 UTC
[incubator-age] branch master updated: Throw error when assigning
incorrect labels
This is an automated email from the ASF dual-hosted git repository.
dehowef pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-age.git
The following commit(s) were added to refs/heads/master by this push:
new cbbd5c3 Throw error when assigning incorrect labels
cbbd5c3 is described below
commit cbbd5c3491741c8edfed5ba14dcd9ad56066305c
Author: Dehowe Feng <de...@gmail.com>
AuthorDate: Wed Jun 16 13:15:13 2021 -0700
Throw error when assigning incorrect labels
Addressed issue when database was forcibly terminated when vertex labels
were assigned to edge labels and vice versa.
Added regression tests for this case as well.
---
regress/expected/cypher_create.out | 31 ++++++++++++++++++++++++++++++-
regress/sql/cypher_create.sql | 20 ++++++++++++++++++++
src/backend/parser/cypher_clause.c | 28 ++++++++++++++++++++++++++++
3 files changed, 78 insertions(+), 1 deletion(-)
diff --git a/regress/expected/cypher_create.out b/regress/expected/cypher_create.out
index c3ff157..dcb08fb 100644
--- a/regress/expected/cypher_create.out
+++ b/regress/expected/cypher_create.out
@@ -551,12 +551,39 @@ ERROR: column definition list for CREATE clause must contain a single agtype at
LINE 1: SELECT * FROM cypher('cypher_create', $$CREATE ()$$) AS (a a...
^
HINT: ... cypher($$ ... CREATE ... $$) AS t(c agtype) ...
+-- nodes cannot use edge labels and edge labels cannot use node labels
+SELECT * FROM cypher('cypher_create', $$
+ CREATE
+ (:existing_vlabel {id: 1})
+ -[c:existing_elabel {id: 3}]->
+ (:existing_vlabel {id: 2})
+$$) as (a agtype);
+ a
+---
+(0 rows)
+
+SELECT * FROM cypher('cypher_create', $$
+ MATCH(a), (b)
+ WHERE a.id = 1 AND b.id = 2
+ CREATE (a)-[c:existing_vlabel { id: 4}]->(b)
+ RETURN c.id
+$$) as (c agtype);
+ERROR: label existing_vlabel is for vertices, not edges
+LINE 4: CREATE (a)-[c:existing_vlabel { id: 4}]->(b)
+ ^
+SELECT * FROM cypher('cypher_create', $$
+ CREATE (a:existing_elabel { id: 5})
+ RETURN a.id
+$$) as (a agtype);
+ERROR: label existing_elabel is for edges, not vertices
+LINE 2: CREATE (a:existing_elabel { id: 5})
+ ^
--
-- Clean up
--
DROP FUNCTION create_test;
SELECT drop_graph('cypher_create', true);
-NOTICE: drop cascades to 9 other objects
+NOTICE: drop cascades to 11 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
@@ -566,6 +593,8 @@ drop cascades to table cypher_create.e_var
drop cascades to table cypher_create.n_other_node
drop cascades to table cypher_create.b_var
drop cascades to table cypher_create.new_vertex
+drop cascades to table cypher_create.existing_vlabel
+drop cascades to table cypher_create.existing_elabel
NOTICE: graph "cypher_create" has been dropped
drop_graph
------------
diff --git a/regress/sql/cypher_create.sql b/regress/sql/cypher_create.sql
index 81611c0..e59e960 100644
--- a/regress/sql/cypher_create.sql
+++ b/regress/sql/cypher_create.sql
@@ -253,6 +253,26 @@ $$) as t(b agtype);
SELECT * FROM cypher('cypher_create', $$CREATE ()$$) AS (a int);
SELECT * FROM cypher('cypher_create', $$CREATE ()$$) AS (a agtype, b int);
+-- nodes cannot use edge labels and edge labels cannot use node labels
+SELECT * FROM cypher('cypher_create', $$
+ CREATE
+ (:existing_vlabel {id: 1})
+ -[c:existing_elabel {id: 3}]->
+ (:existing_vlabel {id: 2})
+$$) as (a agtype);
+
+SELECT * FROM cypher('cypher_create', $$
+ MATCH(a), (b)
+ WHERE a.id = 1 AND b.id = 2
+ CREATE (a)-[c:existing_vlabel { id: 4}]->(b)
+ RETURN c.id
+$$) as (c agtype);
+
+SELECT * FROM cypher('cypher_create', $$
+ CREATE (a:existing_elabel { id: 5})
+ RETURN a.id
+$$) as (a agtype);
+
--
-- Clean up
--
diff --git a/src/backend/parser/cypher_clause.c b/src/backend/parser/cypher_clause.c
index 8b9ebac..3032b24 100644
--- a/src/backend/parser/cypher_clause.c
+++ b/src/backend/parser/cypher_clause.c
@@ -2642,6 +2642,20 @@ transform_create_cypher_edge(cypher_parsestate *cpstate, List **target_list,
char *alias;
AttrNumber resno;
+ if (edge->label)
+ {
+ label_cache_data *lcd =
+ search_label_name_graph_cache(edge->label, cpstate->graph_oid);
+
+ if (lcd && lcd->kind != LABEL_KIND_EDGE)
+ {
+ ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("label %s is for vertices, not edges",
+ edge->label),
+ parser_errposition(pstate, edge->location)));
+ }
+ }
+
rel->type = LABEL_KIND_EDGE;
rel->flags = CYPHER_TARGET_NODE_FLAG_INSERT;
rel->label_name = edge->label;
@@ -2759,6 +2773,20 @@ transform_create_cypher_node(cypher_parsestate *cpstate, List **target_list,
{
ParseState *pstate = (ParseState *)cpstate;
+ if (node->label)
+ {
+ label_cache_data *lcd =
+ search_label_name_graph_cache(node->label, cpstate->graph_oid);
+
+ if (lcd && lcd->kind != LABEL_KIND_VERTEX)
+ {
+ ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("label %s is for edges, not vertices",
+ node->label),
+ parser_errposition(pstate, node->location)));
+ }
+ }
+
/*
* Check if the variable already exists, if so find the entity and
* setup the target node