Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
berkaysynnada committed Dec 27, 2023
1 parent b35bc73 commit cf26827
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
11 changes: 7 additions & 4 deletions datafusion-cli/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub async fn exec_from_repl(
)));
rl.load_history(".history").ok();

let mut print_options = print_options.clone();
let mut print_options = *print_options;

loop {
match rl.readline("❯ ") {
Expand Down Expand Up @@ -215,13 +215,17 @@ async fn exec_and_print(
for statement in statements {
let mut plan = ctx.state().statement_to_plan(statement).await?;

// For plans like `Explain` ignore `MaxRows` option and always display all rows
let should_ignore_maxrows = matches!(
plan,
LogicalPlan::Explain(_)
| LogicalPlan::DescribeTable(_)
| LogicalPlan::Analyze(_)
);

// Note that cmd is a mutable reference so that create_external_table function can remove all
// datafusion-cli specific options before passing through to datafusion. Otherwise, datafusion
// will raise Configuration errors.
if let LogicalPlan::Ddl(DdlStatement::CreateExternalTable(cmd)) = &mut plan {
create_external_table(ctx, cmd).await?;
}
Expand Down Expand Up @@ -293,9 +297,8 @@ mod tests {
use std::str::FromStr;

use super::*;

use datafusion_common::file_options::StatementOptions;
use datafusion_common::{plan_err, FileTypeWriterOptions};
use datafusion::common::plan_err;
use datafusion_common::{file_options::StatementOptions, FileTypeWriterOptions};

async fn create_external_table_test(location: &str, sql: &str) -> Result<()> {
let ctx = SessionContext::new();
Expand Down
1 change: 0 additions & 1 deletion datafusion-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ fn extract_memory_pool_size(size: &str) -> Result<usize, String> {
#[cfg(test)]
mod tests {
use super::*;

use datafusion::assert_batches_eq;

fn assert_conversion(input: &str, expected: Result<usize, String>) {
Expand Down
4 changes: 1 addition & 3 deletions datafusion-cli/src/print_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,13 @@ fn format_batches_with_maxrows<W: std::io::Write>(
}
}

// Formatting and writing to the writer
let formatted = pretty_format_batches_with_options(
&filtered_batches,
&DEFAULT_FORMAT_OPTIONS,
)?;
write!(writer, "{}", formatted)?;
}
MaxRows::Unlimited => {
// Format all rows and write to the writer
let formatted =
pretty_format_batches_with_options(batches, &DEFAULT_FORMAT_OPTIONS)?;
write!(writer, "{}", formatted)?;
Expand All @@ -124,7 +122,7 @@ fn format_batches_with_maxrows<W: std::io::Write>(

impl PrintFormat {
/// Print the batches to a writer using the specified format
pub fn print_batches_to_writer<W: std::io::Write>(
pub fn print_batches<W: std::io::Write>(
&self,
writer: &mut W,
batches: &[RecordBatch],
Expand Down
6 changes: 3 additions & 3 deletions datafusion-cli/src/print_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl PrintOptions {
let mut writer = stdout.lock();

self.format
.print_batches_to_writer(&mut writer, batches, self.maxrows, true)?;
.print_batches(&mut writer, batches, self.maxrows, true)?;

let row_count: usize = batches.iter().map(|b| b.num_rows()).sum();
let timing_info = get_timing_info_str(row_count, self.maxrows, query_start_time);
Expand Down Expand Up @@ -134,9 +134,9 @@ impl PrintOptions {

while let Some(Ok(batch)) = stream.next().await {
row_count += batch.num_rows();
self.format.print_batches_to_writer(
self.format.print_batches(
&mut writer,
&vec![batch],
&[batch],
MaxRows::Unlimited,
with_header,
)?;
Expand Down

0 comments on commit cf26827

Please sign in to comment.