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

Function _replace_create_clause

src/ast/ast_rewrite_same_clauses.c:24–61  ·  view source on GitHub ↗

compresses multiple consecutive CREATE clauses into a single CREATE clause

Source from the content-addressed store, hash-verified

22
23// compresses multiple consecutive CREATE clauses into a single CREATE clause
24static void _replace_create_clause
25(
26 cypher_astnode_t *root, // ast root
27 cypher_astnode_t **clauses, // clause being replaced
28 int scope_start, // beginning of scope
29 int scope_end, // ending of scope
30 replace_func replace // replace function pointer
31) {
32 uint count = array_len(clauses);
33
34 struct cypher_input_range range = cypher_astnode_range(clauses[0]);
35 cypher_astnode_t **paths = array_new(cypher_astnode_t *, count);
36
37 // collect paths
38 for (uint i = 0; i < count; i++) {
39 const cypher_astnode_t *pattern =
40 cypher_ast_create_get_pattern(clauses[i]);
41 uint npaths = cypher_ast_pattern_npaths(pattern);
42 for (uint j = 0; j < npaths; j++) {
43 const cypher_astnode_t *path =
44 cypher_ast_pattern_get_path(pattern, j);
45 array_append(paths, cypher_ast_clone(path));
46 }
47 }
48
49 // build the replacement pattern
50 cypher_astnode_t *pattern = cypher_ast_pattern(paths, array_len(paths),
51 paths, array_len(paths), range);
52
53 // build the replacement clause
54 cypher_astnode_t *new_clause = cypher_ast_create(false, pattern, &pattern,
55 1, range);
56
57 // replace original clause with the new one
58 replace(root, new_clause, scope_start, scope_end);
59
60 array_free(paths);
61}
62
63// compresses multiple consecutive MATCH clauses into a single MATCH clause
64static void _replace_match_clause

Callers 1

_compress_clausesFunction · 0.85

Calls 2

array_lenFunction · 0.85
array_freeFunction · 0.85

Tested by

no test coverage detected