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



##########
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:
       @emkornfield Unrelated to this PR, but Chathura and I were looking at 
this last week and I was curious what the advantage was for writing the header 
backwards in this way.  Is there something we gain from this?




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