This is an automated email from the ASF dual-hosted git repository.
joshinnis pushed a commit to branch AGE_label_inheritance
in repository https://gitbox.apache.org/repos/asf/age.git
The following commit(s) were added to refs/heads/AGE_label_inheritance by this
push:
new ec4a2002 Added a function Named getChildren in the file (#786)
ec4a2002 is described below
commit ec4a2002ea51f3bc5bb40f65fec39d21f9c42c81
Author: Muhammad Zahid <[email protected]>
AuthorDate: Sat Apr 1 20:10:20 2023 +0500
Added a function Named getChildren in the file (#786)
age_global_graph.c. This function returns the
children of a node in the graph. This function
is used in the function is_an_edge_match in
the file age_vle.c. Which chekcs if the edge
is a match or not.
---
src/backend/utils/adt/age_global_graph.c | 57 ++++++++++++++++++++++++++++++++
src/backend/utils/adt/age_vle.c | 31 ++++++++++++++++-
src/include/utils/age_global_graph.h | 1 +
3 files changed, 88 insertions(+), 1 deletion(-)
diff --git a/src/backend/utils/adt/age_global_graph.c
b/src/backend/utils/adt/age_global_graph.c
index c18f9c93..6f7562ab 100644
--- a/src/backend/utils/adt/age_global_graph.c
+++ b/src/backend/utils/adt/age_global_graph.c
@@ -25,6 +25,7 @@
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "commands/label_commands.h"
+#include "catalog/pg_inherits.h"
#include "utils/age_global_graph.h"
#include "utils/agtype.h"
@@ -989,6 +990,62 @@ graphid get_edge_entry_end_vertex_id(edge_entry *ee)
return ee->end_vertex_id;
}
+List* getChildren(GRAPH_global_context *ggctx)
+{
+
+ Oid graph_oid;
+ Oid graph_namespace_oid;
+ Snapshot snapshot;
+ List *edge_label_names = NIL;
+ ListCell *lc;
+ List *children = NIL;
+
+ /* get the specific graph OID and namespace (schema) OID */
+ graph_oid = ggctx->graph_oid;
+ graph_namespace_oid = get_namespace_oid(ggctx->graph_name, false);
+ /* get the active snapshot */
+ snapshot = GetActiveSnapshot();
+ /* get the names of all of the edge label tables */
+ edge_label_names = get_ag_labels_names(snapshot, graph_oid,
+ LABEL_TYPE_EDGE);
+ /* go through all edge label tables in list */
+ foreach (lc, edge_label_names)
+ {
+ Relation graph_edge_label;
+ HeapScanDesc scan_desc;
+ HeapTuple tuple;
+ char *edge_label_name;
+ Oid edge_label_table_oid;
+ TupleDesc tupdesc;
+
+
+ /* get the edge label name */
+ edge_label_name = lfirst(lc);
+
+ /* get the edge label name's OID */
+ edge_label_table_oid = get_relname_relid(edge_label_name,
+ graph_namespace_oid);
+
+ List *child_edges_oid_temp = NIL;
+
+ if( has_subclass(edge_label_table_oid))
+ {
+ child_edges_oid_temp =
find_inheritance_children(edge_label_table_oid, NoLock);
+
+ //loop through the child edges
+ ListCell *lc1;
+ foreach (lc1, child_edges_oid_temp)
+ {
+ Oid child_edge_oid = lfirst_oid(lc1);
+ children = lappend_oid(children, child_edge_oid);
+ }
+ }
+
+ }
+
+ return children;
+}
+
/* PostgreSQL SQL facing functions */
/* PG wrapper function for age_delete_global_graphs */
diff --git a/src/backend/utils/adt/age_vle.c b/src/backend/utils/adt/age_vle.c
index f86a9e9b..b123d263 100644
--- a/src/backend/utils/adt/age_vle.c
+++ b/src/backend/utils/adt/age_vle.c
@@ -22,6 +22,7 @@
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "utils/lsyscache.h"
+#include "catalog/pg_inherits.h"
#include "utils/age_vle.h"
#include "catalog/ag_graph.h"
@@ -333,6 +334,19 @@ static bool is_an_edge_match(VLE_local_context *vlelctx,
edge_entry *ee)
char *edge_label_name = NULL;
int num_edge_property_constraints = 0;
int num_edge_properties = 0;
+ List *child_oid_list = NIL;
+ bool isChild = false;
+ GRAPH_global_context *ggctx = NULL;
+
+ /*get the graph global context */
+ ggctx = find_GRAPH_global_context(vlelctx->graph_oid);
+ if (ggctx == NULL)
+ {
+ elog(ERROR, "could not find GRAPH global context for graph oid %d",
+ vlelctx->graph_oid);
+ }
+
+
/* get the number of conditions from the prototype edge */
num_edge_property_constraints =
AGT_ROOT_COUNT(vlelctx->edge_property_constraint);
@@ -367,11 +381,26 @@ static bool is_an_edge_match(VLE_local_context *vlelctx,
edge_entry *ee)
return false;
}
+ /* get the children list of the current VLE_local_context*/
+ child_oid_list = getChildren(ggctx);
+ ListCell *lc;
+
+ /* check if child exists or not*/
+ foreach(lc, child_oid_list)
+ {
+ Oid child_oid = lfirst_oid(lc);
+ char *child_name = get_rel_name(child_oid);
+ if (strcmp(edge_label_name, child_name) == 0)
+ {
+ isChild = true;
+ }
+ }
+
/*
* Check for a label constraint. If the label name is NULL, there isn't
one.
*/
if (vlelctx->edge_label_name != NULL &&
- strcmp(vlelctx->edge_label_name, edge_label_name) != 0)
+ strcmp(vlelctx->edge_label_name, edge_label_name) != 0 && !isChild)
{
return false;
}
diff --git a/src/include/utils/age_global_graph.h
b/src/include/utils/age_global_graph.h
index daa1e513..78011415 100644
--- a/src/include/utils/age_global_graph.h
+++ b/src/include/utils/age_global_graph.h
@@ -60,4 +60,5 @@ Oid get_edge_entry_label_table_oid(edge_entry *ee);
Datum get_edge_entry_properties(edge_entry *ee);
graphid get_edge_entry_start_vertex_id(edge_entry *ee);
graphid get_edge_entry_end_vertex_id(edge_entry *ee);
+List* getChildren(GRAPH_global_context *ggctx);
#endif