This is an automated email from the ASF dual-hosted git repository.

agrove pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new b02fe5bbd7 Minor: simplify update code (#7943)
b02fe5bbd7 is described below

commit b02fe5bbd7854bf186c54c542b80ab75ac323c38
Author: Andrew Lamb <[email protected]>
AuthorDate: Sat Oct 28 11:40:34 2023 -0400

    Minor: simplify update code (#7943)
---
 datafusion/sql/src/statement.rs | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/datafusion/sql/src/statement.rs b/datafusion/sql/src/statement.rs
index b5196c0866..80a27db6e6 100644
--- a/datafusion/sql/src/statement.rs
+++ b/datafusion/sql/src/statement.rs
@@ -36,7 +36,6 @@ use datafusion_common::{
     Result, SchemaReference, TableReference, ToDFSchema,
 };
 use datafusion_expr::dml::{CopyOptions, CopyTo};
-use datafusion_expr::expr::Placeholder;
 use 
datafusion_expr::expr_rewriter::normalize_col_with_schemas_and_ambiguity_check;
 use datafusion_expr::logical_plan::builder::project;
 use datafusion_expr::logical_plan::DdlStatement;
@@ -1025,20 +1024,13 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
         // Projection
         let mut exprs = vec![];
         for (col_name, expr, dt) in values_and_types.into_iter() {
-            let expr = self.sql_to_expr(expr, &table_schema, &mut 
planner_context)?;
-            let expr = match expr {
-                datafusion_expr::Expr::Placeholder(Placeholder {
-                    ref id,
-                    ref data_type,
-                }) => match data_type {
-                    None => 
datafusion_expr::Expr::Placeholder(Placeholder::new(
-                        id.clone(),
-                        Some(dt.clone()),
-                    )),
-                    Some(_) => expr,
-                },
-                _ => expr,
-            };
+            let mut expr = self.sql_to_expr(expr, &table_schema, &mut 
planner_context)?;
+            // Update placeholder's datatype to the type of the target column
+            if let datafusion_expr::Expr::Placeholder(placeholder) = &mut expr 
{
+                placeholder.data_type =
+                    placeholder.data_type.take().or_else(|| Some(dt.clone()));
+            }
+            // Cast to target column type, if necessary
             let expr = expr.cast_to(dt, source.schema())?.alias(col_name);
             exprs.push(expr);
         }

Reply via email to