Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

disable create space without vid_type #1129

Merged
merged 4 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/parser/AdminSentences.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ class SpaceOptItem final {
}
}

bool isVidType() {
return optType_ == OptionType::VID_TYPE;
}

std::string toString() const;

private:
Expand All @@ -293,6 +297,16 @@ class SpaceOptList final {
return result;
}

bool hasVidType() const {
auto spaceOptItems = getOpts();
for (SpaceOptItem* item : spaceOptItems) {
if (item->isVidType()) {
return true;
}
}
return false;
}

std::string toString() const;

private:
Expand Down Expand Up @@ -323,6 +337,10 @@ class CreateSpaceSentence final : public CreateSentence {
return groupName_.get();
}

const SpaceOptList* spaceOpts() const {
return spaceOpts_.get();
}

void setComment(std::string *name) {
comment_.reset(name);
}
Expand Down
4 changes: 4 additions & 0 deletions src/validator/AdminValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Status CreateSpaceValidator::validateImpl() {
StatusOr<std::string> retStatusOr;
std::string result;
auto* charsetInfo = qctx_->getCharsetInfo();
auto *spaceOpts = sentence->spaceOpts();
if (!spaceOpts || !spaceOpts->hasVidType()) {
return Status::SemanticError("space vid_type must be specified explicitly");
}
for (auto &item : sentence->getOpts()) {
switch (item->getOptType()) {
case SpaceOptItem::PARTITION_NUM: {
Expand Down
13 changes: 6 additions & 7 deletions src/validator/test/AdminValidatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ class AdminValidatorTest : public ValidatorTestBase {

TEST_F(AdminValidatorTest, SpaceTest) {
{
std::vector<PlanNode::Kind> expected = {
PK::kDescSpace, PK::kCreateSpace, PK::kStart
};
ASSERT_TRUE(checkResult("CREATE SPACE TEST; DESC SPACE TEST;", expected));
std::vector<PlanNode::Kind> expected = {PK::kDescSpace, PK::kCreateSpace, PK::kStart};
ASSERT_TRUE(checkResult("CREATE SPACE TEST(vid_type = fixed_string(2)); DESC SPACE TEST;",
expected));
}
{
std::vector<PlanNode::Kind> expected = {
PK::kUpdateSession, PK::kSwitchSpace, PK::kCreateSpace, PK::kStart
};
ASSERT_TRUE(checkResult("CREATE SPACE TEST; USE TEST;", expected));
PK::kUpdateSession, PK::kSwitchSpace, PK::kCreateSpace, PK::kStart};
ASSERT_TRUE(
checkResult("CREATE SPACE TEST(vid_type = fixed_string(2)); USE TEST;", expected));
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/validator/test/MaintainValidatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ class MaintainValidatorTest : public ValidatorTestBase {
};

TEST_F(MaintainValidatorTest, SpaceTest) {
std::vector<PlanNode::Kind> expected = {
PK::kDescSpace, PK::kCreateSpace, PK::kStart
};
ASSERT_TRUE(checkResult("CREATE SPACE TEST; DESC SPACE TEST;", expected));
std::vector<PlanNode::Kind> expected = {PK::kDescSpace, PK::kCreateSpace, PK::kStart};
ASSERT_TRUE(
checkResult("CREATE SPACE TEST(vid_type = fixed_string(2)); DESC SPACE TEST;", expected));
}

TEST_F(MaintainValidatorTest, TagTest) {
Expand Down
2 changes: 1 addition & 1 deletion tests/admin/test_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TestParts(NebulaTestSuite):

@classmethod
def prepare(self):
resp = self.client.execute('CREATE SPACE space_show_parts(partition_num=5); '
resp = self.client.execute('CREATE SPACE space_show_parts(partition_num=5, vid_type=FIXED_STRING(8));'
'USE space_show_parts;')
self.check_resp_succeeded(resp)

Expand Down
12 changes: 6 additions & 6 deletions tests/admin/test_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_simple(self):
self.release_nebula_client(client)

# test root user password and use space.
query = 'CREATE SPACE test_permission_space(partition_num=1, replica_factor=1)'
query = 'CREATE SPACE test_permission_space(partition_num=1, replica_factor=1, vid_type=FIXED_STRING(8))'
resp = self.execute(query)
self.check_resp_succeeded(resp)
time.sleep(self.delay)
Expand Down Expand Up @@ -116,7 +116,7 @@ def test_simple(self):
self.check_resp_succeeded(resp)

def test_user_write(self):
query = 'CREATE SPACE space1(partition_num=1, replica_factor=1)'
query = 'CREATE SPACE space1(partition_num=1, replica_factor=1, vid_type=FIXED_STRING(8))'
resp = self.execute(query)
self.check_resp_succeeded(resp)
time.sleep(self.delay)
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_user_write(self):
self.check_resp_succeeded(resp)

def test_schema_and_data(self):
query = 'CREATE SPACE space2(partition_num=1, replica_factor=1)'
query = 'CREATE SPACE space2(partition_num=1, replica_factor=1, vid_type=FIXED_STRING(8))'
resp = self.execute(query)
self.check_resp_succeeded(resp)
time.sleep(self.delay)
Expand Down Expand Up @@ -638,7 +638,7 @@ def test_schema_and_data(self):
self.check_resp_succeeded(resp)

# use space test
query = "CREATE SPACE space3(partition_num=1, replica_factor=1)";
query = "CREATE SPACE space3(partition_num=1, replica_factor=1, vid_type=FIXED_STRING(8))";
resp = self.execute(query)
self.check_resp_succeeded(resp)
time.sleep(self.delay)
Expand Down Expand Up @@ -669,7 +669,7 @@ def test_show_test(self):
ret, self.guestClient = self.spawn_nebula_client_and_auth('guest', 'guest')
assert ret

query = 'CREATE SPACE space4(partition_num=1, replica_factor=1)'
query = 'CREATE SPACE space4(partition_num=1, replica_factor=1, vid_type=FIXED_STRING(8))'
resp = self.execute(query)
self.check_resp_succeeded(resp)
time.sleep(self.delay)
Expand Down Expand Up @@ -732,7 +732,7 @@ def test_show_test(self):
self.check_resp_succeeded(resp)

def test_show_roles(self):
query = 'CREATE SPACE space5(partition_num=1, replica_factor=1)'
query = 'CREATE SPACE space5(partition_num=1, replica_factor=1, vid_type=FIXED_STRING(8))'
resp = self.execute(query)
self.check_resp_succeeded(resp)
time.sleep(self.delay)
Expand Down
26 changes: 13 additions & 13 deletions tests/admin/test_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_space(self):
self.check_resp_failed(resp)

# with default options
resp = self.client.execute('CREATE SPACE space_with_default_options')
resp = self.client.execute('CREATE SPACE space_with_default_options (vid_type=FIXED_STRING(8))')
self.check_resp_succeeded(resp)

resp = self.client.execute('CREATE SPACE space_on_default_group on default')
Expand All @@ -35,7 +35,7 @@ def test_space(self):
self.check_resp_succeeded(resp)

# create space succeeded
resp = self.client.execute('CREATE SPACE default_space(partition_num=9, replica_factor=1)')
resp = self.client.execute('CREATE SPACE default_space(partition_num=9, replica_factor=1, vid_type=FIXED_STRING(8))')
self.check_resp_succeeded(resp)

# show spaces
Expand Down Expand Up @@ -91,7 +91,7 @@ def test_space(self):

def test_charset_collate(self):
resp = self.client.execute('CREATE SPACE space_charset_collate (partition_num=9, '
'replica_factor=1, charset=utf8, collate=utf8_bin)')
'replica_factor=1, charset=utf8, collate=utf8_bin, vid_type=FIXED_STRING(8))')
self.check_resp_succeeded(resp)

resp = self.client.execute('DESC SPACE space_charset_collate')
Expand All @@ -104,7 +104,7 @@ def test_charset_collate(self):
self.check_resp_succeeded(resp)

resp = self.client.execute('CREATE SPACE space_charset (partition_num=9, '
'replica_factor=1, charset=utf8)')
'replica_factor=1, charset=utf8, vid_type=FIXED_STRING(8))')
self.check_resp_succeeded(resp)

resp = self.client.execute('DESC SPACE space_charset')
Expand All @@ -117,7 +117,7 @@ def test_charset_collate(self):
self.check_resp_succeeded(resp)

resp = self.client.execute('CREATE SPACE space_collate (partition_num=9, '
'replica_factor=1, collate=utf8_bin)')
'replica_factor=1, collate=utf8_bin, vid_type=FIXED_STRING(8))')
self.check_resp_succeeded(resp)

resp = self.client.execute('DESC SPACE space_collate')
Expand All @@ -131,30 +131,30 @@ def test_charset_collate(self):

# not supported collate
resp = self.client.execute('CREATE SPACE space_charset_collate_nomatch (partition_num=9, '
'replica_factor=1, charset = utf8, collate=gbk_bin)')
'replica_factor=1, charset = utf8, collate=gbk_bin, vid_type=FIXED_STRING(8))')
self.check_resp_failed(resp)

# not supported charset
resp = self.client.execute('CREATE SPACE space_charset_collate_nomatch (partition_num=9, '
'replica_factor=1, charset = gbk, collate=utf8_bin)')
'replica_factor=1, charset = gbk, collate=utf8_bin, vid_type=FIXED_STRING(8))')
self.check_resp_failed(resp)

# not supported charset
resp = self.client.execute('CREATE SPACE space_illegal_charset (partition_num=9, '
'replica_factor=1, charset = gbk)')
'replica_factor=1, charset = gbk, vid_type=FIXED_STRING(8))')
self.check_resp_failed(resp)

# not supported collate
resp = self.client.execute('CREATE SPACE space_illegal_collate (partition_num=9, '
'replica_factor=1, collate = gbk_bin)')
'replica_factor=1, collate = gbk_bin, vid_type=FIXED_STRING(8))')
self.check_resp_failed(resp)

resp = self.client.execute('CREATE SPACE space_illegal_collate (partition_num=9, '
'replica_factor=1, collate = gbk_bin)')
'replica_factor=1, collate = gbk_bin, vid_type=FIXED_STRING(8))')
self.check_resp_failed(resp)

