Skip to content

Commit

Permalink
feat: impl display for DataType::List
Browse files Browse the repository at this point in the history
  • Loading branch information
irenjj committed Jan 31, 2025
1 parent 3bf29a2 commit 94d5365
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion arrow-schema/src/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,13 @@ pub enum UnionMode {

impl fmt::Display for DataType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{self:?}")
match self {
DataType::List(field) => {
let nullstr = if field.is_nullable() { "Y" } else { "N" };
write!(f, "List({};{})", field.data_type(), nullstr)
}
_ => write!(f, "{self:?}"),
}
}
}

Expand Down Expand Up @@ -1129,4 +1135,18 @@ mod tests {
let data_type: DataType = "UInt64".parse().unwrap();
assert_eq!(data_type, DataType::UInt64);
}

#[test]
fn test_display_list() {
let list_data_type = DataType::List(Arc::new(Field::new_list_field(DataType::Int32, true)));
let list_data_type_string = list_data_type.to_string();
let expected_string = "List(Int32;Y)";
assert_eq!(list_data_type_string, expected_string);

let list_data_type =
DataType::List(Arc::new(Field::new_list_field(DataType::UInt64, false)));
let list_data_type_string = list_data_type.to_string();
let expected_string = "List(UInt64;N)";
assert_eq!(list_data_type_string, expected_string);
}
}

0 comments on commit 94d5365

Please sign in to comment.