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


##########
arrow-cast/src/cast.rs:
##########
@@ -9172,4 +9172,46 @@ mod tests {
         );
         assert!(casted_array.is_err());
     }
+
+    #[test]
+    fn test_cast_below_unixtimestamp() {
+        let valid = StringArray::from(vec![
+            "1900-01-03 23:59:59",
+            "1969-12-31 00:00:01",
+            "1989-12-31 00:00:01",
+        ]);
+
+        let array = Arc::new(valid) as ArrayRef;
+        let casted_array = cast_with_options(
+            &array,
+            &DataType::Timestamp(TimeUnit::Nanosecond, Some("+00:00".into())),
+            &CastOptions {
+                safe: false,
+                format_options: FormatOptions::default(),
+            },
+        )
+        .unwrap();
+
+        let ts_array = casted_array
+            .as_any()
+            .downcast_ref::<TimestampNanosecondArray>()
+            .unwrap();
+
+        let ts_array = ts_array
+            .values()
+            .iter()
+            .map(|ts| Some(ts / 1_000_000))
+            .collect::<Vec<_>>();
+        let array =
+            
TimestampMillisecondArray::from(ts_array).with_timezone("UTC".to_string());
+
+        let casted_array = cast(&array, &DataType::Date32).unwrap();
+        let date_array = 
casted_array.as_any().downcast_ref::<Date32Array>().unwrap();

Review Comment:
   ```suggestion
           let date_array = casted_array.as_primitive::<Date32Type>();
   ```



##########
arrow-cast/src/cast.rs:
##########
@@ -9172,4 +9172,46 @@ mod tests {
         );
         assert!(casted_array.is_err());
     }
+
+    #[test]
+    fn test_cast_below_unixtimestamp() {
+        let valid = StringArray::from(vec![
+            "1900-01-03 23:59:59",
+            "1969-12-31 00:00:01",
+            "1989-12-31 00:00:01",
+        ]);
+
+        let array = Arc::new(valid) as ArrayRef;
+        let casted_array = cast_with_options(
+            &array,
+            &DataType::Timestamp(TimeUnit::Nanosecond, Some("+00:00".into())),
+            &CastOptions {
+                safe: false,
+                format_options: FormatOptions::default(),
+            },
+        )
+        .unwrap();
+
+        let ts_array = casted_array
+            .as_any()
+            .downcast_ref::<TimestampNanosecondArray>()
+            .unwrap();
+
+        let ts_array = ts_array
+            .values()
+            .iter()
+            .map(|ts| Some(ts / 1_000_000))
+            .collect::<Vec<_>>();
+        let array =
+            
TimestampMillisecondArray::from(ts_array).with_timezone("UTC".to_string());
+
+        let casted_array = cast(&array, &DataType::Date32).unwrap();
+        let date_array = 
casted_array.as_any().downcast_ref::<Date32Array>().unwrap();
+
+        let casted_array = cast(&date_array, &DataType::Utf8).unwrap();
+        let string_array = 
casted_array.as_any().downcast_ref::<StringArray>().unwrap();

Review Comment:
   ```suggestion
           let string_array = casted_array.as_string::<i32>();
   ```



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