(
writer: &mut W,
batches: &[RecordBatch],
maxrows: MaxRows,
format_options: &FormatOptions,
)
| 107 | } |
| 108 | |
| 109 | fn format_batches_with_maxrows<W: std::io::Write>( |
| 110 | writer: &mut W, |
| 111 | batches: &[RecordBatch], |
| 112 | maxrows: MaxRows, |
| 113 | format_options: &FormatOptions, |
| 114 | ) -> Result<()> { |
| 115 | let options: arrow::util::display::FormatOptions = format_options.try_into()?; |
| 116 | |
| 117 | match maxrows { |
| 118 | MaxRows::Limited(maxrows) => { |
| 119 | // Filter batches to meet the maxrows condition |
| 120 | let mut filtered_batches = Vec::new(); |
| 121 | let mut row_count: usize = 0; |
| 122 | let mut over_limit = false; |
| 123 | for batch in batches { |
| 124 | if row_count + batch.num_rows() > maxrows { |
| 125 | // If adding this batch exceeds maxrows, slice the batch |
| 126 | let limit = maxrows - row_count; |
| 127 | let sliced_batch = batch.slice(0, limit); |
| 128 | filtered_batches.push(sliced_batch); |
| 129 | over_limit = true; |
| 130 | break; |
| 131 | } else { |
| 132 | filtered_batches.push(batch.clone()); |
| 133 | row_count += batch.num_rows(); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | let formatted = |
| 138 | pretty_format_batches_with_options(&filtered_batches, &options)?; |
| 139 | if over_limit { |
| 140 | let mut formatted_str = format!("{formatted}"); |
| 141 | formatted_str = keep_only_maxrows(&formatted_str, maxrows); |
| 142 | writeln!(writer, "{formatted_str}")?; |
| 143 | } else { |
| 144 | writeln!(writer, "{formatted}")?; |
| 145 | } |
| 146 | } |
| 147 | MaxRows::Unlimited => { |
| 148 | let formatted = pretty_format_batches_with_options(batches, &options)?; |
| 149 | writeln!(writer, "{formatted}")?; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | Ok(()) |
| 154 | } |
| 155 | |
| 156 | impl PrintFormat { |
| 157 | /// Print the batches to a writer using the specified format |
no test coverage detected
searching dependent graphs…