GH-51368: [C++] Fix CSV reader dropping '\n' after a straddling '\r' inside a quoted field #51394
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 325 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.346
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #51394"
general
weight: 0.35
Reranko05
Rationale for this change
With
newlines_in_values = true, a quoted CRLF sequence split across two input buffers was silently corrupted:"…\rat the end of one buffer and\n…at the start of the next lost the\n(it stayed inside the field as\ronly). Reported in #51368.The root cause is in
CSVBufferIterator, which unconditionally skipped a leading\nwhenever the previous buffer ended with\r. At that layer there is no quoting context, so the code cannot distinguish a\r\nthat is a physical line separator from\r\nthat is the contents of an unfinished quoted field.What changes are included in this PR?
CSVBufferIteratorno longer resolves straddling CRLF sequences (it still strips a leading UTF-8 BOM).BlockReadernow owns the decision viatrailing_cr_+ aSkipStraddlingCRLFhelper: the next buffer's leading\nis skipped only when the previous buffer's trailing\rwas fully consumed as a line separator. When the\rbelongs to an unfinished quoted field, it is carried inpartial_(non-empty), the flag stays false, and the\nis preserved as field contents.SerialBlockReader(throughconsume_bytes, driven by how much of the buffer the parser consumed) andThreadedBlockReader(throughnext_partialfrom the chunker), including the row-skipping paths. Empty buffers never overwrite the state.prev_ended_crflag is plumbed through the block-reader factories for the edge case where a header row ends exactly at a buffer boundary with\r(the post-header buffer is then empty and the next buffer starts with\n).TestStraddlingCRLFcovering a quoted\r\nsplit across the boundary, a line-separator\r\nsplit across the boundary, and a header row ending with\rat the boundary. Registered for the serial, threaded-async and streaming readers.Are these changes tested?
Yes — a new
StraddlingCRLFtest incsv/reader_test.cccovers all three cases above with a block size that forces the split. (Note: the change was developed and cross-validated against a transliteration of the reader/chunker/parser pipeline; the gtest cases should be run in CI.)Are there any user-facing changes?
No API changes. Files with
newlines_in_valuesenabled whose quoted fields contain\r\nstraddling a read block boundary are now parsed correctly instead of losing the\n.Closes #51368
Was AI used for this PR?
PR code and description written by:
Reviewed before submission by: