Skip to content

Commit

Permalink
fix bug and test
Browse files Browse the repository at this point in the history
  • Loading branch information
zwang28 committed Mar 7, 2024
1 parent e53346e commit 2e4d10e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
15 changes: 9 additions & 6 deletions src/frontend/src/handler/alter_source_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions src/frontend/src/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,11 @@ pub struct HandlerArgs {

impl HandlerArgs {
pub fn new(session: Arc<SessionImpl>, stmt: &Statement, sql: Arc<str>) -> Result<Self> {
// 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),
})
}

Expand Down Expand Up @@ -214,7 +212,7 @@ impl HandlerArgs {
}
_ => {}
}
stmt.to_string()
stmt.to_unredacted_string()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/handler/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
5 changes: 3 additions & 2 deletions src/meta/src/manager/catalog/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/sqlparser/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 2e4d10e

Please sign in to comment.