diff --git a/src/executor/FindPathExecutor.cpp b/src/executor/FindPathExecutor.cpp index 49cd9bc78e3bd9a8f72359d00aba95efa0bd771b..2a77b732ebc42c794f9991646f776b8f251448be 100644 --- a/src/executor/FindPathExecutor.cpp +++ b/src/executor/FindPathExecutor.cpp @@ -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; @@ -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 @@ -275,7 +283,7 @@ void FindPathExecutor::findPath() { onFinish_(); return; } else { - LOG(INFO) << "Current step:" << currentStep_; + VLOG(2) << "Current step:" << currentStep_; ++currentStep_; } getNeighborsAndFindPath(); diff --git a/src/executor/test/FindPathTest.cpp b/src/executor/test/FindPathTest.cpp index 6bc6d6f281499fd6549f6b2b4078c879423281d9..a0d3736c8cfdb0f4952947596fcf77e91140ddf1 100644 --- a/src/executor/test/FindPathTest.cpp +++ b/src/executor/test/FindPathTest.cpp @@ -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