From 7f8c603e1d960ebb4534ca1f3ce84eb60a5bc302 Mon Sep 17 00:00:00 2001 From: comphead Date: Fri, 1 Dec 2023 14:03:30 -0800 Subject: [PATCH] Adding `is_null` datatype shortcut method --- arrow-schema/src/datatype.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arrow-schema/src/datatype.rs b/arrow-schema/src/datatype.rs index b78c785ae279..330ae5c9e346 100644 --- a/arrow-schema/src/datatype.rs +++ b/arrow-schema/src/datatype.rs @@ -350,23 +350,27 @@ impl DataType { } /// Returns true if this type is floating: (Float*). + #[inline] pub fn is_floating(&self) -> bool { use DataType::*; matches!(self, Float16 | Float32 | Float64) } /// Returns true if this type is integer: (Int*, UInt*). + #[inline] pub fn is_integer(&self) -> bool { self.is_signed_integer() || self.is_unsigned_integer() } /// Returns true if this type is signed integer: (Int*). + #[inline] pub fn is_signed_integer(&self) -> bool { use DataType::*; matches!(self, Int8 | Int16 | Int32 | Int64) } /// Returns true if this type is unsigned integer: (UInt*). + #[inline] pub fn is_unsigned_integer(&self) -> bool { use DataType::*; matches!(self, UInt8 | UInt16 | UInt32 | UInt64) @@ -387,6 +391,7 @@ impl DataType { /// Returns true if this type is nested (List, FixedSizeList, LargeList, Struct, Union, /// or Map), or a dictionary of a nested type + #[inline] pub fn is_nested(&self) -> bool { use DataType::*; match self { @@ -398,6 +403,13 @@ impl DataType { } } + /// Returns true if this type is DataType::Null. + #[inline] + pub fn is_null(&self) -> bool { + use DataType::*; + matches!(self, Null) + } + /// Compares the datatype with another, ignoring nested field names /// and metadata. pub fn equals_datatype(&self, other: &DataType) -> bool { @@ -855,6 +867,12 @@ mod tests { assert!(!DataType::is_floating(&DataType::Int32)); } + #[test] + fn test_datatype_is_null() { + assert!(DataType::is_null(&DataType::Null)); + assert!(!DataType::is_null(&DataType::Int32)); + } + #[test] fn size_should_not_regress() { assert_eq!(std::mem::size_of::(), 24);