Skip to content
Merged
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions datafusion-cli/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ pub(super) async fn exec_and_print(
reservation.try_grow(get_record_batch_memory_size(&batch))?;
results.push(batch);
}
} else if let MaxRows::Unlimited = print_options.maxrows {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good catch, wondering to avoid code duplication would it be better to

                let max_rows = match print_options.maxrows {
                    MaxRows::Unlimited => usize::MAX,
                    MaxRows::Limited(n) => n
                };

           while let Some(batch) = stream.next().await {
                let batch = batch?;
                let curr_num_rows = batch.num_rows();
                if row_count < max_rows + curr_num_rows {
                        // Try to grow the reservation to accommodate the batch in memory
                        reservation.try_grow(get_record_batch_memory_size(&batch))?;
                        results.push(batch);
                    }
                row_count += curr_num_rows;
            }

so we also remove unnecessary branch and literal evaulation every batch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @comphead for review, this is a good suggestion, i have addressed in latest PR!

// Collect all results for unlimited maxrows
// Try to grow the reservation to accommodate the batch in memory
reservation.try_grow(get_record_batch_memory_size(&batch))?;
results.push(batch);
}
row_count += curr_num_rows;
}
Expand Down