You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tustvold (via GitHub)" <gi...@apache.org> on 2023/06/01 11:30:59 UTC

[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4182: feat: cast between `Intervals`

tustvold commented on code in PR #4182:
URL: https://github.com/apache/arrow-rs/pull/4182#discussion_r1213012070


##########
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| {

Review Comment:
   If the method is infallible you can just use `unary`



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org