From 8f9674440ff7470e811d9735f028bef78faf7d93 Mon Sep 17 00:00:00 2001 From: Weny Xu Date: Mon, 22 Dec 2025 19:34:19 +0800 Subject: [PATCH] chore: pick #7148 into release/v0.16 (#7455) refactor: add test feature gate to numbers table (#7148) * refactor: add test feature gate to numbers table * chore: add debug_assertions * refactor: extract numbers table provider * chore: address CR issues --------- Signed-off-by: shuiyisong Signed-off-by: WenyXu Co-authored-by: shuiyisong <113876041+shuiyisong@users.noreply.github.com> --- src/catalog/src/kvbackend/builder.rs | 2 + src/catalog/src/kvbackend/manager.rs | 16 +++-- src/catalog/src/system_schema.rs | 1 + .../system_schema/numbers_table_provider.rs | 59 +++++++++++++++++++ 4 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 src/catalog/src/system_schema/numbers_table_provider.rs diff --git a/src/catalog/src/kvbackend/builder.rs b/src/catalog/src/kvbackend/builder.rs index 2834673baa..03d552fccb 100644 --- a/src/catalog/src/kvbackend/builder.rs +++ b/src/catalog/src/kvbackend/builder.rs @@ -29,6 +29,7 @@ use crate::information_schema::{InformationExtensionRef, InformationSchemaProvid use crate::kvbackend::manager::{SystemCatalog, CATALOG_CACHE_MAX_CAPACITY}; use crate::kvbackend::KvBackendCatalogManager; use crate::process_manager::ProcessManagerRef; +use crate::system_schema::numbers_table_provider::NumbersTableProvider; use crate::system_schema::pg_catalog::PGCatalogProvider; pub struct KvBackendCatalogManagerBuilder { @@ -119,6 +120,7 @@ impl KvBackendCatalogManagerBuilder { DEFAULT_CATALOG_NAME.to_string(), me.clone(), )), + numbers_table_provider: NumbersTableProvider, backend, process_manager, #[cfg(feature = "enterprise")] diff --git a/src/catalog/src/kvbackend/manager.rs b/src/catalog/src/kvbackend/manager.rs index df4489a519..f9c8a26e54 100644 --- a/src/catalog/src/kvbackend/manager.rs +++ b/src/catalog/src/kvbackend/manager.rs @@ -18,8 +18,7 @@ use std::sync::{Arc, Weak}; use async_stream::try_stream; use common_catalog::consts::{ - DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME, INFORMATION_SCHEMA_NAME, NUMBERS_TABLE_ID, - PG_CATALOG_NAME, + DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME, INFORMATION_SCHEMA_NAME, PG_CATALOG_NAME, }; use common_error::ext::BoxedError; use common_meta::cache::{ @@ -43,7 +42,6 @@ use snafu::prelude::*; use store_api::metric_engine_consts::METRIC_ENGINE_NAME; use table::dist_table::DistTable; use table::metadata::{TableId, TableInfoRef}; -use table::table::numbers::{NumbersTable, NUMBERS_TABLE_NAME}; use table::table_name::TableName; use table::TableRef; use tokio::sync::Semaphore; @@ -58,6 +56,7 @@ use crate::information_schema::InformationSchemaTableFactoryRef; use crate::information_schema::{InformationExtensionRef, InformationSchemaProvider}; use crate::kvbackend::TableCacheRef; use crate::process_manager::ProcessManagerRef; +use crate::system_schema::numbers_table_provider::NumbersTableProvider; use crate::system_schema::pg_catalog::PGCatalogProvider; use crate::system_schema::SystemSchemaProvider; use crate::CatalogManager; @@ -537,6 +536,7 @@ pub(super) struct SystemCatalog { // system_schema_provider for default catalog pub(super) information_schema_provider: Arc, pub(super) pg_catalog_provider: Arc, + pub(super) numbers_table_provider: NumbersTableProvider, pub(super) backend: KvBackendRef, pub(super) process_manager: Option, #[cfg(feature = "enterprise")] @@ -566,9 +566,7 @@ impl SystemCatalog { PG_CATALOG_NAME if channel == Channel::Postgres => { self.pg_catalog_provider.table_names() } - DEFAULT_SCHEMA_NAME => { - vec![NUMBERS_TABLE_NAME.to_string()] - } + DEFAULT_SCHEMA_NAME => self.numbers_table_provider.table_names(), _ => vec![], } } @@ -586,7 +584,7 @@ impl SystemCatalog { if schema == INFORMATION_SCHEMA_NAME { self.information_schema_provider.table(table).is_some() } else if schema == DEFAULT_SCHEMA_NAME { - table == NUMBERS_TABLE_NAME + self.numbers_table_provider.table_exists(table) } else if schema == PG_CATALOG_NAME && channel == Channel::Postgres { self.pg_catalog_provider.table(table).is_some() } else { @@ -631,8 +629,8 @@ impl SystemCatalog { }); pg_catalog_provider.table(table_name) } - } else if schema == DEFAULT_SCHEMA_NAME && table_name == NUMBERS_TABLE_NAME { - Some(NumbersTable::table(NUMBERS_TABLE_ID)) + } else if schema == DEFAULT_SCHEMA_NAME { + self.numbers_table_provider.table(table_name) } else { None } diff --git a/src/catalog/src/system_schema.rs b/src/catalog/src/system_schema.rs index 15191a818a..228c29ac22 100644 --- a/src/catalog/src/system_schema.rs +++ b/src/catalog/src/system_schema.rs @@ -14,6 +14,7 @@ pub mod information_schema; mod memory_table; +pub mod numbers_table_provider; pub mod pg_catalog; pub mod predicate; mod utils; diff --git a/src/catalog/src/system_schema/numbers_table_provider.rs b/src/catalog/src/system_schema/numbers_table_provider.rs new file mode 100644 index 0000000000..8b1e565953 --- /dev/null +++ b/src/catalog/src/system_schema/numbers_table_provider.rs @@ -0,0 +1,59 @@ +// Copyright 2023 Greptime Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[cfg(any(test, feature = "testing", debug_assertions))] +use common_catalog::consts::NUMBERS_TABLE_ID; +#[cfg(any(test, feature = "testing", debug_assertions))] +use table::table::numbers::NumbersTable; +#[cfg(any(test, feature = "testing", debug_assertions))] +use table::table::numbers::NUMBERS_TABLE_NAME; +use table::TableRef; + +// NumbersTableProvider is a dedicated provider for feature-gating the numbers table. +#[derive(Clone)] +pub struct NumbersTableProvider; + +#[cfg(any(test, feature = "testing", debug_assertions))] +impl NumbersTableProvider { + pub(crate) fn table_exists(&self, name: &str) -> bool { + name == NUMBERS_TABLE_NAME + } + + pub(crate) fn table_names(&self) -> Vec { + vec![NUMBERS_TABLE_NAME.to_string()] + } + + pub(crate) fn table(&self, name: &str) -> Option { + if name == NUMBERS_TABLE_NAME { + Some(NumbersTable::table(NUMBERS_TABLE_ID)) + } else { + None + } + } +} + +#[cfg(not(any(test, feature = "testing", debug_assertions)))] +impl NumbersTableProvider { + pub(crate) fn table_exists(&self, _name: &str) -> bool { + false + } + + pub(crate) fn table_names(&self) -> Vec { + vec![] + } + + pub(crate) fn table(&self, _name: &str) -> Option { + None + } +}