jayzhan211 commented on PR #13305:
URL: https://github.com/apache/datafusion/pull/13305#issuecomment-2464207671
@sydduckworth Do you remember why `cast should drop input metadata since the
type has changed`
```rust
#[test]
fn test_expr_metadata() {
let mut meta = HashMap::new();
meta.insert("bar".to_string(), "buzz".to_string());
let expr = col("foo");
let schema = MockExprSchema::new()
.with_data_type(DataType::Int32)
.with_metadata(meta.clone());
// col and alias should be metadata-preserving
assert_eq!(meta, expr.metadata(&schema).unwrap());
assert_eq!(meta,
expr.clone().alias("bar").metadata(&schema).unwrap());
// cast should drop input metadata since the type has changed
assert_eq!(
HashMap::new(),
expr.clone()
.cast_to(&DataType::Int64, &schema)
.unwrap()
.metadata(&schema)
.unwrap()
);
let schema = DFSchema::from_unqualified_fields(
vec![Field::new("foo", DataType::Int32,
true).with_metadata(meta.clone())]
.into(),
HashMap::new(),
)
.unwrap();
// verify to_field method populates metadata
assert_eq!(&meta, expr.to_field(&schema).unwrap().1.metadata());
}
```
--
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]