Skip to content

Commit

Permalink
Fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xinlifoobar committed Jul 18, 2024
1 parent dbd1ebe commit f3b0791
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 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)
match crate::utils::value_to_string(&value) {
Some(s) => Ok(s),
None => internal_err!("Unsupport value type to string: {:?}", value),
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions datafusion/sql/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,10 +1153,10 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
let value_string = match &value[0] {
SQLExpr::Identifier(i) => ident_to_string(i),
SQLExpr::Value(v) => match crate::utils::value_to_string(v) {
Err(_) => {
None => {
return plan_err!("Unsupported Value {}", value[0]);
}
Ok(v) => v,
Some(v) => v,
},
// for capture signed number e.g. +8, -8
SQLExpr::UnaryOp { op, expr } => match op {
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())
match value_to_string(value) {
Some(s) => Ok(s),
None => exec_err!("Unsupported value to normalize: {:?}", value),
}
}

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
3 changes: 1 addition & 2 deletions datafusion/sql/tests/sql_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ fn test_parse_options_value_normalization() {
enable_options_value_normalization,
},
);
if plan.is_ok() {
let plan = plan.unwrap();
if let Ok(plan) = plan {
assert_eq!(expected_plan, format!("{plan:?}"));

match plan {
Expand Down

0 comments on commit f3b0791

Please sign in to comment.