From 8091858af3aa8c7dd6d98a7d25b10a4a8d1c9373 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 | 3 ++- src/frontend/src/handler/alter_source_with_sr.rs | 2 +- src/frontend/src/handler/extended_handle.rs | 2 +- src/frontend/src/handler/mod.rs | 6 ++---- src/frontend/src/handler/show.rs | 4 ++-- src/frontend/src/session.rs | 2 +- src/meta/src/controller/rename.rs | 4 ++-- src/meta/src/manager/catalog/utils.rs | 5 +++-- src/sqlparser/src/ast/mod.rs | 6 ++++++ src/tests/sqlsmith/src/test_runners/utils.rs | 2 +- 10 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/frontend/src/handler/alter_source_column.rs b/src/frontend/src/handler/alter_source_column.rs index fcabedc1149c4..c12ac3a65b68e 100644 --- a/src/frontend/src/handler/alter_source_column.rs +++ b/src/frontend/src/handler/alter_source_column.rs @@ -144,7 +144,7 @@ pub fn alter_definition_add_column(definition: &str, column: ColumnDef) -> Resul _ => unreachable!(), } - Ok(stmt.to_string()) + Ok(stmt.to_unredacted_string()) } #[cfg(test)] @@ -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; diff --git a/src/frontend/src/handler/alter_source_with_sr.rs b/src/frontend/src/handler/alter_source_with_sr.rs index 06bb2d0387479..8504b756ba825 100644 --- a/src/frontend/src/handler/alter_source_with_sr.rs +++ b/src/frontend/src/handler/alter_source_with_sr.rs @@ -212,7 +212,7 @@ pub fn alter_definition_format_encode( _ => unreachable!(), } - Ok(stmt.to_string()) + Ok(stmt.to_unredacted_string()) } #[cfg(test)] diff --git a/src/frontend/src/handler/extended_handle.rs b/src/frontend/src/handler/extended_handle.rs index b497b1164d144..daab63b1ad308 100644 --- a/src/frontend/src/handler/extended_handle.rs +++ b/src/frontend/src/handler/extended_handle.rs @@ -188,7 +188,7 @@ pub async fn handle_execute(session: Arc, portal: Portal) -> Result } } Portal::PureStatement(stmt) => { - let sql: Arc = Arc::from(stmt.to_string()); + let sql: Arc = Arc::from(stmt.to_unredacted_string()); handle(session, stmt, sql, vec![]).await } } 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/frontend/src/session.rs b/src/frontend/src/session.rs index 30d1b02df7c03..f0fad5a3f20da 100644 --- a/src/frontend/src/session.rs +++ b/src/frontend/src/session.rs @@ -1076,7 +1076,7 @@ impl Session for SessionImpl { stmt: Statement, format: Format, ) -> std::result::Result, BoxedError> { - let string = stmt.to_string(); + let string = stmt.to_unredacted_string(); let sql_str = string.as_str(); let sql: Arc = Arc::from(sql_str); let rsp = handle(self, stmt, sql.clone(), vec![format]) diff --git a/src/meta/src/controller/rename.rs b/src/meta/src/controller/rename.rs index 15be4d7ef83b8..7b9f3cc31deb9 100644 --- a/src/meta/src/controller/rename.rs +++ b/src/meta/src/controller/rename.rs @@ -57,7 +57,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 @@ -113,7 +113,7 @@ 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/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] diff --git a/src/tests/sqlsmith/src/test_runners/utils.rs b/src/tests/sqlsmith/src/test_runners/utils.rs index 98f29df490446..fa744c4c551bc 100644 --- a/src/tests/sqlsmith/src/test_runners/utils.rs +++ b/src/tests/sqlsmith/src/test_runners/utils.rs @@ -199,7 +199,7 @@ pub(super) async fn create_base_tables(testdata: &str, client: &Client) -> Resul mvs_and_base_tables.extend_from_slice(&base_tables); for stmt in &statements { - let create_sql = stmt.to_string(); + let create_sql = stmt.to_unredacted_string(); tracing::info!("[EXECUTING CREATE TABLE]: {}", &create_sql); client.simple_query(&create_sql).await.unwrap(); }