From 05fdf00a06c150d0abe9b0388436c087086d1a69 Mon Sep 17 00:00:00 2001 From: dl239 Date: Mon, 5 Jun 2023 19:38:12 +0800 Subject: [PATCH 1/2] fix: fix dup index --- src/schema/index_test.cc | 23 +++++++++++++++++++++++ src/schema/index_util.cc | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/schema/index_test.cc b/src/schema/index_test.cc index 41844699248..b91e942ce18 100644 --- a/src/schema/index_test.cc +++ b/src/schema/index_test.cc @@ -67,6 +67,29 @@ TEST_F(IndexTest, CheckNewIndex) { ASSERT_TRUE(IndexUtil::CheckNewIndex(test_index3, table_info).OK()); } +TEST_F(IndexTest, CheckIndex) { + PBSchema schema; + SchemaCodec::SetColumnDesc(schema.Add(), "card", ::openmldb::type::kString); + SchemaCodec::SetColumnDesc(schema.Add(), "mcc", ::openmldb::type::kString); + SchemaCodec::SetColumnDesc(schema.Add(), "ts1", ::openmldb::type::kBigInt); + SchemaCodec::SetColumnDesc(schema.Add(), "ts2", ::openmldb::type::kBigInt); + std::map column_map = + { + {"card", schema.Get(0)}, + {"mcc", schema.Get(1)}, + {"ts1", schema.Get(2)}, + {"ts2", schema.Get(3)} + }; + PBIndex indexa; + SchemaCodec::SetIndex(indexa.Add(), "index1", "card", "ts1", ::openmldb::type::kAbsoluteTime, 0, 0); + SchemaCodec::SetIndex(indexa.Add(), "index2", "card", "ts2", ::openmldb::type::kAbsoluteTime, 0, 0); + ASSERT_TRUE(IndexUtil::CheckIndex(column_map, indexa).OK()); + PBIndex indexb; + SchemaCodec::SetIndex(indexb.Add(), "index1", "card", "ts1", ::openmldb::type::kAbsoluteTime, 0, 0); + SchemaCodec::SetIndex(indexb.Add(), "index2", "card", "ts1", ::openmldb::type::kLatestTime, 0, 0); + ASSERT_FALSE(IndexUtil::CheckIndex(column_map, indexb).OK()); +} + } // namespace schema } // namespace openmldb diff --git a/src/schema/index_util.cc b/src/schema/index_util.cc index 1893ddd5aad..44212cee3da 100644 --- a/src/schema/index_util.cc +++ b/src/schema/index_util.cc @@ -73,7 +73,7 @@ base::Status IndexUtil::CheckIndex(const std::map Date: Tue, 6 Jun 2023 14:17:54 +0800 Subject: [PATCH 2/2] fix: resolve cpplint error --- src/schema/index_test.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/schema/index_test.cc b/src/schema/index_test.cc index b91e942ce18..ac8f2bbc4b4 100644 --- a/src/schema/index_test.cc +++ b/src/schema/index_test.cc @@ -73,8 +73,7 @@ TEST_F(IndexTest, CheckIndex) { SchemaCodec::SetColumnDesc(schema.Add(), "mcc", ::openmldb::type::kString); SchemaCodec::SetColumnDesc(schema.Add(), "ts1", ::openmldb::type::kBigInt); SchemaCodec::SetColumnDesc(schema.Add(), "ts2", ::openmldb::type::kBigInt); - std::map column_map = - { + std::map column_map = { {"card", schema.Get(0)}, {"mcc", schema.Get(1)}, {"ts1", schema.Get(2)},