MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / _QueryGraphAddEdge

Function _QueryGraphAddEdge

src/graph/query_graph.c:58–132  ·  view source on GitHub ↗

adds edge to query graph

Source from the content-addressed store, hash-verified

56
57// adds edge to query graph
58static void _QueryGraphAddEdge
59(
60 QueryGraph *qg, // query graph to add edge to
61 const cypher_astnode_t *ast_entity, // edge entity
62 QGNode *src, // src node
63 QGNode *dest, // dest node
64 bool only_shortest // edge is part of a shortest path
65) {
66 GraphContext *gc = QueryCtx_GetGraphCtx();
67 const char *alias = AST_ToString(ast_entity);
68 enum cypher_rel_direction dir =
69 cypher_ast_rel_pattern_get_direction(ast_entity);
70
71 // each edge can only appear once in a QueryGraph
72 ASSERT(QueryGraph_GetEdgeByAlias(qg, alias) == NULL);
73
74 QGEdge *edge = QGEdge_New(NULL, alias);
75 edge->bidirectional = (dir == CYPHER_REL_BIDIRECTIONAL);
76 edge->shortest_path = only_shortest;
77
78 // add the IDs of all reltype matrixes
79 uint nreltypes = cypher_ast_rel_pattern_nreltypes(ast_entity);
80 for(uint i = 0; i < nreltypes; i ++) {
81 const char *reltype = cypher_ast_reltype_get_name(cypher_ast_rel_pattern_get_reltype(ast_entity,
82 i));
83 bool found = false;
84 Schema *s = GraphContext_GetSchema(gc, reltype, SCHEMA_EDGE);
85 if(!s) {
86 // unknown relationship
87 // search if reltype exists in edge->reltypes to don't insert duplicated reltype
88 int len = array_len(edge->reltypes);
89 for (int j = 0; j < len; j++) {
90 if(edge->reltypeIDs[j] == GRAPH_UNKNOWN_RELATION) {
91 if(strcasecmp(edge->reltypes[j],reltype) == 0) {
92 found = true;
93 break;
94 }
95 }
96 }
97 if(!found) {
98 array_append(edge->reltypes, reltype);
99 array_append(edge->reltypeIDs, GRAPH_UNKNOWN_RELATION);
100 qg->unknown_reltype_ids = true;
101 }
102 continue;
103 }
104 // search if s-id exists in edge->reltypeIDs to don't insert duplicated ids
105 int len = array_len(edge->reltypeIDs);
106 for (int j = 0; j < len; j++) {
107 if(edge->reltypeIDs[j] == s->id) {
108 found = true;
109 break;
110 }
111 }
112 if(!found) {
113 array_append(edge->reltypes, reltype);
114 array_append(edge->reltypeIDs, s->id);
115 }

Callers 2

_QueryGraph_ExtractEdgeFunction · 0.85
QueryGraph_AddPathFunction · 0.85

Calls 8

QueryCtx_GetGraphCtxFunction · 0.85
AST_ToStringFunction · 0.85
QGEdge_NewFunction · 0.85
GraphContext_GetSchemaFunction · 0.85
array_lenFunction · 0.85
AST_ParseIntegerNodeFunction · 0.85
QueryGraph_ConnectNodesFunction · 0.85

Tested by

no test coverage detected