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

Function AST_PreparePathCreation

src/ast/ast_build_op_contexts.c:234–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232}
233
234void AST_PreparePathCreation
235(
236 const cypher_astnode_t *path,
237 const QueryGraph *qg,
238 rax *bound_vars,
239 NodeCreateCtx **nodes,
240 EdgeCreateCtx **edges
241) {
242 GraphContext *gc = QueryCtx_GetGraphCtx();
243
244 QueryGraph *g = QueryGraph_ExtractPaths(qg, &path, 1);
245 uint path_elem_count = cypher_ast_pattern_path_nelements(path);
246 for(uint i = 0; i < path_elem_count; i ++) {
247 /* See if current entity needs to be created:
248 * 1. Current entity is NOT bound in a previous clause.
249 * 2. We have yet to account for this entity. */
250 const cypher_astnode_t *elem = cypher_ast_pattern_path_get_element(path, i);
251 const char *alias = AST_ToString(elem);
252
253 // Skip entities defined in previous clauses or already represented in our nodes/edges arrays.
254 int rc = raxTryInsert(bound_vars, (unsigned char *)alias, strlen(alias), NULL, NULL);
255 if(rc == 0) continue;
256
257 if((i % 2) == 1) {
258 // relation
259 QGEdge *e = QueryGraph_GetEdgeByAlias(g, alias);
260 EdgeCreateCtx new_edge = _NewEdgeCreateCtx(gc, e, elem);
261 array_append(*edges, new_edge);
262 } else {
263 // node
264 QGNode *n = QueryGraph_GetNodeByAlias(g, alias);
265 NodeCreateCtx new_node = _NewNodeCreateCtx(gc, n, elem);
266 array_append(*nodes, new_node);
267 }
268 }
269
270 QueryGraph_Free(g);
271}
272
273//------------------------------------------------------------------------------
274// SORT operation

Callers 2

AST_PrepareMergeOpFunction · 0.85
AST_PrepareCreateOpFunction · 0.85

Calls 8

QueryCtx_GetGraphCtxFunction · 0.85
QueryGraph_ExtractPathsFunction · 0.85
AST_ToStringFunction · 0.85
_NewEdgeCreateCtxFunction · 0.85
_NewNodeCreateCtxFunction · 0.85
QueryGraph_FreeFunction · 0.85

Tested by

no test coverage detected