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

Support casting to/from Interval and Duration #3998

Closed
Tracked by #3958
alamb opened this issue Apr 1, 2023 · 3 comments · Fixed by #4020
Closed
Tracked by #3958

Support casting to/from Interval and Duration #3998

alamb opened this issue Apr 1, 2023 · 3 comments · Fixed by #4020
Labels
arrow Changes to the arrow crate good first issue Good for newcomers help wanted

Comments

@alamb
Copy link
Contributor

alamb commented Apr 1, 2023

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
In DataFusion we are trying to add complete date/time support . IN addition to Interval types some of this arithmetic will also likely result in Durations (e.g. timestamp - timestamp -- see #3964)

DataType::Duration(TimeUnit::Second)
DataType::Duration(TimeUnit::Millisecond)
DataType::Duration(TimeUnit::Microsecond)
DataType::Duration(TimeUnit::NanoSecond)
DataType::Interval(IntervalUnit::YearMonth)
DataType::Interval(IntervalUnit::DayTime)
DataType::Interval(IntervalUnit::MonthDayNano)

However, there is no easy way currently to convert between Durations and Intervals

Describe the solution you'd like
Add support for casting durations to intervals to the cast kernel : https://github.com/apache/arrow-rs/blob/master/arrow-cast/src/cast.rs#L18-L36

The following casts should be always supported as they are lossless (DataType::Interval(IntervalUnit::MonthDayNano) has nanosecond precision)

  • DataType::Duration(TimeUnit::Second) <--> DataType::Interval(IntervalUnit::MonthDayNano)
  • DataType::Duration(TimeUnit::Millisecond) <--> DataType::Interval(IntervalUnit::MonthDayNano)
  • DataType::Duration(TimeUnit::Microsecond) <--> DataType::Interval(IntervalUnit::MonthDayNano)
  • DataType::Duration(TimeUnit::NanoSecond) <--> DataType::Interval(IntervalUnit::MonthDayNano)

I am not sure what other, if any, casts should be supported

Describe alternatives you've considered

Additional context

@tustvold
Copy link
Contributor

tustvold commented Apr 1, 2023

as they are lossless

TBC, the duration should be converted into the nanoseconds portion of MonthDayNano, returning an error or null (depending on CastOptions::safe) in the event of overflow.

As a result of daylight savings time, it would be incorrect to assume a day has 24 hours.

I am not sure what other, if any, casts should be supported

Truncating casts to MonthDayTime might also be worthwhile

@Weijun-H
Copy link
Member

Weijun-H commented Apr 4, 2023

I am glad to pick this up.

@tustvold tustvold added the arrow Changes to the arrow crate label Apr 21, 2023
@tustvold
Copy link
Contributor

label_issue.py automatically added labels {'arrow'} from #4020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate good first issue Good for newcomers help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants