From f66682bc0a94ea05fd55c1c222bb22dcc12c633d Mon Sep 17 00:00:00 2001 From: laura-ding <48548375+laura-ding@users.noreply.github.com> Date: Tue, 3 Sep 2019 15:22:51 +0800 Subject: [PATCH] Fix duplicated props and display problem after drop space (#848) --- src/console/CliManager.cpp | 7 +------ src/console/CliManager.h | 1 - src/console/CmdProcessor.cpp | 2 ++ src/console/CmdProcessor.h | 2 +- src/executor/DropSpaceExecutor.cpp | 4 ++++ src/executor/SchemaHelper.cpp | 5 +++++ src/executor/test/SchemaTest.cpp | 15 ++++++++++++++- 7 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/console/CliManager.cpp b/src/console/CliManager.cpp index efc68bc9..96d98582 100644 --- a/src/console/CliManager.cpp +++ b/src/console/CliManager.cpp @@ -26,8 +26,6 @@ const int32_t kMaxUsernameLen = 16; const int32_t kMaxPasswordLen = 24; CliManager::CliManager() { - curSpaceName_ = std::string("(none)"); - if (!fs::FileUtils::isStdinTTY()) { enableHistroy_ = false; isInteractive_ = false; @@ -159,9 +157,6 @@ void CliManager::loop() { break; } - if (!cmdProcessor_->getSpaceName().empty()) { - curSpaceName_ = cmdProcessor_->getSpaceName(); - } cmd.clear(); } saveHistory(); @@ -182,7 +177,7 @@ bool CliManager::readLine(std::string &line, bool linebreak) { "\033[0m" // restore color code "\002", // RL_PROMPT_END_IGNORE color++ % 6 + 31, username_.c_str(), - addr_.c_str(), curSpaceName_.c_str()); + addr_.c_str(), cmdProcessor_->getSpaceName().c_str()); } else { prompt[0] = '\0'; // prompt } diff --git a/src/console/CliManager.h b/src/console/CliManager.h index cd7865d4..8d4d55cc 100644 --- a/src/console/CliManager.h +++ b/src/console/CliManager.h @@ -42,7 +42,6 @@ private: std::string addr_; uint16_t port_; std::string username_; - std::string curSpaceName_; bool enableHistroy_{true}; bool isInteractive_{true}; diff --git a/src/console/CmdProcessor.cpp b/src/console/CmdProcessor.cpp index 40b0e449..e40edf49 100644 --- a/src/console/CmdProcessor.cpp +++ b/src/console/CmdProcessor.cpp @@ -335,6 +335,8 @@ void CmdProcessor::processServerCmd(folly::StringPiece cmd) { auto *spaceName = resp.get_space_name(); if (spaceName && !spaceName->empty()) { curSpaceName_ = std::move(*spaceName); + } else { + curSpaceName_ = "(none)"; } printResult(resp); if (resp.get_rows() != nullptr) { diff --git a/src/console/CmdProcessor.h b/src/console/CmdProcessor.h index 4b7d74a7..b59cd681 100644 --- a/src/console/CmdProcessor.h +++ b/src/console/CmdProcessor.h @@ -30,7 +30,7 @@ public: private: std::unique_ptr<GraphClient> client_; - std::string curSpaceName_; + std::string curSpaceName_{"(none)"}; // The method returns true if the given command is a client command // and has been processed. Otherwise, the method returns false diff --git a/src/executor/DropSpaceExecutor.cpp b/src/executor/DropSpaceExecutor.cpp index 39310781..77274f87 100644 --- a/src/executor/DropSpaceExecutor.cpp +++ b/src/executor/DropSpaceExecutor.cpp @@ -37,6 +37,10 @@ void DropSpaceExecutor::execute() { onError_(Status::Error("Drop space failed")); return; } + + if (*spaceName_ == ectx()->rctx()->session()->spaceName()) { + ectx()->rctx()->session()->setSpace("", -1); + } DCHECK(onFinish_); onFinish_(); }; diff --git a/src/executor/SchemaHelper.cpp b/src/executor/SchemaHelper.cpp index 888a8185..a8069d7e 100644 --- a/src/executor/SchemaHelper.cpp +++ b/src/executor/SchemaHelper.cpp @@ -35,7 +35,12 @@ Status SchemaHelper::createSchema(const std::vector<ColumnSpecification*>& specs nebula::cpp2::Schema& schema) { auto status = Status::OK(); + std::unordered_set<std::string> nameSet; for (auto& spec : specs) { + if (nameSet.find(*spec->name()) != nameSet.end()) { + return Status::Error("Duplicate column name `%s'", spec->name()->c_str()); + } + nameSet.emplace(*spec->name()); nebula::cpp2::ColumnDef column; column.name = *spec->name(); column.type.type = columnTypeToSupportedType(spec->type()); diff --git a/src/executor/test/SchemaTest.cpp b/src/executor/test/SchemaTest.cpp index 339bc7f4..1e7f2479 100644 --- a/src/executor/test/SchemaTest.cpp +++ b/src/executor/test/SchemaTest.cpp @@ -135,7 +135,20 @@ TEST_F(SchemaTest, metaCommunication) { auto code = client->execute(query, resp); ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); } - + // Test same prop name + { + cpp2::ExecutionResponse resp; + std::string query = "CREATE TAG samePropTag(name string, name int)"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::E_EXECUTION_ERROR, code); + } + // Test same prop name + { + cpp2::ExecutionResponse resp; + std::string query = "CREATE EDGE samePropEdge(name string, name int)"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::E_EXECUTION_ERROR, code); + } // Test create tag without prop { cpp2::ExecutionResponse resp; -- GitLab