emkornfield commented on a change in pull request #12504:
URL: https://github.com/apache/arrow/pull/12504#discussion_r816112261
##########
File path: cpp/src/arrow/csv/writer.cc
##########
@@ -265,24 +271,41 @@ class QuotedColumnPopulator : public ColumnPopulator {
Status UpdateRowLengths(int32_t* row_lengths) override {
const StringArray& input = *casted_array_;
- int row_number = 0;
- row_needs_escaping_.resize(casted_array_->length());
- VisitArrayDataInline<StringType>(
- *input.data(),
- [&](arrow::util::string_view s) {
- // Each quote in the value string needs to be escaped.
- int64_t escaped_count = CountQuotes(s);
- // TODO: Maybe use 64 bit row lengths or safe cast?
- row_needs_escaping_[row_number] = escaped_count > 0;
- row_lengths[row_number] += static_cast<int32_t>(s.length()) +
- static_cast<int32_t>(escaped_count +
kQuoteCount);
- row_number++;
- },
- [&]() {
- row_needs_escaping_[row_number] = false;
- row_lengths[row_number] +=
static_cast<int32_t>(null_string_->size());
- row_number++;
- });
+
+ row_needs_escaping_.resize(casted_array_->length(), false);
+
+ if (NoQuoteInArray(input)) {
+ // fast path if no quote
+ int row_number = 0;
+ VisitArrayDataInline<StringType>(
+ *input.data(),
+ [&](arrow::util::string_view s) {
+ row_lengths[row_number] +=
+ static_cast<int32_t>(s.length()) +
static_cast<int32_t>(kQuoteCount);
+ row_number++;
+ },
+ [&]() {
+ row_lengths[row_number] +=
static_cast<int32_t>(null_string_->size());
+ row_number++;
+ });
+ } else {
+ int row_number = 0;
+ VisitArrayDataInline<StringType>(
+ *input.data(),
+ [&](arrow::util::string_view s) {
+ // Each quote in the value string needs to be escaped.
+ int64_t escaped_count = CountQuotes(s);
+ // TODO: Maybe use 64 bit row lengths or safe cast?
Review comment:
i actually seem to recall not that I didn't do this, because if a line
exceeded 2^32 we'd likely run into bottlenecks elsewhere.
--
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]