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

Function _Validate_WITH_Clause

src/ast/ast_validations.c:1399–1470  ·  view source on GitHub ↗

validate a WITH clause

Source from the content-addressed store, hash-verified

1397
1398// validate a WITH clause
1399static VISITOR_STRATEGY _Validate_WITH_Clause
1400(
1401 const cypher_astnode_t *n, // ast-node
1402 bool start, // first traversal
1403 ast_visitor *visitor // visitor
1404) {
1405 validations_ctx *vctx = AST_Visitor_GetContext(visitor);
1406
1407 vctx->clause = cypher_astnode_type(n);
1408
1409 if(_Validate_LIMIT_SKIP_Modifiers(cypher_ast_with_get_limit(n),
1410 cypher_ast_with_get_skip(n)) == AST_INVALID) {
1411 return VISITOR_BREAK;
1412 }
1413
1414 // manually traverse children. order by and predicate should be aware of the
1415 // vars introduced in the with projections, but the projections should not
1416 for(uint i = 0; i < cypher_ast_with_nprojections(n); i++) {
1417 // visit the projection
1418 const cypher_astnode_t *proj = cypher_ast_with_get_projection(n, i);
1419 AST_Visitor_visit(proj, visitor);
1420 if(ErrorCtx_EncounteredError()) {
1421 return VISITOR_BREAK;
1422 }
1423 }
1424
1425 // introduce WITH aliases to the bound vars context
1426 if(!_AST_GetWithAliases(n, vctx->defined_identifiers)) {
1427 return VISITOR_BREAK;
1428 }
1429
1430 // visit predicate clause
1431 const cypher_astnode_t *predicate = cypher_ast_with_get_predicate(n);
1432 if(predicate) {
1433 AST_Visitor_visit(predicate, visitor);
1434 if(ErrorCtx_EncounteredError()) {
1435 return VISITOR_BREAK;
1436 }
1437 }
1438
1439 // visit ORDER BY clause
1440 const cypher_astnode_t *order_by = cypher_ast_with_get_order_by(n);
1441 if(order_by) {
1442 AST_Visitor_visit(order_by, visitor);
1443 if(ErrorCtx_EncounteredError()) {
1444 return VISITOR_BREAK;
1445 }
1446 }
1447
1448 // if one of the 'projections' is a star -> proceed with current env
1449 // otherwise build a new environment using the new column names (aliases)
1450 if(!cypher_ast_with_has_include_existing(n)) {
1451 // free old env, set new one
1452 raxFree(vctx->defined_identifiers);
1453 vctx->defined_identifiers = raxNew();
1454
1455 // introduce the WITH aliases to the bound vars context
1456 for(uint i = 0; i < cypher_ast_with_nprojections(n); i++) {

Callers

nothing calls this directly

Calls 5

AST_Visitor_GetContextFunction · 0.85
AST_Visitor_visitFunction · 0.85
_AST_GetWithAliasesFunction · 0.85

Tested by

no test coverage detected