Skip to content

Add quote style to csv writer - #9004

Merged
alamb merged 3 commits into
apache:mainfrom
xanderbailey:xb/quote_options
Dec 17, 2025
Merged

Add quote style to csv writer#9004
alamb merged 3 commits into
apache:mainfrom
xanderbailey:xb/quote_options

Conversation

@xanderbailey

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Following on from #8960, we are now exposing the quote style as a part of the csv writer options which allows users to quote columns similar to Spark's quoteAll setting.

Rationale for this change

What changes are included in this PR?

Expose QuoteStyle in the WriterBuilder

Are these changes tested?

Yes with examples and unit tests.

Are there any user-facing changes?

@github-actionsgithub-actionsBot added the arrow Changes to the arrow crate label Dec 16, 2025

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @xanderbailey - this is looking good

Comment threadarrow-csv/src/lib.rs
pub use self::reader::Reader;
pub use self::reader::ReaderBuilder;
pub use self::reader::infer_schema_from_files;
pub use self::writer::QuoteStyle;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is publicly exporting something from the csv crate (which I think is good): https://docs.rs/csv/latest/csv/enum.QuoteStyle.html

Comment threadarrow-csv/src/writer.rs Outdated
//!
//! ## Available Quoting Styles
//!
//! - `QuoteStyle::Necessary` (default): Only quotes fields when necessary (e.g., when they

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is redundant with the existing documentation on QuoteStyle -- the link above to QuoteStyle is probably fine

Comment threadarrow-csv/src/writer.rs Outdated
.unwrap();

// Test with QuoteStyle::Necessary (default)
let mut buf = Vec::new();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

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)

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @xanderbailey

@alamb
alamb merged commit 9aca68b into apache:mainDec 17, 2025
23 checks passed
@alambalamb mentioned this pull request Dec 29, 2025
Jefffrey pushed a commit to Jefffrey/datafusion that referenced this pull request Apr 24, 2026
## Which issue does this PR close?
- Closesapache#10669
Related arrow-rs PRs apache/arrow-rs#8960 and
apache/arrow-rs#9004
## Rationale for this change
The CSV writer was missing support for `quote_style`,
`ignore_leading_whitespace`, and `ignore_trailing_whitespace` options
that are available on the underlying arrow `WriterBuilder`. This meant
users couldn't control quoting behaviour or whitespace trimming when
writing CSV files.
## What changes are included in this PR?
Adds three new CSV writer options wired through the full stack:
- `quote_style` — controls when fields are quoted (`Always`,
`Necessary`, `NonNumeric`, `Never`). Modelled as a protobuf enum
(`CsvQuoteStyle`).
- `ignore_leading_whitespace` — trims leading whitespace from string
values on write.
- `ignore_trailing_whitespace` — trims trailing whitespace from string
values on write.
## Are these changes tested?
Yes — sqllogictest coverage added in `csv_files.slt`
## Are there any user-facing changes?
Three new `format.*` options available in COPY TO and CREATE EXTERNAL
TABLE for CSV:
- `format.quote_style` (string: `Always`, `Necessary`, `NonNumeric`,
`Never`)
- `format.ignore_leading_whitespace` (boolean)
- `format.ignore_trailing_whitespace` (boolean)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrowChanges to the arrow crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@xanderbailey@alamb