MCPcopy Create free account
hub / github.com/apache/datafusion / print_batches

Method print_batches

datafusion-cli/src/print_format.rs:158–191  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

156impl 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>(

Callers 3

executeMethod · 0.45
executeMethod · 0.45
output_with_headerMethod · 0.45

Calls 8

print_batches_with_sepFunction · 0.85
collectMethod · 0.80
print_emptyMethod · 0.80
clonedMethod · 0.45
filterMethod · 0.45
iterMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected