From 9033c654040c18dbc7e5419187ab1839fe65a46f Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Fri, 11 Jun 2021 15:33:16 +0800 Subject: [PATCH] disable create space without vid_type fix ut add tck format --- src/parser/AdminSentences.h | 18 +++++++++++++ src/validator/AdminValidator.cpp | 4 +++ src/validator/test/AdminValidatorTest.cpp | 13 +++++---- src/validator/test/MaintainValidatorTest.cpp | 7 +++-- tests/admin/test_parts.py | 2 +- tests/admin/test_permission.py | 12 ++++----- tests/admin/test_space.py | 26 +++++++++--------- tests/admin/test_users.py | 2 +- tests/job/test_session.py | 2 +- tests/query/stateless/test_if_exists.py | 6 ++--- tests/query/stateless/test_keyword.py | 6 ++--- tests/query/stateless/test_range.py | 2 +- tests/query/stateless/test_schema.py | 2 +- tests/tck/features/admin/Hosts.feature | 28 ++++++++++++++++++++ tests/tck/features/schema/Comment.feature | 6 ++--- tests/tck/features/schema/Schema.feature | 6 ++--- tests/tck/features/user/User.feature | 4 +-- 17 files changed, 97 insertions(+), 49 deletions(-) diff --git a/src/parser/AdminSentences.h b/src/parser/AdminSentences.h index 99adffe3a..5273c5387 100644 --- a/src/parser/AdminSentences.h +++ b/src/parser/AdminSentences.h @@ -271,6 +271,10 @@ class SpaceOptItem final { } } + bool isVidType() { + return optType_ == OptionType::VID_TYPE; + } + std::string toString() const; private: @@ -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: @@ -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); } diff --git a/src/validator/AdminValidator.cpp b/src/validator/AdminValidator.cpp index 1be032601..76b34287b 100644 --- a/src/validator/AdminValidator.cpp +++ b/src/validator/AdminValidator.cpp @@ -27,6 +27,10 @@ Status CreateSpaceValidator::validateImpl() { StatusOr 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: { diff --git a/src/validator/test/AdminValidatorTest.cpp b/src/validator/test/AdminValidatorTest.cpp index eac1395f3..51d65e06f 100644 --- a/src/validator/test/AdminValidatorTest.cpp +++ b/src/validator/test/AdminValidatorTest.cpp @@ -14,16 +14,15 @@ class AdminValidatorTest : public ValidatorTestBase { TEST_F(AdminValidatorTest, SpaceTest) { { - std::vector expected = { - PK::kDescSpace, PK::kCreateSpace, PK::kStart - }; - ASSERT_TRUE(checkResult("CREATE SPACE TEST; DESC SPACE TEST;", expected)); + std::vector expected = {PK::kDescSpace, PK::kCreateSpace, PK::kStart}; + ASSERT_TRUE(checkResult("CREATE SPACE TEST(vid_type = fixed_string(2)); DESC SPACE TEST;", + expected)); } { std::vector 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)); } } diff --git a/src/validator/test/MaintainValidatorTest.cpp b/src/validator/test/MaintainValidatorTest.cpp index 169e1dd56..a67fd4dc3 100644 --- a/src/validator/test/MaintainValidatorTest.cpp +++ b/src/validator/test/MaintainValidatorTest.cpp @@ -13,10 +13,9 @@ class MaintainValidatorTest : public ValidatorTestBase { }; TEST_F(MaintainValidatorTest, SpaceTest) { - std::vector expected = { - PK::kDescSpace, PK::kCreateSpace, PK::kStart - }; - ASSERT_TRUE(checkResult("CREATE SPACE TEST; DESC SPACE TEST;", expected)); + std::vector 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) { diff --git a/tests/admin/test_parts.py b/tests/admin/test_parts.py index c734bfed8..ff2c79aea 100644 --- a/tests/admin/test_parts.py +++ b/tests/admin/test_parts.py @@ -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) diff --git a/tests/admin/test_permission.py b/tests/admin/test_permission.py index 43d2100bc..8adb7df11 100644 --- a/tests/admin/test_permission.py +++ b/tests/admin/test_permission.py @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/tests/admin/test_space.py b/tests/admin/test_space.py index ba6aca607..d5fce18f0 100644 --- a/tests/admin/test_space.py +++ b/tests/admin/test_space.py @@ -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') @@ -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 @@ -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') @@ -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') @@ -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') @@ -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') @@ -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') @@ -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) diff --git a/tests/admin/test_users.py b/tests/admin/test_users.py index f41a5148b..d8139f341 100644 --- a/tests/admin/test_users.py +++ b/tests/admin/test_users.py @@ -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) diff --git a/tests/job/test_session.py b/tests/job/test_session.py index 32599f191..5ef9a3a99 100644 --- a/tests/job/test_session.py +++ b/tests/job/test_session.py @@ -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();') diff --git a/tests/query/stateless/test_if_exists.py b/tests/query/stateless/test_if_exists.py index 6953b1daf..fdad69f06 100644 --- a/tests/query/stateless/test_if_exists.py +++ b/tests/query/stateless/test_if_exists.py @@ -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' @@ -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) diff --git a/tests/query/stateless/test_keyword.py b/tests/query/stateless/test_keyword.py index 0078ab297..092303a27 100644 --- a/tests/query/stateless/test_keyword.py +++ b/tests/query/stateless/test_keyword.py @@ -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) @@ -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) @@ -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) diff --git a/tests/query/stateless/test_range.py b/tests/query/stateless/test_range.py index 003d15460..4efa985bf 100644 --- a/tests/query/stateless/test_range.py +++ b/tests/query/stateless/test_range.py @@ -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) diff --git a/tests/query/stateless/test_schema.py b/tests/query/stateless/test_schema.py index 2c489173c..b0b27ca38 100644 --- a/tests/query/stateless/test_schema.py +++ b/tests/query/stateless/test_schema.py @@ -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) diff --git a/tests/tck/features/admin/Hosts.feature b/tests/tck/features/admin/Hosts.feature index 73ba8d4c6..62d8ebcc7 100644 --- a/tests/tck/features/admin/Hosts.feature +++ b/tests/tck/features/admin/Hosts.feature @@ -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 diff --git a/tests/tck/features/schema/Comment.feature b/tests/tck/features/schema/Comment.feature index 731faf9df..48f7aab83 100644 --- a/tests/tck/features/schema/Comment.feature +++ b/tests/tck/features/schema/Comment.feature @@ -8,7 +8,7 @@ Feature: Schema Comment Given an empty graph When executing query: """ - CREATE SPACE comment = ''; + CREATE SPACE (vid_type=FIXED_STRING(8)) comment = ''; """ Then the execution should be successful When try to execute query: @@ -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: @@ -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: diff --git a/tests/tck/features/schema/Schema.feature b/tests/tck/features/schema/Schema.feature index ad78d090c..e663e6c41 100644 --- a/tests/tck/features/schema/Schema.feature +++ b/tests/tck/features/schema/Schema.feature @@ -397,7 +397,7 @@ Feature: Insert string vid of vertex and edge # test same tag in different space When executing query: """ - CREATE SPACE my_space(partition_num=9, replica_factor=1); + CREATE SPACE my_space(partition_num=9, replica_factor=1, vid_type=FIXED_STRING(8)); USE my_space; CREATE TAG animal(name string, kind string); """ @@ -428,7 +428,7 @@ Feature: Insert string vid of vertex and edge # test same tag in different space When executing query: """ - CREATE SPACE test_multi; + CREATE SPACE test_multi(vid_type=FIXED_STRING(8)); USE test_multi; CREATE Tag test_tag(); SHOW TAGS; @@ -486,7 +486,7 @@ Feature: Insert string vid of vertex and edge # test alter tag with default When executing query: """ - CREATE SPACE tag_space(partition_num=9); + CREATE SPACE tag_space(partition_num=9, vid_type=FIXED_STRING(8)); USE tag_space; CREATE TAG t(name string DEFAULT "N/A", age int DEFAULT -1); """ diff --git a/tests/tck/features/user/User.feature b/tests/tck/features/user/User.feature index 86af0afab..5be998fb1 100644 --- a/tests/tck/features/user/User.feature +++ b/tests/tck/features/user/User.feature @@ -148,7 +148,7 @@ Feature: User & privilege Test Scenario: Grant privilege When executing query: """ - CREATE SPACE IF NOT EXISTS user_tmp_space(partition_num=1, replica_factor=1) + CREATE SPACE IF NOT EXISTS user_tmp_space(partition_num=1, replica_factor=1, vid_type=FIXED_STRING(8)) """ Then the execution should be successful And wait 10 seconds @@ -226,7 +226,7 @@ Feature: User & privilege Test Scenario: Revoke role When executing query: """ - CREATE SPACE IF NOT EXISTS user_tmp_space_3(partition_num=1, replica_factor=1) + CREATE SPACE IF NOT EXISTS user_tmp_space_3(partition_num=1, replica_factor=1, vid_type=FIXED_STRING(8)) """ Then the execution should be successful And wait 10 seconds