Skip to content

Commit

Permalink
fix bug of reduce unary not for logic xor (#5091)
Browse files Browse the repository at this point in the history
Co-authored-by: Yichen Wang <18348405+Aiee@users.noreply.github.com>
  • Loading branch information
jievince and Aiee committed Dec 26, 2022
1 parent 8e7aa68 commit 9863ff0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/graph/optimizer/rule/UnionAllIndexScanBaseRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ bool UnionAllIndexScanBaseRule::match(OptContext* ctx, const MatchedResult& matc
auto conditionType = condition->kind();

if (condition->isLogicalExpr()) {
// Case1: OR Expr
if (conditionType == ExprKind::kLogicalOr) {
return true;
}
// Case2: AND Expr
// Don't support XOR yet
if (conditionType == ExprKind::kLogicalXor) return false;
if (graph::ExpressionUtils::findAny(static_cast<LogicalExpression*>(condition),
{ExprKind::kLogicalXor}))
return false;
if (conditionType == ExprKind::kLogicalOr) return true;
if (conditionType == ExprKind::kLogicalAnd &&
graph::ExpressionUtils::findAny(static_cast<LogicalExpression*>(condition),
{ExprKind::kRelIn})) {
Expand Down
3 changes: 2 additions & 1 deletion src/graph/util/ExpressionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ Expression *ExpressionUtils::reduceUnaryNotExpr(const Expression *expr) {
auto operandMatcher = [](const Expression *operandExpr) -> bool {
return (operandExpr->kind() == Expression::Kind::kUnaryNot ||
(operandExpr->isRelExpr() && operandExpr->kind() != Expression::Kind::kRelREG) ||
operandExpr->isLogicalExpr());
operandExpr->kind() == Expression::Kind::kLogicalAnd ||
operandExpr->kind() == Expression::Kind::kLogicalOr);
};

// Match the root expression
Expand Down
27 changes: 25 additions & 2 deletions tests/tck/features/expression/LogicalExpression.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# This source code is licensed under Apache 2.0 License.
Feature: Logical Expression

Scenario: xor crash bug fix 1
Background:
Given a graph with space named "nba"

Scenario: xor
When executing query:
"""
match (v0:player)-[e:serve]->(v1) where not ((e.start_year == 1997 xor e.end_year != 2016) or (e.start_year > 1000 and e.end_year < 3000)) return count(*)
Expand All @@ -18,4 +20,25 @@ Feature: Logical Expression
"""
Then the result should be, in any order:
| count(*) |
| 140 |
| 12 |
When executing query:
"""
match (v0:player)-[e:serve]->(v1) with not ((e.start_year == 1997 xor e.end_year != 2016) and (e.start_year > 1000 and e.end_year < 3000)) AS a where a return count(*)
"""
Then the result should be, in any order:
| count(*) |
| 12 |
When executing query:
"""
WITH 1 AS a WHERE NOT((NOT TRUE) XOR TRUE) RETURN COUNT(*)
"""
Then the result should be, in any order:
| COUNT(*) |
| 0 |
When executing query:
"""
WITH 1 AS a RETURN NOT((NOT TRUE) XOR TRUE) AS b
"""
Then the result should be, in any order:
| b |
| false |

0 comments on commit 9863ff0

Please sign in to comment.