Enhance Time32/Time64 support in date_part#5337
Merged
tustvold merged 2 commits intoapache:masterfrom Jan 31, 2024
Merged
Conversation
Jefffrey
commented
Jan 27, 2024
arrow-arith/src/temporal.rs
Outdated
Comment on lines
323
to
364
| 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 | ||
| } | ||
| })), |
Contributor
Author
There was a problem hiding this comment.
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
tustvold
approved these changes
Jan 30, 2024
tustvold
reviewed
Jan 30, 2024
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) { |
Contributor
There was a problem hiding this comment.
Using Option::then might make this more concise
Contributor
Author
There was a problem hiding this comment.
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 🤔
tustvold
approved these changes
Jan 30, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_parttemporal kernelWhat changes are included in this PR?
Enhance Time32/Time64 support in
date_partAre there any user-facing changes?