From 2e4d10e644cfbd4f3d1406503a36a2d84d16b54c Mon Sep 17 00:00:00 2001 From: zwang28 <84491488@qq.com> Date: Thu, 7 Mar 2024 22:58:51 +0800 Subject: [PATCH] fix bug and test --- src/frontend/src/handler/alter_source_column.rs | 15 +++++++++------ src/frontend/src/handler/mod.rs | 6 ++---- src/frontend/src/handler/show.rs | 4 ++-- src/meta/src/manager/catalog/utils.rs | 5 +++-- src/sqlparser/src/ast/mod.rs | 6 ++++++ 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/frontend/src/handler/alter_source_column.rs b/src/frontend/src/handler/alter_source_column.rs index fcabedc1149c4..a0d0508441e3a 100644 --- a/src/frontend/src/handler/alter_source_column.rs +++ b/src/frontend/src/handler/alter_source_column.rs @@ -153,6 +153,7 @@ pub mod tests { use risingwave_common::catalog::{DEFAULT_DATABASE_NAME, DEFAULT_SCHEMA_NAME}; use risingwave_common::types::DataType; + use risingwave_sqlparser::ast::REDACT_SQL_OPTION; use crate::catalog::root_catalog::SchemaPath; use crate::test_utils::LocalFrontend; @@ -172,12 +173,14 @@ pub mod tests { frontend.run_sql(sql).await.unwrap(); let get_source = || { - let catalog_reader = session.env().catalog_reader().read_guard(); - catalog_reader - .get_source_by_name(DEFAULT_DATABASE_NAME, schema_path, "s") - .unwrap() - .0 - .clone() + REDACT_SQL_OPTION.sync_scope(false, || { + let catalog_reader = session.env().catalog_reader().read_guard(); + catalog_reader + .get_source_by_name(DEFAULT_DATABASE_NAME, schema_path, "s") + .unwrap() + .0 + .clone() + }) }; let source = get_source(); diff --git a/src/frontend/src/handler/mod.rs b/src/frontend/src/handler/mod.rs index a11c20ebf6b7e..39e3de0985b0a 100644 --- a/src/frontend/src/handler/mod.rs +++ b/src/frontend/src/handler/mod.rs @@ -164,13 +164,11 @@ pub struct HandlerArgs { impl HandlerArgs { pub fn new(session: Arc, stmt: &Statement, sql: Arc) -> Result { - // As `normalized_sql` is the source of truth, it shouldn't be redacted. - let normalized_sql = REDACT_SQL_OPTION.sync_scope(false, || Self::normalize_sql(stmt)); Ok(Self { session, sql, with_options: WithOptions::try_from(stmt)?, - normalized_sql, + normalized_sql: Self::normalize_sql(stmt), }) } @@ -214,7 +212,7 @@ impl HandlerArgs { } _ => {} } - stmt.to_string() + stmt.to_unredacted_string() } } diff --git a/src/frontend/src/handler/show.rs b/src/frontend/src/handler/show.rs index ac8f08065357b..5cbd3506d3abc 100644 --- a/src/frontend/src/handler/show.rs +++ b/src/frontend/src/handler/show.rs @@ -494,9 +494,9 @@ pub fn handle_show_create_object( .get_sink_by_name(&object_name) .ok_or_else(|| CatalogError::NotFound("sink", name.to_string()))?; if sink.owner.user_id != user_id { - sink.create_sql() - } else { redact_definition(&sink.create_sql())? + } else { + sink.create_sql() } } ShowCreateType::Source => { diff --git a/src/meta/src/manager/catalog/utils.rs b/src/meta/src/manager/catalog/utils.rs index 69592180aa60a..078b8e37d0217 100644 --- a/src/meta/src/manager/catalog/utils.rs +++ b/src/meta/src/manager/catalog/utils.rs @@ -85,7 +85,7 @@ pub fn alter_relation_rename(definition: &str, new_name: &str) -> String { _ => unreachable!(), }; - stmt.to_string() + stmt.to_unredacted_string() } /// `alter_relation_rename_refs` updates all references of renamed-relation in the definition of @@ -141,7 +141,8 @@ pub fn alter_relation_rename_refs(definition: &str, from: &str, to: &str) -> Str } _ => unreachable!(), }; - stmt.to_string() + + stmt.to_unredacted_string() } /// Replace the last ident in the `table_name` with the given name, the object name is ensured to be diff --git a/src/sqlparser/src/ast/mod.rs b/src/sqlparser/src/ast/mod.rs index d0a022874e69a..927d95daff337 100644 --- a/src/sqlparser/src/ast/mod.rs +++ b/src/sqlparser/src/ast/mod.rs @@ -1963,6 +1963,12 @@ impl fmt::Display for Statement { } } +impl Statement { + pub fn to_unredacted_string(&self) -> String { + REDACT_SQL_OPTION.sync_scope(false, || self.to_string()) + } +} + #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[non_exhaustive]