common_meta/ddl/test_util/region_metadata.rs
1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use api::v1::SemanticType;
16use store_api::metadata::{ColumnMetadata, RegionMetadata, RegionMetadataBuilder};
17use store_api::storage::RegionId;
18
19/// Builds a region metadata with the given column metadatas.
20pub fn build_region_metadata(
21 region_id: RegionId,
22 column_metadatas: &[ColumnMetadata],
23) -> RegionMetadata {
24 let mut builder = RegionMetadataBuilder::new(region_id);
25 let mut primary_key = vec![];
26 for column_metadata in column_metadatas {
27 builder.push_column_metadata(column_metadata.clone());
28 if column_metadata.semantic_type == SemanticType::Tag {
29 primary_key.push(column_metadata.column_id);
30 }
31 }
32 builder.primary_key(primary_key);
33 builder.build().unwrap()
34}