alamb commented on code in PR #4020:
URL: https://github.com/apache/arrow-rs/pull/4020#discussion_r1167251885


##########
arrow-cast/src/cast.rs:
##########
@@ -8246,4 +8385,137 @@ mod tests {
         );
         assert_eq!("Invalid argument error: 1234567000 is too large to store 
in a Decimal256 of precision 7. Max is 9999999", err.unwrap_err().to_string());
     }
+
+    #[test]
+    fn test_cast_from_duration_to_interval() {
+        // from duration second to interval month day nano
+        let array = vec![1234567];
+        let array = DurationSecondArray::from(array);
+        let array = Arc::new(array) as ArrayRef;
+        let casted_array =
+            cast(&array, 
&DataType::Interval(IntervalUnit::MonthDayNano)).unwrap();
+        let casted_array = casted_array
+            .as_any()
+            .downcast_ref::<IntervalMonthDayNanoArray>()
+            .unwrap();
+        assert_eq!(
+            casted_array.data_type(),
+            &DataType::Interval(IntervalUnit::MonthDayNano)
+        );
+        assert_eq!(casted_array.value(0), 1234567000000000);
+
+        // from duration millisecond to interval month day nano
+        let array = vec![1234567];
+        let array = DurationMillisecondArray::from(array);
+        let array = Arc::new(array) as ArrayRef;
+        let casted_array =
+            cast(&array, 
&DataType::Interval(IntervalUnit::MonthDayNano)).unwrap();
+        let casted_array = casted_array
+            .as_any()
+            .downcast_ref::<IntervalMonthDayNanoArray>()
+            .unwrap();
+        assert_eq!(
+            casted_array.data_type(),
+            &DataType::Interval(IntervalUnit::MonthDayNano)
+        );
+        assert_eq!(casted_array.value(0), 1234567000000);
+
+        // from duration microsecond to interval month day nano
+        let array = vec![1234567];
+        let array = DurationMicrosecondArray::from(array);
+        let array = Arc::new(array) as ArrayRef;
+        let casted_array =
+            cast(&array, 
&DataType::Interval(IntervalUnit::MonthDayNano)).unwrap();
+        let casted_array = casted_array
+            .as_any()
+            .downcast_ref::<IntervalMonthDayNanoArray>()
+            .unwrap();
+        assert_eq!(
+            casted_array.data_type(),
+            &DataType::Interval(IntervalUnit::MonthDayNano)
+        );
+        assert_eq!(casted_array.value(0), 1234567000);
+
+        // from duration nanosecond to interval month day nano
+        let array = vec![1234567];
+        let array = DurationNanosecondArray::from(array);
+        let array = Arc::new(array) as ArrayRef;
+        let casted_array =
+            cast(&array, 
&DataType::Interval(IntervalUnit::MonthDayNano)).unwrap();
+        let casted_array = casted_array
+            .as_any()
+            .downcast_ref::<IntervalMonthDayNanoArray>()
+            .unwrap();
+        assert_eq!(
+            casted_array.data_type(),
+            &DataType::Interval(IntervalUnit::MonthDayNano)
+        );
+        assert_eq!(casted_array.value(0), 1234567);
+    }
+
+    #[test]
+    fn test_cast_from_interval_to_duration() {
+        // from interval month day nano to duration second
+        let array = vec![1234567];
+        let array = IntervalMonthDayNanoArray::from(array);
+        let array = Arc::new(array) as ArrayRef;
+        let casted_array = cast(&array, 
&DataType::Duration(TimeUnit::Second)).unwrap();
+        let casted_array = casted_array
+            .as_any()
+            .downcast_ref::<DurationSecondArray>()
+            .unwrap();
+
+        assert_eq!(
+            casted_array.data_type(),
+            &DataType::Duration(TimeUnit::Second)
+        );
+        assert_eq!(casted_array.value(0), 0);
+
+        // from interval month day nano to duration millisecond
+        let array = vec![1234567];

Review Comment:
   You could probably refactor this repetition into a function and avoid so 
much boiler plate in the tests



-- 
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]

Reply via email to