Skip to content
Snippets Groups Projects
Commit 7df98a14 authored by dutor's avatar dutor Committed by GitHub
Browse files

Allow to create graph space without options (#408)

* Allow to create graph space without options

* Addressed @steppenwolfyuetong's comments

* Addressed comments
parent a2f94ac9
No related branches found
No related tags found
No related merge requests found
......@@ -41,4 +41,4 @@
# HTTP service port
--ws_http_port=13000
# HTTP2 service port
--ws_h2_portt=13002
--ws_h2_port=13002
......@@ -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();
}
......
......@@ -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
......
......@@ -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";
......
......@@ -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 {
......
......@@ -222,6 +222,9 @@ public:
}
std::vector<SpaceOptItem*> getOpts() {
if (spaceOpts_ == nullptr) {
return {};
}
return spaceOpts_->getOpts();
}
......
......@@ -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;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment