Skip to content

Commit

Permalink
add limits test
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxxen committed Nov 18, 2024
1 parent 3aabce3 commit 13316e8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/excel/include/xlsx/xlsx_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class XLXSWriter {
};

ZipFileWriter stream;
idx_t sheet_row_limit;
idx_t sheet_row_limit = XLSX_MAX_CELL_ROWS;

// Current sheet data;
string row_str = "1";
Expand Down Expand Up @@ -215,7 +215,14 @@ inline void XLXSWriter::EndRow() {
row_str = std::to_string(row_idx + 1);

if (row_idx > sheet_row_limit) {
throw InvalidInputException("XLSX: Sheet row limit of '%s' rows exceeded!", sheet_row_limit);
if(sheet_row_limit >= XLSX_MAX_CELL_ROWS) {
const auto msg = "XLSX: Sheet row limit of '%d' rows exceeded!\n"
" * XLSX files and compatible applications generally have a limit of '%d' rows\n"
" * You can export larger sheets at your own risk by setting the 'sheet_row_limit' parameter to a higher value";
throw InvalidInputException(msg, sheet_row_limit, XLSX_MAX_CELL_ROWS);
} else {
throw InvalidInputException("XLSX: Sheet row limit of '%d' rows exceeded!", sheet_row_limit);
}
}
}

Expand Down
19 changes: 19 additions & 0 deletions test/sql/excel/xlsx/limits.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require excel

statement error
COPY (SELECT * FROM range(5000))
TO '__TEST_DIR__/test_limit.xlsx' (FORMAT 'XLSX', sheet_row_limit 2049);
----
Invalid Input Error: XLSX: Sheet row limit of '2049' rows exceeded!

statement ok
COPY (SELECT * FROM range(1000))
TO '__TEST_DIR__/test_limit.xlsx' (FORMAT 'XLSX', sheet_row_limit 2049);

statement error
COPY (SELECT * FROM range(1048577))
TO '__TEST_DIR__/test_limit.xlsx' (FORMAT 'XLSX', sheet_name 'test');
----
Invalid Input Error: XLSX: Sheet row limit of '1048576' rows exceeded!
* XLSX files and compatible applications generally have a limit of '1048576' rows
* You can export larger sheets on your own risk by setting the 'sheet_row_limit' parameter to a higher value

0 comments on commit 13316e8

Please sign in to comment.