Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
Expose Hash Entries in VLE process
Browse files Browse the repository at this point in the history
Wanna cut down on the lines of code before I start the major
refactoring.
  • Loading branch information
JoshInnis committed Jun 9, 2024
1 parent 423ec45 commit 49ee0cb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 65 deletions.
60 changes: 30 additions & 30 deletions src/backend/utils/path_finding/dfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ static bool check_edge_constraints(path_finding_context *path_ctx, edge_entry *e
int num_propertiess = 0;
int num_edge_properties = 0;
// get the edge label name from the oid
label_name = get_rel_name(get_edge_entry_label_table_oid(ee));
label_name = get_rel_name(ee->oid);

if (path_ctx->label_name != NULL && strcmp(path_ctx->label_name, label_name) != 0)
return false;

if (path_ctx->properties == NULL)
return true;

label_name = get_rel_name(get_edge_entry_label_table_oid(ee));
edge_property = DATUM_GET_GTYPE_P(get_edge_entry_properties(ee));
label_name = get_rel_name(ee->oid);
edge_property = DATUM_GET_GTYPE_P(ee->properties);
agtc_properties = &path_ctx->properties->root;
agtc_edge_property = &edge_property->root;
// get the number of properties in the edge to be matched
Expand Down Expand Up @@ -334,11 +334,11 @@ static graphid get_next_vertex(path_finding_context *path_ctx, edge_entry *ee)
// get the result based on the specified VLE edge direction
switch (path_ctx->edge_direction) {
case CYPHER_REL_DIR_RIGHT:
id = get_end_id(ee);
id = ee->end_id;
break;

case CYPHER_REL_DIR_LEFT:
id = get_start_id(ee);
id = ee->start_id;
break;

case CYPHER_REL_DIR_NONE:
Expand All @@ -354,10 +354,10 @@ static graphid get_next_vertex(path_finding_context *path_ctx, edge_entry *ee)
*/
parent_vertex_id = PEEK_GRAPHID_STACK(vertex_queue);
// find the terminal vertex
if (get_start_id(ee) == parent_vertex_id)
id = get_end_id(ee);
else if (get_end_id(ee) == parent_vertex_id)
id = get_start_id(ee);
if (ee->start_id == parent_vertex_id)
id = ee->end_id;
else if (ee->end_id == parent_vertex_id)
id = ee->start_id;
else
elog(ERROR, "get_next_vertex: no parent match");

Expand Down Expand Up @@ -488,18 +488,18 @@ static void add_edges(path_finding_context *path_ctx, graphid vertex_id) {
// set to the first edge for each edge list for the specified direction
QueueNode *edge_out = NULL;
if (path_ctx->edge_direction != CYPHER_REL_DIR_LEFT) {
edges = get_vertex_entry_edges_out(ve);
edges = ve->out;
edge_out = (edges != NULL) ? get_list_head(edges) : NULL;
}

QueueNode *edge_in = NULL;
if (path_ctx->edge_direction != CYPHER_REL_DIR_RIGHT) {
edges = get_vertex_entry_edges_in(ve);
edges = ve->in;
edge_in = (edges != NULL) ? get_list_head(edges) : NULL;
}

// set to the first selfloop edge
edges = get_vertex_entry_edges_self(ve);
edges = ve->loop;
QueueNode *edge_self = (edges != NULL) ? get_list_head(edges) : NULL;

// add in valid vertex edges
Expand Down Expand Up @@ -532,7 +532,7 @@ static void add_edges(path_finding_context *path_ctx, graphid vertex_id) {
* you just came from. So, we need to store it.
*/
if (path_ctx->edge_direction == CYPHER_REL_DIR_NONE)
push_graphid_queue(vertex_queue, get_vertex_entry_id(ve));
push_graphid_queue(vertex_queue, ve->id);
push_graphid_queue(edge_queue, edge_id);
}

Expand Down Expand Up @@ -646,21 +646,21 @@ static path_container *build_path_container(path_finding_context *path_ctx) {
for (index = 1; index < vpc->graphid_array_size - 1; index += 2) {
edge_entry *ee = get_edge_entry(path_ctx->ggctx, graphid_array[index]);

graphid_array[index+1] = (vid == get_start_id(ee)) ? get_end_id(ee) : get_start_id(ee);
graphid_array[index+1] = (vid == ee->start_id) ? ee->end_id : ee->start_id;
}

// return the container
return vpc;
}

/*
* 0 - gtype REQUIRED (graph name as string)
* 1 - gtype REQUIRED (start vertex as a vertex or the integer id)
* 2 - gtype OPTIONAL (end vertex as a vertex or the integer id)
* 3 - gtype REQUIRED (edge prototype to match as an edge)
* 4 - gtype OPTIONAL lidx (lower range index)
* 5 - gtype OPTIONAL uidx (upper range index)
* 6 - gtype REQUIRED edge direction (enum) as an integer. REQUIRED
* 0 - graph name as string
* 1 - start vertex as a vertex or the integer id
* 2 - end vertex as a vertex or the integer id
* 3 - edge prototype to match as an edge
* 4 - lower range index
* 5 - upper range index
* 6 - edge direction
*/
PG_FUNCTION_INFO_V1(gtype_vle);
Datum gtype_vle(PG_FUNCTION_ARGS) {
Expand All @@ -672,8 +672,9 @@ Datum gtype_vle(PG_FUNCTION_ARGS) {
if (SRF_IS_FIRSTCALL()) {
// all of these arguments need to be non NULL
if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(5))
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("age_vle: invalid NULL argument passed")));
SRF_RETURN_DONE(funcctx);
// ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
// errmsg("age_vle: invalid NULL argument passed")));

funcctx = SRF_FIRSTCALL_INIT();

Expand Down Expand Up @@ -740,9 +741,8 @@ VariableEdge *create_variable_edge(path_container *vpc) {
if (index != 0 && index + 1 != graphid_array_size) {
vertex_entry *ve = get_vertex_entry(ggctx, graphid_array[index]);

//char *label_name = get_rel_name(get_vertex_entry_label_table_oid(ve));
graphid id = get_vertex_entry_id(ve);
gtype *prop = DATUM_GET_GTYPE_P(get_vertex_entry_properties(ve));
graphid id = ve->id;
gtype *prop = DATUM_GET_GTYPE_P(ve->properties);
Datum d = VERTEX_GET_DATUM(create_vertex(id, vpc->graph_oid, prop));

append_to_buffer(&buffer, DATUM_GET_VERTEX(d), VARSIZE(d));
Expand All @@ -754,11 +754,11 @@ VariableEdge *create_variable_edge(path_container *vpc) {
// get the edge entry from the hashtable
edge_entry *ee = get_edge_entry(ggctx, graphid_array[index+1]);

char *label_name = get_rel_name(get_edge_entry_label_table_oid(ee));
char *label_name = get_rel_name(ee->oid);
graphid id = get_vertex_entry_id(ee);
graphid startid = get_start_id(ee);
graphid endid = get_end_id(ee);
gtype *prop = DATUM_GET_GTYPE_P(get_edge_entry_properties(ee));
graphid startid = ee->start_id;
graphid endid = ee->end_id;
gtype *prop = DATUM_GET_GTYPE_P(ee->properties);
Datum d = EDGE_GET_DATUM(create_edge(id, startid, endid, vpc->graph_oid, prop));

append_to_buffer(&buffer, DATUM_GET_EDGE(d), VARSIZE(d));
Expand Down
20 changes: 0 additions & 20 deletions src/backend/utils/path_finding/global_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,6 @@

// internal data structures implementation

// vertex entry for the vertex_hastable
typedef struct vertex_entry
{
graphid id; // vertex id, it is also the hash key
Queue *in; // List of entering edges graphids (int64)
Queue *out; // List of exiting edges graphids (int64)
Queue *loop; // List of selfloop edges graphids (int64)
Oid oid; // the label table oid
Datum properties; // datum property value
} vertex_entry;

// edge entry for the edge_hashtable
typedef struct edge_entry
{
graphid id; // edge id, it is also the hash key
Oid oid; // the label table oid
Datum properties; // datum property value
graphid start_id; // start vertex
graphid end_id; // end vertex
} edge_entry;

/*
* GRAPH global context per graph. They are chained together via next.
Expand Down
39 changes: 24 additions & 15 deletions src/include/utils/global_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,31 @@
#include "utils/graphid.h"
#include "utils/queue.h"

typedef struct vertex_entry vertex_entry;
typedef struct edge_entry edge_entry;
typedef struct graph_context graph_context;

// vertex entry for the vertex_hastable
typedef struct vertex_entry
{
graphid id; // vertex id, it is also the hash key
Queue *in; // List of entering edges graphids (int64)
Queue *out; // List of exiting edges graphids (int64)
Queue *loop; // List of selfloop edges graphids (int64)
Oid oid; // the label table oid
Datum properties; // datum property value
} vertex_entry;

// edge entry for the edge_hashtable
typedef struct edge_entry
{
graphid id; // edge id, it is also the hash key
Oid oid; // the label table oid
Datum properties; // datum property value
graphid start_id; // start vertex
graphid end_id; // end vertex
} edge_entry;



// GRAPH global context functions
graph_context *manage_graph_contexts(char *graph_name, Oid graph_oid);
graph_context *find_graph_context(Oid graph_oid);
Expand All @@ -33,17 +54,5 @@ bool is_ggctx_invalid(graph_context *ggctx);
Queue *get_graph_vertices(graph_context *ggctx);
vertex_entry *get_vertex_entry(graph_context *ggctx, graphid vertex_id);
edge_entry *get_edge_entry(graph_context *ggctx, graphid edge_id);
// vertex entry accessor functions
graphid get_vertex_entry_id(vertex_entry *ve);
Queue *get_vertex_entry_edges_in(vertex_entry *ve);
Queue *get_vertex_entry_edges_out(vertex_entry *ve);
Queue *get_vertex_entry_edges_self(vertex_entry *ve);
Oid get_vertex_entry_label_table_oid(vertex_entry *ve);
Datum get_vertex_entry_properties(vertex_entry *ve);
// edge entry accessor functions
graphid get_edge_entry_id(edge_entry *ee);
Oid get_edge_entry_label_table_oid(edge_entry *ee);
Datum get_edge_entry_properties(edge_entry *ee);
graphid get_start_id(edge_entry *ee);
graphid get_end_id(edge_entry *ee);

#endif

0 comments on commit 49ee0cb

Please sign in to comment.