-
Notifications
You must be signed in to change notification settings - Fork 3k
API, Core: Move micros and days conversions to DateTimeUtil #6199
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
Conversation
| case DAYS: | ||
| return days; | ||
| default: | ||
| throw new UnsupportedOperationException("Unsupported time unit: " + granularity); |
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.
This block is now similar to toHumanString below.
|
@kbendick @rdblue @RussellSpitzer @szehon-ho @flyrain, could you take a look at this PR? I need to use these conversions in our Spark function catalog. |
| return convertMicros(micros, ChronoUnit.HOURS); | ||
| } | ||
|
|
||
| private static int convertMicros(long micros, ChronoUnit granularity) { |
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.
These conversions are covered by TestDates and TestTimestamps suites.
nastra
left a comment
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.
LGTM, I think it would be good to also move TestDateTimeUtil to api
szehon-ho
left a comment
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.
Yea, would be good to get more eyes on it to double check, but otherwise looks like a clean refactor to me.
|
|
||
| private static int convertMicros(long micros, ChronoUnit granularity) { | ||
| if (micros >= 0) { | ||
| long epochSecond = Math.floorDiv(micros, MICROS_PER_SECOND); |
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.
Nit: am I missing something or can we just pull these out of individual blocks?
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.
I think we can pull only epochSecond so I wasn't sure it was worth it. Let me do that.
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.
I moved that var but it became somehow disconnected from the rest of the logic in each branch. I kept it separate like in the original snippet.
410f187 to
e8b7493
Compare
|
Thanks for reviewing, @nastra @szehon-ho @gaborkaszab! |
While working on time-related functions in the Spark function catalog, I wanted to use
Transform. However, calling transforms on primitive values would require unnecessary boxing. That's why I decided to move relevant conversions toDateTimeUtiland leverage the utility directly. It is in line with what we did for bucketing in PR #5513.