Repository: apache/datafusion (language: rust)

Issue:
New Datafusion-cli streaming printing way should handle corner case for only one small batch which lines are less than max_rows
### Describe the bug

When i continue to test for new way for datafusion-cli exec and print, i found the corner case that only one small batch which lines are less than max_rows and less than preview limit will not print, this ticket will fix it.

New way for datafusion-cli exec and print after the PR:
https://github.com/apache/datafusion/pull/14877

### To Reproduce
```rust
> CREATE EXTERNAL TABLE IF NOT EXISTS lineitem (
        l_orderkey BIGINT,
        l_partkey BIGINT,
        l_suppkey BIGINT,
        l_linenumber INTEGER,
        l_quantity DECIMAL(15, 2),
        l_extendedprice DECIMAL(15, 2),
        l_discount DECIMAL(15, 2),
        l_tax DECIMAL(15, 2),
        l_returnflag VARCHAR,
        l_linestatus VARCHAR,
        l_shipdate DATE,
        l_commitdate DATE,
        l_receiptdate DATE,
        l_shipinstruct VARCHAR,
        l_shipmode VARCHAR,
        l_comment VARCHAR
) STORED AS parquet
LOCATION '/Users/zhuqi/arrow-datafusion/benchmarks/data/tpch_sf10/lineitem';
0 row(s) fetched.
Elapsed 0.007 seconds.


> select l_comment from lineitem limit 1;
```


It will show nothing to print.


### Expected behavior

_No response_

### Additional context

_No response_


Discussion / hints:

Fix patch:
diff --git a/datafusion-cli/src/print_options.rs b/datafusion-cli/src/print_options.rs
index 092483faed63..8dd7ca9c8081 100644
--- a/datafusion-cli/src/print_options.rs
+++ b/datafusion-cli/src/print_options.rs
@@ -151,7 +151,6 @@ impl PrintOptions {
                             print_options
                                 .format
                                 .print_header(&schema, &widths, writer)?;
-                            header_printed = true;
                         }
                         for preview_batch in preview_batches.drain(..) {
                             print_options.format.print_batch_with_widths(
@@ -198,6 +197,13 @@ impl PrintOptions {
                         writer,
                     )?;
                 }
+                for preview_batch in preview_batches.drain(..) {
+                    print_options.format.print_batch_with_widths(
+                        &preview_batch,
+                        precomputed_widths.as_ref().unwrap(),
+                        writer,
+                    )?;
+                }
             }
             if let Some(ref widths) = precomputed_widths {
                 print_options.format.print_bottom_border(widths, writer)?;


Test patch:
diff --git a/datafusion-cli/tests/cli_integration.rs b/datafusion-cli/tests/cli_integration.rs
index 27cabf15afec..55c5d53e8098 100644
--- a/datafusion-cli/tests/cli_integration.rs
+++ b/datafusion-cli/tests/cli_integration.rs
@@ -47,6 +47,12 @@ fn init() {
     ["--command", "show datafusion.execution.batch_size", "--format", "json", "-q", "-b", "1"],
     "[{\"name\":\"datafusion.execution.batch_size\",\"value\":\"1\"}]\n"
 )]
+
+/// Add case fixed issue: https://github.com/apache/datafusion/issues/14920
+#[case::exec_from_commands(
+    ["--command", "SELECT * FROM generate_series(1, 5) t1(v1) ORDER BY v1 DESC;", "--format", "table", "-q"],
+    "+----+\n| v1 |\n+----+\n| 5  |\n| 4  |\n| 3  |\n| 2  |\n| 1  |\n+----+\n"
+)]
 #[test]
 fn cli_quick_test<'a>(
     #[case] args: impl IntoIterator<Item = &'a str>,