Skip to content

Commit 2622d22

Browse files
committed
save
1 parent 36d8314 commit 2622d22

File tree

1 file changed

+69
-1
lines changed

1 file changed

+69
-1
lines changed

be/test/olap/snapshot_manager_test.cpp

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ TEST_F(SnapshotManagerTest, TestConvertRowsetIdsNormal) {
175175
rowset_meta->set_index_disk_size(24);
176176
rowset_meta->set_empty(false);
177177

178+
TabletSchemaPB* rowset_schema = rowset_meta->mutable_tablet_schema();
179+
rowset_schema->CopyFrom(*schema_pb);
180+
178181
// new ids
179182
int64_t tablet_id = 20006;
180183
int64_t replica_id = 2;
@@ -186,6 +189,56 @@ TEST_F(SnapshotManagerTest, TestConvertRowsetIdsNormal) {
186189
std::string meta_file = clone_dir + "/" + std::to_string(tablet_id) + ".hdr";
187190
EXPECT_TRUE(TabletMeta::save(meta_file, tablet_meta_pb).ok());
188191

192+
TCreateTabletReq create_tablet_req;
193+
create_tablet_req.__set_tablet_id(tablet_id);
194+
create_tablet_req.__set_replica_id(replica_id);
195+
create_tablet_req.__set_table_id(table_id);
196+
create_tablet_req.__set_partition_id(partition_id);
197+
create_tablet_req.__set_version(1);
198+
199+
TTabletSchema tablet_schema;
200+
tablet_schema.__set_schema_hash(schema_hash);
201+
tablet_schema.__set_short_key_column_count(schema_pb->num_short_key_columns());
202+
tablet_schema.__set_keys_type(TKeysType::AGG_KEYS);
203+
tablet_schema.__set_storage_type(TStorageType::COLUMN);
204+
205+
std::vector<TColumn> columns;
206+
for (int i = 0; i < schema_pb->column_size(); i++) {
207+
const ColumnPB& column_pb = schema_pb->column(i);
208+
TColumn tcolumn;
209+
tcolumn.__set_column_name(column_pb.name());
210+
tcolumn.__set_is_key(column_pb.is_key());
211+
TColumnType col_type;
212+
col_type.__set_type(TPrimitiveType::INT);
213+
tcolumn.__set_column_type(col_type);
214+
tcolumn.__set_is_allow_null(column_pb.is_nullable());
215+
if (!column_pb.is_key()) {
216+
tcolumn.__set_aggregation_type(TAggregationType::SUM);
217+
}
218+
columns.push_back(tcolumn);
219+
}
220+
tablet_schema.__set_columns(columns);
221+
222+
std::vector<TOlapTableIndex> indexes;
223+
for (int i = 0; i < schema_pb->index_size(); i++) {
224+
TOlapTableIndex tindex;
225+
tindex.__set_index_id(2001 + i);
226+
tindex.__set_index_name("test_index");
227+
tindex.__set_index_type(TIndexType::BITMAP);
228+
tindex.__set_columns({"k1"});
229+
tindex.__set_column_unique_ids({0});
230+
indexes.push_back(tindex);
231+
}
232+
tablet_schema.__set_indexes(indexes);
233+
234+
create_tablet_req.__set_tablet_schema(tablet_schema);
235+
std::vector<DataDir*> stores;
236+
stores.push_back(_data_dir);
237+
RuntimeProfile profile("CreateTablet");
238+
239+
Status status = _engine->tablet_manager()->create_tablet(create_tablet_req, stores, &profile);
240+
EXPECT_TRUE(status.ok()) << "Failed to create tablet: " << status;
241+
189242
auto result = _engine->snapshot_mgr()->convert_rowset_ids(clone_dir, tablet_id, replica_id,
190243
table_id, partition_id, schema_hash);
191244
EXPECT_TRUE(result.has_value());
@@ -206,7 +259,7 @@ TEST_F(SnapshotManagerTest, TestConvertRowsetIdsNormal) {
206259
// verify index
207260
EXPECT_EQ(converted_meta_pb.schema().index_size(), 1);
208261
const TabletIndexPB& converted_index = converted_meta_pb.schema().index(0);
209-
EXPECT_EQ(converted_index.index_id(), 1001);
262+
EXPECT_EQ(converted_index.index_id(), 2001);
210263
EXPECT_EQ(converted_index.index_name(), "test_index");
211264
EXPECT_EQ(converted_index.index_type(), IndexType::BITMAP);
212265
EXPECT_EQ(converted_index.col_unique_id_size(), 1);
@@ -224,5 +277,20 @@ TEST_F(SnapshotManagerTest, TestConvertRowsetIdsNormal) {
224277
EXPECT_EQ(converted_rowset_meta.end_version(), 1);
225278
EXPECT_EQ(converted_rowset_meta.num_rows(), 100);
226279
EXPECT_EQ(converted_rowset_meta.total_disk_size(), 1024);
280+
EXPECT_TRUE(converted_rowset_meta.has_tablet_schema());
281+
282+
// verify rowset schema
283+
const TabletSchemaPB& converted_rowset_schema = converted_rowset_meta.tablet_schema();
284+
EXPECT_EQ(converted_rowset_schema.num_short_key_columns(), 1);
285+
EXPECT_EQ(converted_rowset_schema.column_size(), 2);
286+
EXPECT_EQ(converted_rowset_schema.index_size(), 1);
287+
288+
// verify rowset index
289+
const TabletIndexPB& converted_rowset_index = converted_rowset_schema.index(0);
290+
EXPECT_EQ(converted_rowset_index.index_id(), 2001);
291+
EXPECT_EQ(converted_rowset_index.index_name(), "test_index");
292+
EXPECT_EQ(converted_rowset_index.index_type(), IndexType::BITMAP);
293+
EXPECT_EQ(converted_rowset_index.col_unique_id_size(), 1);
294+
EXPECT_EQ(converted_rowset_index.col_unique_id(0), 0);
227295
}
228296
} // namespace doris

0 commit comments

Comments
 (0)