Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cpp/src/arrow/csv/parser-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,31 @@ TEST(BlockParser, Escaping) {
}
}

// Generate test data with the given number of columns.
std::string MakeLotsOfCsvColumns(int32_t num_columns) {
std::string values, header;
header.reserve(num_columns * 10);
values.reserve(num_columns * 10);
for (int x = 0; x < num_columns; x++) {
if (x != 0) {
header += ",";
values += ",";
}
header += "c" + std::to_string(x);
values += std::to_string(x);
}

header += "\n";
values += "\n";
return MakeCSVData({header, values});
}

TEST(BlockParser, LotsOfColumns) {
auto options = ParseOptions::Defaults();
BlockParser parser(options);
AssertParseOk(parser, MakeLotsOfCsvColumns(1024 * 100));
}

TEST(BlockParser, QuotedEscape) {
auto options = ParseOptions::Defaults();
options.escaping = true;
Expand Down
7 changes: 5 additions & 2 deletions cpp/src/arrow/csv/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,19 @@ Status BlockParser::DoParseSpecialized(const char* start, uint32_t size, bool is
return ParseError("Empty CSV file or block: cannot infer number of columns");
}
}

while (!finished_parsing && data < data_end && num_rows_ < max_num_rows_) {
// We know the number of columns, so can presize a values array for
// a given number of rows
DCHECK_GE(num_cols_, 0);

int32_t rows_in_chunk;
constexpr int32_t kTargetChunkSize = 32768;
if (num_cols_ > 0) {
rows_in_chunk = std::min(32768 / num_cols_, max_num_rows_ - num_rows_);
rows_in_chunk = std::min(std::max(kTargetChunkSize / num_cols_, 512),
max_num_rows_ - num_rows_);
} else {
rows_in_chunk = std::min(32768, max_num_rows_ - num_rows_);
rows_in_chunk = std::min(kTargetChunkSize, max_num_rows_ - num_rows_);
}

PresizedValuesWriter values_writer(pool_, rows_in_chunk, num_cols_);
Expand Down