From 8b7c7ae4ac4f0913203e8696b0ea781bb9aed2b4 Mon Sep 17 00:00:00 2001 From: Simon Liu <331435+monadbobo@users.noreply.github.com> Date: Tue, 31 Mar 2020 19:11:09 +0800 Subject: [PATCH] fixed bug for delete vertex without edge (#2001) * When deleting a vertex, if the edge does not exist, then we should continue to delete the vertex instead of reporting an error. * added the testcase for delete vertex without edge. --- src/graph/DeleteVerticesExecutor.cpp | 22 +++++++++----------- src/graph/test/DeleteVerticesTest.cpp | 30 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/graph/DeleteVerticesExecutor.cpp b/src/graph/DeleteVerticesExecutor.cpp index a424a72b3be..a67cdc3e86c 100644 --- a/src/graph/DeleteVerticesExecutor.cpp +++ b/src/graph/DeleteVerticesExecutor.cpp @@ -111,20 +111,18 @@ void DeleteVerticesExecutor::execute() { for (auto& response : rpcResp) { std::unordered_map> edgeSchema; auto *eschema = response.get_edge_schema(); - if (eschema != nullptr) { - std::transform(eschema->cbegin(), eschema->cend(), - std::inserter(edgeSchema, edgeSchema.begin()), [](auto &schema) { - return std::make_pair( - schema.first, - std::make_shared(schema.second)); - }); + if (eschema == nullptr || eschema->empty()) { + continue; } - if (edgeSchema.empty()) { - LOG(ERROR) << "Can't find edge's schema"; - doError(Status::Error("Can't find edge's schema")); - return; - } + std::transform(eschema->cbegin(), + eschema->cend(), + std::inserter(edgeSchema, edgeSchema.begin()), + [](auto &schema) { + return std::make_pair( + schema.first, + std::make_shared(schema.second)); + }); for (auto &vdata : response.vertices) { auto src = vdata.get_vertex_id(); diff --git a/src/graph/test/DeleteVerticesTest.cpp b/src/graph/test/DeleteVerticesTest.cpp index 773d7518f93..1c552fc38e5 100644 --- a/src/graph/test/DeleteVerticesTest.cpp +++ b/src/graph/test/DeleteVerticesTest.cpp @@ -423,5 +423,35 @@ TEST_F(DeleteVerticesTest, DeleteWithUUID) { } } +TEST_F(DeleteVerticesTest, DeleteNoEdges) { + { + cpp2::ExecutionResponse resp; + auto query = "create space deletenoedges_space"; + auto code = client_->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + query = "use deletenoedges_space"; + code = client_->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + query = "CREATE TAG person(name string, age int)"; + code = client_->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + sleep(2); + query = "INSERT VERTEX person(name, age) VALUES 101:(\"Tony Parker\", 36)"; + code = client_->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + query = "DELETE VERTEX 101"; + code = client_->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + query = "FETCH PROP ON person 101 yield person.name, person.age"; + code = client_->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::vector> expected = {}; + ASSERT_TRUE(verifyResult(resp, expected)); + } +} + } // namespace graph } // namespace nebula