You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by jg...@apache.org on 2023/03/01 00:32:14 UTC
[age] branch master updated: Barbell regress tests (#708)
This is an automated email from the ASF dual-hosted git repository.
jgemignani pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/age.git
The following commit(s) were added to refs/heads/master by this push:
new 49ae33ad Barbell regress tests (#708)
49ae33ad is described below
commit 49ae33ade596e020202539b9e839ce439c976f81
Author: Marco Aurélio Silva de Souza Júnior <57...@users.noreply.github.com>
AuthorDate: Tue Feb 28 21:32:08 2023 -0300
Barbell regress tests (#708)
* Fixed bug where the system was crashing
when graph_name was passed as NULL.
* added checks for possible NULL arguments before
calling create_complete_graph.
* Added regress tests for Barbell graph generation
---
regress/expected/graph_generation.out | 111 ++++++++++++++++++++++++++++++++++
regress/sql/graph_generation.sql | 27 +++++++++
src/backend/utils/graph_generation.c | 57 ++++++++++-------
3 files changed, 174 insertions(+), 21 deletions(-)
diff --git a/regress/expected/graph_generation.out b/regress/expected/graph_generation.out
index 118ab6e9..b9ed65b1 100644
--- a/regress/expected/graph_generation.out
+++ b/regress/expected/graph_generation.out
@@ -109,3 +109,114 @@ NOTICE: graph "gp2" has been dropped
(1 row)
+-- Tests for barbell graph generation
+SELECT * FROM age_create_barbell_graph('gp1',5,0,'vertices',NULL,'edges',NULL);
+NOTICE: graph "gp1" has been created
+NOTICE: VLabel "vertices" has been created
+NOTICE: ELabel "edges" has been created
+ age_create_barbell_graph
+--------------------------
+
+(1 row)
+
+SELECT COUNT(*) FROM gp1."edges";
+ count
+-------
+ 21
+(1 row)
+
+SELECT COUNT(*) FROM gp1."vertices";
+ count
+-------
+ 10
+(1 row)
+
+SELECT * FROM cypher('gp1', $$MATCH (a)-[e]->(b) RETURN e$$) as (n agtype);
+ n
+----------------------------------------------------------------------------------------------------------------------------
+ {"id": 1125899906842625, "label": "edges", "end_id": 844424930131970, "start_id": 844424930131969, "properties": {}}::edge
+ {"id": 1125899906842629, "label": "edges", "end_id": 844424930131971, "start_id": 844424930131970, "properties": {}}::edge
+ {"id": 1125899906842626, "label": "edges", "end_id": 844424930131971, "start_id": 844424930131969, "properties": {}}::edge
+ {"id": 1125899906842627, "label": "edges", "end_id": 844424930131972, "start_id": 844424930131969, "properties": {}}::edge
+ {"id": 1125899906842632, "label": "edges", "end_id": 844424930131972, "start_id": 844424930131971, "properties": {}}::edge
+ {"id": 1125899906842630, "label": "edges", "end_id": 844424930131972, "start_id": 844424930131970, "properties": {}}::edge
+ {"id": 1125899906842634, "label": "edges", "end_id": 844424930131973, "start_id": 844424930131972, "properties": {}}::edge
+ {"id": 1125899906842628, "label": "edges", "end_id": 844424930131973, "start_id": 844424930131969, "properties": {}}::edge
+ {"id": 1125899906842631, "label": "edges", "end_id": 844424930131973, "start_id": 844424930131970, "properties": {}}::edge
+ {"id": 1125899906842633, "label": "edges", "end_id": 844424930131973, "start_id": 844424930131971, "properties": {}}::edge
+ {"id": 1125899906842635, "label": "edges", "end_id": 844424930131975, "start_id": 844424930131974, "properties": {}}::edge
+ {"id": 1125899906842639, "label": "edges", "end_id": 844424930131976, "start_id": 844424930131975, "properties": {}}::edge
+ {"id": 1125899906842636, "label": "edges", "end_id": 844424930131976, "start_id": 844424930131974, "properties": {}}::edge
+ {"id": 1125899906842637, "label": "edges", "end_id": 844424930131977, "start_id": 844424930131974, "properties": {}}::edge
+ {"id": 1125899906842642, "label": "edges", "end_id": 844424930131977, "start_id": 844424930131976, "properties": {}}::edge
+ {"id": 1125899906842640, "label": "edges", "end_id": 844424930131977, "start_id": 844424930131975, "properties": {}}::edge
+ {"id": 1125899906842644, "label": "edges", "end_id": 844424930131978, "start_id": 844424930131977, "properties": {}}::edge
+ {"id": 1125899906842638, "label": "edges", "end_id": 844424930131978, "start_id": 844424930131974, "properties": {}}::edge
+ {"id": 1125899906842641, "label": "edges", "end_id": 844424930131978, "start_id": 844424930131975, "properties": {}}::edge
+ {"id": 1125899906842643, "label": "edges", "end_id": 844424930131978, "start_id": 844424930131976, "properties": {}}::edge
+ {"id": 1125899906842645, "label": "edges", "end_id": 844424930131978, "start_id": 844424930131969, "properties": {}}::edge
+(21 rows)
+
+SELECT * FROM age_create_barbell_graph('gp1',5,0,'vertices',NULL,'edges',NULL);
+ age_create_barbell_graph
+--------------------------
+
+(1 row)
+
+SELECT COUNT(*) FROM gp1."edges";
+ count
+-------
+ 42
+(1 row)
+
+SELECT COUNT(*) FROM gp1."vertices";
+ count
+-------
+ 20
+(1 row)
+
+SELECT * FROM age_create_barbell_graph('gp2',5,10,'vertices',NULL,'edges',NULL);
+NOTICE: graph "gp2" has been created
+NOTICE: VLabel "vertices" has been created
+NOTICE: ELabel "edges" has been created
+ age_create_barbell_graph
+--------------------------
+
+(1 row)
+
+-- SHOULD FAIL
+SELECT * FROM age_create_barbell_graph(NULL,NULL,NULL,NULL,NULL,NULL,NULL);
+ERROR: Graph name cannot be NULL
+SELECT * FROM age_create_barbell_graph('gp2',NULL,0,'vertices',NULL,'edges',NULL);
+ERROR: Graph size cannot be NULL or lower than 3
+SELECT * FROM age_create_barbell_graph('gp3',5,NULL,'vertices',NULL,'edges',NULL);
+ERROR: Bridge size cannot be NULL or lower than 0
+SELECT * FROM age_create_barbell_graph('gp4',NULL,0,'vertices',NULL,'edges',NULL);
+ERROR: Graph size cannot be NULL or lower than 3
+SELECT * FROM age_create_barbell_graph('gp5',5,0,'vertices',NULL,NULL,NULL);
+ERROR: edge label can not be NULL
+-- DROPPING GRAPHS
+SELECT drop_graph('gp1', true);
+NOTICE: drop cascades to 4 other objects
+DETAIL: drop cascades to table gp1._ag_label_vertex
+drop cascades to table gp1._ag_label_edge
+drop cascades to table gp1.vertices
+drop cascades to table gp1.edges
+NOTICE: graph "gp1" has been dropped
+ drop_graph
+------------
+
+(1 row)
+
+SELECT drop_graph('gp2', true);
+NOTICE: drop cascades to 4 other objects
+DETAIL: drop cascades to table gp2._ag_label_vertex
+drop cascades to table gp2._ag_label_edge
+drop cascades to table gp2.vertices
+drop cascades to table gp2.edges
+NOTICE: graph "gp2" has been dropped
+ drop_graph
+------------
+
+(1 row)
+
diff --git a/regress/sql/graph_generation.sql b/regress/sql/graph_generation.sql
index 1ad90f5a..32fa56dd 100644
--- a/regress/sql/graph_generation.sql
+++ b/regress/sql/graph_generation.sql
@@ -45,3 +45,30 @@ SELECT * FROM create_complete_graph(NULL,NULL,NULL);
SELECT drop_graph('gp1', true);
SELECT drop_graph('gp2', true);
+
+-- Tests for barbell graph generation
+SELECT * FROM age_create_barbell_graph('gp1',5,0,'vertices',NULL,'edges',NULL);
+
+SELECT COUNT(*) FROM gp1."edges";
+SELECT COUNT(*) FROM gp1."vertices";
+
+SELECT * FROM cypher('gp1', $$MATCH (a)-[e]->(b) RETURN e$$) as (n agtype);
+
+SELECT * FROM age_create_barbell_graph('gp1',5,0,'vertices',NULL,'edges',NULL);
+
+SELECT COUNT(*) FROM gp1."edges";
+SELECT COUNT(*) FROM gp1."vertices";
+
+SELECT * FROM age_create_barbell_graph('gp2',5,10,'vertices',NULL,'edges',NULL);
+
+-- SHOULD FAIL
+SELECT * FROM age_create_barbell_graph(NULL,NULL,NULL,NULL,NULL,NULL,NULL);
+SELECT * FROM age_create_barbell_graph('gp2',NULL,0,'vertices',NULL,'edges',NULL);
+SELECT * FROM age_create_barbell_graph('gp3',5,NULL,'vertices',NULL,'edges',NULL);
+SELECT * FROM age_create_barbell_graph('gp4',NULL,0,'vertices',NULL,'edges',NULL);
+SELECT * FROM age_create_barbell_graph('gp5',5,0,'vertices',NULL,NULL,NULL);
+
+-- DROPPING GRAPHS
+SELECT drop_graph('gp1', true);
+SELECT drop_graph('gp2', true);
+
diff --git a/src/backend/utils/graph_generation.c b/src/backend/utils/graph_generation.c
index 80ef85f2..b40ef07e 100644
--- a/src/backend/utils/graph_generation.c
+++ b/src/backend/utils/graph_generation.c
@@ -273,25 +273,23 @@ Datum age_create_barbell_graph(PG_FUNCTION_ARGS)
arguments = fcinfo;
- // create two separate complete graphs
- DirectFunctionCall4(create_complete_graph, arguments->arg[0],
- arguments->arg[1],
- arguments->arg[5],
- arguments->arg[3]);
- DirectFunctionCall4(create_complete_graph, arguments->arg[0],
- arguments->arg[1],
- arguments->arg[5],
- arguments->arg[3]);
-
- // Handling remaining arguments
- /*
- * graph_name: doesn't need to validate, since the create_complete_graph
- * function already does that.
- */
+ // Checking for possible NULL arguments
+ // Name graph_name
+ if (PG_ARGISNULL(0))
+ {
+ ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("Graph name cannot be NULL")));
+ }
graph_name = PG_GETARG_NAME(0);
graph_name_str = NameStr(*graph_name);
- graph_oid = get_graph_oid(graph_name_str);
+ // int graph size (number of nodes in each complete graph)
+ if (PG_ARGISNULL(1) && PG_GETARG_INT32(1) < 3)
+ {
+ ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("Graph size cannot be NULL or lower than 3")));
+ }
+
/*
* int64 bridge_size: currently only stays at zero.
* to do: implement bridge with variable number of nodes.
@@ -299,7 +297,7 @@ Datum age_create_barbell_graph(PG_FUNCTION_ARGS)
if (PG_ARGISNULL(2) || PG_GETARG_INT32(2) < 0 )
{
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("Bridge size must not be NULL or lower than 0")));
+ errmsg("Bridge size cannot be NULL or lower than 0")));
}
// node label: if null, gets default label, which is "_ag_label_vertex"
@@ -312,14 +310,31 @@ Datum age_create_barbell_graph(PG_FUNCTION_ARGS)
node_label_name = PG_GETARG_NAME(3);
}
node_label_str = NameStr(*node_label_name);
- node_label_id = get_label_id(node_label_str, graph_oid);
/*
- * edge_label: doesn't need to validate, since the create_complete_graph
- * function already does that.
- */
+ * Name edge_label
+ */
+ if (PG_ARGISNULL(5))
+ {
+ ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("edge label can not be NULL")));
+ }
edge_label_name = PG_GETARG_NAME(5);
edge_label_str = NameStr(*edge_label_name);
+
+
+ // create two separate complete graphs
+ DirectFunctionCall4(create_complete_graph, arguments->arg[0],
+ arguments->arg[1],
+ arguments->arg[5],
+ arguments->arg[3]);
+ DirectFunctionCall4(create_complete_graph, arguments->arg[0],
+ arguments->arg[1],
+ arguments->arg[5],
+ arguments->arg[3]);
+
+ graph_oid = get_graph_oid(graph_name_str);
+ node_label_id = get_label_id(node_label_str, graph_oid);
edge_label_id = get_label_id(edge_label_str, graph_oid);
/*