Jefffrey commented on code in PR #20169:
URL: https://github.com/apache/datafusion/pull/20169#discussion_r3121112337


##########
datafusion/physical-expr/src/planner.rs:
##########
@@ -288,16 +288,28 @@ pub fn create_physical_expr(
                 };
             Ok(expressions::case(expr, when_then_expr, else_expr)?)
         }
-        Expr::Cast(Cast { expr, data_type }) => expressions::cast(
-            create_physical_expr(expr, input_dfschema, execution_props)?,
-            input_schema,
-            data_type.clone(),
-        ),
-        Expr::TryCast(TryCast { expr, data_type }) => expressions::try_cast(
-            create_physical_expr(expr, input_dfschema, execution_props)?,
-            input_schema,
-            data_type.clone(),
-        ),
+        Expr::Cast(Cast { expr, data_type }) => {
+            let mut expr = create_physical_expr(expr, input_dfschema, 
execution_props)?;
+            if let Some(placeholder) = 
expr.as_any().downcast_ref::<PlaceholderExpr>()
+                && placeholder.field.is_none()
+            {
+                expr = expressions::placeholder(&placeholder.id, 
data_type.clone());

Review Comment:
   I do wonder what will happen if we then replace the placeholder with a value 
of type that can't be casted; just a regular execution error? 🤔 



##########
datafusion/physical-expr/src/planner.rs:
##########
@@ -288,16 +288,28 @@ pub fn create_physical_expr(
                 };
             Ok(expressions::case(expr, when_then_expr, else_expr)?)
         }
-        Expr::Cast(Cast { expr, data_type }) => expressions::cast(
-            create_physical_expr(expr, input_dfschema, execution_props)?,
-            input_schema,
-            data_type.clone(),
-        ),
-        Expr::TryCast(TryCast { expr, data_type }) => expressions::try_cast(
-            create_physical_expr(expr, input_dfschema, execution_props)?,
-            input_schema,
-            data_type.clone(),
-        ),
+        Expr::Cast(Cast { expr, data_type }) => {
+            let mut expr = create_physical_expr(expr, input_dfschema, 
execution_props)?;
+            if let Some(placeholder) = 
expr.as_any().downcast_ref::<PlaceholderExpr>()
+                && placeholder.field.is_none()
+            {
+                expr = expressions::placeholder(&placeholder.id, 
data_type.clone());
+            }
+
+            expressions::cast(expr, input_schema, data_type.clone())
+        }
+        Expr::TryCast(TryCast { expr, data_type }) => {
+            let mut expr = create_physical_expr(expr, input_dfschema, 
execution_props)?;
+            if let Some(placeholder) = 
expr.as_any().downcast_ref::<PlaceholderExpr>()
+                && placeholder.field.is_none()
+            {
+                // To maintain try_cast behavior, we initially resolve the 
placeholder with the

Review Comment:
   Would it make more sense here to use `DataType::Null` instead of 
`DataType::Utf8` then?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to