resp = self.client.execute('CREATE SPACE space_capital (partition_num=9, '
'replica_factor=1, charset=UTF8, collate=UTF8_bin)')
'replica_factor=1, charset=UTF8, collate=UTF8_bin, vid_type=FIXED_STRING(8))')
self.check_resp_succeeded(resp)

resp = self.client.execute('DESC SPACE space_capital')
Expand All @@ -174,7 +174,7 @@ def test_if_not_exists_and_if_exist(self):

# exist but success
resp = self.client.execute('CREATE SPACE IF NOT EXISTS default_space')
self.check_resp_succeeded(resp)
self.check_resp_failed(resp)

# not exist but success
resp = self.client.execute('DROP SPACE IF EXISTS not_exist_space')
Expand All @@ -185,7 +185,7 @@ def test_if_not_exists_and_if_exist(self):
self.check_resp_failed(resp)

resp = self.client.execute('CREATE SPACE exist_space')
self.check_resp_succeeded(resp)
self.check_resp_failed(resp)

resp = self.client.execute('DROP SPACE IF EXISTS exist_space')
self.check_resp_succeeded(resp)
Expand Down
2 changes: 1 addition & 1 deletion tests/admin/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class TestUsers(NebulaTestSuite):
@classmethod
def prepare(self):
query = 'CREATE SPACE user_space(partition_num=1, replica_factor=1)'
query = 'CREATE SPACE user_space(partition_num=1, replica_factor=1, vid_type=FIXED_STRING(8))'
resp = self.execute(query)
self.check_resp_succeeded(resp)
time.sleep(self.delay)
Expand Down
2 changes: 1 addition & 1 deletion tests/job/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def get_connection(ip, port):
assert resp.error_code == ttypes.ErrorCode.SUCCEEDED
session_id = resp.session_id

