Skip to content

Commit

Permalink
Fix build path. (vesoft-inc#4091)
Browse files Browse the repository at this point in the history
Co-authored-by: jie.wang <38901892+jievince@users.noreply.github.com>
Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 30, 2022
1 parent 808f75a commit 90a2c02
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/common/expression/PathBuildExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ bool PathBuildExpression::buildPath(const Value& value, Path& path) const {
switch (value.type()) {
case Value::Type::EDGE: {
Step step;
bool result = true;
if (!path.steps.empty()) {
getEdge(value, path.steps.back().dst.vid, step);
result = getEdge(value, path.steps.back().dst.vid, step);
} else {
getEdge(value, path.src.vid, step);
result = getEdge(value, path.src.vid, step);
}
if (!result) {
return result;
}
path.steps.emplace_back(std::move(step));
break;
Expand All @@ -68,9 +72,20 @@ bool PathBuildExpression::buildPath(const Value& value, Path& path) const {
break;
}
case Value::Type::LIST: {
bool result = true;
for (const auto& val : value.getList().values) {
if (!buildPath(val, path)) {
return false;
result = false;
break;
}
}
if (!result) {
for (std::vector<Value>::const_reverse_iterator it = value.getList().values.rbegin();
it != value.getList().values.rend();
++it) {
if (!buildPath(*it, path)) {
return false;
}
}
}
break;
Expand Down Expand Up @@ -110,12 +125,14 @@ bool PathBuildExpression::getEdge(const Value& value, const Value& lastStepVid,
step.ranking = edge.ranking;
step.props = edge.props;
step.dst.vid = edge.dst;
} else {
} else if (lastStepVid == edge.dst) {
step.type = -edge.type;
step.name = edge.name;
step.ranking = edge.ranking;
step.props = edge.props;
step.dst.vid = edge.src;
} else {
return false;
}
return true;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/tck/features/bugfix/BuildPathMistake.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2022 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
Feature: Test crash when null path expression

Background:
Given a graph with space named "nba"

Scenario: Null path expression in multiple patterns
When executing query:
"""
MATCH p = ()-[:like*2]->(v:player) WHERE id(v) == 'Grant Hill' RETURN p
"""
Then the result should be, in any order, with relax comparison:
| p |
| <("Yao Ming" :player{age: 38, name: "Yao Ming"})-[:like@0 {likeness: 90}]->("Tracy McGrady" :player{age: 39, name: "Tracy McGrady"})-[:like@0 {likeness: 90}]->("Grant Hill" :player{age: 46, name: "Grant Hill"})> |
| <("Grant Hill" :player{age: 46, name: "Grant Hill"})<-[:like@0 {likeness: 90}]-("Tracy McGrady" :player{age: 39, name: "Tracy McGrady"})<-[:like@0 {likeness: 90}]-("Grant Hill" :player{age: 46, name: "Grant Hill"})> |
| <("Vince Carter" :player{age: 42, name: "Vince Carter"})-[:like@0 {likeness: 90}]->("Tracy McGrady" :player{age: 39, name: "Tracy McGrady"})-[:like@0 {likeness: 90}]->("Grant Hill" :player{age: 46, name: "Grant Hill"})> |

0 comments on commit 90a2c02

Please sign in to comment.