kou commented on code in PR #50846:
URL: https://github.com/apache/arrow/pull/50846#discussion_r3763798945


##########
cpp/src/arrow/csv/writer.cc:
##########
@@ -601,13 +622,12 @@ class CSVWriterImpl : public ipc::RecordBatchWriter {
     int64_t header_length = 0;
     for (int col = 0; col < schema_->num_fields(); col++) {
       const std::string& col_name = schema_->field(col)->name();
-      header_length += col_name.size();
+      header_length += EscapedLength(col_name, options_.escape_style);

Review Comment:
   Can we call this when `quoting_style == QuotingStyle::None`?



##########
cpp/src/arrow/csv/writer.cc:
##########
@@ -167,16 +167,32 @@ class ColumnPopulator {
 
 // Copies the contents of s to out properly escaping any necessary characters.
 // Returns the position next to last copied character.
-char* Escape(std::string_view s, char* out) {
+char* Escape(std::string_view s, char* out, EscapeStyle escape_style) {
   for (const char c : s) {
+    if (c == '"' && escape_style == EscapeStyle::Backslash) {
+      *out++ = '\\';
+    }
     *out++ = c;
-    if (c == '"') {
+    if (c == '"' && escape_style == EscapeStyle::Double) {
       *out++ = '"';
     }

Review Comment:
   Can we simplify this?
   
   
   ```suggestion
       if (c == '"') {
         if (escape_style == EscapeStyle::Double) {
           *out++ = '"';
         } else if (escape_style == EscapeStyle::Backslash) {
           *out++ = '\\';
         }
       }
       *out++ = c;
   }
   ```



##########
cpp/src/arrow/csv/writer.cc:
##########
@@ -366,8 +384,7 @@ class QuotedColumnPopulator : public ColumnPopulator {
             // Each quote in the value string needs to be escaped.
             int64_t escaped_count = CountQuotes(s);
             row_needs_escaping_[row_number] = escaped_count > 0;
-            row_lengths[row_number] +=
-                static_cast<int64_t>(s.length()) + escaped_count + kQuoteCount;
+            row_lengths[row_number] += EscapedLength(s, escape_style_) + 
kQuoteCount;

Review Comment:
   Can we reuse `escaped_count` here?



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