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

Function collect_aliases_in_scope

src/ast/ast_shared.c:389–440  ·  view source on GitHub ↗

collect aliases defined in a scope bounded by scope_start and scope_end

Source from the content-addressed store, hash-verified

387
388// collect aliases defined in a scope bounded by scope_start and scope_end
389void collect_aliases_in_scope
390(
391 const cypher_astnode_t *root, // the query root
392 uint scope_start, // start index of scope
393 uint scope_end, // end index of scope
394 rax *identifiers // rax to populate with identifiers
395) {
396 ASSERT(scope_start != scope_end);
397 ASSERT(identifiers != NULL);
398
399 for(uint i = scope_start; i < scope_end; i ++) {
400 const cypher_astnode_t *clause = cypher_astnode_type(root) ==
401 CYPHER_AST_QUERY ?
402 cypher_ast_query_get_clause(root, i) :
403 cypher_ast_query_get_clause(
404 cypher_ast_call_subquery_get_query(root), i);
405 cypher_astnode_type_t type = cypher_astnode_type(clause);
406
407 if(type == CYPHER_AST_WITH) {
408 // the WITH clause contains either
409 // aliases or its own STAR projection
410 _collect_with_projections(clause, identifiers);
411 } else if(type == CYPHER_AST_MATCH) {
412 // the MATCH clause contains one pattern of N paths
413 const cypher_astnode_t *pattern =
414 cypher_ast_match_get_pattern(clause);
415 _collect_aliases_in_pattern(pattern, identifiers);
416 } else if(type == CYPHER_AST_CREATE) {
417 // the CREATE clause contains one pattern of N paths
418 const cypher_astnode_t *pattern =
419 cypher_ast_create_get_pattern(clause);
420 _collect_aliases_in_pattern(pattern, identifiers);
421 } else if(type == CYPHER_AST_MERGE) {
422 // the MERGE clause contains one path
423 const cypher_astnode_t *path =
424 cypher_ast_merge_get_pattern_path(clause);
425 _collect_aliases_in_path(path, identifiers);
426 } else if(type == CYPHER_AST_UNWIND) {
427 // the UNWIND clause introduces one alias
428 const cypher_astnode_t *unwind_alias =
429 cypher_ast_unwind_get_alias(clause);
430 const char *identifier =
431 cypher_ast_identifier_get_name(unwind_alias);
432 raxTryInsert(identifiers, (unsigned char *)identifier,
433 strlen(identifier), (void *)unwind_alias, NULL);
434 } else if(type == CYPHER_AST_CALL) {
435 _collect_call_projections(clause, identifiers);
436 } else if(type == CYPHER_AST_CALL_SUBQUERY) {
437 _collect_call_subquery_projections(clause, identifiers);
438 }
439 }
440}

Callers 3

_rewrite_projectionsFunction · 0.85
replace_clauseFunction · 0.85

Tested by

no test coverage detected