Skip to content

Commit

Permalink
Merge pull request #2298 from Mytherin/issue2294
Browse files Browse the repository at this point in the history
Fix #2294: In CSV reader correctly generate column names with many columns
  • Loading branch information
Mytherin committed Sep 20, 2021
2 parents 7dd852e + a9cadc0 commit 0e6969f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/execution/operator/persistent/buffered_csv_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ unique_ptr<FileHandle> BufferedCSVReader::OpenCSV(const BufferedCSVReaderOptions
static string GenerateColumnName(const idx_t total_cols, const idx_t col_number, const string &prefix = "column") {
int max_digits = NumericHelper::UnsignedLength(total_cols - 1);
int digits = NumericHelper::UnsignedLength(col_number);
string leading_zeros = string("0", max_digits - digits);
string leading_zeros = string(max_digits - digits, '0');
string value = to_string(col_number);
return string(prefix + leading_zeros + value);
}
Expand Down
1 change: 1 addition & 0 deletions test/sql/copy/csv/data/manycolumns.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101
12 changes: 12 additions & 0 deletions test/sql/copy/csv/test_many_columns.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# name: test/sql/copy/csv/test_many_columns.test
# description: Test read CSV function with many (>100) auto-generated columns
# group: [csv]

statement ok
PRAGMA enable_verification

statement ok
CREATE TABLE t AS SELECT * FROM read_csv_auto('test/sql/copy/csv/data/manycolumns.csv');

statement ok
PRAGMA SHOW('t');

0 comments on commit 0e6969f

Please sign in to comment.