Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion datafusion-cli/src/print_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn keep_only_maxrows(s: &str, maxrows: usize) -> String {
let last_line = &lines[lines.len() - 1]; // bottom border line

let spaces = last_line.len().saturating_sub(4);
let dotted_line = format!("| .{:<spaces$}|", "", spaces = spaces);
let dotted_line = format!("| .{}|", " ".repeat(spaces));

let mut result = lines[0..(maxrows + 3)].to_vec(); // Keep top border and `maxrows` lines
result.extend(vec![dotted_line; 3]); // Append ... lines
Expand Down Expand Up @@ -632,6 +632,41 @@ mod tests {
.unwrap()
}

#[test]
fn print_maxrows_limited_wide_table() {
let output = PrintBatchesTest::new()
.with_format(PrintFormat::Table)
.with_batches(vec![wide_column_batch()])
.with_maxrows(MaxRows::Limited(1))
.run();
assert_snapshot!(output, @r"
+----+----+----+----+----+----+----+----+----+----+
| c0 | c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 |
+----+----+----+----+----+----+----+----+----+----+
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| . |
| . |
| . |
+----+----+----+----+----+----+----+----+----+----+
");
}

/// return a schema with many columns (to exercise wide table formatting)
fn wide_column_schema() -> SchemaRef {
let fields: Vec<Field> = (0..10)
.map(|i| Field::new(format!("c{i}"), DataType::Int32, false))
.collect();
Arc::new(Schema::new(fields))
}

/// return a batch with many columns and three rows
fn wide_column_batch() -> RecordBatch {
let arrays: Vec<Arc<dyn arrow::array::Array>> = (0..10)
.map(|_| Arc::new(Int32Array::from(vec![0, 1, 2])) as _)
.collect();
RecordBatch::try_new(wide_column_schema(), arrays).unwrap()
}

/// Slice the record batch into 2 batches
fn split_batch(batch: &RecordBatch) -> Vec<RecordBatch> {
assert!(batch.num_rows() > 1);
Expand Down
17 changes: 17 additions & 0 deletions datafusion-cli/tests/cli_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,23 @@ fn test_cli_with_unbounded_memory_pool() {
assert_cmd_snapshot!(cmd);
}

#[test]
fn test_cli_wide_result_set_no_crash() {
let mut settings = make_settings();

settings.set_snapshot_suffix("wide_result_set");

let _bound = settings.bind_to_scope();

let mut cmd = cli();
let sql = "SELECT v1 as c0, v1+1 as c1, v1+2 as c2, v1+3 as c3, v1+4 as c4, \
v1+5 as c5, v1+6 as c6, v1+7 as c7, v1+8 as c8, v1+9 as c9 \
FROM generate_series(1, 100) as t1(v1);";
cmd.args(["--maxrows", "5", "--command", sql]);

assert_cmd_snapshot!(cmd);
}

#[tokio::test]
async fn test_cli() {
if env::var("TEST_STORAGE_INTEGRATION").is_err() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
source: datafusion-cli/tests/cli_integration.rs
assertion_line: 307
info:
program: datafusion-cli
args:
- "--maxrows"
- "5"
- "--command"
- "SELECT v1 as c0, v1+1 as c1, v1+2 as c2, v1+3 as c3, v1+4 as c4, v1+5 as c5, v1+6 as c6, v1+7 as c7, v1+8 as c8, v1+9 as c9 FROM generate_series(1, 100) as t1(v1);"
---
success: true
exit_code: 0
----- stdout -----
[CLI_VERSION]
+----+----+----+----+----+----+----+----+----+----+
| c0 | c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 |
+----+----+----+----+----+----+----+----+----+----+
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| . |
| . |
| . |
+----+----+----+----+----+----+----+----+----+----+
100 row(s) fetched. (First 5 displayed. Use --maxrows to adjust)
[ELAPSED]


----- stderr -----
Loading