diff --git a/src/console/CliManager.cpp b/src/console/CliManager.cpp index efc68bc93b1c6e90a345064b65bc4563621e635c..96d985825781c69f24954d6883f6185df4a16249 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 cd7865d40f36416fa07b4f28083f36d57a1e609d..8d4d55cc0e9132ac7a6e2babc611b4ac65ba760f 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 40b0e449b019b3c15529c767dbdc859efabd6d52..e40edf4916ec20053c63bf4bd916972af403411a 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 4b7d74a7d18dea2342c13c0558552b5013a4a52d..b59cd681c48f0e26b06a62c41e5c662dcff7695b 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 3931078112f3c1a754c651c33025724ac38a7cf9..77274f8794ffddfecc2a2adc83b60d205ae68afc 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 888a818581c2bd22a630d9a12058e14875d819b6..a8069d7e6914b32ef6d32fabb23d5ebe57551b4c 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 339bc7f42b001b11dd17807dbf8c2210ee54c954..1e7f2479edcf4d3fa16e0d103440801c354e60af 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;