Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Decimal128, Decimal256, Float16 to DataType::is_numeric #3121

Merged
merged 1 commit into from Nov 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 9 additions & 21 deletions arrow-schema/src/datatype.rs
Expand Up @@ -263,30 +263,13 @@ impl fmt::Display for DataType {

impl DataType {
/// Returns true if the type is primitive: (numeric, temporal).
#[inline]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also took the opportunity to add #[inline] so that these inline correctly across crate boundaries - which will help with eliding redundant checks

pub fn is_primitive(t: &DataType) -> bool {
use DataType::*;
matches!(
t,
Int8 | Int16
| Int32
| Int64
| UInt8
| UInt16
| UInt32
| UInt64
| Float32
| Float64
| Date32
| Date64
| Time32(_)
| Time64(_)
| Timestamp(_, _)
| Interval(_)
| Duration(_)
)
Self::is_numeric(t) || Self::is_temporal(t)
}

/// Returns true if this type is numeric: (UInt*, Int*, or Float*).
/// Returns true if this type is numeric: (UInt*, Int*, Float*, Decimal*).
#[inline]
pub fn is_numeric(t: &DataType) -> bool {
use DataType::*;
matches!(
Expand All @@ -299,12 +282,16 @@ impl DataType {
| Int16
| Int32
| Int64
| Float16
| Float32
| Float64
| Decimal128(_, _)
| Decimal256(_, _)
)
}

/// Returns true if this type is temporal: (Date*, Time*, Duration, or Interval).
#[inline]
pub fn is_temporal(t: &DataType) -> bool {
use DataType::*;
matches!(
Expand All @@ -320,6 +307,7 @@ impl DataType {
}

/// Returns true if this type is valid as a dictionary key
#[inline]
pub fn is_dictionary_key_type(t: &DataType) -> bool {
use DataType::*;
matches!(
Expand Down