Skip to content

Commit

Permalink
fix tck
Browse files Browse the repository at this point in the history
  • Loading branch information
czpmango committed Nov 23, 2022
1 parent bdd612e commit 634ea61
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/graph/util/ExpressionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,32 @@ Expression *ExpressionUtils::rewriteStartsWithExpr(const Expression *expr) {
return LogicalExpression::makeAnd(pool, resultLeft, resultRight);
}

Expression *ExpressionUtils::foldInnerLogicalExpr(const Expression *originExpr) {
auto matcher = [](const Expression *e) -> bool {
return e->kind() == Expression::Kind::kLogicalAnd || e->kind() == Expression::Kind::kLogicalOr;
};
auto rewriter = [](const Expression *e) -> Expression * {
auto expr = e->clone();
auto &operands = static_cast<LogicalExpression *>(expr)->operands();
for (auto iter = operands.begin(); iter != operands.end();) {
if (*iter == nullptr) {
operands.erase(iter);
} else {
iter++;
}
}
auto n = operands.size();
if (n == 0) {
return nullptr;
} else if (n == 1) {
return operands[0];
}
return expr;
};

return RewriteVisitor::transform(originExpr, std::move(matcher), std::move(rewriter));
}

Expression *ExpressionUtils::rewriteLogicalAndToLogicalOr(const Expression *expr) {
DCHECK(expr->kind() == Expression::Kind::kLogicalAnd);

Expand Down
2 changes: 2 additions & 0 deletions src/graph/util/ExpressionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class ExpressionUtils {
// (A or B) and (C or D) => (A and C) or (A and D) or (B and C) or (B or D)
static Expression* rewriteLogicalAndToLogicalOr(const Expression* expr);

static Expression* foldInnerLogicalExpr(const Expression* expr);

// Returns the operands of container expressions
// For list and set, return the operands
// For map, return the keys
Expand Down
6 changes: 4 additions & 2 deletions src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,8 +1124,10 @@ Status MatchValidator::validatePathInWhere(
if (extractMultiPathPredicate(expr, pathPreds)) {
wctx.filter = nullptr;
} else {
// Flatten the inner logical expressions that already have operands that can be compacted
wctx.filter = ExpressionUtils::flattenInnerLogicalExpr(expr);
// Flatten and fold the inner logical expressions that already have operands that can be
// compacted
wctx.filter =
ExpressionUtils::foldInnerLogicalExpr(ExpressionUtils::flattenInnerLogicalExpr(expr));
}
for (auto &pred : pathPreds) {
NG_RETURN_IF_ERROR(checkMatchPathExpr(pred, availableAliases));
Expand Down

0 comments on commit 634ea61

Please sign in to comment.