catalog/system_schema/utils/
tables.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 datatypes::prelude::ConcreteDataType;
16use datatypes::schema::ColumnSchema;
17
18pub fn string_columns(names: &[&'static str]) -> Vec<ColumnSchema> {
19    names.iter().map(|name| string_column(name)).collect()
20}
21
22pub fn string_column(name: &str) -> ColumnSchema {
23    ColumnSchema::new(
24        str::to_lowercase(name),
25        ConcreteDataType::string_datatype(),
26        false,
27    )
28}
29
30pub fn u32_column(name: &str) -> ColumnSchema {
31    ColumnSchema::new(
32        str::to_lowercase(name),
33        ConcreteDataType::uint32_datatype(),
34        false,
35    )
36}
37
38pub fn i16_column(name: &str) -> ColumnSchema {
39    ColumnSchema::new(
40        str::to_lowercase(name),
41        ConcreteDataType::int16_datatype(),
42        false,
43    )
44}
45
46pub fn bigint_column(name: &str) -> ColumnSchema {
47    ColumnSchema::new(
48        str::to_lowercase(name),
49        ConcreteDataType::int64_datatype(),
50        false,
51    )
52}
53
54pub fn timestamp_micro_column(name: &str) -> ColumnSchema {
55    ColumnSchema::new(
56        str::to_lowercase(name),
57        ConcreteDataType::timestamp_microsecond_datatype(),
58        false,
59    )
60}
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65
66    #[test]
67    fn test_string_columns() {
68        let columns = ["a", "b", "c"];
69        let column_schemas = string_columns(&columns);
70
71        assert_eq!(3, column_schemas.len());
72        for (i, name) in columns.iter().enumerate() {
73            let cs = column_schemas.get(i).unwrap();
74
75            assert_eq!(*name, cs.name);
76            assert_eq!(ConcreteDataType::string_datatype(), cs.data_type);
77        }
78    }
79}