common_meta/key/
test_utils.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 std::sync::Arc;
16
17use datatypes::prelude::ConcreteDataType;
18use datatypes::schema::{ColumnSchema, SchemaBuilder};
19use store_api::storage::TableId;
20use table::metadata::{TableInfo, TableInfoBuilder, TableMetaBuilder};
21
22pub fn new_test_table_info_with_name<I: IntoIterator<Item = u32>>(
23    table_id: TableId,
24    table_name: &str,
25    region_numbers: I,
26) -> TableInfo {
27    let column_schemas = vec![
28        ColumnSchema::new("col1", ConcreteDataType::int32_datatype(), true),
29        ColumnSchema::new(
30            "ts",
31            ConcreteDataType::timestamp_millisecond_datatype(),
32            false,
33        )
34        .with_time_index(true),
35        ColumnSchema::new("col2", ConcreteDataType::int32_datatype(), true),
36    ];
37    let schema = SchemaBuilder::try_from(column_schemas)
38        .unwrap()
39        .version(123)
40        .build()
41        .unwrap();
42
43    let meta = TableMetaBuilder::empty()
44        .schema(Arc::new(schema))
45        .primary_key_indices(vec![0])
46        .engine("engine")
47        .next_column_id(3)
48        .region_numbers(region_numbers.into_iter().collect::<Vec<_>>())
49        .build()
50        .unwrap();
51    TableInfoBuilder::default()
52        .table_id(table_id)
53        .table_version(5)
54        .name(table_name)
55        .meta(meta)
56        .build()
57        .unwrap()
58}
59pub fn new_test_table_info<I: IntoIterator<Item = u32>>(
60    table_id: TableId,
61    region_numbers: I,
62) -> TableInfo {
63    new_test_table_info_with_name(table_id, "mytable", region_numbers)
64}