Skip to content

Commit

Permalink
Minor: remove .. pattern matching in sql planner (#9531)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored Mar 11, 2024
1 parent 4cd3c43 commit 44936ef
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions datafusion/sql/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,14 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
),

SQLExpr::Cast {
expr, data_type, ..
expr,
data_type,
format,
} => {
if let Some(format) = format {
return not_impl_err!("CAST with format is not supported: {format}");
}

let dt = self.convert_data_type(&data_type)?;
let expr =
self.sql_expr_to_logical_expr(*expr, schema, planner_context)?;
Expand All @@ -295,15 +301,23 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
}

SQLExpr::TryCast {
expr, data_type, ..
} => Ok(Expr::TryCast(TryCast::new(
Box::new(self.sql_expr_to_logical_expr(
*expr,
schema,
planner_context,
)?),
self.convert_data_type(&data_type)?,
))),
expr,
data_type,
format,
} => {
if let Some(format) = format {
return not_impl_err!("CAST with format is not supported: {format}");
}

Ok(Expr::TryCast(TryCast::new(
Box::new(self.sql_expr_to_logical_expr(
*expr,
schema,
planner_context,
)?),
self.convert_data_type(&data_type)?,
)))
}

SQLExpr::TypedString { data_type, value } => Ok(Expr::Cast(Cast::new(
Box::new(lit(value)),
Expand Down Expand Up @@ -478,7 +492,6 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
trim_where,
trim_what,
trim_characters,
..
} => self.sql_trim_to_expr(
*expr,
trim_where,
Expand Down Expand Up @@ -801,7 +814,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
distinct,
order_by,
null_treatment,
..
filter: None, // filter is passed in
}) => Ok(Expr::AggregateFunction(expr::AggregateFunction::new(
fun,
args,
Expand All @@ -814,7 +827,10 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
order_by,
null_treatment,
))),
_ => plan_err!(
Expr::AggregateFunction(..) => {
internal_err!("Expected null filter clause in aggregate function")
}
_ => internal_err!(
"AggregateExpressionWithFilter expression was not an AggregateFunction"
),
}
Expand Down

0 comments on commit 44936ef

Please sign in to comment.