Skip to content

Commit aeeb0ba

Browse files
authored
fix(datafusion-cli): solve row count bug addingsaturating_add to prevent potential overflow (#20185)
Currently `print_options::MaxRows::Unlimited` basically always panics with `attempt to add with overflow`, because we are summing `usize::MAX` with a positive number. `saturating_add` solves this issue # MRE ```rs fn main() { let max = usize::MAX; println!("max: {}", max); let max = max + 1; println!("max: {}", max); } ```
1 parent 75428f1 commit aeeb0ba

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

datafusion-cli/src/exec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl StatementExecutor {
300300
let curr_num_rows = batch.num_rows();
301301
// Stop collecting results if the number of rows exceeds the limit
302302
// results batch should include the last batch that exceeds the limit
303-
if row_count < max_rows + curr_num_rows {
303+
if row_count < max_rows.saturating_add(curr_num_rows) {
304304
// Try to grow the reservation to accommodate the batch in memory
305305
reservation.try_grow(get_record_batch_memory_size(&batch))?;
306306
results.push(batch);

0 commit comments

Comments
 (0)