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

Function _add_first_clause

src/ast/ast_rewrite_call_subquery.c:200–254  ·  view source on GitHub ↗

adds a leading WITH clause to the query, projecting all bound vars (names) to their internal representation (inter_names)

Source from the content-addressed store, hash-verified

198// adds a leading WITH clause to the query, projecting all bound vars (names) to
199// their internal representation (inter_names)
200static void _add_first_clause
201(
202 cypher_astnode_t *callsubquery, // call subquery ast-node
203 uint callsubquery_ind, // index of the call subquery node
204 uint first_ind, // the index in which to plant the clause
205 char **names, // original bound vars
206 char **inter_names // internal representation of bound vars
207) {
208 uint n_names = array_len(names);
209 uint n_inter_names = array_len(inter_names);
210
211 uint n_projections = n_inter_names;
212 uint proj_idx = 0;
213 cypher_astnode_t *projections[n_projections];
214
215 // -------------------------------------------------------------------------
216 // create projections for bound vars
217 // -------------------------------------------------------------------------
218 proj_idx = _add_projections(projections, proj_idx, names, inter_names,
219 true);
220
221 // -------------------------------------------------------------------------
222 // prepare additional arguments
223 //--------------------------------------------------------------------------
224
225 struct cypher_input_range range = {0};
226
227 // build the replacement clause
228 cypher_astnode_t *new_clause;
229 new_clause = cypher_ast_with(false, false, projections, n_projections,
230 NULL, NULL, NULL, NULL, projections, n_projections, range);
231
232 // -------------------------------------------------------------------------
233 // replace original clause with fully populated one
234 // -------------------------------------------------------------------------
235
236 cypher_astnode_t *query = cypher_ast_call_subquery_get_query(callsubquery);
237
238 uint n_clauses = cypher_ast_query_nclauses(query);
239 cypher_astnode_t *clauses[n_clauses + 1];
240 for(uint i = 0; i < first_ind; i++) {
241 clauses[i] = cypher_ast_clone(cypher_ast_query_get_clause(query, i));
242 }
243
244 clauses[first_ind] = new_clause;
245
246 for(uint i = first_ind; i < n_clauses; i++) {
247 clauses[i + 1] = cypher_ast_clone(cypher_ast_query_get_clause(query, i));
248 }
249
250 cypher_astnode_t *q = cypher_ast_query(NULL, 0, clauses, n_clauses + 1,
251 clauses, n_clauses + 1, range);
252
253 cypher_ast_call_subquery_replace_query(callsubquery, q);
254}
255
256// replace all intermediate WITH clauses in the query with new WITH clauses,
257// containing projections from the internal representation of bound vars to

Callers 1

_rewrite_projectionsFunction · 0.85

Calls 2

array_lenFunction · 0.85
_add_projectionsFunction · 0.85

Tested by

no test coverage detected