Skip to content

Commit

Permalink
fix the bug of all/any/single/none expr
Browse files Browse the repository at this point in the history
  • Loading branch information
jievince authored and xtcyclist committed Dec 27, 2022
1 parent a0c9b1c commit a30e99b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
44 changes: 27 additions & 17 deletions src/common/expression/PredicateExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ const Value& PredicateExpression::eval(ExpressionContext& ctx) {
auto& v = list[i];
ctx.setInnerVar(innerVar_, v);
auto& filterVal = filter_->eval(ctx);
if (!filterVal.empty() && !filterVal.isNull() && !filterVal.isImplicitBool()) {
if (filterVal.empty() || filterVal.isNull()) {
return Value::kNullValue;
} else if (!filterVal.isImplicitBool()) {
return Value::kNullBadType;
}
if (filterVal.empty() || filterVal.isNull() || !filterVal.implicitBool()) {
} else if (!filterVal.implicitBool()) {
result_ = false;
return result_;
}
Expand All @@ -110,34 +111,42 @@ const Value& PredicateExpression::eval(ExpressionContext& ctx) {
auto& v = list[i];
ctx.setInnerVar(innerVar_, v);
auto& filterVal = filter_->eval(ctx);
if (!filterVal.empty() && !filterVal.isNull() && !filterVal.isImplicitBool()) {
if (filterVal.empty() || filterVal.isNull()) {
result_ = Value::kNullValue;
} else if (!filterVal.isImplicitBool()) {
return Value::kNullBadType;
}
if (filterVal.isBool() && filterVal.implicitBool()) {
} else if (filterVal.implicitBool()) {
result_ = true;
return result_;
}
}
return result_;
}
case Type::SINGLE: {
result_ = false;
bool hasNull = false;
// If there are more than one satisfied, the result is false
bool hasSatisfied = false;
for (size_t i = 0; i < list.size(); ++i) {
auto& v = list[i];
ctx.setInnerVar(innerVar_, v);
auto& filterVal = filter_->eval(ctx);
if (!filterVal.empty() && !filterVal.isNull() && !filterVal.isImplicitBool()) {
if (filterVal.empty() || filterVal.isNull()) {
hasNull = true;
} else if (!filterVal.isImplicitBool()) {
return Value::kNullBadType;
}
if (filterVal.isBool() && filterVal.implicitBool()) {
if (result_ == false) {
result_ = true;
} else {
} else if (filterVal.implicitBool()) {
if (hasSatisfied) {
result_ = false;
return result_;
}
hasSatisfied = true;
}
}
if (hasNull) {
result_ = Value::kNullValue;
} else {
result_ = hasSatisfied;
}
return result_;
}
case Type::NONE: {
Expand All @@ -146,10 +155,12 @@ const Value& PredicateExpression::eval(ExpressionContext& ctx) {
auto& v = list[i];
ctx.setInnerVar(innerVar_, v);
auto& filterVal = filter_->eval(ctx);
if (!filterVal.empty() && !filterVal.isNull() && !filterVal.isImplicitBool()) {
if (filterVal.empty() || filterVal.isNull()) {
result_ = Value::kNullValue;
return result_;
} else if (!filterVal.isImplicitBool()) {
return Value::kNullBadType;
}
if (filterVal.isBool() && filterVal.implicitBool()) {
} else if (filterVal.implicitBool()) {
result_ = false;
return result_;
}
Expand All @@ -159,7 +170,6 @@ const Value& PredicateExpression::eval(ExpressionContext& ctx) {
// no default so the compiler will warning when lack
}

result_ = Value::kNullBadType;
return result_;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/tck/features/expression/Predicate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ Feature: Predicate
Then the result should be, in any order:
| r |
| False |
When executing query:
"""
RETURN ALL(a IN [2, 3, NULL] WHERE a > 0) AS r
"""
Then the result should be, in any order:
| r |
| NULL |
When executing query:
"""
RETURN Any(a IN [2, 3] WHERE a > 1) AS r
Expand Down
2 changes: 1 addition & 1 deletion tests/tck/features/match/PipeAndVariable.feature
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Feature: Pipe/Variable
$v1 = YIELD "Tony Parker" AS a;
LOOKUP ON player WHERE player.name == "Tim Duncan" YIELD player.name AS name, $v1.a
"""
Then a SemanticError should be raised at runtime: unsupport input/variable property expression in yield.
Then a SemanticError should be raised at runtime: unsupported input/variable property expression in yield.

@skip
Scenario: pipe lookup results
Expand Down

0 comments on commit a30e99b

Please sign in to comment.