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


##########
arrow-csv/src/writer.rs:
##########
@@ -88,6 +88,35 @@ where
     lexical_to_string(c.value(i))
 }
 
+fn invalid_cast_error(dt: String, col_index: usize, row_index: usize) -> 
ArrowError {
+    let mut s = String::new();

Review Comment:
   format! might be a nicer way to write this, should also perform better



##########
arrow-csv/src/writer.rs:
##########
@@ -88,6 +88,35 @@ where
     lexical_to_string(c.value(i))
 }
 
+fn invalid_cast_error(dt: String, col_index: usize, row_index: usize) -> 
ArrowError {
+    let mut s = String::new();
+    s.push_str("Cannot cast to ");
+    s.push_str(&dt);
+    s.push_str(" at col index: ");
+    s.push_str(col_index.to_string().as_str());
+    s.push_str(" row index: ");
+    s.push_str(row_index.to_string().as_str());
+    ArrowError::CastError(s)
+}
+
+macro_rules! write_temporal_value {

Review Comment:
   Does this need to be a macro or can it be a generic



##########
arrow-csv/src/writer.rs:
##########
@@ -672,4 +710,26 @@ sed do eiusmod 
tempor,-556132.25,1,,2019-04-18T02:45:55.555000000,23:46:03,foo
         let expected = nanoseconds.into_iter().map(Some).collect::<Vec<_>>();
         assert_eq!(actual, expected);
     }
+
+    #[test]
+    fn test_write_csv_invalid_cast() {
+        let schema = Schema::new(vec![
+            Field::new("c0", DataType::UInt32, false),
+            Field::new("c1", DataType::Date64, false),
+        ]);
+
+        let c0 = UInt32Array::from(vec![Some(123), Some(234)]);
+        let c1 = Date64Array::from(vec![Some(1926632005177), 
Some(1926632005177685347)]);
+        let batch =
+            RecordBatch::try_new(Arc::new(schema), vec![Arc::new(c0), 
Arc::new(c1)])
+                .unwrap();
+
+        let mut file = tempfile::tempfile().unwrap();
+        let mut writer = Writer::new(&mut file);
+        let batches = vec![&batch, &batch];
+        for batch in batches {
+            writer.write(batch).map_err(|e| { dbg!(e.to_string()); 
assert!(e.to_string().ends_with(invalid_cast_error("arrow_array::array::primitive_array::PrimitiveArray<arrow_array::types::Date64Type>".to_owned(),
 1, 1).to_string().as_str()))}).unwrap_err();

Review Comment:
   How about printing the DataType instead?



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