cyberbeam524 commented on code in PR #21714:
URL: https://github.com/apache/datafusion/pull/21714#discussion_r3214652919


##########
datafusion/sql/src/statement.rs:
##########
@@ -530,11 +531,18 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
                                 .iter()
                                 .zip(input_fields)
                                 .map(|(field, input_field)| {
-                                    cast(
-                                        col(input_field.name()),
-                                        field.data_type().clone(),
-                                    )
-                                    .alias(field.name())
+                                    let metadata =
+                                        
FieldMetadata::new_from_field(field.as_ref());
+                                    let alias_metadata = if 
metadata.is_empty() {
+                                        None
+                                    } else {
+                                        Some(metadata)
+                                    };
+                                    Expr::Cast(Cast::new_from_field(
+                                        Box::new(col(input_field.name())),
+                                        Arc::clone(field),
+                                    ))
+                                    .alias_with_metadata(field.name(), 
alias_metadata)

Review Comment:
   I’ve refactored this logic to address this metadata propagation concern. The 
code now does a gated validation strategy based on checks on whether its an 
extension type:
   - For existing non-extensions types, it uses simple aliases or cast_to 
calls, ensuring no new metadata is introduced and allows regression tests to 
pass.
   - For extension types, it uses check_metadata_with_storage_equal to verify 
compatibility.
   - If a conversion is necessary, it uses Cast::new_from_field(). This ensures 
the resulting expression strictly adheres to the target field's metadata, 
sanitizing the output and preventing unexpected propagation from the input.



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