Skip to content

Commit

Permalink
Finish find path when we meet the dead end. (vesoft-inc#1124)
Browse files Browse the repository at this point in the history
  • Loading branch information
CPWstatic authored and dangleptr committed Oct 22, 2019
1 parent e05e342 commit eef0f0e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/executor/FindPathExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ void FindPathExecutor::execute() {
}

void FindPathExecutor::getNeighborsAndFindPath() {
// We meet the dead end.
if (fromVids_.empty() || toVids_.empty()) {
onFinish_();
return;
}

fPro_ = std::make_unique<folly::Promise<folly::Unit>>();
tPro_ = std::make_unique<folly::Promise<folly::Unit>>();
std::vector<folly::Future<folly::Unit>> futures;
Expand Down Expand Up @@ -213,6 +219,8 @@ void FindPathExecutor::findPath() {
VLOG(2) << "Find Path.";
visitedFrom_.clear();
std::multimap<VertexID, Path> pathF;
VLOG(2) << "Get froms: " << fromFrontiers_.second.size();
VLOG(2) << "Get tos: " << toFrontiers_.second.size();
for (auto &frontier : fromFrontiers_.second) {
// Notice: we treat edges with different ranking
// between two vertices as different path
Expand Down Expand Up @@ -275,7 +283,7 @@ void FindPathExecutor::findPath() {
onFinish_();
return;
} else {
LOG(INFO) << "Current step:" << currentStep_;
VLOG(2) << "Current step:" << currentStep_;
++currentStep_;
}
getNeighborsAndFindPath();
Expand Down
63 changes: 63 additions & 0 deletions src/executor/test/FindPathTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,5 +437,68 @@ TEST_F(FindPathTest, multiEdgesAll) {
ASSERT_TRUE(verifyPath(resp, expected));
}
}

TEST_F(FindPathTest, vertexNotExist) {
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND SHORTEST PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto query = folly::stringPrintf(fmt,
std::hash<std::string>()("Nobody1"), std::hash<std::string>()("Nobody2"));
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND SHORTEST PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto &tim = players_["Tim Duncan"];
auto query = folly::stringPrintf(fmt, tim.vid(), std::hash<std::string>()("Nobody"));
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND SHORTEST PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto &tim = players_["Tim Duncan"];
auto query = folly::stringPrintf(fmt, std::hash<std::string>()("Nobody"), tim.vid());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND ALL PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto query = folly::stringPrintf(fmt,
std::hash<std::string>()("Nobody1"), std::hash<std::string>()("Nobody2"));
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND ALL PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto &tim = players_["Tim Duncan"];
auto query = folly::stringPrintf(fmt, tim.vid(), std::hash<std::string>()("Nobody"));
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
{
cpp2::ExecutionResponse resp;
auto *fmt = "FIND ALL PATH FROM %ld TO %ld OVER like UPTO 5 STEPS";
auto &tim = players_["Tim Duncan"];
auto query = folly::stringPrintf(fmt, std::hash<std::string>()("Nobody"), tim.vid());
auto code = client_->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code) << *(resp.get_error_msg());
std::vector<std::string> expected;
ASSERT_TRUE(verifyPath(resp, expected));
}
}
} // namespace graph
} // namespace nebula

0 comments on commit eef0f0e

Please sign in to comment.