Skip to content

Commit

Permalink
fix vid select error
Browse files Browse the repository at this point in the history
  • Loading branch information
nevermore3 committed Jan 13, 2022
1 parent 34e2e7c commit afa027c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 33 deletions.
4 changes: 4 additions & 0 deletions src/graph/planner/match/VertexIdSeek.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ bool VertexIdSeek::matchNode(NodeContext *nodeCtx) {
if (vidResult.spec != VidExtractVisitor::VidPattern::Special::kInUsed) {
return false;
}
if (vidResult.nodes.size() > 1) {
// where id(v) == 'xxx' or id(t) == 'yyy'
return false;
}
for (auto &nodeVid : vidResult.nodes) {
if (nodeVid.second.kind == VidExtractVisitor::VidPattern::Vids::Kind::kIn) {
if (nodeVid.first == node.alias) {
Expand Down
18 changes: 9 additions & 9 deletions src/graph/util/ExpressionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,32 +570,32 @@ Expression *ExpressionUtils::rewriteRelExprHelper(const Expression *expr,
}

StatusOr<Expression *> ExpressionUtils::filterTransform(const Expression *filter) {
// Check if any overflow happen before filter tranform
auto initialConstFold = foldConstantExpr(filter);
NG_RETURN_IF_ERROR(initialConstFold);
auto newFilter = initialConstFold.value();

// If the filter contains more than one different Label expr, this filter cannot be
// pushed down, such as where v1.player.name == 'xxx' or v2.player.age == 20
auto propExprs = ExpressionUtils::collectAll(filter, {Expression::Kind::kLabel});
auto propExprs = ExpressionUtils::collectAll(newFilter, {Expression::Kind::kLabel});
// Deduplicate the list
std::unordered_set<std::string> dedupPropExprSet;
for (auto &iter : propExprs) {
dedupPropExprSet.emplace(iter->toString());
}
if (dedupPropExprSet.size() > 1) {
return const_cast<Expression *>(filter);
return const_cast<Expression *>(newFilter);
}

// Check if any overflow happen before filter tranform
auto initialConstFold = foldConstantExpr(filter);
NG_RETURN_IF_ERROR(initialConstFold);

// Rewrite relational expression
auto rewrittenExpr = initialConstFold.value();
rewrittenExpr = rewriteRelExpr(rewrittenExpr);
auto rewrittenExpr = rewriteRelExpr(newFilter);

// Fold constant expression
auto constantFoldRes = foldConstantExpr(rewrittenExpr);
// If errors like overflow happened during the constant fold, stop transferming and return the
// original expression
if (!constantFoldRes.ok()) {
return const_cast<Expression *>(filter);
return const_cast<Expression *>(newFilter);
}
rewrittenExpr = constantFoldRes.value();

Expand Down
35 changes: 17 additions & 18 deletions tests/tck/features/match/SeekById.feature
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,23 @@ Feature: Match seek by id
RETURN v.player.name AS Name, t.team.name AS Team
"""
Then the result should be, in any order:
| Name | Team |
| 'Paul Gasol' | 'Grizzlies' |
| 'Paul Gasol' | 'Lakers' |
| 'Paul Gasol' | 'Bulls' |
| 'Paul Gasol' | 'Spurs' |
| 'Paul Gasol' | 'Bucks' |
| Name | Team |
| "Paul Gasol" | "Bucks" |
| "Paul Gasol" | "Bulls" |
| "Rudy Gay" | "Grizzlies" |
| "Kyle Anderson" | "Grizzlies" |
| "Paul Gasol" | "Grizzlies" |
| "Marc Gasol" | "Grizzlies" |
| "Vince Carter" | "Grizzlies" |
| "Paul Gasol" | "Spurs" |
| "Dwight Howard" | "Lakers" |
| "Shaquille O'Neal" | "Lakers" |
| "Steve Nash" | "Lakers" |
| "Paul Gasol" | "Lakers" |
| "Kobe Bryant" | "Lakers" |
| "JaVale McGee" | "Lakers" |
| "Rajon Rondo" | "Lakers" |
| "LeBron James" | "Lakers" |

Scenario: can't refer
When executing query:
Expand Down Expand Up @@ -327,18 +338,6 @@ Feature: Match seek by id
Then the result should be, in any order:
| v |
| ("Tim Duncan" :bachelor{name: "Tim Duncan", speciality: "psychology"} :player{age: 42, name: "Tim Duncan"}) |
When executing query:
"""
MATCH (v:player)-[e:like]->(t)
WHERE "Tim Duncan" == v.player.name
OR 25 - 2 == v.player.age
RETURN t
"""
Then the result should be, in any order:
| t |
| ("Tony Parker" :player{age: 36, name: "Tony Parker"}) |
| ("Luka Doncic" :player{age: 20, name: "Luka Doncic"}) |
| ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) |

Scenario: Start from end
When executing query:
Expand Down
23 changes: 17 additions & 6 deletions tests/tck/features/match/SeekById.intVid.feature
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,23 @@ Feature: Match seek by id
RETURN v.player.name AS Name, t.team.name AS Team
"""
Then the result should be, in any order:
| Name | Team |
| 'Paul Gasol' | 'Grizzlies' |
| 'Paul Gasol' | 'Lakers' |
| 'Paul Gasol' | 'Bulls' |
| 'Paul Gasol' | 'Spurs' |
| 'Paul Gasol' | 'Bucks' |
| Name | Team |
| "Paul Gasol" | "Bucks" |
| "Paul Gasol" | "Bulls" |
| "Rudy Gay" | "Grizzlies" |
| "Kyle Anderson" | "Grizzlies" |
| "Paul Gasol" | "Grizzlies" |
| "Marc Gasol" | "Grizzlies" |
| "Vince Carter" | "Grizzlies" |
| "Paul Gasol" | "Spurs" |
| "Dwight Howard" | "Lakers" |
| "Shaquille O'Neal" | "Lakers" |
| "Steve Nash" | "Lakers" |
| "Paul Gasol" | "Lakers" |
| "Kobe Bryant" | "Lakers" |
| "JaVale McGee" | "Lakers" |
| "Rajon Rondo" | "Lakers" |
| "LeBron James" | "Lakers" |

Scenario: can't refer
When executing query:
Expand Down

0 comments on commit afa027c

Please sign in to comment.