diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs index 4c28c65aa6c5a..c8bd77dd8af9d 100644 --- a/datafusion/sql/src/planner.rs +++ b/datafusion/sql/src/planner.rs @@ -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) } } } diff --git a/datafusion/sql/src/utils.rs b/datafusion/sql/src/utils.rs index 3fd403feab918..31ba48b24286b 100644 --- a/datafusion/sql/src/utils.rs +++ b/datafusion/sql/src/utils.rs @@ -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(_) @@ -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, } }