From 1619a8ad1da962417e1b23528588129cd42de399 Mon Sep 17 00:00:00 2001 From: xtcyclist <7731943+xtcyclist@users.noreply.github.com> Date: Tue, 21 Mar 2023 11:34:55 +0800 Subject: [PATCH] Fix ExtractFilterExprVisitor. --- .../visitor/ExtractFilterExprVisitor.cpp | 21 ++++++++++++++++--- src/graph/visitor/ExtractFilterExprVisitor.h | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/graph/visitor/ExtractFilterExprVisitor.cpp b/src/graph/visitor/ExtractFilterExprVisitor.cpp index 64ae1d70a71..77692f4d526 100644 --- a/src/graph/visitor/ExtractFilterExprVisitor.cpp +++ b/src/graph/visitor/ExtractFilterExprVisitor.cpp @@ -240,12 +240,26 @@ void ExtractFilterExprVisitor::ExtractRemainExpr(LogicalExpression *expr, extractedExpr_ = operands[0]; } + LogicalExpression *remainedExpr = nullptr; if (remainedOperands.size() > 1) { - auto remainedExpr = LogicalExpression::makeAnd(pool_); + remainedExpr = LogicalExpression::makeAnd(pool_); remainedExpr->setOperands(std::move(remainedOperands)); - remainedExpr_ = std::move(remainedExpr); } else { - remainedExpr_ = std::move(remainedOperands[0]); + remainedExpr = static_cast(std::move(remainedOperands[0])); + } + if (remainedExpr_ != nullptr) { + if (remainedExprFromAnd_) { + auto mergeExpr = LogicalExpression::makeAnd(pool_, remainedExpr_, std::move(remainedExpr)); + remainedExpr_ = std::move(mergeExpr); + remainedExprFromAnd_ = true; + } else { + auto mergeExpr = LogicalExpression::makeOr(pool_, remainedExpr_, std::move(remainedExpr)); + remainedExpr_ = std::move(mergeExpr); + remainedExprFromAnd_ = true; + } + } else { + remainedExpr_ = std::move(remainedExpr); + remainedExprFromAnd_ = true; } } @@ -375,6 +389,7 @@ void ExtractFilterExprVisitor::visit(LogicalExpression *expr) { DCHECK_EQ(expr->kind(), Expression::Kind::kLogicalAnd); DCHECK_EQ(expr->operands().size(), 2); remainedExpr_ = expr->operands()[1]->clone(); + remainedExprFromAnd_ = false; expr->operands().pop_back(); } } else { diff --git a/src/graph/visitor/ExtractFilterExprVisitor.h b/src/graph/visitor/ExtractFilterExprVisitor.h index bf3789001c0..ed917092997 100644 --- a/src/graph/visitor/ExtractFilterExprVisitor.h +++ b/src/graph/visitor/ExtractFilterExprVisitor.h @@ -94,6 +94,7 @@ class ExtractFilterExprVisitor final : public ExprVisitorImpl { bool hasSplit{false}; bool splitForbidden{false}; Expression *remainedExpr_{nullptr}; + bool remainedExprFromAnd_{false}; Expression *extractedExpr_{nullptr}; PushType pushType_{PushType::kGetNeighbors}; std::vector colNames_;