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

Function _replace_delete_clause

src/ast/ast_rewrite_same_clauses.c:123–166  ·  view source on GitHub ↗

compresses multiple consecutive DELETE clauses into a single DELETE clause

Source from the content-addressed store, hash-verified

121
122// compresses multiple consecutive DELETE clauses into a single DELETE clause
123static void _replace_delete_clause
124(
125 cypher_astnode_t *root, // ast root
126 cypher_astnode_t **clauses, // clause being replaced
127 int scope_start, // beginning of scope
128 int scope_end, // ending of scope
129 replace_func replace // replace function pointer
130) {
131 uint count = array_len(clauses);
132
133 struct cypher_input_range range = cypher_astnode_range(clauses[0]);
134 cypher_astnode_t **exps = array_new(cypher_astnode_t *, count);
135 rax *identifiers = raxNew();
136
137 // collect expressions
138 for (uint i = 0; i < count; i++) {
139 uint nexps = cypher_ast_delete_nexpressions(clauses[i]);
140 for(uint j = 0; j < nexps; j++) {
141 const cypher_astnode_t *exp =
142 cypher_ast_delete_get_expression(clauses[i], j);
143
144 // do not aggregate multiple appearances of an identifier
145 if(cypher_astnode_type(exp) == CYPHER_AST_IDENTIFIER) {
146 const char *identifier = cypher_ast_identifier_get_name(exp);
147 if(raxTryInsert(identifiers, (unsigned char *)identifier, strlen(identifier), NULL, NULL)) {
148 array_append(exps, cypher_ast_clone(exp));
149 }
150 } else {
151 // "MATCH p1=(n:N), p2=(m:M) DELETE nodes(p1)[0] DELETE nodes(p2)[0]"
152 array_append(exps, cypher_ast_clone(exp));
153 }
154 }
155 }
156 raxFree(identifiers);
157
158 // build the replacement clause
159 cypher_astnode_t *new_clause = cypher_ast_delete(false, exps,
160 array_len(exps), exps, array_len(exps), range);
161
162 // replace original clause with the new one
163 replace(root, new_clause, scope_start, scope_end);
164
165 array_free(exps);
166}
167
168// compresses multiple consecutive SET clauses into a single SET clause
169static void _replace_set_clause

Callers 1

_compress_clausesFunction · 0.85

Calls 2

array_lenFunction · 0.85
array_freeFunction · 0.85

Tested by

no test coverage detected