-
Notifications
You must be signed in to change notification settings - Fork 796
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
Enhance Time32/Time64 support in date_part #5337
Enhance Time32/Time64 support in date_part #5337
Conversation
arrow-arith/src/temporal.rs
Outdated
DatePart::Hour => Ok(self.unary_opt(|ns| { | ||
if (0..NANOSECONDS_IN_DAY).contains(&ns) { | ||
Some((ns / 3_600 / NANOSECONDS) as i32) | ||
} else { | ||
None | ||
} | ||
})), | ||
DatePart::Minute => Ok(self.unary_opt(|ns| { | ||
if (0..NANOSECONDS_IN_DAY).contains(&ns) { | ||
Some(((ns / 60 / NANOSECONDS) % 60) as i32) | ||
} else { | ||
None | ||
} | ||
})), | ||
DatePart::Second => Ok(self.unary_opt(|ns| { | ||
if (0..NANOSECONDS_IN_DAY).contains(&ns) { | ||
Some(((ns / NANOSECONDS) % 60) as i32) | ||
} else { | ||
None | ||
} | ||
})), | ||
DatePart::Millisecond => Ok(self.unary_opt(|ns| { | ||
if (0..NANOSECONDS_IN_DAY).contains(&ns) { | ||
Some(((ns % NANOSECONDS) / 1_000_000) as i32) | ||
} else { | ||
None | ||
} | ||
})), | ||
DatePart::Microsecond => Ok(self.unary_opt(|ns| { | ||
if (0..NANOSECONDS_IN_DAY).contains(&ns) { | ||
Some(((ns % NANOSECONDS) / 1_000) as i32) | ||
} else { | ||
None | ||
} | ||
})), | ||
DatePart::Nanosecond => Ok(self.unary_opt(|ns| { | ||
if (0..NANOSECONDS_IN_DAY).contains(&ns) { | ||
Some((ns % NANOSECONDS) as i32) | ||
} else { | ||
None | ||
} | ||
})), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Hour/Minute/Second arms could be deduplicated as they almost identical across seconds/milli/micro/nano, but the handling of milli/micro/nano isn't as straight forward I guess. Though could be handled with a macro I suppose? Let me know if prefer to try reduce this duplication or if it's fine as is
arrow-arith/src/temporal.rs
Outdated
DatePart::Hour => Ok(self.unary_opt(|d| time32s_to_time(d).map(|c| c.hour() as i32))), | ||
// TODO expand support for Time types, see: https://github.com/apache/arrow-rs/issues/5261 | ||
DatePart::Hour => Ok(self.unary_opt(|s| { | ||
if (0..SECONDS_IN_DAY as i32).contains(&s) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Option::then might make this more concise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried applying some refactoring as suggested. Clippy does push for use of Option::then_some
so I wonder if its better to use that (even though it eagerly evaluates) or to try force usage of Option::then
🤔
Which issue does this PR close?
Closes #5261
Rationale for this change
Want to be able to extract hour/minute/second/etc. from Time32/Time64 types via
date_part
temporal kernelWhat changes are included in this PR?
Enhance Time32/Time64 support in
date_part
Are there any user-facing changes?