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(table_id: TableId, table_name: &str) -> TableInfo {
23    let column_schemas = vec![
24        ColumnSchema::new("col1", ConcreteDataType::int32_datatype(), true),
25        ColumnSchema::new(
26            "ts",
27            ConcreteDataType::timestamp_millisecond_datatype(),
28            false,
29        )
30        .with_time_index(true),
31        ColumnSchema::new("col2", ConcreteDataType::int32_datatype(), true),
32    ];
33    let schema = SchemaBuilder::try_from(column_schemas)
34        .unwrap()
35        .version(123)
36        .build()
37        .unwrap();
38
39    let meta = TableMetaBuilder::empty()
40        .schema(Arc::new(schema))
41        .primary_key_indices(vec![0])
42        .engine("engine")
43        .next_column_id(3)
44        .build()
45        .unwrap();
46    TableInfoBuilder::default()
47        .table_id(table_id)
48        .table_version(5)
49        .name(table_name)
50        .meta(meta)
51        .build()
52        .unwrap()
53}
54pub fn new_test_table_info(table_id: TableId) -> TableInfo {
55    new_test_table_info_with_name(table_id, "mytable")
56}