diff --git a/conf/nebula-graphd.conf.default b/conf/nebula-graphd.conf.default index 80e99b36efada457073b7f36198feff3a92238d9..6d1017a641c8f496701077db1e52d7ead4022a17 100644 --- a/conf/nebula-graphd.conf.default +++ b/conf/nebula-graphd.conf.default @@ -41,4 +41,4 @@ # HTTP service port --ws_http_port=13000 # HTTP2 service port ---ws_h2_portt=13002 +--ws_h2_port=13002 diff --git a/src/executor/CreateSpaceExecutor.cpp b/src/executor/CreateSpaceExecutor.cpp index c9bde4fffc0573937eb9e6f1e12fd868fb0b47d2..48011be3a784170bcc69daf5705fec697c6ebe02 100644 --- a/src/executor/CreateSpaceExecutor.cpp +++ b/src/executor/CreateSpaceExecutor.cpp @@ -21,18 +21,18 @@ Status CreateSpaceExecutor::prepare() { switch (item->getOptType()) { case SpaceOptItem::PARTITION_NUM: partNum_ = item->get_partition_num(); + if (partNum_ <= 0) { + return Status::Error("Partition_num value should be greater than zero"); + } break; case SpaceOptItem::REPLICA_FACTOR: replicaFactor_ = item->get_replica_factor(); + if (replicaFactor_ <= 0) { + return Status::Error("Replica_factor value should be greater than zero"); + } break; } } - if (partNum_ <= 0) { - return Status::Error("Partition_num value should be greater than zero"); - } - if (replicaFactor_ <= 0) { - return Status::Error("Replica_factor value should be greater than zero"); - } return Status::OK(); } diff --git a/src/executor/CreateSpaceExecutor.h b/src/executor/CreateSpaceExecutor.h index 0f7aa4dbe5233ee9b070c1a49c4040196e0907fb..8847c865562372557a0c2683fc806391cffcd972 100644 --- a/src/executor/CreateSpaceExecutor.h +++ b/src/executor/CreateSpaceExecutor.h @@ -26,10 +26,12 @@ public: void execute() override; private: - CreateSpaceSentence *sentence_{nullptr}; - const std::string *spaceName_{nullptr}; - int32_t partNum_{0}; - int32_t replicaFactor_{0}; + CreateSpaceSentence *sentence_{nullptr}; + const std::string *spaceName_{nullptr}; + // TODO Due to the currently design of the createSpace interface, + // it's impossible to express *not specified*, so we use 0 to indicate this. + int32_t partNum_{0}; + int32_t replicaFactor_{0}; }; } // namespace graph diff --git a/src/executor/test/SchemaTest.cpp b/src/executor/test/SchemaTest.cpp index 7dd1e56c3a5ad092537795a3e351ad9f3727f4c2..b96b43127bc26b35aaa89c28bc5c7dec73c97d20 100644 --- a/src/executor/test/SchemaTest.cpp +++ b/src/executor/test/SchemaTest.cpp @@ -81,6 +81,28 @@ TEST_F(SchemaTest, metaCommunication) { }; ASSERT_TRUE(verifyResult(resp, expected)); } + { + cpp2::ExecutionResponse resp; + std::string query = "CREATE SPACE space_with_default_options"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } + { + cpp2::ExecutionResponse resp; + std::string query = "DESCRIBE SPACE space_with_default_options"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + std::vector<std::tuple<int, std::string, int, int>> expected{ + {2, "space_with_default_options", 1024, 1}, + }; + ASSERT_TRUE(verifyResult(resp, expected)); + } + { + cpp2::ExecutionResponse resp; + std::string query = "DROP SPACE space_with_default_options"; + auto code = client->execute(query, resp); + ASSERT_EQ(cpp2::ErrorCode::SUCCEEDED, code); + } { cpp2::ExecutionResponse resp; std::string query = "USE default_space"; diff --git a/src/parser/AdminSentences.cpp b/src/parser/AdminSentences.cpp index f185b7dbc8b31d41a4fe8170deeea36a59fbd7fa..f1eda5dc5f786ee9883d68344b04ce6c7e4db33c 100644 --- a/src/parser/AdminSentences.cpp +++ b/src/parser/AdminSentences.cpp @@ -84,8 +84,16 @@ std::string SpaceOptList::toString() const { std::string CreateSpaceSentence::toString() const { - return folly::stringPrintf("CREATE SPACE %s(%s) ", spaceName_.get()->c_str(), - spaceOpts_->toString().c_str()); + std::string buf; + buf.reserve(256); + buf += "CREATE SPACE "; + buf += *spaceName_; + if (spaceOpts_ != nullptr) { + buf += "("; + buf += spaceOpts_->toString(); + buf += ")"; + } + return buf; } std::string DropSpaceSentence::toString() const { diff --git a/src/parser/AdminSentences.h b/src/parser/AdminSentences.h index 2cf457f0646bcb584322d1add8af838690af7132..7f3a9cec18a82287e7d427a4f4224b309e90eb7c 100644 --- a/src/parser/AdminSentences.h +++ b/src/parser/AdminSentences.h @@ -222,6 +222,9 @@ public: } std::vector<SpaceOptItem*> getOpts() { + if (spaceOpts_ == nullptr) { + return {}; + } return spaceOpts_->getOpts(); } diff --git a/src/parser/parser.yy b/src/parser/parser.yy index 97248cb5eadcc85814dee3bdf5ab4a357b18d5a4..6a70c59d95ac92c35400c29ca20b738774c52aa2 100644 --- a/src/parser/parser.yy +++ b/src/parser/parser.yy @@ -1015,7 +1015,11 @@ host_item port : INTEGER { $$ = $1; } create_space_sentence - : KW_CREATE KW_SPACE name_label L_PAREN space_opt_list R_PAREN { + : KW_CREATE KW_SPACE name_label { + auto sentence = new CreateSpaceSentence($3); + $$ = sentence; + } + | KW_CREATE KW_SPACE name_label L_PAREN space_opt_list R_PAREN { auto sentence = new CreateSpaceSentence($3); sentence->setOpts($5); $$ = sentence;