diff --git a/src/executor/AlterTagExecutor.cpp b/src/executor/AlterTagExecutor.cpp
index 0ec65fbbfd4e5b92808c36e23bcb439189d93542..8c3bf2da789e33fde40bca1acb057087b408c931 100644
--- a/src/executor/AlterTagExecutor.cpp
+++ b/src/executor/AlterTagExecutor.cpp
@@ -48,7 +48,6 @@ void AlterTagExecutor::execute() {
auto *name = sentence_->name();
auto spaceId = ectx()->rctx()->session()->space();
-
auto future = mc->alterTagSchema(spaceId, *name, std::move(options_), std::move(schemaProp_));
auto *runner = ectx()->rctx()->runner();
auto cb = [this] (auto &&resp) {
diff --git a/src/executor/DescribeSpaceExecutor.cpp b/src/executor/DescribeSpaceExecutor.cpp
index 7258f2915222b374f64ba3a31a27b24d2cb83940..89777a4da117c8bf42c9698a22370f6266b33cdf 100644
--- a/src/executor/DescribeSpaceExecutor.cpp
+++ b/src/executor/DescribeSpaceExecutor.cpp
@@ -1,7 +1,7 @@
-/* Copyright (c) 2019 - present, VE Software Inc. All rights reserved
+/* Copyright (c) 2019 vesoft inc. All rights reserved.
*
- * This source code is licensed under Apache 2.0 License
- * (found in the LICENSE.Apache file in the root directory)
+ * 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"
diff --git a/src/executor/DescribeSpaceExecutor.h b/src/executor/DescribeSpaceExecutor.h
index 371258dbb7b65930d374edb55f1d1ad009836b04..31e8a37b14f6455b52a08c0cc4bfef9bc037b2f3 100644
--- a/src/executor/DescribeSpaceExecutor.h
+++ b/src/executor/DescribeSpaceExecutor.h
@@ -1,7 +1,7 @@
-/* Copyright (c) 2019 - present, VE Software Inc. All rights reserved
+/* Copyright (c) 2019 vesoft inc. All rights reserved.
*
- * This source code is licensed under Apache 2.0 License
- * (found in the LICENSE.Apache file in the root directory)
+ * This source code is licensed under Apache 2.0 License,
+ * attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/
#ifndef GRAPH_DESCRIBESPACEEXECUTOR_H_
diff --git a/src/executor/ShowExecutor.cpp b/src/executor/ShowExecutor.cpp
index 270b4aa0daf53336c894fedf2747615acca2da15..3504529567967cb1370aa80065aba565c7928e72 100644
--- a/src/executor/ShowExecutor.cpp
+++ b/src/executor/ShowExecutor.cpp
@@ -25,7 +25,9 @@ Status ShowExecutor::prepare() {
void ShowExecutor::execute() {
if (sentence_->showType() == ShowSentence::ShowType::kShowTags ||
- sentence_->showType() == ShowSentence::ShowType::kShowEdges) {
+ sentence_->showType() == ShowSentence::ShowType::kShowEdges ||
+ sentence_->showType() == ShowSentence::ShowType::kShowCreateTag ||
+ sentence_->showType() == ShowSentence::ShowType::kShowCreateEdge) {
auto status = checkIfGraphSpaceChosen();
if (!status.ok()) {
DCHECK(onError_);
@@ -52,6 +54,15 @@ void ShowExecutor::execute() {
case ShowSentence::ShowType::kShowRoles:
// TODO(boshengchen)
break;
+ case ShowSentence::ShowType::kShowCreateSpace:
+ showCreateSpace();
+ break;
+ case ShowSentence::ShowType::kShowCreateTag:
+ showCreateTag();
+ break;
+ case ShowSentence::ShowType::kShowCreateEdge:
+ showCreateEdge();
+ break;
case ShowSentence::ShowType::kUnknown:
onError_(Status::Error("Type unknown"));
break;
@@ -73,12 +84,8 @@ void ShowExecutor::showHosts() {
auto retShowHosts = std::move(resp).value();
std::vector<cpp2::RowValue> rows;
- std::vector<std::string> header;
+ std::vector<std::string> header{"Ip", "Port", "Status"};
resp_ = std::make_unique<cpp2::ExecutionResponse>();
-
- header.emplace_back("Ip");
- header.emplace_back("Port");
- header.emplace_back("Status");
resp_->set_column_names(std::move(header));
for (auto &status : retShowHosts) {
@@ -120,10 +127,8 @@ void ShowExecutor::showSpaces() {
auto retShowSpaces = std::move(resp).value();
std::vector<cpp2::RowValue> rows;
- std::vector<std::string> header;
+ std::vector<std::string> header{"Name"};
resp_ = std::make_unique<cpp2::ExecutionResponse>();
-
- header.emplace_back("Name");
resp_->set_column_names(std::move(header));
for (auto &space : retShowSpaces) {
@@ -149,6 +154,7 @@ void ShowExecutor::showSpaces() {
std::move(future).via(runner).thenValue(cb).thenError(error);
}
+
void ShowExecutor::showTags() {
auto spaceId = ectx()->rctx()->session()->space();
auto future = ectx()->getMetaClient()->listTagSchemas(spaceId);
@@ -196,6 +202,7 @@ void ShowExecutor::showTags() {
std::move(future).via(runner).thenValue(cb).thenError(error);
}
+
void ShowExecutor::showEdges() {
auto spaceId = ectx()->rctx()->session()->space();
auto future = ectx()->getMetaClient()->listEdgeSchemas(spaceId);
@@ -241,6 +248,215 @@ void ShowExecutor::showEdges() {
std::move(future).via(runner).thenValue(cb).thenError(error);
}
+
+void ShowExecutor::showCreateSpace() {
+ auto *name = sentence_->getName();
+ auto future = ectx()->getMetaClient()->getSpace(*name);
+ auto *runner = ectx()->rctx()->runner();
+
+ auto cb = [this] (auto &&resp) {
+ if (!resp.ok()) {
+ DCHECK(onError_);
+ onError_(std::move(resp).status());
+ return;
+ }
+
+ resp_ = std::make_unique<cpp2::ExecutionResponse>();
+ std::vector<std::string> header{"Space", "Create Space"};
+ resp_->set_column_names(std::move(header));
+
+ std::vector<cpp2::RowValue> rows;
+ std::vector<cpp2::ColumnValue> row;
+ row.resize(2);
+ auto properties = resp.value().get_properties();
+ row[0].set_str(properties.get_space_name());
+
+ std::string buf;
+ buf.reserve(256);
+ buf += folly::stringPrintf("CREATE SPACE %s (", properties.get_space_name().c_str());
+ buf += "partition_num = ";
+ buf += folly::to<std::string>(properties.get_partition_num());
+ buf += ", ";
+ buf += "replica_factor = ";
+ buf += folly::to<std::string>(properties.get_replica_factor());
+ buf += ")";
+
+ row[1].set_str(buf);;
+ rows.emplace_back();
+ rows.back().set_columns(std::move(row));
+ resp_->set_rows(std::move(rows));
+
+ DCHECK(onFinish_);
+ onFinish_();
+ };
+
+ auto error = [this] (auto &&e) {
+ LOG(ERROR) << "Exception caught: " << e.what();
+ DCHECK(onError_);
+ onError_(Status::Error(folly::stringPrintf("Internal error : %s",
+ e.what().c_str())));
+ return;
+ };
+
+ std::move(future).via(runner).thenValue(cb).thenError(error);
+}
+
+
+void ShowExecutor::showCreateTag() {
+ auto *name = sentence_->getName();
+ auto spaceId = ectx()->rctx()->session()->space();
+
+ // Get the lastest ver
+ auto future = ectx()->getMetaClient()->getTagSchema(spaceId, *name);
+ auto *runner = ectx()->rctx()->runner();
+
+
+ auto cb = [this] (auto &&resp) {
+ auto *tagName = sentence_->getName();
+ if (!resp.ok()) {
+ DCHECK(onError_);
+ onError_(std::move(resp).status());
+ return;
+ }
+
+ resp_ = std::make_unique<cpp2::ExecutionResponse>();
+ std::vector<std::string> header{"Tag", "Create Tag"};
+ resp_->set_column_names(std::move(header));
+
+ std::vector<cpp2::RowValue> rows;
+ std::vector<cpp2::ColumnValue> row;
+ row.resize(2);
+ row[0].set_str(*tagName);
+
+ std::string buf;
+ buf.reserve(256);
+ buf += folly::stringPrintf("CREATE TAG %s (\n", tagName->c_str());
+
+ auto schema = resp.value();
+ for (auto& item : schema.columns) {
+ buf += " ";
+ buf += item.name;
+ buf += " ";
+ buf += valueTypeToString(item.type);
+ buf += ",\n";
+ }
+
+ if (!schema.columns.empty()) {
+ buf.resize(buf.size() -2);
+ buf += "\n";
+ }
+ buf += ") ";
+ nebula::cpp2::SchemaProp prop = schema.schema_prop;
+ buf += "ttl_duration = ";
+ if (prop.get_ttl_duration()) {
+ buf += folly::to<std::string>(*prop.get_ttl_duration());
+ } else {
+ buf += "0";
+ }
+ buf += ", ttl_col = ";
+ if (prop.get_ttl_col() && !(prop.get_ttl_col()->empty())) {
+ buf += *prop.get_ttl_col();
+ } else {
+ buf += "\"\"";
+ }
+
+ row[1].set_str(buf);
+ rows.emplace_back();
+ rows.back().set_columns(std::move(row));
+ resp_->set_rows(std::move(rows));
+
+ DCHECK(onFinish_);
+ onFinish_();
+ };
+
+ auto error = [this] (auto &&e) {
+ LOG(ERROR) << "Exception caught: " << e.what();
+ DCHECK(onError_);
+ onError_(Status::Error(folly::stringPrintf("Internal error : %s",
+ e.what().c_str())));
+ };
+
+ std::move(future).via(runner).thenValue(cb).thenError(error);
+}
+
+
+void ShowExecutor::showCreateEdge() {
+ auto *name = sentence_->getName();
+ auto spaceId = ectx()->rctx()->session()->space();
+
+ // Get the lastest ver
+ auto future = ectx()->getMetaClient()->getEdgeSchema(spaceId, *name);
+ auto *runner = ectx()->rctx()->runner();
+
+ auto cb = [this] (auto &&resp) {
+ auto *edgeName = sentence_->getName();
+ if (!resp.ok()) {
+ DCHECK(onError_);
+ onError_(std::move(resp).status());
+ return;
+ }
+
+ resp_ = std::make_unique<cpp2::ExecutionResponse>();
+ std::vector<std::string> header{"Edge", "Create Edge"};
+ resp_->set_column_names(std::move(header));
+
+ std::vector<cpp2::RowValue> rows;
+ std::vector<cpp2::ColumnValue> row;
+ row.resize(2);
+ row[0].set_str(*edgeName);
+
+ std::string buf;
+ buf.reserve(256);
+ buf += folly::stringPrintf("CREATE EDGE %s (\n", edgeName->c_str());
+
+ auto schema = resp.value();
+ for (auto& item : schema.columns) {
+ buf += " ";
+ buf += item.name;
+ buf += " ";
+ buf += valueTypeToString(item.type);
+ buf += ",\n";
+ }
+
+ if (!schema.columns.empty()) {
+ buf.resize(buf.size() -2);
+ buf += "\n";
+ }
+ buf += ") ";
+ nebula::cpp2::SchemaProp prop = schema.schema_prop;
+ buf += "ttl_duration = ";
+ if (prop.get_ttl_duration()) {
+ buf += folly::to<std::string>(*prop.get_ttl_duration());
+ } else {
+ buf += "0";
+ }
+ buf += ", ttl_col = ";
+ if (prop.get_ttl_col() && !(prop.get_ttl_col()->empty())) {
+ buf += *prop.get_ttl_col();
+ } else {
+ buf += "\"\"";
+ }
+
+ row[1].set_str(buf);
+ rows.emplace_back();
+ rows.back().set_columns(std::move(row));
+ resp_->set_rows(std::move(rows));
+
+ DCHECK(onFinish_);
+ onFinish_();
+ };
+
+ auto error = [this] (auto &&e) {
+ LOG(ERROR) << "Exception caught: " << e.what();
+ DCHECK(onError_);
+ onError_(Status::Error(folly::stringPrintf("Internal error : %s",
+ e.what().c_str())));
+ };
+
+ std::move(future).via(runner).thenValue(cb).thenError(error);
+}
+
+
void ShowExecutor::setupResponse(cpp2::ExecutionResponse &resp) {
resp = std::move(*resp_);
}
diff --git a/src/executor/ShowExecutor.h b/src/executor/ShowExecutor.h
index 8d3df51f16dc22cca246d168a020175b23f0de68..6966edf5a6561803b4fa652956d83226cee3a57a 100644
--- a/src/executor/ShowExecutor.h
+++ b/src/executor/ShowExecutor.h
@@ -28,6 +28,9 @@ public:
void showSpaces();
void showTags();
void showEdges();
+ void showCreateSpace();
+ void showCreateTag();
+ void showCreateEdge();
void setupResponse(cpp2::ExecutionResponse &resp) override;
diff --git a/src/executor/test/SchemaTest.cpp b/src/executor/test/SchemaTest.cpp
index 85e5d7e35cdffc2e5371d3489d595646f33bcf3b..5af4c465a8e2a8c772ccb7b00d01dd98f434fbf4 100644
--- a/src/executor/test/SchemaTest.cpp
+++ b/src/executor/test/SchemaTest.cpp
@@ -57,6 +57,7 @@ TEST_F(SchemaTest, metaCommunication) {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
+
// Test space not exist
{
cpp2::ExecutionResponse resp;
@@ -92,6 +93,19 @@ TEST_F(SchemaTest, metaCommunication) {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
+ {
+ cpp2::ExecutionResponse resp;
+ std::string query = "SHOW CREATE SPACE default_space";
+ auto code = client->execute(query, resp);
+ ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
+ std::string createSpaceStr = "CREATE SPACE default_space ("
+ "partition_num = 9, "
+ "replica_factor = 1)";
+ std::vector<uniform_tuple_t<std::string, 2>> expected{
+ {"default_space", createSpaceStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
+ }
{
cpp2::ExecutionResponse resp;
std::string query = "CREATE SPACE space_with_default_options";
@@ -120,6 +134,7 @@ TEST_F(SchemaTest, metaCommunication) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
+
// Test create tag without prop
{
cpp2::ExecutionResponse resp;
@@ -188,6 +203,31 @@ TEST_F(SchemaTest, metaCommunication) {
};
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<uniform_tuple_t<std::string, 2>> expected{
+ {"person", createTagStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
+ }
+ {
+ // Test tag not exist
+ cpp2::ExecutionResponse resp;
+ std::string query = "DESCRIBE TAG not_exist";
+ auto code = client->execute(query, resp);
+ ASSERT_EQ(cpp2::ErrorCode::E_EXECUTION_ERROR, code);
+ }
+
// Test unreserved keyword
{
cpp2::ExecutionResponse resp;
@@ -255,6 +295,24 @@ TEST_F(SchemaTest, metaCommunication) {
};
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 string,\n"
+ " row_timestamp timestamp,\n"
+ " col1 int,\n"
+ " col2 string\n"
+ ") ttl_duration = 0, ttl_col = \"\"";
+ std::vector<uniform_tuple_t<std::string, 2>> expected{
+ {"person", createTagStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
+ }
{
cpp2::ExecutionResponse resp;
std::string query = "SHOW TAGS";
@@ -313,7 +371,8 @@ TEST_F(SchemaTest, metaCommunication) {
{
cpp2::ExecutionResponse resp;
std::string query = "DESCRIBE EDGE buy";
- client->execute(query, resp);
+ auto code = client->execute(query, resp);
+ ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<uniform_tuple_t<std::string, 2>> expected{
{"id", "int"},
{"time", "string"},
@@ -331,15 +390,30 @@ TEST_F(SchemaTest, metaCommunication) {
{
cpp2::ExecutionResponse resp;
std::string query = "DESC EDGE buy";
- client->execute(query, resp);
+ auto code = client->execute(query, resp);
+ ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
std::vector<uniform_tuple_t<std::string, 2>> expected{
{"id", "int"},
{"time", "string"},
};
EXPECT_TRUE(verifyResult(resp, expected));
}
- // Test edge not exist
{
+ cpp2::ExecutionResponse resp;
+ std::string query = "SHOW CREATE EDGE buy";
+ auto code = client->execute(query, resp);
+ ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
+ std::string createEdgeStr = "CREATE EDGE buy (\n"
+ " id int,\n"
+ " time string\n"
+ ") ttl_duration = 0, ttl_col = \"\"";
+ std::vector<uniform_tuple_t<std::string, 2>> expected{
+ {"buy", createEdgeStr},
+ };
+ EXPECT_TRUE(verifyResult(resp, expected));
+ }
+ {
+ // Test edge not exist
cpp2::ExecutionResponse resp;
std::string query = "DESCRIBE EDGE not_exist";
auto code = client->execute(query, resp);
@@ -397,9 +471,9 @@ TEST_F(SchemaTest, metaCommunication) {
std::string query = "DESCRIBE EDGE education";
client->execute(query, resp);
std::vector<uniform_tuple_t<std::string, 2>> expected{
+ {"school", "int"},
{"col1", "int"},
{"col2", "string"},
- {"school", "int"},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
@@ -439,6 +513,23 @@ TEST_F(SchemaTest, metaCommunication) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
+ // Test different tag and edge in different space
+ {
+ cpp2::ExecutionResponse resp;
+ std::string query = "SHOW CREATE EDGE education";
+ auto code = client->execute(query, resp);
+ ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
+ std::string createEdgeStr = "CREATE EDGE education (\n"
+ " school int,\n"
+ " col1 int,\n"
+ " col2 string\n"
+ ") ttl_duration = 0, ttl_col = \"\"";
+ std::vector<uniform_tuple_t<std::string, 2>> expected{
+ {"education", createEdgeStr},
+ };
+ EXPECT_TRUE(verifyResult(resp, expected));
+ }
+
// Test different tag and edge in different space
{
cpp2::ExecutionResponse resp;
@@ -599,7 +690,23 @@ TEST_F(SchemaTest, TTLtest) {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
- // TODO(YT) Add show create tag
+ {
+ 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<uniform_tuple_t<std::string, 2>> expected{
+ {"person", createTagStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
+ }
{
cpp2::ExecutionResponse resp;
std::string query = "CREATE TAG man(name string, email string, "
@@ -610,20 +717,23 @@ TEST_F(SchemaTest, TTLtest) {
}
{
cpp2::ExecutionResponse resp;
- std::string query = "DESCRIBE TAG man";
+ 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<uniform_tuple_t<std::string, 2>> expected{
- {"name", "string"},
- {"email", "string"},
- {"age", "int"},
- {"gender", "string"},
- {"row_timestamp", "timestamp"},
+ {"man", createTagStr},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
- // Add show create tag test
+
+ // Abnormal test
{
// Disable implicit ttl mode
cpp2::ExecutionResponse resp;
@@ -650,7 +760,23 @@ TEST_F(SchemaTest, TTLtest) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
- // TODO(YT) Use show create tag instead
+ {
+ 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<uniform_tuple_t<std::string, 2>> expected{
+ {"woman", createTagStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
+ }
{
cpp2::ExecutionResponse resp;
std::string query = "CREATE TAG only_ttl_col(name string, email string, "
@@ -659,7 +785,23 @@ TEST_F(SchemaTest, TTLtest) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
- // TODO(YT) Use show create tag instead
+ {
+ 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<uniform_tuple_t<std::string, 2>> expected{
+ {"only_ttl_col", createTagStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
+ }
{
cpp2::ExecutionResponse resp;
std::string query = "ALTER TAG woman "
@@ -667,17 +809,20 @@ TEST_F(SchemaTest, TTLtest) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
- // Use show create tag instead
{
cpp2::ExecutionResponse resp;
- std::string query = "DESCRIBE TAG woman";
- client->execute(query, 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<uniform_tuple_t<std::string, 2>> expected{
- {"name", "string"},
- {"email", "string"},
- {"age", "int"},
- {"gender", "string"},
- {"row_timestamp", "timestamp"},
+ {"woman", createTagStr},
};
ASSERT_TRUE(verifyResult(resp, expected));
}
@@ -689,28 +834,29 @@ TEST_F(SchemaTest, TTLtest) {
auto code = client->execute(query, resp);
ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code);
}
- // Use show create tag instead
{
cpp2::ExecutionResponse resp;
- std::string query = "DESCRIBE TAG woman";
- client->execute(query, resp);
- std::vector<uniform_tuple_t<std::string, 2>> expected{
- {"name", "string"},
- {"email", "string"},
- {"age", "int"},
- {"gender", "string"},
- {"row_timestamp", "timestamp"},
- };
- ASSERT_TRUE(verifyResult(resp, expected));
+ 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 = "ALTER TAG woman "
- "Drop (name) ttl_duration = 200";
+ 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<uniform_tuple_t<std::string, 2>> expected{
+ {"woman", createTagStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
}
- // TODO(YT) Use show create tag
{
// When the column is as TTL column, droping column failed
cpp2::ExecutionResponse resp;
@@ -719,7 +865,6 @@ TEST_F(SchemaTest, TTLtest) {
auto code = client->execute(query, resp);
ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code);
}
- // TODO(YT) Use show create tag
{
// First remove TTL property, then drop column
cpp2::ExecutionResponse resp;
@@ -728,7 +873,23 @@ TEST_F(SchemaTest, TTLtest) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
- // TODO(YT) Use show create tag
+ {
+ 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 = age";
+ std::vector<uniform_tuple_t<std::string, 2>> expected{
+ {"woman", createTagStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
+ }
{
cpp2::ExecutionResponse resp;
std::string query = "ALTER TAG woman "
@@ -736,17 +897,29 @@ TEST_F(SchemaTest, TTLtest) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
- // TODO(YT) Use show create tag
+ {
+ 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 = 200, ttl_col = age";
+ std::vector<uniform_tuple_t<std::string, 2>> expected{
+ {"woman", createTagStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
+ }
- // Edge ttl test
+ // Edge with TTL test
{
cpp2::ExecutionResponse resp;
- std::string query = "CREATE EDGE work(number string, start_time timestamp)"
- "ttl_duration = 100, ttl_col = start_time";
+ std::string query = "CREATE EDGE work(number string, start_time timestamp)";
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
- // TODO(YT) Use show create edge test
{
cpp2::ExecutionResponse resp;
std::string query = "DESCRIBE EDGE work";
@@ -758,11 +931,51 @@ TEST_F(SchemaTest, TTLtest) {
};
ASSERT_TRUE(verifyResult(resp, expected));
}
- // TODO(YT) Use show create edge test
+ {
+ 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<uniform_tuple_t<std::string, 2>> 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<uniform_tuple_t<std::string, 2>> expected{
+ {"work1", createEdgeStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
+ }
+
+ // Abnormal test
{
// Disable implicit ttl mode
cpp2::ExecutionResponse resp;
- std::string query = "CREATE EDGE work1(number string, start_time timestamp)"
+ 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);
@@ -777,12 +990,29 @@ TEST_F(SchemaTest, TTLtest) {
}
{
cpp2::ExecutionResponse resp;
- std::string query = "CREATE EDGE work2(name string, number string, start_time timestamp)"
+ 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);
}
- // TODO(YT) Use show create edge
+ {
+ 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<uniform_tuple_t<std::string, 2>> expected{
+ {"work2", createEdgeStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
+ }
{
cpp2::ExecutionResponse resp;
std::string query = "CREATE EDGE edge_only_ttl_col(name string, email string, "
@@ -791,7 +1021,23 @@ TEST_F(SchemaTest, TTLtest) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
- // TODO(YT) Use show create edge
+ {
+ 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<uniform_tuple_t<std::string, 2>> expected{
+ {"edge_only_ttl_col", createEdgeStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
+ }
{
cpp2::ExecutionResponse resp;
std::string query = "ALTER EDGE work2 "
@@ -799,24 +1045,55 @@ TEST_F(SchemaTest, TTLtest) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
- // TODO(YT) Use show create edge
{
cpp2::ExecutionResponse resp;
- std::string query = "ALTER EDGE work2 "
- "Drop (name) ttl_duration = 200";
+
+ 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<uniform_tuple_t<std::string, 2>> expected{
+ {"work2", createEdgeStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
}
- // TODO(YT) Use show create edge
{
- // Failed when alter tag to set ttl_col on not integer and timestamp column
+ // 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 = number";
+ "ttl_col = name";
auto code = client->execute(query, resp);
ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code);
}
- // TODO(YT) Use show create edge
+ {
+ 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<uniform_tuple_t<std::string, 2>> expected{
+ {"work2", createEdgeStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
+ }
{
// When the column is as TTL column, droping column failed
cpp2::ExecutionResponse resp;
@@ -825,16 +1102,30 @@ TEST_F(SchemaTest, TTLtest) {
auto code = client->execute(query, resp);
ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code);
}
- // TODO(YT) Use show create edge
{
// First remove TTL property, then drop column
cpp2::ExecutionResponse resp;
- std::string query = "ALTER EDGE work2 CHANGE(number int) "
- "ttl_col = number";
+ std::string query = "ALTER EDGE work2 "
+ "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 createEdgeStr = "CREATE EDGE work2 (\n"
+ " email string,\n"
+ " age int,\n"
+ " gender string,\n"
+ " start_time timestamp\n"
+ ") ttl_duration = 200, ttl_col = age";
+ std::vector<uniform_tuple_t<std::string, 2>> expected{
+ {"work2", createEdgeStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
}
- // TODO(YT) Use show create edge
{
cpp2::ExecutionResponse resp;
std::string query = "ALTER EDGE work2 "
@@ -842,7 +1133,33 @@ TEST_F(SchemaTest, TTLtest) {
auto code = client->execute(query, resp);
ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code);
}
- // TODO(YT) Use show create edge
+ {
+ cpp2::ExecutionResponse resp;
+ std::string query = "DESCRIBE EDGE work2";
+ client->execute(query, resp);
+ std::vector<uniform_tuple_t<std::string, 2>> expected{
+ {"email", "string"},
+ {"age", "int"},
+ {"gender", "string"},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
+ }
+ {
+ 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 = 200, ttl_col = age";
+ std::vector<uniform_tuple_t<std::string, 2>> expected{
+ {"work2", createEdgeStr},
+ };
+ ASSERT_TRUE(verifyResult(resp, expected));
+ }
+
{
cpp2::ExecutionResponse resp;
std::string query = "DROP SPACE default_space";
diff --git a/src/parser/AdminSentences.cpp b/src/parser/AdminSentences.cpp
index 157116a9713f226d36065a72271df5b222b40075..41a86961fd1593d178a5dcf2e94073f312bce024 100644
--- a/src/parser/AdminSentences.cpp
+++ b/src/parser/AdminSentences.cpp
@@ -21,9 +21,15 @@ std::string ShowSentence::toString() const {
case ShowType::kShowUsers:
return std::string("SHOW USERS");
case ShowType::kShowUser:
- return folly::stringPrintf("SHOW USER %s", name_.get()->data());
+ return folly::stringPrintf("SHOW USER %s", name_.get()->c_str());
case ShowType::kShowRoles:
- return folly::stringPrintf("SHOW ROLES IN %s", name_.get()->data());
+ return folly::stringPrintf("SHOW ROLES IN %s", name_.get()->c_str());
+ case ShowType::kShowCreateSpace:
+ return folly::stringPrintf("SHOW CREATE SPACE %s", name_.get()->c_str());
+ case ShowType::kShowCreateTag:
+ return folly::stringPrintf("SHOW CREATE TAG %s", name_.get()->c_str());
+ case ShowType::kShowCreateEdge:
+ return folly::stringPrintf("SHOW CREATE EDGE %s", name_.get()->c_str());
case ShowType::kUnknown:
default:
FLOG_FATAL("Type illegal");
@@ -96,12 +102,14 @@ std::string CreateSpaceSentence::toString() const {
return buf;
}
+
std::string DropSpaceSentence::toString() const {
- return folly::stringPrintf("DROP SPACE %s", spaceName_.get()->c_str());
+ return folly::stringPrintf("DROP SPACE %s", spaceName_.get()->c_str());
}
+
std::string DescribeSpaceSentence::toString() const {
- return folly::stringPrintf("DESCRIBE SPACE %s", spaceName_.get()->c_str());
+ return folly::stringPrintf("DESCRIBE SPACE %s", spaceName_.get()->c_str());
}
std::string ConfigRowItem::toString() const {
diff --git a/src/parser/AdminSentences.h b/src/parser/AdminSentences.h
index 98296fb15e91b977714c9fd99b311b72649cb581..e742474fac3197e5c980c562e4f0ef9291df20af 100644
--- a/src/parser/AdminSentences.h
+++ b/src/parser/AdminSentences.h
@@ -26,18 +26,23 @@ public:
kShowEdges,
kShowUsers,
kShowUser,
- kShowRoles
+ kShowRoles,
+ kShowCreateSpace,
+ kShowCreateTag,
+ kShowCreateEdge
};
explicit ShowSentence(ShowType sType) {
kind_ = Kind::kShow;
showType_ = std::move(sType);
}
+
ShowSentence(ShowType sType, std::string *name) {
kind_ = Kind::kShow;
name_.reset(name);
showType_ = std::move(sType);
}
+
std::string toString() const override;
ShowType showType() const {
diff --git a/src/parser/MaintainSentences.h b/src/parser/MaintainSentences.h
index 40fc7acaf9d6952eea6fea0b0591035e89cd0461..1a280117a7ea02bda76e3867f06d062fa23c1e69 100644
--- a/src/parser/MaintainSentences.h
+++ b/src/parser/MaintainSentences.h
@@ -411,6 +411,7 @@ private:
std::unique_ptr<std::string> name_;
};
+
class DropTagSentence final : public Sentence {
public:
explicit DropTagSentence(std::string *name) {
diff --git a/src/parser/parser.yy b/src/parser/parser.yy
index 590f2d80d1754863c543ede8de1a97142bf72eb9..6d9d8efd9c073a97883362137673b9620703a260 100644
--- a/src/parser/parser.yy
+++ b/src/parser/parser.yy
@@ -1219,6 +1219,15 @@ show_sentence
| KW_SHOW KW_VARIABLES show_config_item {
$$ = new ConfigSentence(ConfigSentence::SubType::kShow, $3);
}
+ | KW_SHOW KW_CREATE KW_SPACE name_label {
+ $$ = new ShowSentence(ShowSentence::ShowType::kShowCreateSpace, $4);
+ }
+ | KW_SHOW KW_CREATE KW_TAG name_label {
+ $$ = new ShowSentence(ShowSentence::ShowType::kShowCreateTag, $4);
+ }
+ | KW_SHOW KW_CREATE KW_EDGE name_label {
+ $$ = new ShowSentence(ShowSentence::ShowType::kShowCreateEdge, $4);
+ }
;
add_hosts_sentence
diff --git a/src/parser/test/ParserTest.cpp b/src/parser/test/ParserTest.cpp
index e682cbafcce5dc5ac768ca468945d47c3d8de74c..8e0e4f5e8c27fc8c5a22f7bb8b4c89b094c66fa9 100644
--- a/src/parser/test/ParserTest.cpp
+++ b/src/parser/test/ParserTest.cpp
@@ -134,6 +134,12 @@ TEST(Parser, SpaceOperation) {
auto result = parser.parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
+ {
+ GQLParser parser;
+ std::string query = "SHOW CREATE SPACE default_space";
+ auto result = parser.parse(query);
+ ASSERT_TRUE(result.ok()) << result.status();
+ }
{
GQLParser parser;
std::string query = "DROP SPACE default_space";
@@ -213,7 +219,7 @@ TEST(Parser, TagOperation) {
}
{
GQLParser parser;
- std::string query = "DESCRIBE TAG person";
+ std::string query = "SHOW CREATE TAG person";
auto result = parser.parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
@@ -296,7 +302,7 @@ TEST(Parser, EdgeOperation) {
}
{
GQLParser parser;
- std::string query = "DESCRIBE EDGE e1";
+ std::string query = "SHOW CREATE EDGE e1";
auto result = parser.parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
@@ -765,6 +771,24 @@ TEST(Parser, AdminOperation) {
auto result = parser.parse(query);
ASSERT_TRUE(result.ok()) << result.status();
}
+ {
+ GQLParser parser;
+ std::string query = "SHOW CREATE SPACE default_space";
+ auto result = parser.parse(query);
+ ASSERT_TRUE(result.ok()) << result.status();
+ }
+ {
+ GQLParser parser;
+ std::string query = "SHOW CREATE TAG person";
+ auto result = parser.parse(query);
+ ASSERT_TRUE(result.ok()) << result.status();
+ }
+ {
+ GQLParser parser;
+ std::string query = "SHOW CREATE EDGE e1";
+ auto result = parser.parse(query);
+ ASSERT_TRUE(result.ok()) << result.status();
+ }
}
TEST(Parser, UserOperation) {