Print the batches to a writer using the specified format
(
&self,
writer: &mut W,
schema: SchemaRef,
batches: &[RecordBatch],
maxrows: MaxRows,
with_header: bool,
format_options: &FormatOptions,
)
| 156 | impl PrintFormat { |
| 157 | /// Print the batches to a writer using the specified format |
| 158 | pub fn print_batches<W: std::io::Write>( |
| 159 | &self, |
| 160 | writer: &mut W, |
| 161 | schema: SchemaRef, |
| 162 | batches: &[RecordBatch], |
| 163 | maxrows: MaxRows, |
| 164 | with_header: bool, |
| 165 | format_options: &FormatOptions, |
| 166 | ) -> Result<()> { |
| 167 | // filter out any empty batches |
| 168 | let batches: Vec<_> = batches |
| 169 | .iter() |
| 170 | .filter(|b| b.num_rows() > 0) |
| 171 | .cloned() |
| 172 | .collect(); |
| 173 | if batches.is_empty() { |
| 174 | return self.print_empty(writer, schema, format_options); |
| 175 | } |
| 176 | |
| 177 | match self { |
| 178 | Self::Csv | Self::Automatic => { |
| 179 | print_batches_with_sep(writer, &batches, b',', with_header) |
| 180 | } |
| 181 | Self::Tsv => print_batches_with_sep(writer, &batches, b'\t', with_header), |
| 182 | Self::Table => { |
| 183 | if maxrows == MaxRows::Limited(0) { |
| 184 | return Ok(()); |
| 185 | } |
| 186 | format_batches_with_maxrows(writer, &batches, maxrows, format_options) |
| 187 | } |
| 188 | Self::Json => batches_to_json!(ArrayWriter, writer, &batches), |
| 189 | Self::NdJson => batches_to_json!(LineDelimitedWriter, writer, &batches), |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | /// Print when the result batches contain no rows |
| 194 | fn print_empty<W: std::io::Write>( |
no test coverage detected