Skip to content

Commit ca49a25

Browse files
committed
chore: Add a test for metadata
1 parent 586236d commit ca49a25

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

arrow-schema/src/datatype_display.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,5 +282,25 @@ mod tests {
282282
let union_data_type_string = union_data_type.to_string();
283283
let expected_string = "Union(Sparse, 0: Int32, 1: nullable Utf8)";
284284
assert_eq!(union_data_type_string, expected_string);
285+
286+
// Test with metadata
287+
let mut field_with_metadata = Field::new("b", DataType::Utf8, true);
288+
let metadata = HashMap::from([("key".to_string(), "value".to_string())]);
289+
field_with_metadata.set_metadata(metadata);
290+
let union_fields_with_metadata = vec![
291+
(0, Arc::new(Field::new("a", DataType::Int32, false))),
292+
(1, Arc::new(field_with_metadata)),
293+
]
294+
.into_iter()
295+
.collect();
296+
let union_data_type_with_metadata =
297+
DataType::Union(union_fields_with_metadata, crate::UnionMode::Sparse);
298+
let union_data_type_with_metadata_string = union_data_type_with_metadata.to_string();
299+
let expected_string_with_metadata =
300+
"Union(Sparse, 0: Int32, 1: nullable Utf8, metadata: {\"key\": \"value\"})";
301+
assert_eq!(
302+
union_data_type_with_metadata_string,
303+
expected_string_with_metadata
304+
);
285305
}
286306
}

0 commit comments

Comments
 (0)