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


##########
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:
   I slightly updated the comment. What I meant is that we set the data type to 
UTF8 so that try_cast can return NULL if the value cannot be converted to the 
required type. If we try to assign the required type to the placeholder right 
away, the call will fail with an error instead of returning NULL.



-- 
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