alamb commented on code in PR #9004: URL: https://github.com/apache/arrow-rs/pull/9004#discussion_r2624723556
########## arrow-csv/src/lib.rs: ########## @@ -30,6 +30,7 @@ pub mod writer; pub use self::reader::Reader; pub use self::reader::ReaderBuilder; pub use self::reader::infer_schema_from_files; +pub use self::writer::QuoteStyle; Review Comment: This is publicly exporting something from the csv crate (which I think is good): https://docs.rs/csv/latest/csv/enum.QuoteStyle.html ########## arrow-csv/src/writer.rs: ########## @@ -141,6 +141,66 @@ //! "name,comment\nAlice ,Great job! \nBob,Well done\nCharlie,Excellent \n" //! ); //! ``` +//! +//! # Quoting Styles +//! +//! The writer supports different quoting styles for fields, compatible with Apache Spark's +//! CSV options like `quoteAll`. You can control when fields are quoted using the +//! [`QuoteStyle`] enum. +//! +//! ## Available Quoting Styles +//! +//! - `QuoteStyle::Necessary` (default): Only quotes fields when necessary (e.g., when they Review Comment: I think this is redundant with the existing documentation on `QuoteStyle` -- the link above to `QuoteStyle` is probably fine ########## arrow-csv/src/writer.rs: ########## @@ -1181,4 +1286,106 @@ sed do eiusmod tempor,-556132.25,1,,2019-04-18T02:45:55.555,23:46:03,foo String::from_utf8(buf).unwrap() ); } + + #[test] + fn test_write_csv_quote_style() { + let schema = Schema::new(vec![ + Field::new("text", DataType::Utf8, false), + Field::new("number", DataType::Int32, false), + Field::new("float", DataType::Float64, false), + ]); + + let text = StringArray::from(vec!["hello", "world", "comma,value", "quote\"test"]); + let number = Int32Array::from(vec![1, 2, 3, 4]); + let float = Float64Array::from(vec![1.1, 2.2, 3.3, 4.4]); + + let batch = RecordBatch::try_new( + Arc::new(schema), + vec![Arc::new(text), Arc::new(number), Arc::new(float)], + ) + .unwrap(); + + // Test with QuoteStyle::Necessary (default) + let mut buf = Vec::new(); Review Comment: Can you please reduce some of this boiler plate code? It is obscuring what is going on in the tests -- maybe a helper so these tests end up looking something like this: ```rust assert_eq!( "text,number,float\nhello,1,1.1\nworld,2,2.2\n\"comma,value\",3,3.3\n\"quote\"\"test\",4,4.4\n", write_quote_style(batch, QuoteStyle::Necessary ) -- 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]