resp = conn1.execute(session_id, 'CREATE SPACE IF NOT EXISTS aSpace(partition_num=1);USE aSpace;')
resp = conn1.execute(session_id, 'CREATE SPACE IF NOT EXISTS aSpace(partition_num=1, vid_type=FIXED_STRING(8));USE aSpace;')
self.check_resp_succeeded(ResultSet(resp, 0))
time.sleep(3)
resp = conn1.execute(session_id, 'CREATE TAG IF NOT EXISTS a();')
Expand Down
6 changes: 3 additions & 3 deletions tests/query/stateless/test_if_exists.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ def test_drop_space(self):
resp = self.execute(cmd)
self.check_resp_succeeded(resp)

resp = self.execute('CREATE SPACE shakespaces(partition_num=1024)')
resp = self.execute('CREATE SPACE shakespaces(partition_num=1024, vid_type=FIXED_STRING(8))')
self.check_resp_succeeded(resp)

resp = self.execute('CREATE SPACE IF NOT EXISTS shakespaces(partition_num=1024)')
resp = self.execute('CREATE SPACE IF NOT EXISTS shakespaces(partition_num=1024, vid_type=FIXED_STRING(8))')
self.check_resp_succeeded(resp)

cmd = 'drop space shakespaces'
Expand All @@ -39,7 +39,7 @@ def test_drop_space(self):
resp = self.execute(cmd)
self.check_resp_succeeded(resp)

resp = self.execute('CREATE SPACE IF NOT EXISTS shakespaces(partition_num=1024)')
resp = self.execute('CREATE SPACE IF NOT EXISTS shakespaces(partition_num=1024, vid_type=FIXED_STRING(8))')
self.check_resp_succeeded(resp)

