You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by jo...@apache.org on 2021/02/17 18:30:55 UTC

[incubator-age] branch master updated: [Bug Fix] Fix Edge typecasting issue

This is an automated email from the ASF dual-hosted git repository.

joshinnis 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 4432864  [Bug Fix] Fix Edge typecasting issue
4432864 is described below

commit 4432864df7845fd008cd03718dc011f9b2e99d4d
Author: Josh Innis <Jo...@gmail.com>
AuthorDate: Wed Feb 17 10:29:25 2021 -0800

    [Bug Fix] Fix Edge typecasting issue
    
    The edge typecasting function was not properly checking that the
    passed in map has a start and end id, that was formatted correctly.
    Fixed the checks.
    
    Fixed error messages in the edge contrustion function.
---
 regress/expected/expr.out      |  9 +++++++++
 regress/sql/expr.sql           |  7 +++++++
 src/backend/utils/adt/agtype.c | 10 +++++-----
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/regress/expected/expr.out b/regress/expected/expr.out
index 58942ee..5f4ddba 100644
--- a/regress/expected/expr.out
+++ b/regress/expected/expr.out
@@ -1042,6 +1042,15 @@ $$) AS r(result agtype);
  {"edge_0": {"id": 3, "label": "edge 0", "end_id": 1, "start_id": 0, "properties": {}}::edge}
 (1 row)
 
+--invalid edge typecast
+SELECT * FROM cypher('expr', $$
+RETURN {edge_0:{id:3, label:"edge 0", properties:{}, startid:0, end_id:1}::edge}
+$$) AS r(result agtype);
+ERROR:  edge typecast object has an invalid or missing start_id
+SELECT * FROM cypher('expr', $$
+RETURN {edge_0:{id:3, label:"edge 0", properties:{}, start_id:0, endid:1}::edge}
+$$) AS r(result agtype);
+ERROR:  edge typecast object has an invalid or missing end_id
 SELECT * FROM cypher('expr', $$
 RETURN {name:"container 1", edges:[{id:3, label:"edge 0", properties:{}, start_id:0, end_id:1}::edge, {id:4, label:"edge 1", properties:{}, start_id:1, end_id:0}::edge]}
 $$) AS r(result agtype);
diff --git a/regress/sql/expr.sql b/regress/sql/expr.sql
index 52fee04..1e845db 100644
--- a/regress/sql/expr.sql
+++ b/regress/sql/expr.sql
@@ -506,6 +506,13 @@ $$) AS r(result agtype);
 SELECT * FROM cypher('expr', $$
 RETURN {edge_0:{id:3, label:"edge 0", properties:{}, start_id:0, end_id:1}::edge}
 $$) AS r(result agtype);
+--invalid edge typecast
+SELECT * FROM cypher('expr', $$
+RETURN {edge_0:{id:3, label:"edge 0", properties:{}, startid:0, end_id:1}::edge}
+$$) AS r(result agtype);
+SELECT * FROM cypher('expr', $$
+RETURN {edge_0:{id:3, label:"edge 0", properties:{}, start_id:0, endid:1}::edge}
+$$) AS r(result agtype);
 SELECT * FROM cypher('expr', $$
 RETURN {name:"container 1", edges:[{id:3, label:"edge 0", properties:{}, start_id:0, end_id:1}::edge, {id:4, label:"edge 1", properties:{}, start_id:1, end_id:0}::edge]}
 $$) AS r(result agtype);
diff --git a/src/backend/utils/adt/agtype.c b/src/backend/utils/adt/agtype.c
index c349aae..3212608 100644
--- a/src/backend/utils/adt/agtype.c
+++ b/src/backend/utils/adt/agtype.c
@@ -1880,7 +1880,7 @@ Datum _agtype_build_edge(PG_FUNCTION_ARGS)
     if (fcinfo->argnull[0])
         ereport(ERROR,
                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                 errmsg("agtype_build_vertex() graphid cannot be NULL")));
+                 errmsg("agtype_build_edge() graphid cannot be NULL")));
 
     id = AG_GETARG_GRAPHID(0);
     add_agtype(id, false, &result, GRAPHIDOID, false);
@@ -1892,7 +1892,7 @@ Datum _agtype_build_edge(PG_FUNCTION_ARGS)
     if (fcinfo->argnull[1])
         ereport(ERROR,
                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                 errmsg("agtype_build_vertex() startid cannot be NULL")));
+                 errmsg("agtype_build_edge() startid cannot be NULL")));
 
     start_id = AG_GETARG_GRAPHID(1);
     add_agtype(start_id, false, &result, GRAPHIDOID, false);
@@ -1904,7 +1904,7 @@ Datum _agtype_build_edge(PG_FUNCTION_ARGS)
     if (fcinfo->argnull[2])
         ereport(ERROR,
                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-                 errmsg("agtype_build_vertex() endoid cannot be NULL")));
+                 errmsg("agtype_build_edge() endid cannot be NULL")));
 
     end_id = AG_GETARG_GRAPHID(2);
     add_agtype(end_id, false, &result, GRAPHIDOID, false);
@@ -3075,7 +3075,7 @@ Datum agtype_typecast_edge(PG_FUNCTION_ARGS)
     agtv_key.val.string.len = 8;
     agtv_startid = find_agtype_value_from_container(&arg_agt->root,
                                                     AGT_FOBJECT, &agtv_key);
-    if (agtv_graphid == NULL || agtv_graphid->type != AGTV_INTEGER)
+    if (agtv_startid == NULL || agtv_startid->type != AGTV_INTEGER)
         ereport(ERROR,
                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                  errmsg("edge typecast object has an invalid or missing start_id")));
@@ -3084,7 +3084,7 @@ Datum agtype_typecast_edge(PG_FUNCTION_ARGS)
     agtv_key.val.string.len = 6;
     agtv_endid = find_agtype_value_from_container(&arg_agt->root,
                                                     AGT_FOBJECT, &agtv_key);
-    if (agtv_graphid == NULL || agtv_graphid->type != AGTV_INTEGER)
+    if (agtv_endid == NULL || agtv_endid->type != AGTV_INTEGER)
         ereport(ERROR,
                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                  errmsg("edge typecast object has an invalid or missing end_id")));