catalog/system_schema/
numbers_table_provider.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#[cfg(any(test, feature = "testing", debug_assertions))]
16use common_catalog::consts::NUMBERS_TABLE_ID;
17use table::TableRef;
18#[cfg(any(test, feature = "testing", debug_assertions))]
19use table::table::numbers::NUMBERS_TABLE_NAME;
20#[cfg(any(test, feature = "testing", debug_assertions))]
21use table::table::numbers::NumbersTable;
22
23// NumbersTableProvider is a dedicated provider for feature-gating the numbers table.
24#[derive(Clone)]
25pub struct NumbersTableProvider;
26
27#[cfg(any(test, feature = "testing", debug_assertions))]
28impl NumbersTableProvider {
29    pub(crate) fn table_exists(&self, name: &str) -> bool {
30        name == NUMBERS_TABLE_NAME
31    }
32
33    pub(crate) fn table_names(&self) -> Vec<String> {
34        vec![NUMBERS_TABLE_NAME.to_string()]
35    }
36
37    pub(crate) fn table(&self, name: &str) -> Option<TableRef> {
38        if name == NUMBERS_TABLE_NAME {
39            Some(NumbersTable::table(NUMBERS_TABLE_ID))
40        } else {
41            None
42        }
43    }
44}
45
46#[cfg(not(any(test, feature = "testing", debug_assertions)))]
47impl NumbersTableProvider {
48    pub(crate) fn table_exists(&self, _name: &str) -> bool {
49        false
50    }
51
52    pub(crate) fn table_names(&self) -> Vec<String> {
53        vec![]
54    }
55
56    pub(crate) fn table(&self, _name: &str) -> Option<TableRef> {
57        None
58    }
59}