diff --git a/src/graph/validator/LookupValidator.cpp b/src/graph/validator/LookupValidator.cpp index 60a6b9b5903..1c922ca4948 100644 --- a/src/graph/validator/LookupValidator.cpp +++ b/src/graph/validator/LookupValidator.cpp @@ -164,8 +164,8 @@ Status LookupValidator::validateYield() { if (lookupCtx_->isEdge) { idxReturnCols_.emplace_back(kSrc); idxReturnCols_.emplace_back(kDst); - idxReturnCols_.emplace_back(kType); idxReturnCols_.emplace_back(kRank); + idxReturnCols_.emplace_back(kType); outputs_.emplace_back(kSrcVID, vidType_); outputs_.emplace_back(kDstVID, vidType_); outputs_.emplace_back(kRanking, Value::Type::INT); diff --git a/src/graph/validator/test/LookupValidatorTest.cpp b/src/graph/validator/test/LookupValidatorTest.cpp index 98c0eb1722c..8a42194db19 100644 --- a/src/graph/validator/test/LookupValidatorTest.cpp +++ b/src/graph/validator/test/LookupValidatorTest.cpp @@ -128,5 +128,31 @@ TEST_F(LookupValidatorTest, InvalidFilterExpression) { EXPECT_TRUE(checkResult(query, {})); } } + +TEST_F(LookupValidatorTest, wrongYield) { + { + std::string query = "LOOKUP ON person YIELD vertex"; + auto result = checkResult(query); + EXPECT_EQ(std::string(result.message()), + "SyntaxError: please add alias when using vertex. near `vertex'"); + } + { + std::string query = "LOOKUP ON person YIELD vertex as node, edge"; + auto result = checkResult(query); + EXPECT_EQ(std::string(result.message()), + "SyntaxError: please add alias when using edge. near `edge'"); + } + { + std::string query = "LOOKUP ON person YIELD edge as e"; + auto result = checkResult(query); + EXPECT_EQ(std::string(result.message()), "SemanticError: illegal yield clauses `EDGE AS e'"); + } + { + std::string query = "LOOKUP ON person YIELD vertex as node, player.age"; + auto result = checkResult(query); + EXPECT_EQ(std::string(result.message()), "SemanticError: Schema name error: player"); + } +} + } // namespace graph } // namespace nebula diff --git a/tests/tck/features/lookup/LookupTag.feature b/tests/tck/features/lookup/LookupTag.feature index 90d4f2cf73f..c499a77b808 100644 --- a/tests/tck/features/lookup/LookupTag.feature +++ b/tests/tck/features/lookup/LookupTag.feature @@ -1,4 +1,3 @@ -@jmq Feature: Test lookup on tag index Examples: | where_condition | diff --git a/tests/tck/features/lookup/WithYield.feature b/tests/tck/features/lookup/WithYield.feature index 65d9e6b4f1d..b3a960f6270 100644 --- a/tests/tck/features/lookup/WithYield.feature +++ b/tests/tck/features/lookup/WithYield.feature @@ -12,6 +12,22 @@ Feature: Lookup with yield | VertexID | player.name | | 'Kobe Bryant' | 'Kobe Bryant' | | 'Dirk Nowitzki' | 'Dirk Nowitzki' | + When executing query: + """ + LOOKUP ON player WHERE player.age == 40 YIELD player.name, player.age + 1 + """ + Then the result should be, in any order: + | VertexID | player.name | (player.age+1) | + | 'Kobe Bryant' | 'Kobe Bryant' | 41 | + | 'Dirk Nowitzki' | 'Dirk Nowitzki' | 41 | + When executing query: + """ + LOOKUP ON player WHERE player.age == 40 YIELD player.name, player.age + 1, vertex as node + """ + Then the result should be, in any order: + | VertexID | player.name | (player.age+1) | node | + | 'Kobe Bryant' | 'Kobe Bryant' | 41 | ("Kobe Bryant" : player {age : 40, name : "Kobe Bryant"}) | + | 'Dirk Nowitzki' | 'Dirk Nowitzki' | 41 | ("Dirk Nowitzki" : player {age : 40, name : "Dirk Nowitzki"}) | Scenario: [1] tag with yield rename When executing query: @@ -22,6 +38,15 @@ Feature: Lookup with yield | VertexID | name | | 'Kobe Bryant' | 'Kobe Bryant' | | 'Dirk Nowitzki' | 'Dirk Nowitzki' | + When executing query: + """ + LOOKUP ON team WHERE team.name in ["76ers", "Lakers", "Spurs"] YIELD vertex AS node + """ + Then the result should be, in any order: + | VertexID | node | + | '76ers' | ("76ers" : team {name : "76ers"}) | + | 'Lakers' | ("Lakers" : team {name : "Lakers"}) | + | 'Spurs' | ("Spurs" : team {name : "Spurs"}) | Scenario: [2] edge with yield When executing query: @@ -33,6 +58,15 @@ Feature: Lookup with yield | SrcVID | DstVID | Ranking | serve.start_year | | 'Russell Westbrook' | 'Thunders' | 0 | 2008 | | 'Marc Gasol' | 'Grizzlies' | 0 | 2008 | + When executing query: + """ + LOOKUP ON serve WHERE serve.start_year == 2008 and serve.end_year == 2019 + YIELD serve.start_year, edge as relationship + """ + Then the result should be, in any order: + | SrcVID | DstVID | Ranking | serve.start_year | relationship | + | 'Russell Westbrook' | 'Thunders' | 0 | 2008 | [:serve "Russell Westbrook"->"Thunders" @0 {end_year: 2019, start_year: 2008}] | + | 'Marc Gasol' | 'Grizzlies' | 0 | 2008 | [:serve "Marc Gasol"->"Grizzlies" @0 {end_year: 2019, start_year: 2008}] | Scenario: [2] edge with yield rename When executing query: @@ -44,3 +78,15 @@ Feature: Lookup with yield | SrcVID | DstVID | Ranking | startYear | | 'Russell Westbrook' | 'Thunders' | 0 | 2008 | | 'Marc Gasol' | 'Grizzlies' | 0 | 2008 | + When executing query: + """ + LOOKUP ON like WHERE like.likeness < 50 + 1 YIELD like.likeness, edge as relationship + """ + Then the result should be, in any order: + | SrcVID | DstVID | Ranking | like.likeness | relationship | + | "Blake Griffin" | "Chris Paul" | 0 | -1 | [:like "Blake Griffin"->"Chris Paul" @0 {likeness: -1}] | + | "Dirk Nowitzki" | "Dwyane Wade" | 0 | 10 | [:like "Dirk Nowitzki"->"Dwyane Wade" @0 {likeness: 10}] | + | "Kyrie Irving" | "LeBron James" | 0 | 13 | [:like "Kyrie Irving"->"LeBron James" @0 {likeness: 13}] | + | "Marco Belinelli" | "Tony Parker" | 0 | 50 | [:like "Marco Belinelli"->"Tony Parker" @0 {likeness: 50}] | + | "Rajon Rondo" | "Ray Allen" | 0 | -1 | [:like "Rajon Rondo"->"Ray Allen" @0 {likeness: -1}] | + | "Ray Allen" | "Rajon Rondo" | 0 | 9 | [:like "Ray Allen"->"Rajon Rondo" @0 {likeness: 9}] | diff --git a/tests/tck/features/lookup/WithYield.intVid.feature b/tests/tck/features/lookup/WithYield.intVid.feature index 78a175a39ca..5d102620501 100644 --- a/tests/tck/features/lookup/WithYield.intVid.feature +++ b/tests/tck/features/lookup/WithYield.intVid.feature @@ -12,6 +12,22 @@ Feature: Lookup with yield in integer vid | VertexID | player.name | | 'Kobe Bryant' | 'Kobe Bryant' | | 'Dirk Nowitzki' | 'Dirk Nowitzki' | + When executing query: + """ + LOOKUP ON player WHERE player.age == 40 YIELD player.name, player.age + 1 + """ + Then the result should be, in any order, and the columns 0 should be hashed: + | VertexID | player.name | (player.age+1) | + | 'Kobe Bryant' | 'Kobe Bryant' | 41 | + | 'Dirk Nowitzki' | 'Dirk Nowitzki' | 41 | + When executing query: + """ + LOOKUP ON player WHERE player.age == 40 YIELD player.name, player.age + 1, vertex as node + """ + Then the result should be, in any order, and the columns 0 should be hashed: + | VertexID | player.name | (player.age+1) | node | + | 'Kobe Bryant' | 'Kobe Bryant' | 41 | ("Kobe Bryant" : player {age : 40, name : "Kobe Bryant"}) | + | 'Dirk Nowitzki' | 'Dirk Nowitzki' | 41 | ("Dirk Nowitzki" : player {age : 40, name : "Dirk Nowitzki"}) | Scenario: [1] tag with yield rename When executing query: @@ -22,6 +38,15 @@ Feature: Lookup with yield in integer vid | VertexID | name | | 'Kobe Bryant' | 'Kobe Bryant' | | 'Dirk Nowitzki' | 'Dirk Nowitzki' | + When executing query: + """ + LOOKUP ON team WHERE team.name in ["76ers", "Lakers", "Spurs"] YIELD vertex AS node + """ + Then the result should be, in any order, and the columns 0 should be hashed: + | VertexID | node | + | '76ers' | ("76ers" : team {name : "76ers"}) | + | 'Lakers' | ("Lakers" : team {name : "Lakers"}) | + | 'Spurs' | ("Spurs" : team {name : "Spurs"}) | Scenario: [2] edge with yield When executing query: @@ -33,6 +58,15 @@ Feature: Lookup with yield in integer vid | SrcVID | DstVID | Ranking | serve.start_year | | 'Russell Westbrook' | 'Thunders' | 0 | 2008 | | 'Marc Gasol' | 'Grizzlies' | 0 | 2008 | + When executing query: + """ + LOOKUP ON serve WHERE serve.start_year == 2008 and serve.end_year == 2019 + YIELD serve.start_year, edge as relationship + """ + Then the result should be, in any order, and the columns 0,1 should be hashed: + | SrcVID | DstVID | Ranking | serve.start_year | relationship | + | 'Russell Westbrook' | 'Thunders' | 0 | 2008 | [:serve "Russell Westbrook"->"Thunders" @0 {end_year: 2019, start_year: 2008}] | + | 'Marc Gasol' | 'Grizzlies' | 0 | 2008 | [:serve "Marc Gasol"->"Grizzlies" @0 {end_year: 2019, start_year: 2008}] | Scenario: [2] edge with yield rename When executing query: @@ -44,3 +78,15 @@ Feature: Lookup with yield in integer vid | SrcVID | DstVID | Ranking | startYear | | 'Russell Westbrook' | 'Thunders' | 0 | 2008 | | 'Marc Gasol' | 'Grizzlies' | 0 | 2008 | + When executing query: + """ + LOOKUP ON like WHERE like.likeness < 50 + 1 YIELD like.likeness, edge as relationship + """ + Then the result should be, in any order, and the columns 0,1 should be hashed: + | SrcVID | DstVID | Ranking | like.likeness | relationship | + | "Blake Griffin" | "Chris Paul" | 0 | -1 | [:like "Blake Griffin"->"Chris Paul" @0 {likeness: -1}] | + | "Dirk Nowitzki" | "Dwyane Wade" | 0 | 10 | [:like "Dirk Nowitzki"->"Dwyane Wade" @0 {likeness: 10}] | + | "Kyrie Irving" | "LeBron James" | 0 | 13 | [:like "Kyrie Irving"->"LeBron James" @0 {likeness: 13}] | + | "Marco Belinelli" | "Tony Parker" | 0 | 50 | [:like "Marco Belinelli"->"Tony Parker" @0 {likeness: 50}] | + | "Rajon Rondo" | "Ray Allen" | 0 | -1 | [:like "Rajon Rondo"->"Ray Allen" @0 {likeness: -1}] | + | "Ray Allen" | "Rajon Rondo" | 0 | 9 | [:like "Ray Allen"->"Rajon Rondo" @0 {likeness: 9}] |