From cab7a1d44c2c65884c656d3a844b130424cfc458 Mon Sep 17 00:00:00 2001 From: Xin Li Date: Sun, 21 Jul 2024 11:08:01 +0800 Subject: [PATCH] fix fmt --- datafusion/sql/src/planner.rs | 16 ++++++---------- datafusion/sql/src/statement.rs | 8 +++++--- datafusion/sql/src/utils.rs | 7 ------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs index b359a56cb9bb..bf7c3fe0be4f 100644 --- a/datafusion/sql/src/planner.rs +++ b/datafusion/sql/src/planner.rs @@ -38,8 +38,7 @@ use datafusion_expr::logical_plan::{LogicalPlan, LogicalPlanBuilder}; use datafusion_expr::utils::find_column_exprs; use datafusion_expr::{col, Expr}; -use crate::utils::make_decimal_type; - +use crate::utils::{make_decimal_type, value_to_string}; pub use datafusion_expr::planner::ContextProvider; /// SQL parser options @@ -105,14 +104,11 @@ impl ValueNormalizer { Self { normalize } } - pub fn normalize(&self, value: Value) -> Result { - if self.normalize { - crate::utils::normalize_value(&value) - } else { - match crate::utils::value_to_string(&value) { - Some(s) => Ok(s), - None => internal_err!("Unsupport value type to string: {:?}", value), - } + pub fn normalize(&self, value: Value) -> Option { + match (value_to_string(&value), self.normalize) { + (Some(s), true) => Some(s.to_ascii_lowercase()), + (Some(s), false) => Some(s), + (None, _) => None, } } } diff --git a/datafusion/sql/src/statement.rs b/datafusion/sql/src/statement.rs index 9e4c0272deb8..fd0799add2cb 100644 --- a/datafusion/sql/src/statement.rs +++ b/datafusion/sql/src/statement.rs @@ -857,8 +857,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { } }; - let options_map: HashMap = - self.parse_options_map(statement.options, true)?; + let options_map = self.parse_options_map(statement.options, true)?; let maybe_file_type = if let Some(stored_as) = &statement.stored_as { if let Ok(ext_file_type) = self.context_provider.get_file_type(stored_as) { @@ -1029,7 +1028,10 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { return plan_err!("Option {key} is specified multiple times"); } - let value_string = self.value_normalizer.normalize(value)?; + let Some(value_string) = self.value_normalizer.normalize(value.clone()) + else { + return plan_err!("Unsupported Value {}", value); + }; if !(&key.contains('.')) { // If config does not belong to any namespace, assume it is diff --git a/datafusion/sql/src/utils.rs b/datafusion/sql/src/utils.rs index a50c59482631..12507034c596 100644 --- a/datafusion/sql/src/utils.rs +++ b/datafusion/sql/src/utils.rs @@ -263,13 +263,6 @@ pub(crate) fn normalize_ident(id: Ident) -> String { } } -pub(crate) fn normalize_value(value: &Value) -> Result { - match value_to_string(value) { - Some(s) => Ok(s.to_ascii_lowercase()), - None => exec_err!("Unsupported value to normalize: {:?}", value), - } -} - pub(crate) fn value_to_string(value: &Value) -> Option { match value { Value::SingleQuotedString(s) => Some(s.to_string()),