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

Function _ValidateCallInitialWith

src/ast/ast_validations.c:1201–1251  ·  view source on GitHub ↗

validates a leading `WITH` clause of a subquery

Source from the content-addressed store, hash-verified

1199
1200// validates a leading `WITH` clause of a subquery
1201static bool _ValidateCallInitialWith
1202(
1203 const cypher_astnode_t *with_clause, // `WITH` clause to validate
1204 validations_ctx *vctx // validation context
1205) {
1206 bool found_simple = false;
1207 bool found_non_simple = false;
1208
1209 for(uint i = 0; i < cypher_ast_with_nprojections(with_clause); i++) {
1210 const cypher_astnode_t *curr_proj =
1211 cypher_ast_with_get_projection(with_clause, i);
1212 const cypher_astnode_t *exp =
1213 cypher_ast_projection_get_expression(curr_proj);
1214 const cypher_astnode_type_t t = cypher_astnode_type(exp);
1215
1216 if (t == CYPHER_AST_IDENTIFIER ) {
1217 const cypher_astnode_t *alias =
1218 cypher_ast_projection_get_alias(curr_proj);
1219 // if this is an internal representation of a variable, skip it
1220 if(alias != NULL && cypher_ast_identifier_get_name(alias)[0] == '@') {
1221 continue;
1222 }
1223 const char *identifier = cypher_ast_identifier_get_name(exp);
1224 int len = strlen(identifier);
1225 if(found_non_simple || alias != NULL) {
1226 return false;
1227 }
1228 found_simple = true;
1229 } else {
1230 // check that the import does not make reference to an outer scope
1231 // identifier. This is invalid:
1232 // 'WITH 1 AS a CALL {WITH a + 1 AS b RETURN b} RETURN b'
1233 if(found_simple ||
1234 !_ValidateSubqueryFirstWithClauseIdentifiers(exp)) {
1235 return false;
1236 }
1237 found_non_simple = true;
1238 }
1239 }
1240
1241 // order by, predicates, limit and skips are not valid
1242 if(cypher_ast_with_get_skip(with_clause) != NULL ||
1243 cypher_ast_with_get_limit(with_clause) != NULL ||
1244 cypher_ast_with_get_order_by(with_clause) != NULL ||
1245 cypher_ast_with_get_predicate(with_clause) != NULL) {
1246
1247 return false;
1248 }
1249
1250 return true;
1251}
1252
1253// validate a CALL {} (subquery) clause
1254static VISITOR_STRATEGY _Validate_call_subquery

Callers 1

_Validate_call_subqueryFunction · 0.85

Tested by

no test coverage detected