From 56385c4fda986d1a9f64e8e5bd9cfa5f305da362 Mon Sep 17 00:00:00 2001 From: panda-sheep <59197347+panda-sheep@users.noreply.github.com> Date: Tue, 31 Mar 2020 17:50:23 +0800 Subject: [PATCH] fix go without yield return errror result (#2012) * fix go without yield return errror result * fix format * address dangleptr's comment * address issue change TTL_DURATION not negative * add onlyStructure is true test case Co-authored-by: bright-starry-sky <56461666+bright-starry-sky@users.noreply.github.com> --- src/graph/test/TTLTest.cpp | 389 ++++++++++++++++++++++- src/meta/MetaServiceUtils.cpp | 1 - src/parser/parser.yy | 16 +- src/storage/query/QueryBaseProcessor.inl | 3 +- 4 files changed, 382 insertions(+), 27 deletions(-) diff --git a/src/graph/test/TTLTest.cpp b/src/graph/test/TTLTest.cpp index e7dc1e2a66f..35c96ca6dfa 100644 --- a/src/graph/test/TTLTest.cpp +++ b/src/graph/test/TTLTest.cpp @@ -145,7 +145,7 @@ TEST_F(TTLTest, schematest) { cpp2::ExecutionResponse resp; std::string query = "CREATE TAG woman(name string, email string, " "age int, gender string, row_timestamp timestamp)" - "ttl_duration = -100, ttl_col = \"row_timestamp\""; + "ttl_duration = 0, ttl_col = \"row_timestamp\""; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -427,7 +427,7 @@ TEST_F(TTLTest, schematest) { cpp2::ExecutionResponse resp; std::string query = "CREATE EDGE work2(name string, email string, " "age int, gender string, start_time timestamp)" - "ttl_duration = -100, ttl_col = \"start_time\""; + "ttl_duration = 0, ttl_col = \"start_time\""; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } @@ -660,7 +660,7 @@ TEST_F(TTLTest, Datatest) { ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code3); cpp2::ExecutionResponse resp4; - std::string cmd4 = "CREATE TAG career(name string)"; + std::string cmd4 = "CREATE TAG career(id int)"; auto code4 = client->execute(cmd4, resp4); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code4); @@ -671,24 +671,41 @@ TEST_F(TTLTest, Datatest) { auto code5 = client->execute(cmd5, resp5); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code5); + cpp2::ExecutionResponse resp6; + std::string cmd6 = "CREATE Edge friend(id int)"; + auto code6 = client->execute(cmd6, resp6); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code6); + + sleep(FLAGS_heartbeat_interval_secs + 3); } { cpp2::ExecutionResponse resp; - std::string cmd = "INSERT VERTEX person(id)" - " VALUES 1:(100), 2:(200)"; + std::string cmd = "INSERT VERTEX person(id) " + "VALUES 1:(100), 2:(200)"; auto code = client->execute(cmd, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } { cpp2::ExecutionResponse resp; - std::string cmd = "INSERT VERTEX career(name)" - " VALUES 2:(\"liming\")"; + std::string cmd = "INSERT VERTEX career(id) " + "VALUES 2:(200)"; auto code = client->execute(cmd, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } + + // Fetch tag test + { + cpp2::ExecutionResponse resp; + std::string cmd = "FETCH PROP ON person 1"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector> expected = {}; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } { cpp2::ExecutionResponse resp; std::string cmd = "FETCH PROP ON person 1 YIELD person.id as id"; @@ -704,7 +721,57 @@ TEST_F(TTLTest, Datatest) { auto code = client->execute(cmd, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::vector> expected = {}; + std::vector> expected = {}; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "FETCH PROP ON person 2"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector> expected = {}; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "FETCH PROP ON person 2 YIELD person.id as id"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector> expected = {}; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "FETCH PROP ON career 2"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"VertexID"}, + {"career.id"} + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + std::vector> expected = { + {2, 200}, + }; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "FETCH PROP ON career 2 YIELD career.id"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"VertexID"}, + {"career.id"} + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + std::vector> expected = { + {2, 200}, + }; ASSERT_TRUE(verifyResult(resp, expected, false)); } { @@ -714,23 +781,82 @@ TEST_F(TTLTest, Datatest) { ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); std::vector expectedColNames{ - {"VertexID"}, {"career.name"} + {"VertexID"}, + {"career.id"} }; ASSERT_TRUE(verifyColNames(resp, expectedColNames)); - std::vector> expected = { - {2, "liming"}, + std::vector> expected = { + {2, 200}, }; ASSERT_TRUE(verifyResult(resp, expected, false)); } { cpp2::ExecutionResponse resp; - std::string cmd = "INSERT EDGE like(id)" - "VALUES 100->1:(100)," + std::string cmd = "INSERT EDGE like(id) " + "VALUES 100->1:(100), " "100->2:(200)"; auto code = client->execute(cmd, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + cpp2::ExecutionResponse resp1; + std::string cmd1 = "INSERT EDGE friend(id) " + "VALUES 100->1:(100), " + "100->2:(200)"; + + auto code1 = client->execute(cmd1, resp1); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code1); + } + // Fetch edge test + { + cpp2::ExecutionResponse resp; + std::string cmd = "FETCH PROP ON friend 100->1,100->2"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"friend._src"}, + {"friend._dst"}, + {"friend._rank"}, + {"friend.id"}, + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + + std::vector> expected = { + {100, 1, 0, 100}, + {100, 2, 0, 200}, + }; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "FETCH PROP ON friend 100->1,100->2 YIELD friend.id AS id"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"friend._src"}, + {"friend._dst"}, + {"friend._rank"}, + {"id"}, + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + + std::vector> expected = { + {100, 1, 0, 100}, + {100, 2, 0, 200}, + }; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "FETCH PROP ON like 100->1,100->2"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector> expected = {}; + ASSERT_TRUE(verifyResult(resp, expected, false)); } { cpp2::ExecutionResponse resp; @@ -741,6 +867,152 @@ TEST_F(TTLTest, Datatest) { std::vector> expected = {}; ASSERT_TRUE(verifyResult(resp, expected, false)); } + + // GO test + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 100 OVER friend"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"friend._dst"}, + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + + std::vector> expected = { + {1}, + {2}, + }; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 100 OVER friend WHERE friend.id == 100"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"friend._dst"}, + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + + std::vector> expected = { + {1}, + }; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 100 OVER friend YIELD friend.id"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"friend.id"}, + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + + std::vector> expected = { + {100}, + {200}, + }; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 1 OVER friend reversely"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"friend._dst"}, + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + + std::vector> expected = { + {100}, + }; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 1 OVER friend reversely YIELD friend.id"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"friend.id"}, + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + + std::vector> expected = { + {100}, + }; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 100 OVER friend bidirect"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"friend._dst"}, + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + + std::vector> expected = { + {1}, + {2}, + }; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 100 OVER friend bidirect YIELD friend.id"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"friend.id"}, + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + + std::vector> expected = { + {100}, + {200}, + }; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 100 OVER like"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector> expected = {}; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 100 OVER like WHERE like.id == 100;"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector> expected = {}; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 100 OVER like YIELD like.id"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector> expected = {}; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } { cpp2::ExecutionResponse resp; std::string cmd = "GO FROM 100 OVER like YIELD like.id AS id, " @@ -751,6 +1023,97 @@ TEST_F(TTLTest, Datatest) { std::vector> expected = {}; ASSERT_TRUE(verifyResult(resp, expected, false)); } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 1 OVER like reversely"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector> expected = {}; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 1 OVER like reversely YIELD like.id"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector> expected = {}; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 100 OVER like bidirect"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector> expected = {}; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 100 OVER like bidirect YIELD like.id"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector> expected = {}; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "INSERT EDGE like(id) " + "VALUES 100->3:(2436781720)"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 100 OVER like"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"like._dst"}, + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + + std::vector> expected = { + {3}, + }; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 100 OVER like WHERE like.id == 2436781720"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"like._dst"}, + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + + std::vector> expected = { + {3}, + }; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "GO FROM 100 OVER like WHERE like._dst == 3"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"like._dst"}, + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + + std::vector> expected = { + {3}, + }; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } { cpp2::ExecutionResponse resp; std::string cmd = "DROP SPACE default_space"; diff --git a/src/meta/MetaServiceUtils.cpp b/src/meta/MetaServiceUtils.cpp index 8351f146bdb..3a0ef8e8d27 100644 --- a/src/meta/MetaServiceUtils.cpp +++ b/src/meta/MetaServiceUtils.cpp @@ -479,7 +479,6 @@ cpp2::ErrorCode MetaServiceUtils::alterSchemaProp(std::vector admin_sentence %type create_user_sentence alter_user_sentence drop_user_sentence change_password_sentence -%type show_sentence +%type show_sentence %type mutate_sentence %type insert_vertex_sentence insert_edge_sentence @@ -1015,11 +1015,8 @@ create_schema_prop_list ; create_schema_prop_item - : KW_TTL_DURATION ASSIGN unary_integer { - // Less than or equal to 0 means infinity, so less than 0 is equivalent to 0 - if ($3 < 0) { - $3 = 0; - } + : KW_TTL_DURATION ASSIGN INTEGER { + ifOutOfRange($3, @3); $$ = new SchemaPropItem(SchemaPropItem::TTL_DURATION, $3); } | KW_TTL_COL ASSIGN STRING { @@ -1096,11 +1093,8 @@ alter_schema_prop_list ; alter_schema_prop_item - : KW_TTL_DURATION ASSIGN unary_integer { - // Less than or equal to 0 means infinity, so less than 0 is equivalent to 0 - if ($3 < 0) { - $3 = 0; - } + : KW_TTL_DURATION ASSIGN INTEGER { + ifOutOfRange($3, @3); $$ = new SchemaPropItem(SchemaPropItem::TTL_DURATION, $3); } | KW_TTL_COL ASSIGN STRING { diff --git a/src/storage/query/QueryBaseProcessor.inl b/src/storage/query/QueryBaseProcessor.inl index c4ddea7e0cc..56ec947cb8b 100644 --- a/src/storage/query/QueryBaseProcessor.inl +++ b/src/storage/query/QueryBaseProcessor.inl @@ -524,8 +524,7 @@ kvstore::ResultCode QueryBaseProcessor::collectEdgeProps( lastRank = rank; lastDstId = dstId; std::unique_ptr reader; - if (!onlyStructure - && !val.empty()) { + if ((!onlyStructure || retTTL.has_value()) && !val.empty()) { reader = RowReader::getEdgePropReader(this->schemaMan_, val, spaceId_,