bjchambers commented on issue #527:
URL: https://github.com/apache/arrow-rs/issues/527#issuecomment-885250399
I don't think that entirely works for two reasons -- first, there are
actually multiple `Duration` types (in Rust) for the same `DataType`. Second,
the delta may also be an interval. Specifically, it needs to be constrained in
a way that supports the following arrays:
* `PrimitiveArray<DurationSecondType>` - add a fixed number of seconds
* `PrimitiveArray<DurationMicrosecondType>` - add a fixed number of
microseconds
* `PrimitiveArray<DurationMillisecondType>` - add a fixed number of
milliseconds
* `PrimitiveArray<DurationNanosecondType>` - add a fixed number of
nanoseconds
* `PrimitiveArray<IntervalDayTimeType>` - add a number of calendar days (and
seconds) (description says this is a pair of i32 packed into an i64)
* `PrimitiveArray<IntervalYearMonthType>` - add a number of calendar months
From an implementation, I think we can do this using `chrono` and
`chronoutil`. Something like:
```
pub trait ArrowTimeDelta: ArrowPrimitiveType {
fn add_to(time: NaiveDateTime, value: Self::Native) -> NaiveDateTime;
}
impl ArrowTimeDelta<RelativeDuration> for IntervalDayTimeType {
fn get_delta(value: Self::Native) -> RelativeDuration {
// DayTime is represented as a 64 bit value -- 32 bit day and 32 bit
seconds.
let days = RelativeDuration::days(value >> 32);
let seconds = RelativeDuration::seconds((value as i32) as i64);
days + seconds
}
}
impl ArrowTimeDelta for IntervalYearMonthType {
fn add_to(time: NaiveDateTime, value: Self::Native) -> NaiveDateTime {
// YearMonth is represented as a 32 bit value containing the number
of months.
time + RelativeDuration::months(value)
}
}
impl ArrowTimeDelta for DurationSecondType {
fn add_to(time: NaiveDateTime, value: Self::Native) -> NaiveDateTime {
time + Duration::seconds(value)
}
}
impl ArrowTimeDelta for DurationMillisecondType {
fn add_to(time: NaiveDateTime, value: Self::Native) -> NaiveDateTime {
time + Duration::milliseconds(value)
}
}
impl ArrowTimeDelta for DurationMicrosecondType {
fn add_to(time: NaiveDateTime, value: Self::Native) -> NaiveDateTime {
time + Duration::microseconds(value)
}
}
impl ArrowTimeDelta for DurationNanosecondType {
fn add_to(time: NaiveDateTime, value: Self::Native) -> NaiveDateTime {
time + Duration::nanoseconds(value)
}
}
```
Then the implementation is basically iterating over a pair of arrays and
callling `add_to`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]