diff --git a/src/dataman/ResultSchemaProvider.cpp b/src/dataman/ResultSchemaProvider.cpp index 3f48a9ddc58..2ce26f9a5b7 100644 --- a/src/dataman/ResultSchemaProvider.cpp +++ b/src/dataman/ResultSchemaProvider.cpp @@ -46,8 +46,7 @@ bool ResultSchemaProvider::ResultSchemaField::isValid() const { * **********************************/ ResultSchemaProvider::ResultSchemaProvider(Schema schema) - : columns_(std::move(schema.get_columns())), - schemaProp_(std::move(schema.get_schema_prop())) { + : columns_(std::move(schema.get_columns())) { for (int64_t i = 0; i < static_cast(columns_.size()); i++) { const std::string& name = columns_[i].get_name(); nameIndex_.emplace(std::make_pair(SpookyHashV2::Hash64(name.data(), name.size(), 0), i)); @@ -114,10 +113,5 @@ std::shared_ptr ResultSchemaProvider::field return std::make_shared(&(columns_[index])); } - -const cpp2::SchemaProp ResultSchemaProvider::getProp() const { - return schemaProp_; -} - } // namespace nebula diff --git a/src/dataman/ResultSchemaProvider.h b/src/dataman/ResultSchemaProvider.h index db2ff885be3..dfb0662c045 100644 --- a/src/dataman/ResultSchemaProvider.h +++ b/src/dataman/ResultSchemaProvider.h @@ -50,8 +50,6 @@ class ResultSchemaProvider : public meta::SchemaProviderIf { std::shared_ptr field( const folly::StringPiece name) const override; - const cpp2::SchemaProp getProp() const override; - protected: SchemaVer schemaVer_{0}; @@ -61,8 +59,6 @@ class ResultSchemaProvider : public meta::SchemaProviderIf { // Default constructor, only used by SchemaWriter explicit ResultSchemaProvider(SchemaVer ver = 0) : schemaVer_(ver) {} - - cpp2::SchemaProp schemaProp_; }; } // namespace nebula diff --git a/src/graph/CMakeLists.txt b/src/graph/CMakeLists.txt index fbd5f15ffda..2e67a65e4a4 100644 --- a/src/graph/CMakeLists.txt +++ b/src/graph/CMakeLists.txt @@ -21,8 +21,6 @@ add_library( DropEdgeExecutor.cpp DescribeTagExecutor.cpp DescribeEdgeExecutor.cpp - ShowCreateTagExecutor.cpp - ShowCreateEdgeExecutor.cpp InsertVertexExecutor.cpp InsertEdgeExecutor.cpp AssignmentExecutor.cpp @@ -33,7 +31,6 @@ add_library( CreateSpaceExecutor.cpp DropSpaceExecutor.cpp DescribeSpaceExecutor.cpp - ShowCreateSpaceExecutor.cpp ShowExecutor.cpp YieldExecutor.cpp SchemaHelper.cpp diff --git a/src/graph/CreateEdgeExecutor.h b/src/graph/CreateEdgeExecutor.h index 07d1960674a..ba185c50998 100644 --- a/src/graph/CreateEdgeExecutor.h +++ b/src/graph/CreateEdgeExecutor.h @@ -25,10 +25,6 @@ class CreateEdgeExecutor final : public Executor { void execute() override; - Status setTTLDuration(SchemaPropItem* schemaProp); - - Status setTTLCol(SchemaPropItem* schemaProp); - private: CreateEdgeSentence *sentence_{nullptr}; nebula::cpp2::Schema schema_; diff --git a/src/graph/CreateTagExecutor.h b/src/graph/CreateTagExecutor.h index cb99f2beefa..11d19f4d44a 100644 --- a/src/graph/CreateTagExecutor.h +++ b/src/graph/CreateTagExecutor.h @@ -25,10 +25,6 @@ class CreateTagExecutor final : public Executor { void execute() override; - Status setTTLDuration(SchemaPropItem* schemaProp); - - Status setTTLCol(SchemaPropItem* schemaProp); - private: CreateTagSentence *sentence_{nullptr}; nebula::cpp2::Schema schema_; diff --git a/src/graph/Executor.cpp b/src/graph/Executor.cpp index 3820aa73f04..9e9722716dd 100644 --- a/src/graph/Executor.cpp +++ b/src/graph/Executor.cpp @@ -21,8 +21,6 @@ #include "graph/DropEdgeExecutor.h" #include "graph/DescribeTagExecutor.h" #include "graph/DescribeEdgeExecutor.h" -#include "graph/ShowCreateTagExecutor.h" -#include "graph/ShowCreateEdgeExecutor.h" #include "graph/InsertVertexExecutor.h" #include "graph/InsertEdgeExecutor.h" #include "graph/AssignmentExecutor.h" @@ -31,7 +29,6 @@ #include "graph/RemoveHostsExecutor.h" #include "graph/CreateSpaceExecutor.h" #include "graph/DescribeSpaceExecutor.h" -#include "graph/ShowCreateSpaceExecutor.h" #include "graph/DropSpaceExecutor.h" #include "graph/YieldExecutor.h" @@ -69,12 +66,6 @@ std::unique_ptr Executor::makeExecutor(Sentence *sentence) { case Sentence::Kind::kDescribeEdge: executor = std::make_unique(sentence, ectx()); break; - case Sentence::Kind::kShowCreateTag: - executor = std::make_unique(sentence, ectx()); - break; - case Sentence::Kind::kShowCreateEdge: - executor = std::make_unique(sentence, ectx()); - break; case Sentence::Kind::kDropTag: executor = std::make_unique(sentence, ectx()); break; @@ -108,9 +99,6 @@ std::unique_ptr Executor::makeExecutor(Sentence *sentence) { case Sentence::Kind::kDescribeSpace: executor = std::make_unique(sentence, ectx()); break; - case Sentence::Kind::kShowCreateSpace: - executor = std::make_unique(sentence, ectx()); - break; case Sentence::Kind::kYield: executor = std::make_unique(sentence, ectx()); break; diff --git a/src/graph/ShowCreateEdgeExecutor.cpp b/src/graph/ShowCreateEdgeExecutor.cpp deleted file mode 100644 index 16b9aedce24..00000000000 --- a/src/graph/ShowCreateEdgeExecutor.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* Copyright (c) 2019 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/ShowCreateEdgeExecutor.h" -#include "meta/SchemaManager.h" - -namespace nebula { -namespace graph { - -ShowCreateEdgeExecutor::ShowCreateEdgeExecutor(Sentence *sentence, - ExecutionContext *ectx) : Executor(ectx) { - sentence_ = static_cast(sentence); -} - - -Status ShowCreateEdgeExecutor::prepare() { - return checkIfGraphSpaceChosen(); -} - - -void ShowCreateEdgeExecutor::execute() { - auto *name = sentence_->name(); - 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, &name] (auto &&resp) { - if (!resp.ok()) { - DCHECK(onError_); - onError_(Status::Error("Schema not found for edge '%s'", name->c_str())); - return; - } - - resp_ = std::make_unique(); - std::vector header{"Edge", "Create Edge"}; - resp_->set_column_names(std::move(header)); - - std::vector rows; - std::vector row; - row.resize(2); - row[0].set_str(*name); - - std::string buf; - buf.reserve(256); - buf += folly::stringPrintf("create edge %s (\n", name->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 = "; - buf += folly::to(prop.get_ttl_duration()); - buf += " ttl_col = "; - std::string ttlCol = prop.get_ttl_col(); - if (ttlCol.empty()) { - buf += "\"\""; - } else { - buf += ttlCol; - } - - 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("Internal error")); - }; - - std::move(future).via(runner).thenValue(cb).thenError(error); -} - - -void ShowCreateEdgeExecutor::setupResponse(cpp2::ExecutionResponse &resp) { - resp = std::move(*resp_); -} - -} // namespace graph -} // namespace nebula diff --git a/src/graph/ShowCreateEdgeExecutor.h b/src/graph/ShowCreateEdgeExecutor.h deleted file mode 100644 index 39dfd72c6c4..00000000000 --- a/src/graph/ShowCreateEdgeExecutor.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright (c) 2019 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. - */ - -#ifndef GRAPH_SHOWCREATEEDGEEXECUTOR_H_ -#define GRAPH_SHOWCREATEEDGEEXECUTOR_H_ - -#include "base/Base.h" -#include "graph/Executor.h" - -namespace nebula { -namespace graph { - -class ShowCreateEdgeExecutor final : public Executor { -public: - ShowCreateEdgeExecutor(Sentence *sentence, ExecutionContext *ectx); - - const char* name() const override { - return "ShowCreateEdgeExecutor"; - } - - Status MUST_USE_RESULT prepare() override; - - void execute() override; - - void setupResponse(cpp2::ExecutionResponse &resp) override; - -private: - ShowCreateEdgeSentence *sentence_{nullptr}; - std::unique_ptr resp_; -}; - -} // namespace graph -} // namespace nebula - -#endif // GRAPH_SHOWCREATEEDGEEXECUTOR_H_ diff --git a/src/graph/ShowCreateSpaceExecutor.cpp b/src/graph/ShowCreateSpaceExecutor.cpp deleted file mode 100644 index 3f53689725d..00000000000 --- a/src/graph/ShowCreateSpaceExecutor.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* Copyright (c) 2019 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/ShowCreateSpaceExecutor.h" -#include "meta/SchemaManager.h" - -namespace nebula { -namespace graph { - -ShowCreateSpaceExecutor::ShowCreateSpaceExecutor(Sentence *sentence, - ExecutionContext *ectx) : Executor(ectx) { - sentence_ = static_cast(sentence); -} - -Status ShowCreateSpaceExecutor::prepare() { - return Status::OK(); -} - -void ShowCreateSpaceExecutor::execute() { - auto *name = sentence_->spaceName(); - auto future = ectx()->getMetaClient()->getSpace(*name); - auto *runner = ectx()->rctx()->runner(); - - auto cb = [this] (auto &&resp) { - if (!resp.ok()) { - onError_(Status::Error("Space not found")); - return; - } - - resp_ = std::make_unique(); - std::vector header{"Space", "Create Space"}; - resp_->set_column_names(std::move(header)); - - std::vector rows; - std::vector 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(properties.get_partition_num()); - buf += ", "; - buf += "replica_factor = "; - buf += folly::to(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("Internal error")); - return; - }; - - std::move(future).via(runner).thenValue(cb).thenError(error); -} - - -void ShowCreateSpaceExecutor::setupResponse(cpp2::ExecutionResponse &resp) { - resp = std::move(*resp_); -} - -} // namespace graph -} // namespace nebula diff --git a/src/graph/ShowCreateSpaceExecutor.h b/src/graph/ShowCreateSpaceExecutor.h deleted file mode 100644 index 1c93a09e8ec..00000000000 --- a/src/graph/ShowCreateSpaceExecutor.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright (c) 2019 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. - */ - -#ifndef GRAPH_SHOWCREATESPACEEXECUTOR_H_ -#define GRAPH_SHOWCREATESPACEEXECUTOR_H_ - -#include "base/Base.h" -#include "graph/Executor.h" - -namespace nebula { -namespace graph { - -class ShowCreateSpaceExecutor final : public Executor { -public: - ShowCreateSpaceExecutor(Sentence *sentence, ExecutionContext *ectx); - - const char* name() const override { - return "ShowCreateSpaceExecutor"; - } - - Status MUST_USE_RESULT prepare() override; - - void execute() override; - - void setupResponse(cpp2::ExecutionResponse &resp) override; - -private: - ShowCreateSpaceSentence *sentence_{nullptr}; - std::unique_ptr resp_; -}; - -} // namespace graph -} // namespace nebula - -#endif // GRAPH_SHOWCREATESPACEEXECUTOR_H_ diff --git a/src/graph/ShowCreateTagExecutor.cpp b/src/graph/ShowCreateTagExecutor.cpp deleted file mode 100644 index e54c2c51bed..00000000000 --- a/src/graph/ShowCreateTagExecutor.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* Copyright (c) 2019 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/ShowCreateTagExecutor.h" -#include "meta/SchemaManager.h" - -namespace nebula { -namespace graph { - -ShowCreateTagExecutor::ShowCreateTagExecutor(Sentence *sentence, - ExecutionContext *ectx) : Executor(ectx) { - sentence_ = static_cast(sentence); -} - - -Status ShowCreateTagExecutor::prepare() { - return checkIfGraphSpaceChosen(); -} - - -void ShowCreateTagExecutor::execute() { - auto *name = sentence_->name(); - 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, &name] (auto &&resp) { - if (!resp.ok()) { - DCHECK(onError_); - onError_(Status::Error("Schema not found for tag '%s'", name->c_str())); - return; - } - - resp_ = std::make_unique(); - std::vector header{"Tag", "Create Tag"}; - resp_->set_column_names(std::move(header)); - - std::vector rows; - std::vector row; - row.resize(2); - row[0].set_str(*name); - - std::string buf; - buf.reserve(256); - buf += folly::stringPrintf("create tag %s (\n", name->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 = "; - buf += folly::to(prop.get_ttl_duration()); - buf += " ttl_col = "; - std::string ttlCol = prop.get_ttl_col(); - if (ttlCol.empty()) { - buf += "\"\""; - } else { - buf += ttlCol; - } - - 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("Internal error")); - }; - - std::move(future).via(runner).thenValue(cb).thenError(error); -} - - -void ShowCreateTagExecutor::setupResponse(cpp2::ExecutionResponse &resp) { - resp = std::move(*resp_); -} - -} // namespace graph -} // namespace nebula diff --git a/src/graph/ShowCreateTagExecutor.h b/src/graph/ShowCreateTagExecutor.h deleted file mode 100644 index e5edbba6309..00000000000 --- a/src/graph/ShowCreateTagExecutor.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright (c) 2019 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. - */ - -#ifndef GRAPH_SHOWCREATETAGEXECUTOR_H_ -#define GRAPH_SHOWCREATETAGEXECUTOR_H_ - -#include "base/Base.h" -#include "graph/Executor.h" - -namespace nebula { -namespace graph { - -class ShowCreateTagExecutor final : public Executor { -public: - ShowCreateTagExecutor(Sentence *sentence, ExecutionContext *ectx); - - const char* name() const override { - return "ShowCreateTagExecutor"; - } - - Status MUST_USE_RESULT prepare() override; - - void execute() override; - - void setupResponse(cpp2::ExecutionResponse &resp) override; - -private: - ShowCreateTagSentence *sentence_{nullptr}; - std::unique_ptr resp_; -}; - -} // namespace graph -} // namespace nebula - -#endif // GRAPH_SHOWCREATETAGEXECUTOR_H_ diff --git a/src/graph/ShowExecutor.cpp b/src/graph/ShowExecutor.cpp index 92905c77f7f..5b4831d0d85 100644 --- a/src/graph/ShowExecutor.cpp +++ b/src/graph/ShowExecutor.cpp @@ -20,7 +20,9 @@ ShowExecutor::ShowExecutor(Sentence *sentence, Status ShowExecutor::prepare() { 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) { return checkIfGraphSpaceChosen(); } else { return Status::OK(); @@ -48,6 +50,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; @@ -69,12 +80,8 @@ void ShowExecutor::showHosts() { auto retShowHosts = std::move(resp).value(); std::vector rows; - std::vector header; + std::vector header{"Ip", "Port", "Status"}; resp_ = std::make_unique(); - - header.emplace_back("Ip"); - header.emplace_back("Port"); - header.emplace_back("Status"); resp_->set_column_names(std::move(header)); for (auto &status : retShowHosts) { @@ -116,10 +123,8 @@ void ShowExecutor::showSpaces() { auto retShowSpaces = std::move(resp).value(); std::vector rows; - std::vector header; + std::vector header{"Name"}; resp_ = std::make_unique(); - - header.emplace_back("Name"); resp_->set_column_names(std::move(header)); for (auto &space : retShowSpaces) { @@ -145,6 +150,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); @@ -186,6 +192,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); @@ -226,6 +233,208 @@ 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()) { + onError_(Status::Error("Space not found")); + return; + } + + resp_ = std::make_unique(); + std::vector header{"Space", "Create Space"}; + resp_->set_column_names(std::move(header)); + + std::vector rows; + std::vector 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(properties.get_partition_num()); + buf += ", "; + buf += "replica_factor = "; + buf += folly::to(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_(Status::Error("Schema not found for tag '%s'", tagName->c_str())); + return; + } + + resp_ = std::make_unique(); + std::vector header{"Tag", "Create Tag"}; + resp_->set_column_names(std::move(header)); + + std::vector rows; + std::vector 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 = "; + buf += folly::to(prop.get_ttl_duration()); + buf += " ttl_col = "; + std::string ttlCol = prop.get_ttl_col(); + if (ttlCol.empty()) { + buf += "\"\""; + } else { + buf += ttlCol; + } + + 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_(Status::Error("Schema not found for edge '%s'", edgeName->c_str())); + return; + } + + resp_ = std::make_unique(); + std::vector header{"Edge", "Create Edge"}; + resp_->set_column_names(std::move(header)); + + std::vector rows; + std::vector 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 = "; + buf += folly::to(prop.get_ttl_duration()); + buf += " ttl_col = "; + std::string ttlCol = prop.get_ttl_col(); + if (ttlCol.empty()) { + buf += "\"\""; + } else { + buf += ttlCol; + } + + 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/graph/ShowExecutor.h b/src/graph/ShowExecutor.h index 1b08fcc879a..105a5c39942 100644 --- a/src/graph/ShowExecutor.h +++ b/src/graph/ShowExecutor.h @@ -28,6 +28,9 @@ class ShowExecutor final : public Executor { void showSpaces(); void showTags(); void showEdges(); + void showCreateSpace(); + void showCreateTag(); + void showCreateEdge(); void setupResponse(cpp2::ExecutionResponse &resp) override; diff --git a/src/graph/test/SchemaTest.cpp b/src/graph/test/SchemaTest.cpp index 94e087e8a81..1e992c890c5 100644 --- a/src/graph/test/SchemaTest.cpp +++ b/src/graph/test/SchemaTest.cpp @@ -49,7 +49,7 @@ TEST_F(SchemaTest, metaCommunication) { ASSERT_TRUE(verifyResult(resp, expected)); } - // Test space + // Space test { // Test space not exist cpp2::ExecutionResponse resp; @@ -88,7 +88,7 @@ TEST_F(SchemaTest, metaCommunication) { 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 (" + std::string createSpaceStr = "CREATE SPACE default_space (" "partition_num = 9, " "replica_factor = 1)"; std::vector> expected{ @@ -125,7 +125,7 @@ TEST_F(SchemaTest, metaCommunication) { ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } - // Test tag + // Tag test { cpp2::ExecutionResponse resp; std::string query = "CREATE TAG person(name string, email string, " @@ -166,7 +166,7 @@ TEST_F(SchemaTest, metaCommunication) { 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" + std::string createTagStr = "CREATE TAG person (\n" " name string,\n" " email string,\n" " age int,\n" @@ -187,28 +187,6 @@ TEST_F(SchemaTest, metaCommunication) { } // Unreserved keyword as filed name - { - cpp2::ExecutionResponse resp; - std::string query = "CREATE TAG man(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 man"; - 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 = "CREATE TAG upper(name string, EMAIL string, " @@ -279,7 +257,7 @@ TEST_F(SchemaTest, metaCommunication) { std::string query = "SHOW CREATE TAG account"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); - std::string createTagStr = "create tag account (\n" + std::string createTagStr = "CREATE TAG account (\n" " balance string,\n" " col1 int,\n" " col2 string\n" @@ -290,7 +268,7 @@ TEST_F(SchemaTest, metaCommunication) { ASSERT_TRUE(verifyResult(resp, expected)); } - // Test edge + // Edge test { cpp2::ExecutionResponse resp; std::string query = "CREATE EDGE buy(id int, time string)"; @@ -331,7 +309,7 @@ TEST_F(SchemaTest, metaCommunication) { 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" + std::string createEdgeStr = "CREATE EDGE buy (\n" " id int,\n" " time string\n" ") ttl_duration = 0 ttl_col = \"\""; @@ -403,14 +381,12 @@ TEST_F(SchemaTest, metaCommunication) { }; ASSERT_TRUE(verifyResult(resp, expected)); } - - // 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" + std::string createEdgeStr = "CREATE EDGE education (\n" " school int,\n" " col1 int,\n" " col2 string\n" @@ -572,7 +548,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> expected{ + {"person", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } { cpp2::ExecutionResponse resp; std::string query = "CREATE TAG man(name string, email string, " @@ -583,20 +575,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> 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; @@ -623,7 +618,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> expected{ + {"woman", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } { cpp2::ExecutionResponse resp; std::string query = "CREATE TAG only_ttl_col(name string, email string, " @@ -632,7 +643,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> expected{ + {"only_ttl_col", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } { cpp2::ExecutionResponse resp; std::string query = "ALTER TAG woman " @@ -640,17 +667,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> expected{ - {"name", "string"}, - {"email", "string"}, - {"age", "int"}, - {"gender", "string"}, - {"row_timestamp", "timestamp"}, + {"woman", createTagStr}, }; ASSERT_TRUE(verifyResult(resp, expected)); } @@ -662,28 +692,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> 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> 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; @@ -692,7 +723,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; @@ -701,7 +731,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> expected{ + {"woman", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } { cpp2::ExecutionResponse resp; std::string query = "ALTER TAG woman " @@ -709,9 +755,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" + ") ttl_duration = 200 ttl_col = age"; + std::vector> expected{ + {"woman", createTagStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } - // Edge ttl test + // Edge with TTL test { cpp2::ExecutionResponse resp; std::string query = "CREATE EDGE person(name string, email string, " @@ -733,7 +793,23 @@ 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 person"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE EDGE 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", createEdgeStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } { cpp2::ExecutionResponse resp; std::string query = "CREATE EDGE man(name string, email string, " @@ -742,7 +818,25 @@ TEST_F(SchemaTest, TTLtest) { 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 = "SHOW CREATE EDGE man"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE EDGE 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", createEdgeStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + + // Abnormal test { // Disable implicit ttl mode cpp2::ExecutionResponse resp; @@ -762,23 +856,30 @@ TEST_F(SchemaTest, TTLtest) { 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 woman(name string, email string, " "age int, gender string, row_timestamp timestamp)" - "ttl_col = name"; + "ttl_duration = -100, ttl_col = row_timestamp"; auto code = client->execute(query, resp); - ASSERT_NE(cpp2::ErrorCode::SUCCEEDED, code); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } { cpp2::ExecutionResponse resp; - std::string query = "CREATE EDGE woman(name string, email string, " - "age int, gender string, row_timestamp timestamp)" - "ttl_duration = -100, ttl_col = row_timestamp"; + std::string query = "SHOW CREATE EDGE woman"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE EDGE 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", createEdgeStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); } - // TODO(YT) Use show create edge { cpp2::ExecutionResponse resp; std::string query = "CREATE EDGE only_ttl_col(name string, email string, " @@ -787,7 +888,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 only_ttl_col"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE 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{ + {"only_ttl_col", createEdgeStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } { cpp2::ExecutionResponse resp; std::string query = "ALTER EDGE woman " @@ -795,24 +912,54 @@ 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 woman " - "Drop (name) ttl_duration = 200"; + std::string query = "SHOW CREATE EDGE woman"; auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE EDGE 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", 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 woman " - "ttl_col = email"; + "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 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 EDGE woman"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE EDGE 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", createEdgeStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } { // When the column is as TTL column, droping column failed cpp2::ExecutionResponse resp; @@ -821,7 +968,6 @@ 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; @@ -830,7 +976,22 @@ 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 woman"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE EDGE woman (\n" + " email string,\n" + " age int,\n" + " gender string,\n" + " row_timestamp timestamp\n" + ") ttl_duration = 200 ttl_col = age"; + std::vector> expected{ + {"woman", createEdgeStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } { cpp2::ExecutionResponse resp; std::string query = "ALTER EDGE woman " @@ -838,7 +999,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 woman"; + client->execute(query, resp); + std::vector> expected{ + {"email", "string"}, + {"age", "int"}, + {"gender", "string"}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + { + cpp2::ExecutionResponse resp; + std::string query = "SHOW CREATE EDGE woman"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::string createEdgeStr = "CREATE EDGE woman (\n" + " email string,\n" + " age int,\n" + " gender string\n" + ") ttl_duration = 200 ttl_col = age"; + std::vector> expected{ + {"woman", createEdgeStr}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + { cpp2::ExecutionResponse resp; std::string query = "DROP SPACE default_space"; diff --git a/src/interface/graph.thrift b/src/interface/graph.thrift index b909959b6a3..d4f9b1faf61 100644 --- a/src/interface/graph.thrift +++ b/src/interface/graph.thrift @@ -90,8 +90,6 @@ struct ExecutionResponse { 3: optional string error_msg; 4: optional list column_names; // Column names 5: optional list rows; - 6: optional list schema_prop_names; - 7: optional list schema_prop_rows; } diff --git a/src/interface/meta.thrift b/src/interface/meta.thrift index 129cb38cd84..155339b31b0 100644 --- a/src/interface/meta.thrift +++ b/src/interface/meta.thrift @@ -45,12 +45,6 @@ enum AlterSchemaOp { UNKNOWN = 0x04, } (cpp.enum_strict) -enum AlterSchemaPropType { - TTL_DURATION = 0; - TTL_COL = 1; - UNKNOWN = 2; -} (cpp.enum_strict) - /** ** GOD is A global senior administrator.like root of Linux systems. ** ADMIN is an administrator for a given Graph Space. @@ -101,14 +95,9 @@ struct TagItem { 4: common.Schema schema, } -struct AlterSchemaOption { - 1: AlterSchemaOptionType type, - 2: common.Schema schema, -} - -struct AlterSchemaProp { - 1: AlterSchemaPropType type, - 2: string value, +struct AlterSchemaItem { + 1: AlterSchemaOp op, + 2: common.Schema schema, } struct EdgeItem { diff --git a/src/meta/MetaServiceUtils.h b/src/meta/MetaServiceUtils.h index a9175d6d7d8..27baa51dc5d 100644 --- a/src/meta/MetaServiceUtils.h +++ b/src/meta/MetaServiceUtils.h @@ -90,13 +90,7 @@ class MetaServiceUtils final { static cpp2::ErrorCode alterColumnDefs(std::vector& cols, nebula::cpp2::SchemaProp& prop, const nebula::cpp2::ColumnDef col, - const cpp2::AlterSchemaOptionType op); - - static cpp2::ErrorCode alterSchemaProp(std::vector& cols, - nebula::cpp2::SchemaProp& prop, - cpp2::AlterSchemaProp alterProp); - - static Status checkSchemaTTLProp(nebula::cpp2::SchemaProp& prop); + const cpp2::AlterSchemaOp op); static cpp2::ErrorCode alterSchemaProp(std::vector& cols, nebula::cpp2::SchemaProp& schemaProp, diff --git a/src/meta/SchemaProviderIf.h b/src/meta/SchemaProviderIf.h index 8f8a171ad9a..adec7e8561a 100644 --- a/src/meta/SchemaProviderIf.h +++ b/src/meta/SchemaProviderIf.h @@ -100,7 +100,6 @@ class SchemaProviderIf { virtual std::shared_ptr field(int64_t index) const = 0; virtual std::shared_ptr field(const folly::StringPiece name) const = 0; - virtual const nebula::cpp2::SchemaProp getProp() const = 0; /****************************************** * * Iterator implementation diff --git a/src/meta/processors/schemaMan/AlterTagProcessor.cpp b/src/meta/processors/schemaMan/AlterTagProcessor.cpp index 99dc0f6c559..2c6c6e4f33b 100644 --- a/src/meta/processors/schemaMan/AlterTagProcessor.cpp +++ b/src/meta/processors/schemaMan/AlterTagProcessor.cpp @@ -58,6 +58,7 @@ void AlterTagProcessor::process(const cpp2::AlterTagReq& req) { // Update schema property auto& alterSchemaProp = req.get_schema_prop(); auto retCode = MetaServiceUtils::alterSchemaProp(columns, prop, std::move(alterSchemaProp)); + if (retCode != cpp2::ErrorCode::SUCCEEDED) { LOG(WARNING) << "Alter tag property error " << static_cast(retCode); resp_.set_code(retCode); diff --git a/src/meta/test/ProcessorTest.cpp b/src/meta/test/ProcessorTest.cpp index efebf150972..9ca2f9ea51e 100644 --- a/src/meta/test/ProcessorTest.cpp +++ b/src/meta/test/ProcessorTest.cpp @@ -904,11 +904,10 @@ TEST(ProcessorTest, AlterTagTest) { auto kv = TestUtils::initKV(rootPath.path()); ASSERT_TRUE(TestUtils::assembleSpace(kv.get(), 1)); TestUtils::mockTag(kv.get(), 1); - // Alter tag options test { cpp2::AlterTagReq req; - std::vector options; + std::vector items; nebula::cpp2::Schema addSch; for (auto i = 0; i < 2; i++) { nebula::cpp2::ColumnDef column; @@ -933,7 +932,7 @@ TEST(ProcessorTest, AlterTagTest) { items.emplace_back(FRAGILE, cpp2::AlterSchemaOp::DROP, std::move(dropSch)); req.set_space_id(1); req.set_tag_name("tag_0"); - req.set_schema_options(options); + req.set_tag_items(items); auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -972,12 +971,8 @@ TEST(ProcessorTest, AlterTagTest) { column.name = "tag_0_col_11"; column.type.type = SupportedType::STRING; cols.emplace_back(std::move(column)); - schema.set_columns(std::move(cols)); - nebula::cpp2::SchemaProp schemaProp; - schemaProp.ttl_duration = 100; - schemaProp.ttl_col = "tag_0_col_10"; - schema.set_schema_prop(std::move(schemaProp)); + schema.set_columns(std::move(cols)); EXPECT_EQ(schema, tag.get_schema()); } // Alter tag with ttl @@ -1060,7 +1055,6 @@ TEST(ProcessorTest, AlterTagTest) { *tag.get_schema().get_schema_prop().get_ttl_col()); } - // Alter tag options test { // Drop ttl_col column, failed cpp2::AlterTagReq req; @@ -1083,7 +1077,7 @@ TEST(ProcessorTest, AlterTagTest) { // Verify ErrorCode of add { cpp2::AlterTagReq req; - std::vector options; + std::vector items; nebula::cpp2::Schema addSch; nebula::cpp2::ColumnDef column; column.name = "tag_0_col_1"; @@ -1095,7 +1089,7 @@ TEST(ProcessorTest, AlterTagTest) { items.emplace_back(std::move(addItem)); req.set_space_id(1); req.set_tag_name("tag_0"); - req.set_schema_options(options); + req.set_tag_items(items); auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1117,7 +1111,7 @@ TEST(ProcessorTest, AlterTagTest) { items.emplace_back(std::move(changeItem)); req.set_space_id(1); req.set_tag_name("tag_0"); - req.set_schema_options(options); + req.set_tag_items(items); auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1134,8 +1128,9 @@ TEST(ProcessorTest, AlterTagTest) { column.type.type = SupportedType::INT; dropSch.columns.emplace_back(std::move(column)); items.emplace_back(FRAGILE, cpp2::AlterSchemaOp::DROP, std::move(dropSch)); + req.set_space_id(1); req.set_tag_name("tag_0"); - req.set_schema_options(options); + req.set_tag_items(items); auto* processor = AlterTagProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1156,19 +1151,19 @@ TEST(ProcessorTest, AlterEdgeTest) { cpp2::AlterEdgeReq req; nebula::cpp2::Schema dropSch; nebula::cpp2::ColumnDef column; - std::vector options; + std::vector items; column.name = folly::stringPrintf("edge_%d_col_%d", 0, 0); dropSch.columns.emplace_back(std::move(column)); column.name = folly::stringPrintf("edge_%d_col_%d", 0, 1); dropSch.columns.emplace_back(std::move(column)); - auto dropOption = cpp2::AlterSchemaOption(FRAGILE, - cpp2::AlterSchemaOptionType::DROP, - std::move(dropSch)); - options.emplace_back(std::move(dropOption)); + auto dropItem = cpp2::AlterSchemaItem(FRAGILE, + cpp2::AlterSchemaOp::DROP, + std::move(dropSch)); + items.emplace_back(std::move(dropItem)); req.set_space_id(1); req.set_edge_name("edge_0"); - req.set_schema_options(options); + req.set_edge_items(items); auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1195,7 +1190,7 @@ TEST(ProcessorTest, AlterEdgeTest) { cpp2::AlterEdgeReq req; nebula::cpp2::Schema addSch; nebula::cpp2::ColumnDef column; - std::vector options; + std::vector items; column.name = folly::stringPrintf("edge_%d_col_%d", 0, 0); addSch.columns.emplace_back(std::move(column)); column.name = folly::stringPrintf("edge_%d_col_%d", 0, 1); @@ -1207,7 +1202,7 @@ TEST(ProcessorTest, AlterEdgeTest) { items.emplace_back(std::move(addItem)); req.set_space_id(1); req.set_edge_name("edge_0"); - req.set_schema_options(options); + req.set_edge_items(items); auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1216,7 +1211,7 @@ TEST(ProcessorTest, AlterEdgeTest) { } { cpp2::AlterEdgeReq req; - std::vector options; + std::vector items; nebula::cpp2::Schema addSch; for (auto i = 0; i < 2; i++) { nebula::cpp2::ColumnDef column; @@ -1250,7 +1245,7 @@ TEST(ProcessorTest, AlterEdgeTest) { items.emplace_back(std::move(dropItem)); req.set_space_id(1); req.set_edge_name("edge_0"); - req.set_schema_options(options); + req.set_edge_items(items); auto* processor = AlterEdgeProcessor::instance(kv.get()); auto f = processor->getFuture(); processor->process(req); @@ -1477,6 +1472,8 @@ TEST(ProcessorTest, AlterEdgeTest) { EXPECT_EQ(0, edge.get_edge_type()); EXPECT_EQ(folly::stringPrintf("edge_%d", 0), edge.get_edge_name()); EXPECT_EQ(4, edge.version); + } +} } // namespace meta } // namespace nebula diff --git a/src/parser/AdminSentences.cpp b/src/parser/AdminSentences.cpp index f05ac095e43..8916bd4cdac 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"); @@ -106,9 +112,4 @@ std::string DescribeSpaceSentence::toString() const { return folly::stringPrintf("DESCRIBE SPACE %s", spaceName_.get()->c_str()); } - -std::string ShowCreateSpaceSentence::toString() const { - return folly::stringPrintf("SHOW CREATE SPACE %s", spaceName_.get()->c_str()); -} - } // namespace nebula diff --git a/src/parser/AdminSentences.h b/src/parser/AdminSentences.h index a060af4d581..97189a2a6d0 100644 --- a/src/parser/AdminSentences.h +++ b/src/parser/AdminSentences.h @@ -24,18 +24,23 @@ class ShowSentence final : public Sentence { 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 { @@ -271,24 +276,6 @@ class DescribeSpaceSentence final : public Sentence { std::unique_ptr spaceName_; }; - -class ShowCreateSpaceSentence final : public Sentence { -public: - explicit ShowCreateSpaceSentence(std::string *spaceName) { - spaceName_.reset(spaceName); - kind_ = Kind::kShowCreateSpace; - } - - std::string* spaceName() { - return spaceName_.get(); - } - - std::string toString() const override; - -private: - std::unique_ptr spaceName_; -}; - } // namespace nebula #endif // PARSER_ADMINSENTENCES_H_ diff --git a/src/parser/MaintainSentences.cpp b/src/parser/MaintainSentences.cpp index 93d0f44e583..0b40ef548bf 100644 --- a/src/parser/MaintainSentences.cpp +++ b/src/parser/MaintainSentences.cpp @@ -206,16 +206,6 @@ std::string DescribeEdgeSentence::toString() const { } -std::string ShowCreateTagSentence::toString() const { - return folly::stringPrintf("SHOW CREATE TAG %s", name_.get()->c_str()); -} - - -std::string ShowCreateEdgeSentence::toString() const { - return folly::stringPrintf("SHOW CREATE EDGE %s", name_.get()->c_str()); -} - - std::string DropTagSentence::toString() const { return folly::stringPrintf("DROP TAG %s", name_.get()->c_str()); } diff --git a/src/parser/MaintainSentences.h b/src/parser/MaintainSentences.h index 67d5cc7dd00..59882c10a80 100644 --- a/src/parser/MaintainSentences.h +++ b/src/parser/MaintainSentences.h @@ -388,42 +388,6 @@ class DescribeEdgeSentence final : public Sentence { }; -class ShowCreateTagSentence final : public Sentence { -public: - explicit ShowCreateTagSentence(std::string *name) { - name_.reset(name); - kind_ = Kind::kShowCreateTag; - } - - std::string toString() const override; - - const std::string* name() const { - return name_.get(); - } - -private: - std::unique_ptr name_; -}; - - -class ShowCreateEdgeSentence final : public Sentence { -public: - explicit ShowCreateEdgeSentence(std::string *name) { - name_.reset(name); - kind_ = Kind::kShowCreateEdge; - } - - std::string toString() const override; - - const std::string* name() const { - return name_.get(); - } - -private: - std::unique_ptr name_; -}; - - class DropTagSentence final : public Sentence { public: explicit DropTagSentence(std::string *name) { diff --git a/src/parser/Sentence.h b/src/parser/Sentence.h index 4170bbbba1e..d4c9fc18eb1 100644 --- a/src/parser/Sentence.h +++ b/src/parser/Sentence.h @@ -30,8 +30,6 @@ class Sentence { kAlterEdge, kDescribeTag, kDescribeEdge, - kShowCreateTag, - kShowCreateEdge, kDropTag, kDropEdge, kInsertVertex, @@ -45,7 +43,6 @@ class Sentence { kCreateSpace, kDropSpace, kDescribeSpace, - kShowCreateSpace, kYield, kCreateUser, kDropUser, diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 9f3eb967bf6..4fafd693e4e 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -161,13 +161,12 @@ class GraphScanner; %type create_tag_sentence create_edge_sentence %type alter_tag_sentence alter_edge_sentence %type describe_tag_sentence describe_edge_sentence -%type show_create_tag_sentence show_create_edge_sentence %type drop_tag_sentence drop_edge_sentence %type traverse_sentence set_sentence piped_sentence assignment_sentence %type maintain_sentence insert_vertex_sentence insert_edge_sentence %type mutate_sentence update_vertex_sentence update_edge_sentence delete_vertex_sentence delete_edge_sentence %type show_sentence add_hosts_sentence remove_hosts_sentence -%type create_space_sentence describe_space_sentence drop_space_sentence show_create_space_sentence +%type create_space_sentence describe_space_sentence drop_space_sentence %type yield_sentence %type create_user_sentence alter_user_sentence drop_user_sentence change_password_sentence %type grant_sentence revoke_sentence @@ -689,12 +688,6 @@ describe_tag_sentence } ; -show_create_tag_sentence - : KW_SHOW KW_CREATE KW_TAG name_label { - $$ = new ShowCreateTagSentence($4); - } - ; - describe_edge_sentence : KW_DESCRIBE KW_EDGE name_label { $$ = new DescribeEdgeSentence($3); @@ -704,12 +697,6 @@ describe_edge_sentence } ; -show_create_edge_sentence - : KW_SHOW KW_CREATE KW_EDGE name_label { - $$ = new ShowCreateEdgeSentence($4); - } - ; - drop_tag_sentence : KW_DROP KW_TAG name_label { $$ = new DropTagSentence($3); @@ -992,6 +979,15 @@ show_sentence | KW_SHOW KW_ROLES KW_IN name_label { $$ = new ShowSentence(ShowSentence::ShowType::kShowRoles, $4); } + | 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 @@ -1056,12 +1052,6 @@ describe_space_sentence } ; -show_create_space_sentence - : KW_SHOW KW_CREATE KW_SPACE name_label { - $$ = new ShowCreateSpaceSentence($4); - } - ; - space_opt_list : space_opt_item { $$ = new SpaceOptList(); @@ -1224,8 +1214,6 @@ maintain_sentence | alter_edge_sentence { $$ = $1; } | describe_tag_sentence { $$ = $1; } | describe_edge_sentence { $$ = $1; } - | show_create_tag_sentence { $$ = $1; } - | show_create_edge_sentence { $$ = $1; } | drop_tag_sentence { $$ = $1; } | drop_edge_sentence { $$ = $1; } | show_sentence { $$ = $1; } @@ -1233,7 +1221,6 @@ maintain_sentence | remove_hosts_sentence { $$ = $1; } | create_space_sentence { $$ = $1; } | describe_space_sentence { $$ = $1; } - | show_create_space_sentence { $$ = $1; } | drop_space_sentence { $$ = $1; } | yield_sentence { // Now we take YIELD as a normal maintenance sentence.