@@ -61,6 +61,38 @@ TEST_F(CloudSnapshotMgrTest, TestConvertRowsets) {
6161 input_meta_pb.set_schema_hash (123456 );
6262 *input_meta_pb.mutable_tablet_uid () = TabletUid::gen_uid ().to_proto ();
6363
64+ TabletSchemaPB* input_schema = input_meta_pb.mutable_schema ();
65+ input_schema->set_keys_type (KeysType::DUP_KEYS);
66+ input_schema->set_num_short_key_columns (1 );
67+ input_schema->set_num_rows_per_row_block (1024 );
68+ input_schema->set_compress_kind (COMPRESS_LZ4);
69+
70+ ColumnPB* col1 = input_schema->add_column ();
71+ col1->set_unique_id (1 );
72+ col1->set_name (" col1" );
73+ col1->set_type (" INT" );
74+ col1->set_is_key (true );
75+ col1->set_aggregation (" NONE" );
76+
77+ ColumnPB* col2 = input_schema->add_column ();
78+ col2->set_unique_id (2 );
79+ col2->set_name (" col2" );
80+ col2->set_type (" VARCHAR" );
81+ col2->set_is_key (false );
82+ col2->set_aggregation (" REPLACE" );
83+
84+ doris::TabletIndexPB* index1 = input_schema->add_index ();
85+ index1->set_index_id (1001 );
86+ index1->set_index_name (" test_index1" );
87+ index1->set_index_type (IndexType::BITMAP);
88+ index1->add_col_unique_id (2 );
89+
90+ doris::TabletIndexPB* index2 = input_schema->add_index ();
91+ index2->set_index_id (1002 );
92+ index2->set_index_name (" test_index2" );
93+ index2->set_index_type (IndexType::INVERTED);
94+ index2->add_col_unique_id (2 );
95+
6496 RowsetMetaPB* rowset_meta = input_meta_pb.add_rs_metas ();
6597 RowsetId rowset_id;
6698 rowset_id.init (10000 );
@@ -78,8 +110,21 @@ TEST_F(CloudSnapshotMgrTest, TestConvertRowsets) {
78110 rowset_meta->set_rowset_state (RowsetStatePB::VISIBLE);
79111 rowset_meta->set_newest_write_timestamp (1678901234567890 );
80112
113+ TabletSchemaPB* rowset_schema = rowset_meta->mutable_tablet_schema ();
114+ rowset_schema->CopyFrom (*input_schema);
115+
81116 auto tablet_meta = std::make_shared<TabletMeta>();
82117 tablet_meta->init_from_pb (input_meta_pb);
118+
119+ TabletSchemaSPtr local_tablet_schema = std::make_shared<TabletSchema>();
120+ local_tablet_schema->init_from_pb (input_meta_pb.schema ());
121+
122+ // reset the index id
123+ input_schema->mutable_index (0 )->set_index_id (2001 );
124+ input_schema->mutable_index (1 )->set_index_id (2002 );
125+ rowset_meta->mutable_tablet_schema ()->mutable_index (0 )->set_index_id (2001 );
126+ rowset_meta->mutable_tablet_schema ()->mutable_index (1 )->set_index_id (2002 );
127+
83128 CloudTabletSPtr target_tablet = std::make_shared<CloudTablet>(*_engine, tablet_meta);
84129 StorageResource storage_resource {_fs};
85130 std::unordered_map<std::string, std::string> file_mapping;
@@ -92,6 +137,16 @@ TEST_F(CloudSnapshotMgrTest, TestConvertRowsets) {
92137 EXPECT_EQ (output_meta_pb.rs_metas (0 ).tablet_id (), 3000 );
93138 EXPECT_EQ (output_meta_pb.rs_metas (0 ).rowset_id (), 0 );
94139 EXPECT_NE (output_meta_pb.rs_metas (0 ).rowset_id_v2 (), rowset_id.to_string ());
140+ EXPECT_TRUE (output_meta_pb.has_schema ());
141+ EXPECT_EQ (output_meta_pb.schema ().index_size (), 2 );
142+ EXPECT_EQ (output_meta_pb.schema ().index (0 ).index_id (), 1001 );
143+ EXPECT_EQ (output_meta_pb.schema ().index (0 ).index_name (), " test_index1" );
144+ EXPECT_EQ (output_meta_pb.schema ().index (1 ).index_id (), 1002 );
145+ EXPECT_EQ (output_meta_pb.schema ().index (1 ).index_name (), " test_index2" );
146+ EXPECT_TRUE (output_meta_pb.rs_metas (0 ).has_tablet_schema ());
147+ EXPECT_EQ (output_meta_pb.rs_metas (0 ).tablet_schema ().index_size (), 2 );
148+ EXPECT_EQ (output_meta_pb.rs_metas (0 ).tablet_schema ().index (0 ).index_id (), 1001 );
149+ EXPECT_EQ (output_meta_pb.rs_metas (0 ).tablet_schema ().index (1 ).index_id (), 1002 );
95150 EXPECT_EQ (output_meta_pb.rs_metas (0 ).num_segments (), 3 );
96151 EXPECT_EQ (output_meta_pb.rs_metas (0 ).num_rows (), 100 );
97152 EXPECT_EQ (output_meta_pb.rs_metas (0 ).start_version (), 100 );
@@ -105,4 +160,55 @@ TEST_F(CloudSnapshotMgrTest, TestConvertRowsets) {
105160 EXPECT_TRUE (status.ok ());
106161}
107162
163+ TEST_F (CloudSnapshotMgrTest, TestRenameIndexIds) {
164+ TabletSchemaPB source_schema_pb;
165+ source_schema_pb.set_keys_type (KeysType::DUP_KEYS);
166+ source_schema_pb.set_num_short_key_columns (1 );
167+ source_schema_pb.set_num_rows_per_row_block (1024 );
168+ source_schema_pb.set_compress_kind (COMPRESS_LZ4);
169+
170+ ColumnPB* col1 = source_schema_pb.add_column ();
171+ col1->set_unique_id (1 );
172+ col1->set_name (" col1" );
173+ col1->set_type (" INT" );
174+ col1->set_is_key (true );
175+ col1->set_aggregation (" NONE" );
176+
177+ ColumnPB* col2 = source_schema_pb.add_column ();
178+ col2->set_unique_id (2 );
179+ col2->set_name (" col2" );
180+ col2->set_type (" VARCHAR" );
181+ col2->set_is_key (false );
182+ col2->set_aggregation (" REPLACE" );
183+
184+ doris::TabletIndexPB* index1 = source_schema_pb.add_index ();
185+ index1->set_index_id (1001 );
186+ index1->set_index_name (" test_index1" );
187+ index1->set_index_type (IndexType::BITMAP);
188+ index1->add_col_unique_id (2 );
189+
190+ doris::TabletIndexPB* index2 = source_schema_pb.add_index ();
191+ index2->set_index_id (1002 );
192+ index2->set_index_name (" test_index2" );
193+ index2->set_index_type (IndexType::INVERTED);
194+ index2->add_col_unique_id (2 );
195+
196+ TabletSchemaSPtr local_tablet_schema = std::make_shared<TabletSchema>();
197+ local_tablet_schema->init_from_pb (source_schema_pb);
198+
199+ // reset the index id
200+ source_schema_pb.mutable_index (0 )->set_index_id (2001 );
201+ source_schema_pb.mutable_index (1 )->set_index_id (2002 );
202+
203+ Status status = _snapshot_mgr->_rename_index_ids (source_schema_pb, local_tablet_schema);
204+ EXPECT_TRUE (status.ok ());
205+ EXPECT_EQ (source_schema_pb.index_size (), 2 );
206+ EXPECT_EQ (source_schema_pb.index (0 ).index_id (), 1001 );
207+ EXPECT_EQ (source_schema_pb.index (0 ).index_name (), " test_index1" );
208+ EXPECT_EQ (source_schema_pb.index (0 ).index_type (), IndexType::BITMAP);
209+ EXPECT_EQ (source_schema_pb.index (1 ).index_id (), 1002 );
210+ EXPECT_EQ (source_schema_pb.index (1 ).index_name (), " test_index2" );
211+ EXPECT_EQ (source_schema_pb.index (1 ).index_type (), IndexType::INVERTED);
212+ }
213+
108214} // namespace doris
0 commit comments