Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Apr 24, 2024
1 parent dc4b2e4 commit 3e36273
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 28 deletions.
11 changes: 7 additions & 4 deletions src/sql/src/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<key> = '******'`.
fn redact_and_sort_options(options: &OptionMap) -> Vec<String> {
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()));
}
}
}
Expand Down
65 changes: 41 additions & 24 deletions src/sql/src/statements/tql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<start>, <end>, <step>, [lookback]) <promql>
#[derive(Debug, Clone, PartialEq, Eq, Visit, VisitMut)]
pub struct TqlEval {
Expand All @@ -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,
)
}
}

Expand All @@ -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,
)
}
}

Expand All @@ -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,
)
}
}

Expand Down

0 comments on commit 3e36273

Please sign in to comment.