From ab4439ab5389a650fb6e02e0dd96984041df153b Mon Sep 17 00:00:00 2001 From: "kyle.cao" Date: Mon, 15 Nov 2021 15:39:45 +0800 Subject: [PATCH] fix index existence check fix ut --- src/meta/processors/BaseProcessor-inl.h | 19 ++++------- src/meta/test/IndexProcessorTest.cpp | 28 ---------------- tests/tck/features/index/Index.feature | 43 +++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 40 deletions(-) diff --git a/src/meta/processors/BaseProcessor-inl.h b/src/meta/processors/BaseProcessor-inl.h index b46862753c3..fef1b77c7c4 100644 --- a/src/meta/processors/BaseProcessor-inl.h +++ b/src/meta/processors/BaseProcessor-inl.h @@ -548,22 +548,17 @@ nebula::cpp2::ErrorCode BaseProcessor::ftIndexCheck( template bool BaseProcessor::checkIndexExist(const std::vector& fields, const cpp2::IndexItem& item) { - if (fields.size() == 0) { - LOG(ERROR) << "Index " << item.get_index_name() << " has existed"; - return true; + auto itemFields = item.get_fields(); + if (fields.size() != itemFields.size()) { + return false; } - for (size_t i = 0; i < fields.size(); i++) { - if (fields[i].get_name() != item.get_fields()[i].get_name()) { - break; - } - - if (i == fields.size() - 1) { - LOG(ERROR) << "Index " << item.get_index_name() << " has existed"; - return true; + if (fields[i].get_name() != itemFields[i].get_name()) { + return false; } } - return false; + LOG(ERROR) << "Index " << item.get_index_name() << " has existed"; + return true; } template diff --git a/src/meta/test/IndexProcessorTest.cpp b/src/meta/test/IndexProcessorTest.cpp index 14aafd24ad9..57a4c5627e9 100644 --- a/src/meta/test/IndexProcessorTest.cpp +++ b/src/meta/test/IndexProcessorTest.cpp @@ -214,20 +214,6 @@ TEST(IndexProcessorTest, TagIndexTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } - { - // Allow to create tag index on no fields - cpp2::CreateTagIndexReq req; - req.set_space_id(1); - req.set_tag_name("tag_0"); - std::vector fields{}; - req.set_fields(std::move(fields)); - req.set_index_name("no_field_index"); - auto* processor = CreateTagIndexProcessor::instance(kv.get()); - auto f = processor->getFuture(); - processor->process(req); - auto resp = std::move(f).get(); - ASSERT_NE(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); - } { cpp2::CreateTagIndexReq req; req.set_space_id(1); @@ -591,20 +577,6 @@ TEST(IndexProcessorTest, EdgeIndexTest) { auto resp = std::move(f).get(); ASSERT_EQ(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); } - { - // Allow to create edge index on no fields - cpp2::CreateEdgeIndexReq req; - req.set_space_id(1); - req.set_edge_name("edge_0"); - std::vector fields{}; - req.set_fields(std::move(fields)); - req.set_index_name("no_field_index"); - auto* processor = CreateEdgeIndexProcessor::instance(kv.get()); - auto f = processor->getFuture(); - processor->process(req); - auto resp = std::move(f).get(); - ASSERT_NE(nebula::cpp2::ErrorCode::SUCCEEDED, resp.get_code()); - } { cpp2::CreateEdgeIndexReq req; req.set_space_id(1); diff --git a/tests/tck/features/index/Index.feature b/tests/tck/features/index/Index.feature index 432dd06153c..12e7336994e 100644 --- a/tests/tck/features/index/Index.feature +++ b/tests/tck/features/index/Index.feature @@ -943,3 +943,46 @@ Feature: IndexTest_Vid_String Then the result should be, in any order: | Tag Index Name | Create Tag Index | | "player_age_index" | "CREATE TAG INDEX `player_age_index` ON `player` (\n `age`\n)" | + + Scenario: IndexTest existence check + Given an empty graph + And create a space with following options: + | partition_num | 9 | + | replica_factor | 1 | + | vid_type | FIXED_STRING(30) | + | charset | utf8 | + | collate | utf8_bin | + And having executed: + """ + create tag recinfo(name string,tm bool,id int); + insert vertex recinfo(name,tm,id) values "r1":("czp",true,1); + create tag index recinfo_index on recinfo(); + create tag index recinfo_name_index on recinfo(name(8)); + create tag index recinfo_multi_index on recinfo(name(8),tm,id); + """ + When executing query: + """ + drop tag index recinfo_name_index + """ + Then the execution should be successful + When executing query: + """ + create tag index recinfo_name_index on recinfo(name(8)); + """ + Then the execution should be successful + When executing query: + """ + create tag index recinfo_index on recinfo(); + """ + Then a ExecutionError should be raised at runtime: Existed! + When executing query: + """ + drop tag index recinfo_index + """ + Then the execution should be successful + When executing query: + """ + create tag index recinfo_index on recinfo(); + """ + Then the execution should be successful + Then drop the used space