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

Commit

Permalink
disable create space without vid_type
Browse files Browse the repository at this point in the history
fix ut

fix some pytest

fix tck
  • Loading branch information
czpmango committed Jun 15, 2021
1 parent 1dcac0c commit ab4362c
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 68 deletions.
14 changes: 14 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
56 changes: 44 additions & 12 deletions src/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -3012,43 +3012,75 @@ zone_name_list

create_space_sentence
: KW_CREATE KW_SPACE opt_if_not_exists name_label {
auto sentence = new CreateSpaceSentence($4, $3);
$$ = sentence;
delete($4);
throw nebula::GraphParser::syntax_error(@1, "space vid_type must be specified explicitly");
$$ = nullptr;
UNUSED($3);
}
| KW_CREATE KW_SPACE opt_if_not_exists name_label comment_prop_assignment {
auto sentence = new CreateSpaceSentence($4, $3);
sentence->setComment($5);
$$ = sentence;
delete($4);
delete($5);
throw nebula::GraphParser::syntax_error(@1, "space vid_type must be specified explicitly");
$$ = nullptr;
UNUSED($3);
}
| KW_CREATE KW_SPACE opt_if_not_exists name_label KW_ON name_label {
auto sentence = new CreateSpaceSentence($4, $3);
sentence->setGroupName($6);
$$ = sentence;
delete($4);
delete($6);
throw nebula::GraphParser::syntax_error(@1, "space vid_type must be specified explicitly");
$$ = nullptr;
UNUSED($3);
}
| KW_CREATE KW_SPACE opt_if_not_exists name_label KW_ON name_label comment_prop_assignment {
auto sentence = new CreateSpaceSentence($4, $3);
sentence->setGroupName($6);
sentence->setComment($7);
$$ = sentence;
delete($4);
delete($6);
delete($7);
throw nebula::GraphParser::syntax_error(@1, "space vid_type must be specified explicitly");
$$ = nullptr;
UNUSED($3);
}
| KW_CREATE KW_SPACE opt_if_not_exists name_label L_PAREN space_opt_list R_PAREN {
if (!$6->hasVidType()) {
delete($4);
delete($6);
throw nebula::GraphParser::syntax_error(@1, "space vid_type must be specified explicitly");
}
auto sentence = new CreateSpaceSentence($4, $3);
sentence->setOpts($6);
$$ = sentence;
}
| KW_CREATE KW_SPACE opt_if_not_exists name_label L_PAREN space_opt_list R_PAREN comment_prop_assignment {
if (!$6->hasVidType()) {
delete($4);
delete($6);
delete($8);
throw nebula::GraphParser::syntax_error(@1, "space vid_type must be specified explicitly");
}
auto sentence = new CreateSpaceSentence($4, $3);
sentence->setOpts($6);
sentence->setComment($8);
$$ = sentence;
}
| KW_CREATE KW_SPACE opt_if_not_exists name_label L_PAREN space_opt_list R_PAREN KW_ON name_label {
if (!$6->hasVidType()) {
delete($4);
delete($6);
delete($9);
throw nebula::GraphParser::syntax_error(@1, "space vid_type must be specified explicitly");
}
auto sentence = new CreateSpaceSentence($4, $3);
sentence->setGroupName($9);
sentence->setOpts($6);
$$ = sentence;
}
| KW_CREATE KW_SPACE opt_if_not_exists name_label L_PAREN space_opt_list R_PAREN KW_ON name_label comment_prop_assignment {
if (!$6->hasVidType()) {
delete($4);
delete($6);
delete($9);
delete($10);
throw nebula::GraphParser::syntax_error(@1, "space vid_type must be specified explicitly");
}
auto sentence = new CreateSpaceSentence($4, $3);
sentence->setGroupName($9);
sentence->setOpts($6);
Expand Down
18 changes: 9 additions & 9 deletions src/parser/test/ParserTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ TEST(Parser, SpaceOperation) {
{
std::string query = "CREATE SPACE default_space(partition_num=9, replica_factor=3)";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
ASSERT_FALSE(result.ok()) << result.status();
}
{
std::string query = "USE default_space";
Expand Down Expand Up @@ -190,47 +190,47 @@ TEST(Parser, SpaceOperation) {
std::string query = "CREATE SPACE default_space(partition_num=9, replica_factor=3) "
"ON group_0";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
ASSERT_FALSE(result.ok()) << result.status();
}
{
std::string query = "CREATE SPACE default_space ON group_0";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
ASSERT_FALSE(result.ok()) << result.status();
}
{
std::string query = "CREATE SPACE default_space";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
ASSERT_FALSE(result.ok()) << result.status();
}
{
std::string query = "CREATE SPACE default_space(partition_num=9, replica_factor=3,"
"charset=utf8, collate=utf8_bin)";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
ASSERT_FALSE(result.ok()) << result.status();
}
{
std::string query = "CREATE SPACE default_space(partition_num=9, replica_factor=3,"
"charset=utf8)";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
ASSERT_FALSE(result.ok()) << result.status();
}
{
std::string query = "CREATE SPACE default_space(partition_num=9, replica_factor=3,"
"collate=utf8_bin)";
auto result = parse(query);
ASSERT_TRUE(result.ok()) << result.status();
ASSERT_FALSE(result.ok()) << result.status();
}
{
std::string query = "CREATE SPACE default_space(partition_num=9, replica_factor=3,"
"atomic_edge=true)";
auto result = parse(query);
EXPECT_TRUE(result.ok()) << result.status();
EXPECT_FALSE(result.ok()) << result.status();
}
{
std::string query = "CREATE SPACE default_space(partition_num=9, replica_factor=3,"
"atomic_edge=FALSE)";
auto result = parse(query);
EXPECT_TRUE(result.ok()) << result.status();
EXPECT_FALSE(result.ok()) << result.status();
}
{
std::string query = "USE default_space";
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
Loading

0 comments on commit ab4362c

Please sign in to comment.