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

Function AST_NewSegment

src/ast/ast.c:432–479  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

430}
431
432AST *AST_NewSegment
433(
434 AST *master_ast,
435 uint start_offset,
436 uint end_offset
437) {
438 AST *ast = rm_malloc(sizeof(AST));
439
440 ast->free_root = true;
441 ast->ref_count = rm_malloc(sizeof(uint));
442 ast->parse_result = NULL;
443 ast->params_parse_result = NULL;
444 ast->referenced_entities = NULL;
445 ast->anot_ctx_collection = master_ast->anot_ctx_collection;
446
447 uint n = end_offset - start_offset;
448
449 *(ast->ref_count) = 1;
450 const cypher_astnode_t *clauses[n];
451 for(uint i = 0; i < n; i ++) {
452 clauses[i] = cypher_ast_query_get_clause(master_ast->root, i + start_offset);
453 }
454 struct cypher_input_range range = {0};
455 ast->root = cypher_ast_query(NULL, 0, (cypher_astnode_t *const *)clauses, n,
456 (cypher_astnode_t **)clauses, n, range);
457
458 // TODO This overwrites the previously-held AST pointer, which could lead to inconsistencies
459 // in the future if we expect the variable to hold a different AST.
460 QueryCtx_SetAST(ast);
461
462 // If the segments are split, the next clause is either RETURN or WITH,
463 // and its references should be included in this segment's map.
464 const cypher_astnode_t *project_clause = NULL;
465 uint clause_count = cypher_ast_query_nclauses(master_ast->root);
466 if(end_offset == clause_count) end_offset = clause_count - 1;
467
468 project_clause = cypher_ast_query_get_clause(master_ast->root, end_offset);
469 // last clause is not necessarily a projection clause
470 // [MATCH (a) RETURN a UNION] MATCH (a) RETURN a
471 // In this case project_clause = UNION, which is not a projection clause
472 cypher_astnode_type_t project_type = cypher_astnode_type(project_clause);
473 if(project_type != CYPHER_AST_WITH && project_type != CYPHER_AST_RETURN) project_clause = NULL;
474
475 // Build the map of referenced entities in this AST segment.
476 AST_BuildReferenceMap(ast, project_clause);
477
478 return ast;
479}
480
481void AST_SetParamsParseResult
482(

Callers 10

_process_segmentsFunction · 0.85
test_matchFunction · 0.85
test_setFunction · 0.85
test_mergeFunction · 0.85
test_unwindFunction · 0.85
test_withFunction · 0.85
test_returnFunction · 0.85
test_namePathFunction · 0.85

Calls 3

rm_mallocFunction · 0.85
QueryCtx_SetASTFunction · 0.85
AST_BuildReferenceMapFunction · 0.85

Tested by 8

test_matchFunction · 0.68
test_setFunction · 0.68
test_mergeFunction · 0.68
test_unwindFunction · 0.68
test_withFunction · 0.68
test_returnFunction · 0.68
test_namePathFunction · 0.68