Skip to content

Commit

Permalink
fixed bug for delete vertex without edge (vesoft-inc#2001)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
monadbobo authored Mar 31, 2020
1 parent 56385c4 commit 8b7c7ae
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/graph/DeleteVerticesExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,18 @@ void DeleteVerticesExecutor::execute() {
for (auto& response : rpcResp) {
std::unordered_map<EdgeType, std::shared_ptr<ResultSchemaProvider>> 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<ResultSchemaProvider>(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<ResultSchemaProvider>(schema.second));
});

for (auto &vdata : response.vertices) {
auto src = vdata.get_vertex_id();
Expand Down
30 changes: 30 additions & 0 deletions src/graph/test/DeleteVerticesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::tuple<std::string, int64_t>> expected = {};
ASSERT_TRUE(verifyResult(resp, expected));
}
}

} // namespace graph
} // namespace nebula

0 comments on commit 8b7c7ae

Please sign in to comment.