Skip to content

Commit 1bd32c6

Browse files
committed
Minor: simplify update code
1 parent a9d66e2 commit 1bd32c6

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

datafusion/sql/src/statement.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use datafusion_common::{
3636
Result, SchemaReference, TableReference, ToDFSchema,
3737
};
3838
use datafusion_expr::dml::{CopyOptions, CopyTo};
39-
use datafusion_expr::expr::Placeholder;
4039
use datafusion_expr::expr_rewriter::normalize_col_with_schemas_and_ambiguity_check;
4140
use datafusion_expr::logical_plan::builder::project;
4241
use datafusion_expr::logical_plan::DdlStatement;
@@ -1025,20 +1024,13 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
10251024
// Projection
10261025
let mut exprs = vec![];
10271026
for (col_name, expr, dt) in values_and_types.into_iter() {
1028-
let expr = self.sql_to_expr(expr, &table_schema, &mut planner_context)?;
1029-
let expr = match expr {
1030-
datafusion_expr::Expr::Placeholder(Placeholder {
1031-
ref id,
1032-
ref data_type,
1033-
}) => match data_type {
1034-
None => datafusion_expr::Expr::Placeholder(Placeholder::new(
1035-
id.clone(),
1036-
Some(dt.clone()),
1037-
)),
1038-
Some(_) => expr,
1039-
},
1040-
_ => expr,
1041-
};
1027+
let mut expr = self.sql_to_expr(expr, &table_schema, &mut planner_context)?;
1028+
// Update placeholder's datatype to the type of the target column
1029+
if let datafusion_expr::Expr::Placeholder(placeholder) = &mut expr {
1030+
placeholder.data_type =
1031+
placeholder.data_type.take().or_else(|| Some(dt.clone()));
1032+
}
1033+
// Cast to target column type, if necessary
10421034
let expr = expr.cast_to(dt, source.schema())?.alias(col_name);
10431035
exprs.push(expr);
10441036
}

0 commit comments

Comments
 (0)