Skip to content

Commit 586236d

Browse files
committed
test: add display test for Union data type
1 parent 9b64973 commit 586236d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

arrow-schema/src/datatype_display.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ impl fmt::Display for DataType {
166166
}
167167
}
168168

169-
170169
#[cfg(test)]
171170
mod tests {
172171

@@ -266,4 +265,22 @@ mod tests {
266265
"FixedSizeList(4 x nullable Int32, metadata: {\"key2\": \"value2\"})";
267266
assert_eq!(fixed_size_metadata_string, expected_metadata_string);
268267
}
268+
269+
#[test]
270+
fn test_display_union() {
271+
let fields = vec![
272+
Field::new("a", DataType::Int32, false),
273+
Field::new("b", DataType::Utf8, true),
274+
];
275+
let type_ids = vec![0, 1];
276+
let union_fields = type_ids
277+
.into_iter()
278+
.zip(fields.into_iter().map(Arc::new))
279+
.collect();
280+
281+
let union_data_type = DataType::Union(union_fields, crate::UnionMode::Sparse);
282+
let union_data_type_string = union_data_type.to_string();
283+
let expected_string = "Union(Sparse, 0: Int32, 1: nullable Utf8)";
284+
assert_eq!(union_data_type_string, expected_string);
285+
}
269286
}

0 commit comments

Comments
 (0)