(
&self,
ctx: &dyn CliSessionContext,
print_options: &mut PrintOptions,
)
| 55 | |
| 56 | impl Command { |
| 57 | pub async fn execute( |
| 58 | &self, |
| 59 | ctx: &dyn CliSessionContext, |
| 60 | print_options: &mut PrintOptions, |
| 61 | ) -> Result<()> { |
| 62 | match self { |
| 63 | Self::Help => { |
| 64 | let now = Instant::now(); |
| 65 | let command_batch = all_commands_info(); |
| 66 | let schema = command_batch.schema(); |
| 67 | let num_rows = command_batch.num_rows(); |
| 68 | let task_ctx = ctx.task_ctx(); |
| 69 | let config = &task_ctx.session_config().options().format; |
| 70 | print_options.print_batches( |
| 71 | schema, |
| 72 | &[command_batch], |
| 73 | now, |
| 74 | num_rows, |
| 75 | config, |
| 76 | ) |
| 77 | } |
| 78 | Self::ListTables => { |
| 79 | exec_and_print(ctx, print_options, "SHOW TABLES".into()).await |
| 80 | } |
| 81 | Self::DescribeTableStmt(name) => { |
| 82 | exec_and_print(ctx, print_options, format!("SHOW COLUMNS FROM {name}")) |
| 83 | .await |
| 84 | } |
| 85 | Self::Include(filename) => { |
| 86 | if let Some(filename) = filename { |
| 87 | let file = File::open(filename).map_err(|e| { |
| 88 | exec_datafusion_err!("Error opening {filename:?} {e}") |
| 89 | })?; |
| 90 | exec_from_lines(ctx, &mut BufReader::new(file), print_options) |
| 91 | .await?; |
| 92 | Ok(()) |
| 93 | } else { |
| 94 | exec_err!("Required filename argument is missing") |
| 95 | } |
| 96 | } |
| 97 | Self::QuietMode(quiet) => { |
| 98 | if let Some(quiet) = quiet { |
| 99 | print_options.quiet = *quiet; |
| 100 | println!( |
| 101 | "Quiet mode set to {}", |
| 102 | if print_options.quiet { "true" } else { "false" } |
| 103 | ); |
| 104 | } else { |
| 105 | println!( |
| 106 | "Quiet mode is {}", |
| 107 | if print_options.quiet { "true" } else { "false" } |
| 108 | ); |
| 109 | } |
| 110 | Ok(()) |
| 111 | } |
| 112 | Self::Quit => exec_err!("Unexpected quit, this should be handled outside"), |
| 113 | Self::ListFunctions => display_all_functions(), |
| 114 | Self::SearchFunctions(function) => { |
no test coverage detected