This is an automated email from the ASF dual-hosted git repository.
jeffreyvo 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 bfd31ccf16 add `DataType::is_string` (#7429)
bfd31ccf16 is described below
commit bfd31ccf16db7baaaa732e4b6e7f0e98ae9cd589
Author: Adrian Garcia Badaracco <[email protected]>
AuthorDate: Fri Dec 26 08:41:38 2025 -0600
add `DataType::is_string` (#7429)
Part of
- #5163
---------
Co-authored-by: Berkay Şahin
<[email protected]>
Co-authored-by: Jeffrey Vo <[email protected]>
---
arrow-schema/src/datatype.rs | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/arrow-schema/src/datatype.rs b/arrow-schema/src/datatype.rs
index 79e78830be..e3f67e6ac0 100644
--- a/arrow-schema/src/datatype.rs
+++ b/arrow-schema/src/datatype.rs
@@ -631,6 +631,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 {
@@ -1147,6 +1154,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));