Skip to content
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
111 changes: 111 additions & 0 deletions regress/expected/graph_generation.out
Original file line number Diff line number Diff line change
Expand Up @@ -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)

27 changes: 27 additions & 0 deletions regress/sql/graph_generation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);

57 changes: 36 additions & 21 deletions src/backend/utils/graph_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,33 +273,31 @@ 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.
*/
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"
Expand All @@ -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);

/*
Expand Down