diff --git a/src/graph/test/CMakeLists.txt b/src/graph/test/CMakeLists.txt index 88c0fb9c633..6b441b30b5f 100644 --- a/src/graph/test/CMakeLists.txt +++ b/src/graph/test/CMakeLists.txt @@ -394,3 +394,18 @@ nebula_add_test( gtest ) +nebula_add_test( + NAME + ttl_test + SOURCES + TTLTest.cpp + OBJECTS + ${GRAPH_TEST_CLIENT_LIBS} + ${GRAPH_TEST_LIBS} + LIBRARIES + ${THRIFT_LIBRARIES} + ${ROCKSDB_LIBRARIES} + proxygenlib + wangle + gtest +) diff --git a/src/graph/test/SchemaTest.cpp b/src/graph/test/SchemaTest.cpp index 0c731e20131..297fb0a7a24 100644 --- a/src/graph/test/SchemaTest.cpp +++ b/src/graph/test/SchemaTest.cpp @@ -1074,615 +1074,5 @@ TEST_F(SchemaTest, TestTagAndEdge) { LOG(FATAL) << "Space still exists after sleep " << retry << " seconds"; } - -TEST_F(SchemaTest, TTLtest) { - auto client = gEnv->getClient(); - ASSERT_NE(nullptr, client); - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW HOSTS"; - client->execute(query, resp); - std::vector> expected { - {"127.0.0.1", std::to_string(gEnv->storageServerPort()), "online", 0, - "No valid partition", "No valid partition"}, - {"Total", "", "", 0, "", ""}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - { - cpp2::ExecutionResponse resp; - std::string query = "CREATE SPACE default_space(partition_num=9, replica_factor=1)"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "USE default_space"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - - // Tag with TTL test - { - cpp2::ExecutionResponse resp; - std::string query = "CREATE TAG person(name string, email string, " - "age int, gender string, row_timestamp timestamp)"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "DESCRIBE TAG person"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::vector> expected{ - {"name", "string"}, - {"email", "string"}, - {"age", "int"}, - {"gender", "string"}, - {"row_timestamp", "timestamp"}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE TAG person"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createTagStr = "CREATE TAG person (\n" - " name string,\n" - " email string,\n" - " age int,\n" - " gender string,\n" - " row_timestamp timestamp\n" - ") ttl_duration = 0, ttl_col = \"\""; - std::vector> expected{ - {"person", createTagStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - { - cpp2::ExecutionResponse resp; - std::string query = "CREATE TAG man(name string, email string, " - "age int, gender string, row_timestamp timestamp)" - "ttl_duration = 100, ttl_col = \"row_timestamp\""; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE TAG man"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createTagStr = "CREATE TAG man (\n" - " name string,\n" - " email string,\n" - " age int,\n" - " gender string,\n" - " row_timestamp timestamp\n" - ") ttl_duration = 100, ttl_col = row_timestamp"; - std::vector> expected{ - {"man", createTagStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - - // Disable implicit ttl mode - { - cpp2::ExecutionResponse resp; - std::string query = "CREATE TAG woman(name string, email string, " - "age int, gender string, row_timestamp timestamp)" - "ttl_duration = 100"; - auto code = client->execute(query, resp); - ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); - } - // Disable when ttl_col is not an integer column or a timestamp column - { - cpp2::ExecutionResponse resp; - std::string query = "CREATE TAG woman(name string, email string, " - "age int, gender string, row_timestamp timestamp)" - "ttl_col = \"name\""; - auto code = client->execute(query, resp); - ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); - } - // Ttl_duration less than 0 - { - 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\""; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE TAG woman"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createTagStr = "CREATE TAG woman (\n" - " name string,\n" - " email string,\n" - " age int,\n" - " gender string,\n" - " row_timestamp timestamp\n" - ") ttl_duration = 0, ttl_col = row_timestamp"; - std::vector> expected{ - {"woman", createTagStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - // Only ttl col - { - cpp2::ExecutionResponse resp; - std::string query = "CREATE TAG only_ttl_col(name string, email string, " - "age int, gender string, row_timestamp timestamp)" - "ttl_col = \"row_timestamp\""; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE TAG only_ttl_col"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createTagStr = "CREATE TAG only_ttl_col (\n" - " name string,\n" - " email string,\n" - " age int,\n" - " gender string,\n" - " row_timestamp timestamp\n" - ") ttl_duration = 0, ttl_col = row_timestamp"; - std::vector> expected{ - {"only_ttl_col", createTagStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER TAG woman " - "ttl_duration = 50, ttl_col = \"row_timestamp\""; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE TAG woman"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createTagStr = "CREATE TAG woman (\n" - " name string,\n" - " email string,\n" - " age int,\n" - " gender string,\n" - " row_timestamp timestamp\n" - ") ttl_duration = 50, ttl_col = row_timestamp"; - std::vector> expected{ - {"woman", createTagStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - // Failed when alter tag to set ttl_col on not integer and timestamp column - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER TAG woman " - "ttl_col = \"name\""; - auto code = client->execute(query, resp); - ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER TAG woman " - "Drop (name) ttl_duration = 200"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE TAG woman"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createTagStr = "CREATE TAG woman (\n" - " email string,\n" - " age int,\n" - " gender string,\n" - " row_timestamp timestamp\n" - ") ttl_duration = 200, ttl_col = row_timestamp"; - std::vector> expected{ - {"woman", createTagStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - // When the column is as TTL column, droping column - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER TAG woman " - "Drop (row_timestamp)"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE TAG woman"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - - std::string createTagStr = "CREATE TAG woman (\n" - " email string,\n" - " age int,\n" - " gender string\n" - ") ttl_duration = 0, ttl_col = \"\""; - std::vector> expected{ - {"woman", createTagStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - // ADD ttl property - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER TAG woman " - "ttl_duration = 100, ttl_col = \"age\""; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE TAG woman"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createTagStr = "CREATE TAG woman (\n" - " email string,\n" - " age int,\n" - " gender string\n" - ") ttl_duration = 100, ttl_col = age"; - std::vector> expected{ - {"woman", createTagStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - // Change ttl col, failed - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER TAG woman " - "CHANGE (age string)"; - auto code = client->execute(query, resp); - ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); - } - // Drop ttl property - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER TAG woman ttl_col = \"\" "; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE TAG woman"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createTagStr = "CREATE TAG woman (\n" - " email string,\n" - " age int,\n" - " gender string\n" - ") ttl_duration = 0, ttl_col = \"\"";; - std::vector> expected{ - {"woman", createTagStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - // Change succeed - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER TAG woman " - "CHANGE (age string)"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE TAG woman"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createTagStr = "CREATE TAG woman (\n" - " email string,\n" - " age string,\n" - " gender string\n" - ") ttl_duration = 0, ttl_col = \"\"";; - std::vector> expected{ - {"woman", createTagStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - - // Edge with TTL test - { - cpp2::ExecutionResponse resp; - std::string query = "CREATE EDGE work(number string, start_time timestamp)"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "DESCRIBE EDGE work"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::vector> expected{ - {"number", "string"}, - {"start_time", "timestamp"}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE EDGE work"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createEdgeStr = "CREATE EDGE work (\n" - " number string,\n" - " start_time timestamp\n" - ") ttl_duration = 0, ttl_col = \"\""; - std::vector> expected{ - {"work", createEdgeStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - { - cpp2::ExecutionResponse resp; - std::string query = "CREATE EDGE work1(name string, email string, " - "age int, gender string, row_timestamp timestamp)" - "ttl_duration = 100, ttl_col = \"row_timestamp\""; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE EDGE work1"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createEdgeStr = "CREATE EDGE work1 (\n" - " name string,\n" - " email string,\n" - " age int,\n" - " gender string,\n" - " row_timestamp timestamp\n" - ") ttl_duration = 100, ttl_col = row_timestamp"; - std::vector> expected{ - {"work1", createEdgeStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - - // Disable implicit ttl mode - { - cpp2::ExecutionResponse resp; - std::string query = "CREATE EDGE work2(number string, start_time timestamp)" - "ttl_duration = 100"; - auto code = client->execute(query, resp); - ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); - } - // Disable when ttl_col is not an integer column or a timestamp column - { - cpp2::ExecutionResponse resp; - std::string query = "CREATE EDGE work2(number string, start_time timestamp)" - "ttl_col = \"name\""; - auto code = client->execute(query, resp); - ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); - } - // Ttl duration less than 0 - { - 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\""; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE EDGE work2"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createEdgeStr = "CREATE EDGE work2 (\n" - " name string,\n" - " email string,\n" - " age int,\n" - " gender string,\n" - " start_time timestamp\n" - ") ttl_duration = 0, ttl_col = start_time"; - std::vector> expected{ - {"work2", createEdgeStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - // Only ttl col - { - cpp2::ExecutionResponse resp; - std::string query = "CREATE EDGE edge_only_ttl_col(name string, email string, " - "age int, gender string, row_timestamp timestamp)" - "ttl_col = \"row_timestamp\""; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE EDGE edge_only_ttl_col"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createEdgeStr = "CREATE EDGE edge_only_ttl_col (\n" - " name string,\n" - " email string,\n" - " age int,\n" - " gender string,\n" - " row_timestamp timestamp\n" - ") ttl_duration = 0, ttl_col = row_timestamp"; - std::vector> expected{ - {"edge_only_ttl_col", createEdgeStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER EDGE work2 " - "ttl_duration = 50, ttl_col = \"start_time\""; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - - std::string query = "SHOW CREATE EDGE work2"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createEdgeStr = "CREATE EDGE work2 (\n" - " name string,\n" - " email string,\n" - " age int,\n" - " gender string,\n" - " start_time timestamp\n" - ") ttl_duration = 50, ttl_col = start_time"; - std::vector> expected{ - {"work2", createEdgeStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - // Failed when alter edge to set ttl_col on not integer and timestamp column - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER EDGE work2 " - "ttl_col = \"name\""; - auto code = client->execute(query, resp); - ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER EDGE work2 " - "Drop (name) ttl_duration = 200"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE EDGE work2"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createEdgeStr = "CREATE EDGE work2 (\n" - " email string,\n" - " age int,\n" - " gender string,\n" - " start_time timestamp\n" - ") ttl_duration = 200, ttl_col = start_time"; - std::vector> expected{ - {"work2", createEdgeStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - // When the column is as TTL column, droping column - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER EDGE work2 " - "Drop (start_time)"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE EDGE work2"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createEdgeStr = "CREATE EDGE work2 (\n" - " email string,\n" - " age int,\n" - " gender string\n" - ") ttl_duration = 0, ttl_col = \"\""; - std::vector> expected{ - {"work2", createEdgeStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - // Add ttl property - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER Edge work2 " - "ttl_duration = 100, ttl_col = \"age\""; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE EDGE work2"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createTagStr = "CREATE EDGE work2 (\n" - " email string,\n" - " age int,\n" - " gender string\n" - ") ttl_duration = 100, ttl_col = age"; - std::vector> expected{ - {"work2", createTagStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - // Change ttl col, failed - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER EDGE work2 " - "CHANGE (age string)"; - auto code = client->execute(query, resp); - ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); - } - // Drop ttl property - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER EDGE work2 " - "ttl_col = \"\""; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE EDGE work2"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createTagStr = "CREATE EDGE work2 (\n" - " email string,\n" - " age int,\n" - " gender string\n" - ") ttl_duration = 0, ttl_col = \"\"";; - std::vector> expected{ - {"work2", createTagStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - // Change succeed - { - cpp2::ExecutionResponse resp; - std::string query = "ALTER EDGE work2 " - "CHANGE (age string)"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } - { - cpp2::ExecutionResponse resp; - std::string query = "SHOW CREATE EDGE work2"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createTagStr = "CREATE EDGE work2 (\n" - " email string,\n" - " age string,\n" - " gender string\n" - ") ttl_duration = 0, ttl_col = \"\"";; - std::vector> expected{ - {"work2", createTagStr}, - }; - ASSERT_TRUE(verifyResult(resp, expected)); - } - { - cpp2::ExecutionResponse resp; - std::string query = "DROP SPACE default_space"; - auto code = client->execute(query, resp); - ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - } -} - } // namespace graph } // namespace nebula diff --git a/src/graph/test/TTLTest.cpp b/src/graph/test/TTLTest.cpp new file mode 100644 index 00000000000..e7dc1e2a66f --- /dev/null +++ b/src/graph/test/TTLTest.cpp @@ -0,0 +1,763 @@ +/* Copyright (c) 2020 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +#include "base/Base.h" +#include "graph/test/TestEnv.h" +#include "graph/test/TestBase.h" +#include "meta/test/TestUtils.h" +#include "graph/test/TraverseTestBase.h" +#include "storage/test/TestUtils.h" + +DECLARE_int32(heartbeat_interval_secs); + +namespace nebula { +namespace graph { + +class TTLTest : public TestBase { +protected: + void SetUp() override { + TestBase::SetUp(); + // ... + } + + void TearDown() override { + // ... + TestBase::TearDown(); + } +}; + +TEST_F(TTLTest, schematest) { + auto client = gEnv->getClient(); + ASSERT_NE(nullptr, client); + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW HOSTS"; + client->execute(query, resp); + std::vector> expected { + {"127.0.0.1", std::to_string(gEnv->storageServerPort()), "online", 0, + "No valid partition", "No valid partition"}, + {"Total", "", "", 0, "", ""}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + { + cpp2::ExecutionResponse resp; + std::string query = "CREATE SPACE default_space(partition_num=9, replica_factor=1)"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "USE default_space"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + + // Tag with TTL test + { + cpp2::ExecutionResponse resp; + std::string query = "CREATE TAG person(name string, email string, " + "age int, gender string, row_timestamp timestamp)"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "DESCRIBE TAG person"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::vector> expected{ + {"name", "string"}, + {"email", "string"}, + {"age", "int"}, + {"gender", "string"}, + {"row_timestamp", "timestamp"}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE TAG person"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createTagStr = "CREATE TAG person (\n" + " name string,\n" + " email string,\n" + " age int,\n" + " gender string,\n" + " row_timestamp timestamp\n" + ") ttl_duration = 0, ttl_col = \"\""; + std::vector> expected{ + {"person", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + { + cpp2::ExecutionResponse resp; + std::string query = "CREATE TAG man(name string, email string, " + "age int, gender string, row_timestamp timestamp)" + "ttl_duration = 100, ttl_col = \"row_timestamp\""; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE TAG man"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createTagStr = "CREATE TAG man (\n" + " name string,\n" + " email string,\n" + " age int,\n" + " gender string,\n" + " row_timestamp timestamp\n" + ") ttl_duration = 100, ttl_col = row_timestamp"; + std::vector> expected{ + {"man", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + + // Disable implicit ttl mode + { + cpp2::ExecutionResponse resp; + std::string query = "CREATE TAG woman(name string, email string, " + "age int, gender string, row_timestamp timestamp)" + "ttl_duration = 100"; + auto code = client->execute(query, resp); + ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); + } + // Disable when ttl_col is not an integer column or a timestamp column + { + cpp2::ExecutionResponse resp; + std::string query = "CREATE TAG woman(name string, email string, " + "age int, gender string, row_timestamp timestamp)" + "ttl_col = \"name\""; + auto code = client->execute(query, resp); + ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); + } + // Ttl_duration less than 0 + { + 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\""; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE TAG woman"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createTagStr = "CREATE TAG woman (\n" + " name string,\n" + " email string,\n" + " age int,\n" + " gender string,\n" + " row_timestamp timestamp\n" + ") ttl_duration = 0, ttl_col = row_timestamp"; + std::vector> expected{ + {"woman", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + // Only ttl col + { + cpp2::ExecutionResponse resp; + std::string query = "CREATE TAG only_ttl_col(name string, email string, " + "age int, gender string, row_timestamp timestamp)" + "ttl_col = \"row_timestamp\""; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE TAG only_ttl_col"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createTagStr = "CREATE TAG only_ttl_col (\n" + " name string,\n" + " email string,\n" + " age int,\n" + " gender string,\n" + " row_timestamp timestamp\n" + ") ttl_duration = 0, ttl_col = row_timestamp"; + std::vector> expected{ + {"only_ttl_col", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER TAG woman " + "ttl_duration = 50, ttl_col = \"row_timestamp\""; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE TAG woman"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createTagStr = "CREATE TAG woman (\n" + " name string,\n" + " email string,\n" + " age int,\n" + " gender string,\n" + " row_timestamp timestamp\n" + ") ttl_duration = 50, ttl_col = row_timestamp"; + std::vector> expected{ + {"woman", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + // Failed when alter tag to set ttl_col on not integer and timestamp column + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER TAG woman " + "ttl_col = \"name\""; + auto code = client->execute(query, resp); + ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER TAG woman " + "Drop (name) ttl_duration = 200"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE TAG woman"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createTagStr = "CREATE TAG woman (\n" + " email string,\n" + " age int,\n" + " gender string,\n" + " row_timestamp timestamp\n" + ") ttl_duration = 200, ttl_col = row_timestamp"; + std::vector> expected{ + {"woman", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + // When the column is as TTL column, droping column + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER TAG woman " + "Drop (row_timestamp)"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE TAG woman"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::string createTagStr = "CREATE TAG woman (\n" + " email string,\n" + " age int,\n" + " gender string\n" + ") ttl_duration = 0, ttl_col = \"\""; + std::vector> expected{ + {"woman", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + // ADD ttl property + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER TAG woman " + "ttl_duration = 100, ttl_col = \"age\""; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE TAG woman"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createTagStr = "CREATE TAG woman (\n" + " email string,\n" + " age int,\n" + " gender string\n" + ") ttl_duration = 100, ttl_col = age"; + std::vector> expected{ + {"woman", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + // Change ttl col, failed + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER TAG woman " + "CHANGE (age string)"; + auto code = client->execute(query, resp); + ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); + } + // Drop ttl property + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER TAG woman ttl_col = \"\" "; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE TAG woman"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createTagStr = "CREATE TAG woman (\n" + " email string,\n" + " age int,\n" + " gender string\n" + ") ttl_duration = 0, ttl_col = \"\"";; + std::vector> expected{ + {"woman", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + // Change succeed + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER TAG woman " + "CHANGE (age string)"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE TAG woman"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createTagStr = "CREATE TAG woman (\n" + " email string,\n" + " age string,\n" + " gender string\n" + ") ttl_duration = 0, ttl_col = \"\"";; + std::vector> expected{ + {"woman", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + + // Edge with TTL test + { + cpp2::ExecutionResponse resp; + std::string query = "CREATE EDGE work(number string, start_time timestamp)"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "DESCRIBE EDGE work"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::vector> expected{ + {"number", "string"}, + {"start_time", "timestamp"}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE EDGE work"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE EDGE work (\n" + " number string,\n" + " start_time timestamp\n" + ") ttl_duration = 0, ttl_col = \"\""; + std::vector> expected{ + {"work", createEdgeStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + { + cpp2::ExecutionResponse resp; + std::string query = "CREATE EDGE work1(name string, email string, " + "age int, gender string, row_timestamp timestamp)" + "ttl_duration = 100, ttl_col = \"row_timestamp\""; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE EDGE work1"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE EDGE work1 (\n" + " name string,\n" + " email string,\n" + " age int,\n" + " gender string,\n" + " row_timestamp timestamp\n" + ") ttl_duration = 100, ttl_col = row_timestamp"; + std::vector> expected{ + {"work1", createEdgeStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + + // Disable implicit ttl mode + { + cpp2::ExecutionResponse resp; + std::string query = "CREATE EDGE work2(number string, start_time timestamp)" + "ttl_duration = 100"; + auto code = client->execute(query, resp); + ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); + } + // Disable when ttl_col is not an integer column or a timestamp column + { + cpp2::ExecutionResponse resp; + std::string query = "CREATE EDGE work2(number string, start_time timestamp)" + "ttl_col = \"name\""; + auto code = client->execute(query, resp); + ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); + } + // Ttl duration less than 0 + { + 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\""; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE EDGE work2"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE EDGE work2 (\n" + " name string,\n" + " email string,\n" + " age int,\n" + " gender string,\n" + " start_time timestamp\n" + ") ttl_duration = 0, ttl_col = start_time"; + std::vector> expected{ + {"work2", createEdgeStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + // Only ttl col + { + cpp2::ExecutionResponse resp; + std::string query = "CREATE EDGE edge_only_ttl_col(name string, email string, " + "age int, gender string, row_timestamp timestamp)" + "ttl_col = \"row_timestamp\""; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE EDGE edge_only_ttl_col"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE EDGE edge_only_ttl_col (\n" + " name string,\n" + " email string,\n" + " age int,\n" + " gender string,\n" + " row_timestamp timestamp\n" + ") ttl_duration = 0, ttl_col = row_timestamp"; + std::vector> expected{ + {"edge_only_ttl_col", createEdgeStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER EDGE work2 " + "ttl_duration = 50, ttl_col = \"start_time\""; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + + std::string query = "SHOW CREATE EDGE work2"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE EDGE work2 (\n" + " name string,\n" + " email string,\n" + " age int,\n" + " gender string,\n" + " start_time timestamp\n" + ") ttl_duration = 50, ttl_col = start_time"; + std::vector> expected{ + {"work2", createEdgeStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + // Failed when alter edge to set ttl_col on not integer and timestamp column + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER EDGE work2 " + "ttl_col = \"name\""; + auto code = client->execute(query, resp); + ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER EDGE work2 " + "Drop (name) ttl_duration = 200"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE EDGE work2"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE EDGE work2 (\n" + " email string,\n" + " age int,\n" + " gender string,\n" + " start_time timestamp\n" + ") ttl_duration = 200, ttl_col = start_time"; + std::vector> expected{ + {"work2", createEdgeStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + // When the column is as TTL column, droping column + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER EDGE work2 " + "Drop (start_time)"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE EDGE work2"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE EDGE work2 (\n" + " email string,\n" + " age int,\n" + " gender string\n" + ") ttl_duration = 0, ttl_col = \"\""; + std::vector> expected{ + {"work2", createEdgeStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + // Add ttl property + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER Edge work2 " + "ttl_duration = 100, ttl_col = \"age\""; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE EDGE work2"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createTagStr = "CREATE EDGE work2 (\n" + " email string,\n" + " age int,\n" + " gender string\n" + ") ttl_duration = 100, ttl_col = age"; + std::vector> expected{ + {"work2", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + // Change ttl col, failed + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER EDGE work2 " + "CHANGE (age string)"; + auto code = client->execute(query, resp); + ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); + } + // Drop ttl property + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER EDGE work2 " + "ttl_col = \"\""; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE EDGE work2"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createTagStr = "CREATE EDGE work2 (\n" + " email string,\n" + " age int,\n" + " gender string\n" + ") ttl_duration = 0, ttl_col = \"\"";; + std::vector> expected{ + {"work2", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + // Change succeed + { + cpp2::ExecutionResponse resp; + std::string query = "ALTER EDGE work2 " + "CHANGE (age string)"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE EDGE work2"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createTagStr = "CREATE EDGE work2 (\n" + " email string,\n" + " age string,\n" + " gender string\n" + ") ttl_duration = 0, ttl_col = \"\"";; + std::vector> expected{ + {"work2", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + { + cpp2::ExecutionResponse resp; + std::string query = "DROP SPACE default_space"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } +} + +TEST_F(TTLTest, Datatest) { + auto client = gEnv->getClient(); + ASSERT_NE(nullptr, client); + { + cpp2::ExecutionResponse resp1; + std::string cmd1 = "CREATE SPACE default_space(partition_num=9, " + "replica_factor=1, charset=utf8, collate=utf8_bin)"; + auto code1 = client->execute(cmd1, resp1); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code1); + + cpp2::ExecutionResponse resp2; + std::string cmd2 = "USE default_space"; + auto code2 = client->execute(cmd2, resp2); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code2); + + cpp2::ExecutionResponse resp3; + std::string cmd3 = "CREATE TAG person(id int) " + "ttl_col=\"id\", ttl_duration=100"; + auto code3 = client->execute(cmd3, resp3); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code3); + + cpp2::ExecutionResponse resp4; + std::string cmd4 = "CREATE TAG career(name string)"; + auto code4 = client->execute(cmd4, resp4); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code4); + + + cpp2::ExecutionResponse resp5; + std::string cmd5 = "CREATE Edge like(id int) " + "ttl_col=\"id\", ttl_duration=100"; + auto code5 = client->execute(cmd5, resp5); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code5); + + sleep(FLAGS_heartbeat_interval_secs + 3); + } + { + cpp2::ExecutionResponse resp; + 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\")"; + + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string cmd = "FETCH PROP ON person 1 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 * 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 * 2"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + + std::vector expectedColNames{ + {"VertexID"}, {"career.name"} + }; + ASSERT_TRUE(verifyColNames(resp, expectedColNames)); + std::vector> expected = { + {2, "liming"}, + }; + ASSERT_TRUE(verifyResult(resp, expected, false)); + } + + { + cpp2::ExecutionResponse resp; + 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 resp; + std::string cmd = "FETCH PROP ON like 100->1,100->2 YIELD like.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 = "GO FROM 100 OVER like YIELD like.id AS id, " + "$$.person.id AS pid"; + 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 = "DROP SPACE default_space"; + auto code = client->execute(cmd, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } +} + +} // namespace graph +} // namespace nebula diff --git a/src/storage/query/QueryVertexPropsProcessor.cpp b/src/storage/query/QueryVertexPropsProcessor.cpp index 5ae965f2c72..d27124229fb 100644 --- a/src/storage/query/QueryVertexPropsProcessor.cpp +++ b/src/storage/query/QueryVertexPropsProcessor.cpp @@ -57,6 +57,45 @@ void QueryVertexPropsProcessor::process(const cpp2::VertexPropRequest& vertexReq } } +folly::Optional> +QueryVertexPropsProcessor::getTagTTLInfo(TagID tagId, const meta::SchemaProviderIf* tagschema) { + folly::Optional> ret; + auto tagFound = tagTTLInfo_.find(tagId); + + if (tagFound == tagTTLInfo_.end()) { + const meta::NebulaSchemaProvider* nschema = + dynamic_cast(tagschema); + if (nschema == NULL) { + VLOG(3) << "Can't find NebulaSchemaProvider in spaceId " << spaceId_; + return ret; + } + + const nebula::cpp2::SchemaProp schemaProp = nschema->getProp(); + int64_t ttlDuration = 0; + if (schemaProp.get_ttl_duration()) { + ttlDuration = *schemaProp.get_ttl_duration(); + } + std::string ttlCol; + if (schemaProp.get_ttl_col()) { + ttlCol = *schemaProp.get_ttl_col(); + } + + // Only support the specified ttl_col mode + // Not specifying or non-positive ttl_duration behaves like ttl_duration = infinity + if (ttlCol.empty() || ttlDuration <= 0) { + VLOG(3) << "TTL property is invalid"; + return ret; + } + + tagTTLInfo_.emplace(tagId, std::make_pair(ttlCol, ttlDuration)); + ret.emplace(ttlCol, ttlDuration); + return ret; + } else { + ret.emplace(tagFound->second.first, tagFound->second.second); + } + return ret; +} + kvstore::ResultCode QueryVertexPropsProcessor::collectVertexProps( PartitionID partId, VertexID vId, @@ -98,7 +137,7 @@ kvstore::ResultCode QueryVertexPropsProcessor::collectVertexProps( } auto reader = RowReader::getTagPropReader(this->schemaMan_, val, spaceId_, tagId); // Check if ttl data expired - auto retTTL = getTagTTLInfo(tagId); + auto retTTL = getTagTTLInfo(tagId, schema.get()); if (retTTL.has_value() && checkDataExpiredForTTL(schema.get(), reader.get(), retTTL.value().first, diff --git a/src/storage/query/QueryVertexPropsProcessor.h b/src/storage/query/QueryVertexPropsProcessor.h index 133a6d0c4aa..5c932c4de8e 100644 --- a/src/storage/query/QueryVertexPropsProcessor.h +++ b/src/storage/query/QueryVertexPropsProcessor.h @@ -25,6 +25,12 @@ class QueryVertexPropsProcessor : public QueryBoundProcessor { void process(const cpp2::VertexPropRequest& req); + // Only use in fetch * + // Check tagId in tagTTLInfo_, if any, get ttl information. + // If not, add it first, then return ttl information + folly::Optional> + getTagTTLInfo(TagID tagId, const meta::SchemaProviderIf* tagschema); + private: explicit QueryVertexPropsProcessor(kvstore::KVStore* kvstore, meta::SchemaManager* schemaMan, @@ -37,6 +43,8 @@ class QueryVertexPropsProcessor : public QueryBoundProcessor { PartitionID partId, VertexID vId, std::vector &tds); + + std::unordered_map> tagTTLInfo_; }; } // namespace storage