Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix #8904] Improved output of datafuson-cli with empty results #8947

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion datafusion-cli/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ async fn exec_and_print(

let df = ctx.execute_logical_plan(plan).await?;
let physical_plan = df.create_physical_plan().await?;
let schema = physical_plan.schema();

if is_plan_streaming(&physical_plan)? {
let stream = execute_stream(physical_plan, task_ctx.clone())?;
Expand All @@ -252,7 +253,7 @@ async fn exec_and_print(
print_options.format = PrintFormat::Table;
}
let results = collect(physical_plan, task_ctx.clone()).await?;
print_options.print_batches(&results, now)?;
print_options.print_batches_with_empty_result(&results, schema, now)?;
}
}

Expand Down
20 changes: 19 additions & 1 deletion datafusion-cli/src/print_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use std::time::Instant;

use crate::print_format::PrintFormat;

use arrow::record_batch::RecordBatch;
use arrow::datatypes::SchemaRef;
use arrow::record_batch::{RecordBatch, RecordBatchOptions};
use datafusion::common::DataFusionError;
use datafusion::error::Result;
use datafusion::physical_plan::RecordBatchStream;
Expand Down Expand Up @@ -94,6 +95,23 @@ fn get_timing_info_str(
}

impl PrintOptions {
pub fn print_batches_with_empty_result(
&self,
batches: &[RecordBatch],
schema: SchemaRef,
query_start_time: Instant,
) -> Result<()> {
if batches.len() == 0 {
let option = RecordBatchOptions::new().with_match_field_names(false);

return self.print_batches(
&[RecordBatch::try_new_with_options(schema, vec![], &option)?],
query_start_time,
);
};
return self.print_batches(batches, query_start_time);
}

/// Print the batches to stdout using the specified format
pub fn print_batches(
&self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@ async fn scalar_udf_zero_params() -> Result<()> {

let result = plan_and_collect(&ctx, "select get_100() from t where a=999").await?;
let expected = [
"++", //
"++",
"+-----------+",
"| get_100() |",
"+-----------+",
"+-----------+",
];
assert_batches_eq!(expected, &result);
Ok(())
Expand Down
Loading