You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "CaptainAni187 (via GitHub)" <gi...@apache.org> on 2026/10/20 02:54:23 UTC

[PR] GH-54535: [C++] Quote nulls in single-column CSV output so rows aren't written as empty lines [arrow]

CaptainAni187 opened a new pull request, #54683:
URL: https://github.com/apache/arrow/pull/54683

   ### Rationale for this change
   
   With a one-column table, a null gets written as the empty null_string followed by the eol, so the row is just an empty line. The CSV reader skips empty lines by default, so every null row is lost on a write_csv / read_csv round trip.
   
   ### What changes are included in this PR?
   
   When the schema has a single column and null_string is empty, the writer now writes nulls as `""` instead of nothing. A quoted empty value already reads back as null for non-string columns (quoted_strings_can_be_null), and the row is kept for string columns too.
   
   It only kicks in for that one case. A custom null_string, tables with more than one column, and QuotingStyle::None keep the old output. I left None alone since it promises no quotes at all.... happy to change that if you'd rather it also writes `""`.
   
   Also added a note about this on WriteOptions::null_string.
   
   ### Are these changes tested?
   
   Yes. Updated the existing SingleColumnWriteCSVTest case (it was asserting the empty line), added cases for Needed, AllValid, None, a custom null_string, a string column and two columns, plus a round trip test that writes a one-column table with nulls and reads it back with default options.
   
   ### Are there any user-facing changes?
   
   Yes, single-column CSV output with nulls changes from an empty line to `""` (with the default empty null_string).
   
   ### Was AI used for this PR?
   
   In accordance to the [AI generation guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code), please disclose below whether and how AI was used in this PR.
   
   The fix, tests and this description were drafted with Claude Code.
   
   **PR code and description written by:**
   
   - [ ] Human
   - [x] AI
   
   **Reviewed before submission by:**
   
   - [ ] Human
   - [x] AI
   - [ ] Not reviewed
   
   * GitHub Issue: #54535
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-54535: [C++] Quote nulls in single-column CSV output so rows aren't written as empty lines [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #54683:
URL: https://github.com/apache/arrow/pull/54683#issuecomment-6428060350

   :warning: GitHub issue #54535 **has been automatically assigned in GitHub** to PR creator.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-54535: [C++] Quote nulls in single-column CSV output so rows aren't written as empty lines [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #54683:
URL: https://github.com/apache/arrow/pull/54683#issuecomment-6427779232

   :warning: GitHub issue #54535 **has been automatically assigned in GitHub** to PR creator.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-54535: [C++] Quote nulls in single-column CSV output so rows aren't written as empty lines [arrow]

Posted by "CaptainAni187 (via GitHub)" <gi...@apache.org>.
CaptainAni187 commented on code in PR #54683:
URL: https://github.com/apache/arrow/pull/54683#discussion_r4382703780


##########
cpp/src/arrow/csv/writer.cc:
##########
@@ -512,10 +512,15 @@ class CSVWriterImpl : public ipc::RecordBatchWriter {
       return Status::Invalid("Null string cannot contain quotes.");
     }
 
+    const std::string null_string_value =
+        schema->num_fields() == 1 && options.null_string.empty() &&
+                options.quoting_style != QuotingStyle::None

Review Comment:
   Good point, thanks. A single string or binary column now keeps the empty line for nulls, since "" is already what a valid empty string becomes there. The `""` for nulls only applies when the column's values can never be written as `""` (ints, dates, etc.). Added the round trip you described: ["a", null, ""] written with Needed and AllValid and read back with strings_can_be_null=true, quoted_strings_can_be_null=false and ignore_empty_lines=false keeps all three values. Also adjusted the AllValid doc to point at the exception.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-54535: [C++] Quote nulls in single-column CSV output so rows aren't written as empty lines [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #54683:
URL: https://github.com/apache/arrow/pull/54683#issuecomment-6282338906

   :warning: GitHub issue #54535 **has no components**, please add labels for components.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-54535: [C++] Quote nulls in single-column CSV output so rows aren't written as empty lines [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #54683:
URL: https://github.com/apache/arrow/pull/54683#issuecomment-6282338761

   :warning: GitHub issue #54535 **has been automatically assigned in GitHub** to PR creator.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-54535: [C++] Quote nulls in single-column CSV output so rows aren't written as empty lines [arrow]

Posted by "dmitry-chirkov-dremio (via GitHub)" <gi...@apache.org>.
dmitry-chirkov-dremio commented on code in PR #54683:
URL: https://github.com/apache/arrow/pull/54683#discussion_r4338228396


##########
cpp/src/arrow/csv/writer.cc:
##########
@@ -512,10 +512,15 @@ class CSVWriterImpl : public ipc::RecordBatchWriter {
       return Status::Invalid("Null string cannot contain quotes.");
     }
 
+    const std::string null_string_value =
+        schema->num_fields() == 1 && options.null_string.empty() &&
+                options.quoting_style != QuotingStyle::None

Review Comment:
   What if we write ["a", null, ""] with all_valid?
   
   AllValid is documented to leave nulls unquoted. This change writes both null and the empty string as "", so a reader cannot distinguish them.
   
   Can we add a round-trip test with strings_can_be_null=true, quoted_strings_can_be_null=false, and ignore_empty_lines=false, and preserve the distinction?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-54535: [C++] Quote nulls in single-column CSV output so rows aren't written as empty lines [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #54683:
URL: https://github.com/apache/arrow/pull/54683#issuecomment-6428067561

   :warning: GitHub issue #54535 **has been automatically assigned in GitHub** to PR creator.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org