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 shortest path crash #5472

Merged
merged 5 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions src/graph/executor/algo/BatchShortestPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ namespace graph {
folly::Future<Status> BatchShortestPath::execute(const HashSet& startVids,
const HashSet& endVids,
DataSet* result) {
if (maxStep_ == 0) {
return Status::OK();
}
// MemoryTrackerVerified
size_t rowSize = init(startVids, endVids);
std::vector<folly::Future<Status>> futures;
Expand Down
3 changes: 3 additions & 0 deletions src/graph/executor/algo/SingleShortestPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace graph {
folly::Future<Status> SingleShortestPath::execute(const HashSet& startVids,
const HashSet& endVids,
DataSet* result) {
if (maxStep_ == 0) {
return Status::OK();
}
size_t rowSize = startVids.size() * endVids.size();
init(startVids, endVids, rowSize);
std::vector<folly::Future<Status>> futures;
Expand Down
11 changes: 7 additions & 4 deletions src/graph/validator/MatchValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,13 @@ Status MatchValidator::buildPathExpr(const MatchPath *path,
return Status::SemanticError(
"`shortestPath(...)' only support pattern like (start)-[edge*..hop]-(end)");
}
auto min = edgeInfos.front().range->min();
if (min != 0 && min != 1) {
return Status::SemanticError(
"`shortestPath(...)' does not support a minimal length different from 0 or 1");
auto *range = edgeInfos.front().range.get();
if (range != nullptr) {
auto min = range->min();
if (min != 0 && min != 1) {
return Status::SemanticError(
"The minimal number of steps for shortestPath() must be either 0 or 1.");
}
}
pathInfo.pathType = static_cast<Path::PathType>(pathType);
}
Expand Down
104 changes: 104 additions & 0 deletions tests/tck/features/match/AllShortestPaths.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,110 @@ Feature: allShortestPaths
Background:
Given a graph with space named "nba"

Scenario: shortest path invalid step
When executing query:
"""
WITH ["Tim Duncan","Tony Parker"] as list1
MATCH allShortestPaths((v1:player)-[e*2]-(v2:player))
WHERE id(v1) in list1 AND id(v2) in list1
RETURN e
"""
Then a SemanticError should be raised at runtime: The minimal number of steps for shortestPath() must be either 0 or 1.
When executing query:
"""
WITH ["Tim Duncan","Tony Parker"] as list1
MATCH allShortestPaths((v1:player)-[e*2..4]-(v2:player))
WHERE id(v1) in list1 AND id(v2) in list1
RETURN e
"""
Then a SemanticError should be raised at runtime: The minimal number of steps for shortestPath() must be either 0 or 1.
When executing query:
"""
WITH ["Tim Duncan","Tony Parker"] as list1
MATCH allShortestPaths((v1:player)-[e]->(b)--(v2:player))
WHERE id(v1) in list1 AND id(v2) in list1
RETURN e
"""
Then a SemanticError should be raised at runtime: `shortestPath(...)' only support pattern like (start)-[edge*..hop]-(end)
When executing query:
"""
WITH ["Tim Duncan","Tony Parker"] as list1
MATCH allShortestPaths((v1:player)-[e]->(b)-[e2:like]-(v2:player))
WHERE id(v1) in list1 AND id(v2) in list1
RETURN e
"""
Then a SemanticError should be raised at runtime: `shortestPath(...)' only support pattern like (start)-[edge*..hop]-(end)

Scenario: zero step shortest path
When executing query:
"""
WITH ["Tim Duncan","Tony Parker"] as list1
MATCH allShortestPaths((v1:player)-[e*0]-(v2:player))
WHERE id(v1) in list1 AND id(v2) in list1
RETURN e
"""
Then the result should be, in any order, with relax comparison:
| e |
When executing query:
"""
MATCH allShortestPaths((v1:player{name:"Tim Duncan"})-[e*0]-(v2:player{name:"Tony Parker"}))
RETURN e
"""
Then the result should be, in any order, with relax comparison:
| e |

Scenario: one step shortest path
When executing query:
"""
WITH ["Tim Duncan","Tony Parker"] as list1
MATCH allShortestPaths((v1:player)-[e]-(v2:player))
WHERE id(v1) in list1 AND id(v2) in list1
RETURN e
"""
Then the result should be, in any order, with relax comparison:
| e |
| [:like "Tony Parker"->"Tim Duncan" @0 {likeness: 95}] |
| [:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}] |
| [:teammate "Tony Parker"->"Tim Duncan" @0 {end_year: 2016, start_year: 2001}] |
| [:teammate "Tim Duncan"->"Tony Parker" @0 {end_year: 2016, start_year: 2001}] |
| [:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}] |
| [:like "Tony Parker"->"Tim Duncan" @0 {likeness: 95}] |
| [:teammate "Tim Duncan"->"Tony Parker" @0 {end_year: 2016, start_year: 2001}] |
| [:teammate "Tony Parker"->"Tim Duncan" @0 {end_year: 2016, start_year: 2001}] |
When executing query:
"""
MATCH allShortestPaths((v1:player{name:"Tim Duncan"})-[e]-(v2:player{name:"Tony Parker"}))
RETURN e
"""
Then the result should be, in any order, with relax comparison:
| e |
| [:teammate "Tony Parker"->"Tim Duncan" @0 {end_year: 2016, start_year: 2001}] |
| [:teammate "Tim Duncan"->"Tony Parker" @0 {end_year: 2016, start_year: 2001}] |
| [:like "Tony Parker"->"Tim Duncan" @0 {likeness: 95}] |
| [:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}] |
When executing query:
"""
MATCH allShortestPaths((v1:player{name:"Tim Duncan"})-[e*1]-(v2:player{name:"Tony Parker"}))
RETURN e
"""
Then the result should be, in any order, with relax comparison:
| e |
| [[:teammate "Tony Parker"->"Tim Duncan" @0 {end_year: 2016, start_year: 2001}]] |
| [[:teammate "Tim Duncan"->"Tony Parker" @0 {end_year: 2016, start_year: 2001}]] |
| [[:like "Tony Parker"->"Tim Duncan" @0 {likeness: 95}]] |
| [[:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}]] |
When executing query:
"""
MATCH allShortestPaths((v1:player{name:"Tim Duncan"})-[e*1..1]-(v2:player{name:"Tony Parker"}))
RETURN e
"""
Then the result should be, in any order, with relax comparison:
| e |
| [[:teammate "Tony Parker"->"Tim Duncan" @0 {end_year: 2016, start_year: 2001}]] |
| [[:teammate "Tim Duncan"->"Tony Parker" @0 {end_year: 2016, start_year: 2001}]] |
| [[:like "Tony Parker"->"Tim Duncan" @0 {likeness: 95}]] |
| [[:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}]] |

