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:
parent
7fc0fb6520
commit
6fe474282a
@ -111,7 +111,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
|||||||
TypedValue Visit(IfOperator &if_operator) override {
|
TypedValue Visit(IfOperator &if_operator) override {
|
||||||
auto condition = if_operator.condition_->Accept(*this);
|
auto condition = if_operator.condition_->Accept(*this);
|
||||||
if (condition.IsNull()) {
|
if (condition.IsNull()) {
|
||||||
return if_operator.then_expression_->Accept(*this);
|
return if_operator.else_expression_->Accept(*this);
|
||||||
}
|
}
|
||||||
if (condition.type() != TypedValue::Type::Bool) {
|
if (condition.type() != TypedValue::Type::Bool) {
|
||||||
// At the moment IfOperator is used only in CASE construct.
|
// At the moment IfOperator is used only in CASE construct.
|
||||||
|
@ -57,3 +57,43 @@ Feature: Case
|
|||||||
Then the result should be:
|
Then the result should be:
|
||||||
| z |
|
| z |
|
||||||
| ['nottwo', 'two', 'nottwo'] |
|
| ['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' |
|
||||||
|
Loading…
Reference in New Issue
Block a user