Forbid merge with null properties

This commit is contained in:
Josip Mrden 2024-03-12 12:37:43 +01:00
parent a282542666
commit bfd8921777
4 changed files with 42 additions and 3 deletions

View File

@ -745,6 +745,14 @@ bool SymbolGenerator::PreVisit(PatternComprehension &pc) {
return true;
}
bool SymbolGenerator::Visit(PrimitiveLiteral &primitive_literal) {
auto &scope = scopes_.back();
if (scope.in_merge && primitive_literal.value_.IsNull()) {
throw SemanticException("Cannot merge node or relationship entity because of null property value!");
}
return true;
}
bool SymbolGenerator::PostVisit(PatternComprehension & /*pc*/) { return true; }
void SymbolGenerator::VisitWithIdentifiers(Expression *expr, const std::vector<Identifier *> &identifiers) {

View File

@ -71,7 +71,7 @@ class SymbolGenerator : public HierarchicalTreeVisitor {
// Expressions
ReturnType Visit(Identifier &) override;
ReturnType Visit(PrimitiveLiteral &) override { return true; }
ReturnType Visit(PrimitiveLiteral &) override;
bool PreVisit(MapLiteral &) override;
bool PostVisit(MapLiteral &) override { return true; };
ReturnType Visit(ParameterLookup &) override { return true; }

View File

@ -187,7 +187,7 @@ Feature: Merge feature
Then the result should be:
| r |
| [:X] |
Scenario: Merge relationship test02
Given an empty graph
And having executed:
@ -417,4 +417,19 @@ Feature: Merge feature
| ({a: 1}) |
| ({a: 2}) |
| ({a: 3)) |
Scenario: Merge node with null property error
Given an empty graph
When executing query:
"""
MERGE ({id: null})
"""
Then an error should be raised
Scenario: Merge edge with null property error
Given an empty graph
When executing query:
"""
MERGE ()-[:TYPE {id:null}]->()
"""
Then an error should be raised

View File

@ -417,3 +417,19 @@ Feature: Merge feature
| ({a: 1}) |
| ({a: 2}) |
| ({a: 3)) |
Scenario: Merge node with null property error
Given an empty graph
When executing query:
"""
MERGE ({id: null})
"""
Then an error should be raised
Scenario: Merge edge with null property error
Given an empty graph
When executing query:
"""
MERGE ()-[:TYPE {id:null}]->()
"""
Then an error should be raised