diff --git a/src/sql/src/statements.rs b/src/sql/src/statements.rs index b7c6807ba53a..27a0c9327a24 100644 --- a/src/sql/src/statements.rs +++ b/src/sql/src/statements.rs @@ -61,18 +61,21 @@ use crate::error::{ const REDACTED_OPTIONS: [&str; 2] = ["access_key_id", "secret_access_key"]; +/// Convert the options into redacted and sorted key-value string. Options with key in +/// [REDACTED_OPTIONS] will be converted into ` = '******'`. fn redact_and_sort_options(options: &OptionMap) -> Vec { - let mut result = vec![]; - let keys = options.as_ref().keys().sorted(); + let options = options.as_ref(); + let mut result = Vec::with_capacity(options.len()); + let keys = options.keys().sorted(); for key in keys { if let Some(val) = options.get(key) { let redacted = REDACTED_OPTIONS .iter() .any(|opt| opt.eq_ignore_ascii_case(key)); if redacted { - result.push(format!("{key} = ******")); + result.push(format!("{key} = '******'")); } else { - result.push(format!("{key} = {val}")); + result.push(format!("{key} = '{}'", val.escape_default())); } } } diff --git a/src/sql/src/statements/tql.rs b/src/sql/src/statements/tql.rs index b9a6e0e4feb6..07f8cb8876ec 100644 --- a/src/sql/src/statements/tql.rs +++ b/src/sql/src/statements/tql.rs @@ -33,6 +33,22 @@ impl Display for Tql { } } +// TODO: encapsulate shard TQL args into a struct and implement Display for it. +fn format_tql( + f: &mut std::fmt::Formatter<'_>, + start: &str, + end: &str, + step: &str, + lookback: Option<&str>, + query: &str, +) -> std::fmt::Result { + write!(f, "({start}, {end}, {step}")?; + if let Some(lookback) = lookback { + write!(f, ", {lookback}")?; + } + write!(f, ") {query}") +} + /// TQL EVAL (, , , [lookback]) #[derive(Debug, Clone, PartialEq, Eq, Visit, VisitMut)] pub struct TqlEval { @@ -45,14 +61,15 @@ pub struct TqlEval { impl Display for TqlEval { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "TQL EVAL(")?; - write!(f, "{}, ", &self.start)?; - write!(f, "{}, ", &self.end)?; - write!(f, "{}", &self.step)?; - if let Some(lookback) = &self.lookback { - write!(f, ", {}", lookback)?; - } - write!(f, ") {}", &self.query) + write!(f, "TQL EVAL")?; + format_tql( + f, + &self.start, + &self.end, + &self.step, + self.lookback.as_deref(), + &self.query, + ) } } @@ -74,14 +91,14 @@ impl Display for TqlExplain { if self.is_verbose { write!(f, "VERBOSE ")?; } - write!(f, "(")?; - write!(f, "{}, ", &self.start)?; - write!(f, "{}, ", &self.end)?; - write!(f, "{}", &self.step)?; - if let Some(lookback) = &self.lookback { - write!(f, ", {}", lookback)?; - } - write!(f, ") {}", &self.query) + format_tql( + f, + &self.start, + &self.end, + &self.step, + self.lookback.as_deref(), + &self.query, + ) } } @@ -103,14 +120,14 @@ impl Display for TqlAnalyze { if self.is_verbose { write!(f, "VERBOSE ")?; } - write!(f, "(")?; - write!(f, "{}, ", &self.start)?; - write!(f, "{}, ", &self.end)?; - write!(f, "{}", &self.step)?; - if let Some(lookback) = &self.lookback { - write!(f, ", {}", lookback)?; - } - write!(f, ") {}", &self.query) + format_tql( + f, + &self.start, + &self.end, + &self.step, + self.lookback.as_deref(), + &self.query, + ) } }