Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug of reduce unary not for logic xor #5091

Merged
merged 2 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
jievince marked this conversation as resolved.
Show resolved Hide resolved
};

// 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 |
Aiee marked this conversation as resolved.
Show resolved Hide resolved
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 |