Skip to content

Commit

Permalink
Modify the behavior of rpc interface getProps when VertexProp/EdgePro…
Browse files Browse the repository at this point in the history
…p is empty (#4832)
  • Loading branch information
czpmango authored Nov 7, 2022
1 parent eb51615 commit fa7f42b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 48 deletions.
6 changes: 2 additions & 4 deletions src/storage/query/GetPropProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,7 @@ nebula::cpp2::ErrorCode GetPropProcessor::checkAndBuildContexts(const cpp2::GetP

nebula::cpp2::ErrorCode GetPropProcessor::buildTagContext(const cpp2::GetPropRequest& req) {
// req.vertex_props_ref().has_value() checked in method checkRequest
auto returnProps =
(*req.vertex_props_ref()).empty() ? buildAllTagProps() : *req.vertex_props_ref();
auto returnProps = *req.vertex_props_ref();
auto ret = handleVertexProps(returnProps);
if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) {
return ret;
Expand All @@ -298,8 +297,7 @@ nebula::cpp2::ErrorCode GetPropProcessor::buildTagContext(const cpp2::GetPropReq

nebula::cpp2::ErrorCode GetPropProcessor::buildEdgeContext(const cpp2::GetPropRequest& req) {
// req.edge_props_ref().has_value() checked in method checkRequest
auto returnProps = (*req.edge_props_ref()).empty() ? buildAllEdgeProps(cpp2::EdgeDirection::BOTH)
: *req.edge_props_ref();
auto returnProps = *req.edge_props_ref();
auto ret = handleEdgeProps(returnProps);
if (ret != nebula::cpp2::ErrorCode::SUCCEEDED) {
return ret;
Expand Down
96 changes: 52 additions & 44 deletions src/storage/test/GetPropTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ TEST(GetPropTest, AllPropertyInAllSchemaTest) {
LOG(INFO) << "GetVertexProp";
std::vector<VertexID> vertices = {"Tim Duncan"};
std::vector<std::pair<TagID, std::vector<std::string>>> tags;
TagID player = 1;
tags.emplace_back(std::make_pair(player, std::vector<std::string>()));
auto req = buildVertexRequest(totalParts, vertices, tags);

auto* processor = GetPropProcessor::instance(env, nullptr, nullptr);
Expand All @@ -445,14 +447,10 @@ TEST(GetPropTest, AllPropertyInAllSchemaTest) {
// The first one is kVid, and player 11 properties in value
std::vector<Value> values{
"Tim Duncan", "Tim Duncan", 44, false, 19, 1997, 2016, 1392, 19.0, 1, "America", 5};
// team: 1 property, tag3: 11 property, in total 12
for (size_t i = 0; i < 12; i++) {
values.emplace_back(Value());
}
row.values = std::move(values);
expected.emplace_back(std::move(row));
// kVid, player: 11, team: 1, tag3: 11
ASSERT_EQ(1 + 11 + 1 + 11, (*resp.props_ref()).colNames.size());
// kVid, player: 11
ASSERT_EQ(1 + 11, (*resp.props_ref()).colNames.size());
verifyResult(expected, *resp.props_ref());
}
}
Expand All @@ -468,6 +466,34 @@ TEST(GetPropTest, AllPropertyInAllSchemaTest) {
edgeKeys.emplace_back(std::move(edgeKey));
}
std::vector<std::pair<TagID, std::vector<std::string>>> edges;
EdgeType serve = 101;
EdgeType teammate = 102;
edges.emplace_back(
-teammate,
std::vector<std::string>{"player1", "player2", "teamName", "startYear", "endYear"});
edges.emplace_back(-serve,
std::vector<std::string>{"playerName",
"teamName",
"startYear",
"endYear",
"teamCareer",
"teamGames",
"teamAvgScore",
"type",
"champions"});
edges.emplace_back(serve,
std::vector<std::string>{"playerName",
"teamName",
"startYear",
"endYear",
"teamCareer",
"teamGames",
"teamAvgScore",
"type",
"champions"});
edges.emplace_back(
-teammate,
std::vector<std::string>{"player1", "player2", "teamName", "startYear", "endYear"});
auto req = buildEdgeRequest(totalParts, edgeKeys, edges);

auto* processor = GetPropProcessor::instance(env, nullptr, nullptr);
Expand Down Expand Up @@ -531,6 +557,10 @@ TEST(GetPropTest, AllPropertyInAllSchemaTest) {
LOG(INFO) << "GetNotExisted";
std::vector<VertexID> vertices = {"Not existed", "Tim Duncan"};
std::vector<std::pair<TagID, std::vector<std::string>>> tags;
TagID player = 1;
tags.emplace_back(std::make_pair(player, std::vector<std::string>()));
TagID team = 2;
tags.emplace_back(std::make_pair(team, std::vector<std::string>()));
auto req = buildVertexRequest(totalParts, vertices, tags);

auto* processor = GetPropProcessor::instance(env, nullptr, nullptr);
Expand All @@ -545,14 +575,12 @@ TEST(GetPropTest, AllPropertyInAllSchemaTest) {
// The first one is kVid, and player have 11 properties in key and value
std::vector<Value> values{
"Tim Duncan", "Tim Duncan", 44, false, 19, 1997, 2016, 1392, 19.0, 1, "America", 5};
// team: 1 property, tag3: 11 property, in total 12
for (size_t i = 0; i < 12; i++) {
values.emplace_back(Value());
}
// team: 1 property
values.emplace_back(Value());
row.values = std::move(values);
expected.emplace_back(std::move(row));
// kVid, player: 11, team: 1, tag3: 11
ASSERT_EQ(1 + 11 + 1 + 11, (*resp.props_ref()).colNames.size());
// kVid, player: 11, team: 1
ASSERT_EQ(1 + 11 + 1, (*resp.props_ref()).colNames.size());
verifyResult(expected, *resp.props_ref());
}
}
Expand All @@ -572,30 +600,20 @@ TEST(GetPropTest, AllPropertyInAllSchemaTest) {
std::vector<nebula::Row> expected;
{
nebula::Row row;
// The first one is kVid, and player have 11 properties in key and value
std::vector<Value> values{
"Tony Parker", "Tony Parker", 38, false, 18, 2001, 2019, 1254, 15.5, 2, "France", 4};
// team: 1 property, tag3: 11 property, in total 12
for (size_t i = 0; i < 12; i++) {
values.emplace_back(Value());
}
// The first one is kVid
std::vector<Value> values{"Tony Parker"};
row.values = std::move(values);
expected.emplace_back(std::move(row));
}
{
nebula::Row row;
// The first one is kVid, and player have 11 properties in key and value
std::vector<Value> values{
"Tim Duncan", "Tim Duncan", 44, false, 19, 1997, 2016, 1392, 19.0, 1, "America", 5};
// team: 1 property, tag3: 11 property, in total 12
for (size_t i = 0; i < 12; i++) {
values.emplace_back(Value());
}
// The first one is kVid
std::vector<Value> values{"Tim Duncan"};
row.values = std::move(values);
expected.emplace_back(std::move(row));
}
// kVid, player: 11, team: 1, tag3: 11
ASSERT_EQ(1 + 11 + 1 + 11, (*resp.props_ref()).colNames.size());
// Only return kVid bcz tags is empty
ASSERT_EQ(1, (*resp.props_ref()).colNames.size());
verifyResult(expected, *resp.props_ref());
}
}
Expand Down Expand Up @@ -628,30 +646,20 @@ TEST(GetPropTest, ConcurrencyTest) {
std::vector<nebula::Row> expected;
{
nebula::Row row;
// The first one is kVid, and player have 11 properties in key and value
std::vector<Value> values{
"Tony Parker", "Tony Parker", 38, false, 18, 2001, 2019, 1254, 15.5, 2, "France", 4};
// team: 1 property, tag3: 11 property, in total 12
for (size_t i = 0; i < 12; i++) {
values.emplace_back(Value());
}
// Only return kVid bcz tags is empty
std::vector<Value> values{"Tony Parker"};
row.values = std::move(values);
expected.emplace_back(std::move(row));
}
{
nebula::Row row;
// The first one is kVid, and player have 11 properties in key and value
std::vector<Value> values{
"Tim Duncan", "Tim Duncan", 44, false, 19, 1997, 2016, 1392, 19.0, 1, "America", 5};
// team: 1 property, tag3: 11 property, in total 12
for (size_t i = 0; i < 12; i++) {
values.emplace_back(Value());
}
// Only return kVid bcz tags is empty
std::vector<Value> values{"Tim Duncan"};
row.values = std::move(values);
expected.emplace_back(std::move(row));
}
// kVid, player: 11, team: 1, tag3: 11
ASSERT_EQ(1 + 11 + 1 + 11, (*resp.props_ref()).colNames.size());
// kVid
ASSERT_EQ(1, (*resp.props_ref()).colNames.size());
verifyResult(expected, *resp.props_ref());
}
}
Expand Down

0 comments on commit fa7f42b

Please sign in to comment.