diff --git a/arrow-schema/src/datatype.rs b/arrow-schema/src/datatype.rs index 5c9073c4eeb6..4c7b9baf3d11 100644 --- a/arrow-schema/src/datatype.rs +++ b/arrow-schema/src/datatype.rs @@ -596,6 +596,13 @@ impl DataType { matches!(self, Null) } + /// Returns true if this type is a String type + #[inline] + pub fn is_string(&self) -> bool { + use DataType::*; + matches!(self, Utf8 | LargeUtf8 | Utf8View) + } + /// Compares the datatype with another, ignoring nested field names /// and metadata. pub fn equals_datatype(&self, other: &DataType) -> bool { @@ -1085,6 +1092,14 @@ mod tests { assert!(!DataType::is_dictionary_key_type(&DataType::Float16)); } + #[test] + fn test_string() { + assert!(DataType::is_string(&DataType::Utf8)); + assert!(DataType::is_string(&DataType::LargeUtf8)); + assert!(DataType::is_string(&DataType::Utf8View)); + assert!(!DataType::is_string(&DataType::Int32)); + } + #[test] fn test_floating() { assert!(DataType::is_floating(&DataType::Float16));