catalog/system_schema/memory_table/
table_columns.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
15#[macro_export]
16macro_rules! memory_table_cols{
17    ([$($colname:ident),*], $t:expr) => {
18        let t = &$t;
19        $(
20            let mut $colname = Vec::with_capacity(t.len());
21        )*
22        paste::paste!{
23            for &($([<r_ $colname>]),*) in t {
24                    $(
25                        $colname.push([<r_ $colname>]);
26                    )*
27            }
28        }
29    };
30}
31
32#[cfg(test)]
33mod tests {
34
35    #[test]
36    fn test_memory_table_columns() {
37        memory_table_cols!(
38            [oid, typname, typlen],
39            [
40                (1, "String", -1),
41                (2, "Binary", -1),
42                (3, "Time", 8),
43                (4, "Datetime", 8)
44            ]
45        );
46        assert_eq!(&oid[..], &[1, 2, 3, 4]);
47        assert_eq!(&typname[..], &["String", "Binary", "Time", "Datetime"]);
48        assert_eq!(&typlen[..], &[-1, -1, 8, 8]);
49    }
50}