Skip to content

Commit

Permalink
fix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
xinlifoobar committed Jul 21, 2024
1 parent d2372bc commit cab7a1d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
16 changes: 6 additions & 10 deletions datafusion/sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -105,14 +104,11 @@ impl ValueNormalizer {
Self { normalize }
}

pub fn normalize(&self, value: Value) -> Result<String> {
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<String> {
match (value_to_string(&value), self.normalize) {
(Some(s), true) => Some(s.to_ascii_lowercase()),
(Some(s), false) => Some(s),
(None, _) => None,
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions datafusion/sql/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
}
};

let options_map: HashMap<String, String> =
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) {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions datafusion/sql/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,6 @@ pub(crate) fn normalize_ident(id: Ident) -> String {
}
}

pub(crate) fn normalize_value(value: &Value) -> Result<String> {
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<String> {
match value {
Value::SingleQuotedString(s) => Some(s.to_string()),
Expand Down

0 comments on commit cab7a1d

Please sign in to comment.