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

Function _ValidateMergeRelation

src/ast/ast_validations.c:215–249  ·  view source on GitHub ↗

Verify that MERGE doesn't redeclare bound relations, that one reltype is specified for unbound relations, and that the entity is not a variable length pattern

Source from the content-addressed store, hash-verified

213// Verify that MERGE doesn't redeclare bound relations, that one reltype is specified for unbound relations,
214// and that the entity is not a variable length pattern
215static AST_Validation _ValidateMergeRelation
216(
217 const cypher_astnode_t *entity, // ast-node (rel-pattern)
218 rax *defined_aliases // bound variables
219) {
220 // Verify that this is not a variable length relationship
221 const cypher_astnode_t *range = cypher_ast_rel_pattern_get_varlength(entity);
222 if(range) {
223 ErrorCtx_SetError("Variable length relationships cannot be used in MERGE");
224 return AST_INVALID;
225 }
226
227 const cypher_astnode_t *identifier = cypher_ast_rel_pattern_get_identifier(entity);
228 const char *alias = NULL;
229 if(identifier) {
230 alias = cypher_ast_identifier_get_name(identifier);
231 // Verify that we're not redeclaring a bound variable
232 if(raxFind(defined_aliases, (unsigned char *)alias, strlen(alias)) != raxNotFound) {
233 ErrorCtx_SetError("The bound variable %s' can't be redeclared in a MERGE clause", alias);
234 return AST_INVALID;
235 }
236 }
237
238 // Exactly one reltype should be specified for the introduced edge
239 uint reltype_count = cypher_ast_rel_pattern_nreltypes(entity);
240 if(reltype_count != 1) {
241 ErrorCtx_SetError("Exactly one relationship type must be specified for each relation in a MERGE pattern.");
242 return AST_INVALID;
243 }
244
245 // We don't need to validate the MERGE edge's direction, as an undirected edge
246 // in MERGE should result a single outgoing edge to be created.
247
248 return AST_VALID;
249}
250
251// Verify that MERGE does not introduce labels or properties to bound nodes
252static AST_Validation _ValidateMergeNode

Callers 1

_Validate_rel_patternFunction · 0.85

Calls 1

ErrorCtx_SetErrorFunction · 0.85

Tested by

no test coverage detected