emkornfield commented on a change in pull request #11857:
URL: https://github.com/apache/arrow/pull/11857#discussion_r762737338



##########
File path: cpp/src/arrow/csv/writer.cc
##########
@@ -392,21 +397,24 @@ class CSVWriterImpl : public ipc::RecordBatchWriter {
       header_length += col_name.size();
       header_length += CountEscapes(col_name);
     }
-    return header_length + (kQuoteDelimiterCount * schema_->num_fields());
+    // header_length + ([quotes + ','] * schema_->num_fields()) + (eol - ',')
+    return header_length + (kQuoteDelimiterCount * schema_->num_fields()) +
+           (options_.eol.size() - 1);
   }
 
   Status WriteHeader() {
     // Only called once, as part of initialization
     RETURN_NOT_OK(data_buffer_->Resize(CalculateHeaderSize(), 
/*shrink_to_fit=*/false));
-    char* next =
-        reinterpret_cast<char*>(data_buffer_->mutable_data() + 
data_buffer_->size() - 1);
+    char* next = reinterpret_cast<char*>(data_buffer_->mutable_data() +
+                                         data_buffer_->size() - 
options_.eol.size());
     for (int col = schema_->num_fields() - 1; col >= 0; col--) {

Review comment:
       I don't recall 100% we might still do validation here to make sure it 
gets back to the start of the buffer?  At least it allows for only a single 
escape method.   instead of having to do it beginning and forward.




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