yordan-pavlov commented on a change in pull request #8794:
URL: https://github.com/apache/arrow/pull/8794#discussion_r533701070



##########
File path: rust/arrow/src/compute/kernels/cast.rs
##########
@@ -2720,6 +2743,42 @@ mod tests {
             .collect()
     }
 
+    #[test]
+    fn test_cast_utf8_to_date32() {
+        use chrono::{NaiveDate, NaiveTime};
+
+        let a = StringArray::from(vec![
+            "2000-01-01",
+            "2000-2-2",
+            "2000-00-00",
+            "2000-01-01T12:00:00",
+            "2000",
+        ]);
+        let array = Arc::new(a) as ArrayRef;
+        let b = cast(&array, &DataType::Date32(DateUnit::Day)).unwrap();
+        let c = b.as_any().downcast_ref::<Date32Array>().unwrap();
+
+        let zero_time = NaiveTime::from_hms(0, 0, 0);
+
+        let date_value = (NaiveDate::from_ymd(2000, 1, 1)
+            .and_time(zero_time)
+            .timestamp()
+            / SECONDS_IN_DAY) as i32;
+        assert_eq!(true, c.is_valid(0));
+        assert_eq!(date_value, c.value(0));
+
+        let date_value = (NaiveDate::from_ymd(2000, 2, 2)
+            .and_time(zero_time)
+            .timestamp()
+            / SECONDS_IN_DAY) as i32;
+        assert_eq!(true, c.is_valid(1));
+        assert_eq!(date_value, c.value(1));
+
+        assert_eq!(false, c.is_valid(2));
+        assert_eq!(false, c.is_valid(3));
+        assert_eq!(false, c.is_valid(4));

Review comment:
       I have added some more comments to make the test easier to read




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to