time.sleep(self.delay)
Expand Down
6 changes: 3 additions & 3 deletions tests/query/stateless/test_keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def prepare(self):
# some reversed keywords are moved to unreversed keywords, and vice versa in #1922
def test_keywords1(self):
resp = self.execute(
'CREATE SPACE IF NOT EXISTS test(partition_num=1024)')
'CREATE SPACE IF NOT EXISTS test(partition_num=1024, vid_type=FIXED_STRING(8))')
self.check_resp_succeeded(resp)
time.sleep(self.delay)

Expand Down Expand Up @@ -302,7 +302,7 @@ def test_keywords1(self):

def test_keywords2(self):
resp = self.execute(
'CREATE SPACE IF NOT EXISTS test(partition_num=1024)')
'CREATE SPACE IF NOT EXISTS test(partition_num=1024, vid_type=FIXED_STRING(8))')
self.check_resp_succeeded(resp)
time.sleep(self.delay)

Expand Down Expand Up @@ -902,7 +902,7 @@ def test_keywords2(self):

def test_keywords3(self):
resp = self.execute(
'CREATE SPACE IF NOT EXISTS test(partition_num=10)')
'CREATE SPACE IF NOT EXISTS test (partition_num=10, vid_type=FIXED_STRING(8))')
self.check_resp_succeeded(resp)
time.sleep(self.delay)

Expand Down
2 changes: 1 addition & 1 deletion tests/query/stateless/test_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TestRangeChecking(NebulaTestSuite):
@classmethod
def prepare(self):
resp = self.execute(
'CREATE SPACE test_range_checking(partition_num={partition_num}, replica_factor={replica_factor})'
'CREATE SPACE test_range_checking(partition_num={partition_num}, replica_factor={replica_factor}, vid_type=FIXED_STRING(8))'
.format(partition_num=self.partition_num,
replica_factor=self.replica_factor))
self.check_resp_succeeded(resp)
Expand Down
2 changes: 1 addition & 1 deletion tests/query/stateless/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TestSchema(NebulaTestSuite):
@classmethod
def prepare(self):
resp = self.execute(
'CREATE SPACE IF NOT EXISTS schema_space(partition_num={partition_num}, replica_factor={replica_factor})'
'CREATE SPACE IF NOT EXISTS schema_space(partition_num={partition_num}, replica_factor={replica_factor}, vid_type=FIXED_STRING(8))'
.format(partition_num=self.partition_num,
replica_factor=self.replica_factor))
self.check_resp_succeeded(resp)
Expand Down
28 changes: 28 additions & 0 deletions tests/tck/features/admin/Hosts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,31 @@ Feature: Admin hosts
Then the result should contain:
| Host | Port | Status | Role | Git Info Sha | Version |
| /\w+/ | /\d+/ | "ONLINE" | "STORAGE" | /[0-9a-f]{7}/ | EMPTY |

Scenario: Create space
When executing query:
"""
CREATE SPACE space_without_vid_type;
"""
Then a SemanticError should be raised at runtime: space vid_type must be specified explicitly
When executing query:
"""
CREATE SPACE space_without_vid_type(partition_num=9, replica_factor=3);
"""
Then a SemanticError should be raised at runtime: space vid_type must be specified explicitly
When executing query:
"""
CREATE SPACE space_without_vid_type(partition_num=9, replica_factor=3) on group_0;
"""
Then a SemanticError should be raised at runtime: space vid_type must be specified explicitly
When executing query:
"""
CREATE SPACE space_without_vid_type on group_0;
"""
Then a SemanticError should be raised at runtime: space vid_type must be specified explicitly
When executing query:
"""
CREATE SPACE space_specify_vid_type(partition_num=9, replica_factor=1, vid_type=FIXED_STRING(8));
DROP SPACE space_specify_vid_type
"""
Then the execution should be successful
6 changes: 3 additions & 3 deletions tests/tck/features/schema/Comment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Feature: Schema Comment
Given an empty graph
When executing query:
"""
CREATE SPACE <space_name> comment = '<space_comment>';
CREATE SPACE <space_name> (vid_type=FIXED_STRING(8)) comment = '<space_comment>';
"""
Then the execution should be successful
When try to execute query:
Expand Down Expand Up @@ -40,7 +40,7 @@ Feature: Schema Comment
Given an empty graph
When executing query:
"""
CREATE SPACE test_comment_not_set;
CREATE SPACE test_comment_not_set (vid_type=FIXED_STRING(8));
"""
Then the execution should be successful
When try to execute query:
Expand All @@ -67,7 +67,7 @@ Feature: Schema Comment
Given an empty graph
When executing query:
"""
CREATE SPACE test_comment_empty comment = '';
CREATE SPACE test_comment_empty (vid_type=FIXED_STRING(8)) comment = '';
"""
Then the execution should be successful
When try to execute query:
Expand Down
Loading