From a1587595d935d02b550876f45852e2bfae09a537 Mon Sep 17 00:00:00 2001 From: Ning Sun Date: Wed, 10 May 2023 02:55:00 +0000 Subject: [PATCH] feat: add information_schema as exception of cross schema check (#1551) * feat: add information_schema as a cross-schema query exception * fix: resolve lint issue --- src/query/src/lib.rs | 5 +++-- src/query/src/query_engine/options.rs | 8 ++++++++ src/table-procedure/src/lib.rs | 5 +++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/query/src/lib.rs b/src/query/src/lib.rs index 878b54dec3..ca150b5c39 100644 --- a/src/query/src/lib.rs +++ b/src/query/src/lib.rs @@ -25,10 +25,11 @@ pub mod plan; pub mod planner; pub mod query_engine; pub mod sql; -#[cfg(test)] -mod tests; pub use crate::datafusion::DfContextProviderAdapter; pub use crate::query_engine::{ QueryEngine, QueryEngineContext, QueryEngineFactory, QueryEngineRef, }; + +#[cfg(test)] +mod tests; diff --git a/src/query/src/query_engine/options.rs b/src/query/src/query_engine/options.rs index e76774d36b..8c60b9465c 100644 --- a/src/query/src/query_engine/options.rs +++ b/src/query/src/query_engine/options.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use common_catalog::consts::INFORMATION_SCHEMA_NAME; use session::context::QueryContextRef; use snafu::ensure; @@ -28,6 +29,11 @@ pub fn validate_catalog_and_schema( schema: &str, query_ctx: &QueryContextRef, ) -> Result<()> { + // information_schema is an exception + if schema.eq_ignore_ascii_case(INFORMATION_SCHEMA_NAME) { + return Ok(()); + } + ensure!( catalog == query_ctx.current_catalog() && schema == query_ctx.current_schema(), QueryAccessDeniedSnafu { @@ -59,5 +65,7 @@ mod tests { assert!(re.is_err()); let re = validate_catalog_and_schema("wrong_catalog", "wrong_schema", &context); assert!(re.is_err()); + + assert!(validate_catalog_and_schema("greptime", "information_schema", &context).is_ok()); } } diff --git a/src/table-procedure/src/lib.rs b/src/table-procedure/src/lib.rs index 6e637a1798..0778a3fac2 100644 --- a/src/table-procedure/src/lib.rs +++ b/src/table-procedure/src/lib.rs @@ -18,8 +18,6 @@ mod alter; mod create; mod drop; pub mod error; -#[cfg(test)] -mod test_util; pub use alter::AlterTableProcedure; use catalog::CatalogManagerRef; @@ -52,3 +50,6 @@ pub fn register_procedure_loaders( ); DropTableProcedure::register_loader(catalog_manager, engine_procedure, procedure_manager); } + +#[cfg(test)] +mod test_util;