Skip to content

Commit 463ef3b

Browse files
authored
Fix: New Datafusion-cli streaming printing way should handle corner case for only one small batch which lines are less than max_rows (#14921)
* BUG: fix datafusion-cli missing case with only one batch and smaller than max_rows size * Fix * Add test case
1 parent 32224b4 commit 463ef3b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

datafusion-cli/src/print_options.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ impl PrintOptions {
151151
print_options
152152
.format
153153
.print_header(&schema, &widths, writer)?;
154-
header_printed = true;
155154
}
156155
for preview_batch in preview_batches.drain(..) {
157156
print_options.format.print_batch_with_widths(
@@ -198,6 +197,13 @@ impl PrintOptions {
198197
writer,
199198
)?;
200199
}
200+
for preview_batch in preview_batches.drain(..) {
201+
print_options.format.print_batch_with_widths(
202+
&preview_batch,
203+
precomputed_widths.as_ref().unwrap(),
204+
writer,
205+
)?;
206+
}
201207
}
202208
if let Some(ref widths) = precomputed_widths {
203209
print_options.format.print_bottom_border(widths, writer)?;

datafusion-cli/tests/cli_integration.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ fn init() {
4747
["--command", "show datafusion.execution.batch_size", "--format", "json", "-q", "-b", "1"],
4848
"[{\"name\":\"datafusion.execution.batch_size\",\"value\":\"1\"}]\n"
4949
)]
50+
51+
/// Add case fixed issue: https://github.com/apache/datafusion/issues/14920
52+
#[case::exec_from_commands(
53+
["--command", "SELECT * FROM generate_series(1, 5) t1(v1) ORDER BY v1 DESC;", "--format", "table", "-q"],
54+
"+----+\n| v1 |\n+----+\n| 5 |\n| 4 |\n| 3 |\n| 2 |\n| 1 |\n+----+\n"
55+
)]
5056
#[test]
5157
fn cli_quick_test<'a>(
5258
#[case] args: impl IntoIterator<Item = &'a str>,

0 commit comments

Comments
 (0)