gene-bordegaray commented on code in PR #24670:
URL: https://github.com/apache/datafusion/pull/24670#discussion_r3899536784


##########
datafusion/expr/src/expr_schema.rs:
##########
@@ -71,18 +71,23 @@ pub trait ExprSchemable {
     -> Result<(DataType, bool)>;
 }
 
-/// Derives the output field for a cast expression from the source field.
+/// Derives the output field for a cast expression from the source field, using
+/// explicit target metadata when supplied.
 /// For `TryCast`, `force_nullable` is `true` since a failed cast returns NULL.
 fn cast_output_field(
     source_field: &FieldRef,
-    target_type: &DataType,
+    target: &CastTarget,
     force_nullable: bool,
 ) -> Arc<Field> {
+    let metadata = target
+        .metadata()
+        .cloned()
+        .unwrap_or_else(|| source_field.metadata().clone());
     let mut f = source_field
         .as_ref()
         .clone()
-        .with_data_type(target_type.clone())
-        .with_metadata(source_field.metadata().clone());
+        .with_data_type(target.data_type().clone())
+        .with_metadata(metadata);

Review Comment:
   yes sorry about the confusion I should've temporarily made this a draft, the 
diff for this PR is much smaller. Allthat the `CastTarget` and protobuf changes 
are mixed into this PR because I had stacked it on #24725 but they shouldn’t be 
reviewed as part of the projection optimizer fix. I’m going to rebase this onto 
#23169 after some discussion to go with that approach for the minor relese.
   
   as far as this particular comment. I originally thought this too and 
@gabotechs also asked about 
[this](https://github.com/apache/datafusion/pull/24670#discussion_r3865163140), 
its a subtle one. Let me know if that clarifies 👍 



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