Modify logaical operators to conform openCyper regarding checking against NULL in CASE expressions (#432)

* Make `IfOperator` return the `else_expression_` in case of `NULL`

* Add gql_behave tests

* Add gql_behave test to specifically check for the case when the test expression itself is null
This commit is contained in:
gvolfing 2022-07-11 15:00:29 +02:00 committed by GitHub
parent 7fc0fb6520
commit 6fe474282a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 1 deletions

View File

@ -111,7 +111,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
TypedValue Visit(IfOperator &if_operator) override {
auto condition = if_operator.condition_->Accept(*this);
if (condition.IsNull()) {
return if_operator.then_expression_->Accept(*this);
return if_operator.else_expression_->Accept(*this);
}
if (condition.type() != TypedValue::Type::Bool) {
// At the moment IfOperator is used only in CASE construct.

View File

@ -57,3 +57,43 @@ Feature: Case
Then the result should be:
| z |
| ['nottwo', 'two', 'nottwo'] |
Scenario: Simple CASE nullcheck does not have match:
Given an empty graph
When executing query:
"""
WITH 2 AS name RETURN CASE name WHEN 3 THEN 'something went wrong' WHEN null THEN "doesn't work" ELSE 'works' END
"""
Then the result should be:
| CASE name WHEN 3 THEN 'something went wrong' WHEN null THEN "doesn't work" ELSE 'works' END |
| 'works' |
Scenario: Simple CASE nullcheck does have match:
Given an empty graph
When executing query:
"""
WITH 2 AS name RETURN CASE name WHEN 2 THEN 'works' WHEN null THEN "doesn't work" ELSE 'something went wrong' END
"""
Then the result should be:
| CASE name WHEN 2 THEN 'works' WHEN null THEN "doesn't work" ELSE 'something went wrong' END |
| 'works' |
Scenario: Generic CASE nullcheck does have match:
Given an empty graph
When executing query:
"""
WITH 2 AS name RETURN CASE WHEN name is NULL THEN "doesn't work" WHEN name = 2 THEN "works" ELSE "something went wrong" END
"""
Then the result should be:
| CASE WHEN name is NULL THEN "doesn't work" WHEN name = 2 THEN "works" ELSE "something went wrong" END |
| 'works' |
Scenario: Generic CASE expression is null:
Given an empty graph
When executing query:
"""
WITH null AS name RETURN CASE name WHEN null THEN "doesn't work" WHEN 2 THEN "doesn't work" ELSE 'works' END
"""
Then the result should be:
| CASE name WHEN null THEN "doesn't work" WHEN 2 THEN "doesn't work" ELSE 'works' END |
| 'works' |