Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xinlifoobar committed Jul 17, 2024
1 parent 4f5e8d3 commit 7ac2dc8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 4 additions & 1 deletion datafusion/sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ impl ValueNormalizer {
if self.normalize {
crate::utils::normalize_value(&value)
} else {
crate::utils::value_to_string(&value)
let Some(v) = crate::utils::value_to_string(&value) else {
return internal_err!("Value {:?} cannot be converted to string", value);
};
Ok(v)
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions datafusion/sql/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,17 @@ pub(crate) fn normalize_ident(id: Ident) -> String {
}

pub(crate) fn normalize_value(value: &Value) -> Result<String> {
value_to_string(value).map(|v| v.to_ascii_lowercase())
let Some(v) = value_to_string(value) else {
return plan_err!("Unsupported Value to normalize {}", value);
};
Ok(v.to_ascii_lowercase())
}

pub(crate) fn value_to_string(value: &Value) -> Result<String> {
pub(crate) fn value_to_string(value: &Value) -> Option<String> {
match value {
Value::SingleQuotedString(s) => Ok(s.to_string()),
Value::DollarQuotedString(s) => Ok(s.to_string()),
Value::Number(_, _) | Value::Boolean(_) => Ok(value.to_string()),
Value::SingleQuotedString(s) => Some(s.to_string()),
Value::DollarQuotedString(s) => Some(s.to_string()),
Value::Number(_, _) | Value::Boolean(_) => Some(value.to_string()),
Value::DoubleQuotedString(_)
| Value::EscapedStringLiteral(_)
| Value::NationalStringLiteral(_)
Expand All @@ -287,7 +290,7 @@ pub(crate) fn value_to_string(value: &Value) -> Result<String> {
| Value::TripleDoubleQuotedRawStringLiteral(_)
| Value::HexStringLiteral(_)
| Value::Null
| Value::Placeholder(_) => plan_err!("Unsupported Value to normalize {}", value),
| Value::Placeholder(_) => None,
}
}

Expand Down

0 comments on commit 7ac2dc8

Please sign in to comment.