izveigor commented on code in PR #4182:
URL: https://github.com/apache/arrow-rs/pull/4182#discussion_r1210788541
##########
arrow-cast/src/cast.rs:
##########
@@ -409,6 +413,125 @@ where
}
}
+/// Cast the array from interval year month to month day nano
+fn cast_interval_year_month_to_interval_month_day_nano(
+ array: &dyn Array,
+ cast_options: &CastOptions,
+) -> Result<ArrayRef, ArrowError> {
+ let array = array.as_primitive::<IntervalYearMonthType>();
+
+ if cast_options.safe {
+ Ok(Arc::new(array.unary_opt::<_, IntervalMonthDayNanoType>(
+ |v| {
+ let months = IntervalYearMonthType::to_months(v);
+ Some(IntervalMonthDayNanoType::make_value(months, 0, 0))
+ },
+ )))
+ } else {
+ Ok(Arc::new(
+ array.try_unary::<_, IntervalMonthDayNanoType, ArrowError>(|v| {
+ let months = IntervalYearMonthType::to_months(v);
+ Ok(IntervalMonthDayNanoType::make_value(months, 0, 0))
+ })?,
+ ))
+ }
+}
+
+/// Cast the array from interval day time to month day nano
+fn cast_interval_day_time_to_interval_month_day_nano(
+ array: &dyn Array,
+ cast_options: &CastOptions,
+) -> Result<ArrayRef, ArrowError> {
+ let array = array.as_primitive::<IntervalDayTimeType>();
+ let mul = 10_i32.pow(6);
+
+ if cast_options.safe {
+ Ok(Arc::new(array.unary_opt::<_, IntervalMonthDayNanoType>(
+ |v| {
+ let (days, ms) = IntervalDayTimeType::to_parts(v);
+ Some(IntervalMonthDayNanoType::make_value(
+ 0,
Review Comment:
I think the method: `months = days * 30` is not entirely accurate?
--
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]