Scenario: allShortestPaths1
When executing query:
"""
Expand Down
52 changes: 52 additions & 0 deletions tests/tck/features/match/SingleShorestPath.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,58 @@ Feature: single shortestPath
Background:
Given a graph with space named "nba"

Scenario: shortest path invalid step
When executing query:
"""
WITH ["Tim Duncan","Tony Parker"] as list1
MATCH shortestPath((v1:player)-[e*2]-(v2:player))
WHERE id(v1) in list1 AND id(v2) in list1
RETURN e
"""
Then a SemanticError should be raised at runtime: The minimal number of steps for shortestPath() must be either 0 or 1.
When executing query:
"""
WITH ["Tim Duncan","Tony Parker"] as list1
MATCH shortestPath((v1:player)-[e*2..4]-(v2:player))
WHERE id(v1) in list1 AND id(v2) in list1
RETURN e
"""
Then a SemanticError should be raised at runtime: The minimal number of steps for shortestPath() must be either 0 or 1.
When executing query:
"""
WITH ["Tim Duncan","Tony Parker"] as list1
MATCH shortestPath((v1:player)-[e]->(b)--(v2:player))
WHERE id(v1) in list1 AND id(v2) in list1
RETURN e
"""
Then a SemanticError should be raised at runtime: `shortestPath(...)' only support pattern like (start)-[edge*..hop]-(end)
When executing query:
"""
WITH ["Tim Duncan","Tony Parker"] as list1
MATCH shortestPath((v1:player)-[e]->(b)-[e2:like]-(v2:player))
WHERE id(v1) in list1 AND id(v2) in list1
RETURN e
"""
Then a SemanticError should be raised at runtime: `shortestPath(...)' only support pattern like (start)-[edge*..hop]-(end)

Scenario: zero step shortestpath
When executing query:
"""
WITH ["Tim Duncan","Tony Parker"] as list1
MATCH shortestPath((v1:player)-[e*0]-(v2:player))
WHERE id(v1) in list1 AND id(v2) in list1
RETURN e
"""
Then the result should be, in any order, with relax comparison:
| e |
When executing query:
"""
MATCH shortestPath((v1:player{name:"Tim Duncan"})-[e*0]-(v2:player{name:"Tony Parker"}))
RETURN e
"""
Then the result should be, in any order, with relax comparison:
| e |

Scenario: single shortestPath1
When executing query:
"""
Expand Down