grtlr commented on code in PR #9221:
URL: https://github.com/apache/arrow-rs/pull/9221#discussion_r2735145013


##########
arrow-cast/src/pretty.rs:
##########
@@ -1776,4 +1776,128 @@ mod tests {
             "Invalid argument error: Expected the same number of columns in a 
record batch (1) as the number of fields (2) in the schema"
         );
     }
+
+    #[test]
+    fn test_quoted_strings() {
+        let schema = Arc::new(Schema::new(vec![Field::new(
+            "strings",
+            DataType::Utf8,
+            true,
+        )]));
+
+        let string_array = StringArray::from(vec![
+            Some("hello"),
+            Some("world"),
+            Some(""),
+            Some("tab\there"),
+            Some("newline\ntest"),
+            Some("quote\"test"),
+            Some("backslash\\test"),
+            None,
+        ]);
+
+        let batch = RecordBatch::try_new(schema.clone(), 
vec![Arc::new(string_array)]).unwrap();
+
+        let options_none = FormatOptions::new().with_null("NULL");
+        let table = 
pretty_format_batches_with_options(std::slice::from_ref(&batch), &options_none)
+            .unwrap()
+            .to_string();
+
+        assert!(table.contains("| hello"));

Review Comment:
   I checked yesterday already, so far Arrow does not use `insta`, but it might 
be very helpful for these cases, if maintainers agree to pull it in. For now I 
looked into using raw string literals.
   
   The problem is with escaping. The current (as in prior to this PR) 
implementation already seems to misrender tables with escaped characters with 
the length calculation being off:
   
   ```rs
   let expected = r#"+-------------------+
   | strings           |
   +-------------------+
   | hello             |
   | world             |
   |                   |
   | tab\there         |
   | newline\ntest     |
   | quote\"test      |
   | backslash\\test  |
   | NULL              |
   +-------------------+"#;
   ```
   
   I hope to be able to look into this later this week.



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