AndreaBozzo commented on code in PR #10903:
URL: https://github.com/apache/arrow-rs/pull/10903#discussion_r3882697895
##########
arrow-csv/src/reader/mod.rs:
##########
@@ -2647,6 +2675,132 @@ mod tests {
assert!(c.is_null(3));
}
+ #[test]
+ fn test_extra_fields_ignore() {
+ let data = "a,b\n1,2,3,4\n5,6\n7,8,9";
+ let schema = Arc::new(Schema::new(vec![
+ Field::new("a", DataType::Int32, true),
+ Field::new("b", DataType::Int32, true),
+ ]));
+
+ let mut reader = ReaderBuilder::new(schema.clone())
+ .with_header(true)
+ .with_extra_fields(ExtraFields::Ignore)
+ .build(Cursor::new(data))
+ .unwrap();
+
+ let batch = reader.next().unwrap().unwrap();
+ assert_eq!(batch.num_rows(), 3);
+ assert_eq!(batch.num_columns(), 2);
+
+ let col_a = batch.column(0).as_primitive::<Int32Type>();
+ assert_eq!(col_a.value(0), 1);
+ assert_eq!(col_a.value(1), 5);
+ assert_eq!(col_a.value(2), 7);
+
+ let col_b = batch.column(1).as_primitive::<Int32Type>();
+ assert_eq!(col_b.value(0), 2);
+ assert_eq!(col_b.value(1), 6);
+ assert_eq!(col_b.value(2), 8);
+ }
+
+ #[test]
+ fn test_extra_fields_default_errors() {
+ let data = "a,b\n1,2,3\n4,5";
+ let schema = Arc::new(Schema::new(vec![
+ Field::new("a", DataType::Int32, true),
+ Field::new("b", DataType::Int32, true),
+ ]));
+
+ // No with_extra_fields called (should default to Error)
+ let mut reader = ReaderBuilder::new(schema.clone())
+ .with_header(true)
+ .build(Cursor::new(data))
+ .unwrap();
+
+ let result = reader.next();
+ assert!(match result {
+ Some(Err(ArrowError::CsvError(e))) => e.contains("got more than"),
Review Comment:
These assertions encode the new wording, so the change to the default
`Error` path described in my comment on `records.rs` is locked . With a
mode-conditional `ends_bound` these would go back to `expected 2 got 3`.
--
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]