This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new c46f419b4f fix(cast): Trying to fix cast losting schema problem
(#10005)
c46f419b4f is described below
commit c46f419b4f87319637869021d46823abeb33ce1f
Author: mwish <[email protected]>
AuthorDate: Fri May 22 02:17:11 2026 +0800
fix(cast): Trying to fix cast losting schema problem (#10005)
# Which issue does this PR close?
- Closes #10004 .
# Rationale for this change
Previously, just `data_type` is considered. Now the field is taking into
account.
# What changes are included in this PR?
Previously, just `data_type` is considered. Now the field is taking into
account.
# Are these changes tested?
Yes
# Are there any user-facing changes?
Maybe cast would be a bit more strict
---
arrow-cast/src/cast/list.rs | 2 +-
arrow-cast/src/cast/mod.rs | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/arrow-cast/src/cast/list.rs b/arrow-cast/src/cast/list.rs
index 5d7209ee11..591afbea5c 100644
--- a/arrow-cast/src/cast/list.rs
+++ b/arrow-cast/src/cast/list.rs
@@ -102,7 +102,7 @@ fn cast_fixed_size_list_to_list_inner<OffsetSize:
OffsetSizeTrait, const IS_LIST
let DataType::FixedSizeList(inner_field, size) = array.data_type() else {
unreachable!()
};
- let array = if to.data_type() != inner_field.data_type() {
+ let array = if to != inner_field {
// To transform inner type, can first cast to FSL with new inner type.
let fsl_to = DataType::FixedSizeList(to.clone(), *size);
let array = cast_with_options(array, &fsl_to, cast_options)?;
diff --git a/arrow-cast/src/cast/mod.rs b/arrow-cast/src/cast/mod.rs
index e100b22d72..6b4355ae3a 100644
--- a/arrow-cast/src/cast/mod.rs
+++ b/arrow-cast/src/cast/mod.rs
@@ -9038,6 +9038,41 @@ mod tests {
}
}
+ #[test]
+ fn test_cast_fixed_size_list_to_list_preserves_field_metadata() {
+ use std::collections::HashMap;
+
+ let metadata: HashMap<String, String> =
+ HashMap::from([("PARQUET:field_id".to_string(),
"89".to_string())]);
+
+ let src = Arc::new(
+ FixedSizeListArray::from_iter_primitive::<Float32Type, _, _>(
+ [[1.0_f32, 2.0].map(Some), [3.0, 4.0].map(Some)].map(Some),
+ 2,
+ ),
+ ) as ArrayRef;
+
+ let target_field = Arc::new(
+ Field::new("element", DataType::Float32,
true).with_metadata(metadata.clone()),
+ );
+
+ let target_types = [
+ DataType::List(target_field.clone()),
+ DataType::LargeList(target_field.clone()),
+ DataType::ListView(target_field.clone()),
+ DataType::LargeListView(target_field.clone()),
+ ];
+
+ for target_type in &target_types {
+ let result = cast(&src, target_type).unwrap();
+ assert_eq!(
+ result.data_type(),
+ target_type,
+ "Cast to {target_type:?} should preserve field metadata"
+ );
+ }
+ }
+
#[test]
fn test_cast_utf8_to_list() {
// DataType::List