From 3a9f179ebd2e5550e3f793b6ef352bcf3db79eff Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Mon, 7 Nov 2022 15:55:46 +0800 Subject: [PATCH] Modify the behavior of rpc interface getProps when VertexProp/EdgeProp is empty --- src/storage/query/GetPropProcessor.cpp | 6 +- src/storage/test/GetPropTest.cpp | 96 ++++++++++++++------------ 2 files changed, 54 insertions(+), 48 deletions(-) diff --git a/src/storage/query/GetPropProcessor.cpp b/src/storage/query/GetPropProcessor.cpp index 1c1303a3131..cc175191497 100644 --- a/src/storage/query/GetPropProcessor.cpp +++ b/src/storage/query/GetPropProcessor.cpp @@ -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; @@ -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; diff --git a/src/storage/test/GetPropTest.cpp b/src/storage/test/GetPropTest.cpp index 91744115c85..2957a1a4304 100644 --- a/src/storage/test/GetPropTest.cpp +++ b/src/storage/test/GetPropTest.cpp @@ -431,6 +431,8 @@ TEST(GetPropTest, AllPropertyInAllSchemaTest) { LOG(INFO) << "GetVertexProp"; std::vector vertices = {"Tim Duncan"}; std::vector>> tags; + TagID player = 1; + tags.emplace_back(std::make_pair(player, std::vector())); auto req = buildVertexRequest(totalParts, vertices, tags); auto* processor = GetPropProcessor::instance(env, nullptr, nullptr); @@ -445,14 +447,10 @@ TEST(GetPropTest, AllPropertyInAllSchemaTest) { // The first one is kVid, and player 11 properties in value std::vector 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()); } } @@ -468,6 +466,34 @@ TEST(GetPropTest, AllPropertyInAllSchemaTest) { edgeKeys.emplace_back(std::move(edgeKey)); } std::vector>> edges; + EdgeType serve = 101; + EdgeType teammate = 102; + edges.emplace_back( + -teammate, + std::vector{"player1", "player2", "teamName", "startYear", "endYear"}); + edges.emplace_back(-serve, + std::vector{"playerName", + "teamName", + "startYear", + "endYear", + "teamCareer", + "teamGames", + "teamAvgScore", + "type", + "champions"}); + edges.emplace_back(serve, + std::vector{"playerName", + "teamName", + "startYear", + "endYear", + "teamCareer", + "teamGames", + "teamAvgScore", + "type", + "champions"}); + edges.emplace_back( + -teammate, + std::vector{"player1", "player2", "teamName", "startYear", "endYear"}); auto req = buildEdgeRequest(totalParts, edgeKeys, edges); auto* processor = GetPropProcessor::instance(env, nullptr, nullptr); @@ -531,6 +557,10 @@ TEST(GetPropTest, AllPropertyInAllSchemaTest) { LOG(INFO) << "GetNotExisted"; std::vector vertices = {"Not existed", "Tim Duncan"}; std::vector>> tags; + TagID player = 1; + tags.emplace_back(std::make_pair(player, std::vector())); + TagID team = 2; + tags.emplace_back(std::make_pair(team, std::vector())); auto req = buildVertexRequest(totalParts, vertices, tags); auto* processor = GetPropProcessor::instance(env, nullptr, nullptr); @@ -545,14 +575,12 @@ TEST(GetPropTest, AllPropertyInAllSchemaTest) { // The first one is kVid, and player have 11 properties in key and value std::vector 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()); } } @@ -572,30 +600,20 @@ TEST(GetPropTest, AllPropertyInAllSchemaTest) { std::vector expected; { nebula::Row row; - // The first one is kVid, and player have 11 properties in key and value - std::vector 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 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 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 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()); } } @@ -628,30 +646,20 @@ TEST(GetPropTest, ConcurrencyTest) { std::vector expected; { nebula::Row row; - // The first one is kVid, and player have 11 properties in key and value - std::vector 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 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 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 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()); } }