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 8091858
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/frontend/src/handler/alter_source_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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 Down
2 changes: 1 addition & 1 deletion src/frontend/src/handler/alter_source_with_sr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub fn alter_definition_format_encode(
_ => unreachable!(),
}

Ok(stmt.to_string())
Ok(stmt.to_unredacted_string())
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/handler/extended_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub async fn handle_execute(session: Arc<SessionImpl>, portal: Portal) -> Result
}
}
Portal::PureStatement(stmt) => {
let sql: Arc<str> = Arc::from(stmt.to_string());
let sql: Arc<str> = Arc::from(stmt.to_unredacted_string());
handle(session, stmt, sql, vec![]).await
}
}
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
2 changes: 1 addition & 1 deletion src/frontend/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ impl Session for SessionImpl {
stmt: Statement,
format: Format,
) -> std::result::Result<PgResponse<PgResponseStream>, BoxedError> {
let string = stmt.to_string();
let string = stmt.to_unredacted_string();
let sql_str = string.as_str();
let sql: Arc<str> = Arc::from(sql_str);
let rsp = handle(self, stmt, sql.clone(), vec![format])
Expand Down
4 changes: 2 additions & 2 deletions src/meta/src/controller/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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
2 changes: 1 addition & 1 deletion src/tests/sqlsmith/src/test_runners/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 8091858

Please sign in to comment.