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

Create Cycle Graph Function #400

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/home/kalyan/Documents/pgsql-11.17/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always be sure, not to include the files with your environment details (unless required/specified)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for rectifying it. Should I remove these files and create a new Pull Request?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove the files and commit them here, and the PR would be updated automatically. No need for creating a new PR.

6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"C_Cpp.errorSquiggles": "Disabled",
"files.associations": {
"parsenodes.h": "c"
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes for this

12 changes: 12 additions & 0 deletions age--1.1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4175,6 +4175,18 @@ STABLE
PARALLEL SAFE
AS 'MODULE_PATHNAME';

CREATE FUNCTION ag_catalog.create_complete_graph(graph_name name, nodes int, edge_label name, node_label name = NULL)
RETURNS void
LANGUAGE c
CALLED ON NULL INPUT
AS 'MODULE_PATHNAME';

CREATE FUNCTION ag_catalog.age_create_cycle_graph(graph_name name, nodes int, vertex_label name, vertex_properties name, edge_label name, edge_properties name, biderectional bool default true)
RETURNS void
LANGUAGE c
CALLED ON NULL INPUT
AS 'MODULE_PATHNAME';

--
-- End
--
152 changes: 151 additions & 1 deletion src/backend/utils/graph_generation.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ Datum create_complete_graph(PG_FUNCTION_ARGS)
if (!PG_ARGISNULL(3))
{
vtx_label_name = PG_GETARG_NAME(3);
vtx_name_str = NameStr(*vtx_label_name);
// Check if label with the input name already exists
vtx_name_str = NameStr(*vtx_label_name);
if (!label_exists(vtx_name_str, graph_id))
{
DirectFunctionCall2(create_vlabel, CStringGetDatum(graph_name), CStringGetDatum(vtx_label_name));
Expand Down Expand Up @@ -201,3 +201,153 @@ Datum create_complete_graph(PG_FUNCTION_ARGS)
PG_RETURN_VOID();
}


PG_FUNCTION_INFO_V1(age_create_cycle_graph);

// SELECT * FROM ag_catalog.age_create_cycle_graph(string graph_name, int no_of_vertices, str vertex_label_name, vertex_properties=NULL, str edge_label_name
//, edge_properties=NULL, biderctional=TRUE);

Datum age_create_cycle_graph(PG_FUNCTION_ARGS)
{

Name vertex_label_name;
Name edge_label_name;
Name vertex_seq_name;
Name edge_seq_name;
Name graph_name;

char* graph_name_str;
char* vertex_name_str;
char* edge_name_str;
char *vertex_seq_name_str;
char *edge_seq_name_str;

int32 vertex_label_id;
int32 edge_label_id;

Oid graph_id;
Oid nsp_id;
Oid vertex_seq_id;
Oid edge_seq_id;

graph_cache_data *graph_cache;
label_cache_data *vertex_cache;
label_cache_data *edge_cache;

graphid object_graph_id;
graphid start_vertex_graph_id;
graphid end_vertex_graph_id;

int64 vid, lid, eid, start_vid, end_vid;
int64 vertices_count;

agtype *props = NULL;


if(PG_ARGISNULL(0)){
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("graph name can not be NULL")));
}

graph_name = PG_GETARG_NAME(0);

DirectFunctionCall1(create_graph, CStringGetDatum(graph_name));
//create_graph(graph_name);

if(PG_ARGISNULL(1)){
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("Number of vertices cannot be NULL")));
}

if(PG_ARGISNULL(2)){
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("vertex label cannot be NULL")));
}

if(PG_ARGISNULL(4)){
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("edge label cannot be NULL")));
}

vertices_count = PG_GETARG_INT64(1);

if(vertices_count<3){
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("Number of vertices cannot be less than 3")));
}

vertex_label_name = PG_GETARG_NAME(2);
edge_label_name = PG_GETARG_NAME(4);

vertex_name_str = NameStr(*vertex_label_name);
edge_name_str = NameStr(*edge_label_name);
graph_name_str = NameStr(*graph_name);

graph_id = get_graph_oid(graph_name_str);

//create_vlabel(graph_name, vertex_label_name);
//create_elabel(graph_name, edge_label_name);
//Can't call functions directly!
DirectFunctionCall2(create_vlabel, CStringGetDatum(graph_name), CStringGetDatum(vertex_label_name));
DirectFunctionCall2(create_elabel, CStringGetDatum(graph_name), CStringGetDatum(edge_label_name));

vertex_label_id = get_label_id(vertex_name_str, graph_id);
edge_label_id = get_label_id(edge_name_str, graph_id);

graph_cache = search_graph_name_cache(graph_name_str);
vertex_cache = search_label_name_graph_cache(vertex_name_str,graph_id);
edge_cache = search_label_name_graph_cache(edge_name_str,graph_id);

nsp_id = graph_cache->namespace;
vertex_seq_name = &(vertex_cache->seq_name);
vertex_seq_name_str = NameStr(*vertex_seq_name);

edge_seq_name = &(edge_cache->seq_name);
edge_seq_name_str = NameStr(*edge_seq_name);

vertex_seq_id = get_relname_relid(vertex_seq_name_str, nsp_id);
edge_seq_id = get_relname_relid(edge_seq_name_str, nsp_id);


/* Creating vertices*/
for (int64 i=(int64)1;i<=vertices_count;i++)
{
vid = nextval_internal(vertex_seq_id, true);
object_graph_id = make_graphid(vertex_label_id, vid);
props = create_empty_agtype();
insert_vertex_simple(graph_id,vertex_name_str,object_graph_id,props);
}

lid = vid;

/* Creating edges*/
/* We create edges such that every vertice has only 1 incoming and outgoing edge and all vertices are connected*/
for (int64 i = 1;i<=vertices_count;i++)
{
start_vid = lid-vertices_count+i;
if (i==vertices_count)
{
end_vid = start_vid - vertices_count + 1;
}
else
{
end_vid = start_vid + 1;
}

eid = nextval_internal(edge_seq_id, true);
object_graph_id = make_graphid(edge_label_id, eid);

start_vertex_graph_id = make_graphid(vertex_label_id, start_vid);
end_vertex_graph_id = make_graphid(vertex_label_id, end_vid);

props = create_empty_agtype();

insert_edge_simple(graph_id, edge_name_str,
object_graph_id, start_vertex_graph_id,
end_vertex_graph_id, props);

}

PG_RETURN_VOID();
}

6 changes: 4 additions & 2 deletions src/include/utils/load/age_load.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@
#include "utils/agtype.h"
#include "utils/graphid.h"

#ifndef AGE_ENTITY_CREATOR_H
#define AGE_ENTITY_CREATOR_H
#ifndef INCUBATOR_AGE_ENTITY_CREATOR_H
#define INCUBATOR_AGE_ENTITY_CREATOR_H

agtype* create_empty_agtype(void);

agtype* create_empty_agtype(void);

Expand Down