|
17 | 17 |
|
18 | 18 | use clap::Parser; |
19 | 19 | use color_eyre::Result; |
20 | | -use datafusion_app::local::ExecutionContext; |
21 | | -use datafusion_app::{config::merge_configs, extensions::DftSessionStateBuilder}; |
22 | 20 | use datafusion_dft::args::Command; |
23 | | -use datafusion_dft::tui::state::AppState; |
24 | | -use datafusion_dft::{ |
25 | | - args::DftArgs, cli::CliApp, config::create_config, execution::AppExecution, telemetry, tui::App, |
26 | | -}; |
27 | | -#[cfg(feature = "flightsql")] |
28 | | -use { |
29 | | - datafusion_app::config::{AuthConfig, FlightSQLConfig}, |
30 | | - datafusion_app::flightsql::FlightSQLContext, |
31 | | - datafusion_dft::flightsql_server::FlightSqlApp, |
32 | | - log::info, |
33 | | -}; |
| 21 | +use datafusion_dft::{args::DftArgs, cli, config::create_config, flightsql_server, tui}; |
34 | 22 |
|
35 | 23 | fn main() -> Result<()> { |
36 | 24 | let cli = DftArgs::parse(); |
@@ -64,82 +52,15 @@ async fn app_entry_point(cli: DftArgs) -> Result<()> { |
64 | 52 | env_logger::init(); |
65 | 53 | } |
66 | 54 | let cfg = create_config(cli.config_path()); |
| 55 | + |
67 | 56 | #[cfg(feature = "flightsql")] |
68 | 57 | if let Some(Command::ServeFlightSql { .. }) = cli.command { |
69 | | - let merged_exec_config = |
70 | | - merge_configs(cfg.shared.clone(), cfg.flightsql_server.execution.clone()); |
71 | | - let session_state_builder = |
72 | | - DftSessionStateBuilder::try_new(Some(merged_exec_config.clone()))? |
73 | | - .with_extensions() |
74 | | - .await?; |
75 | | - // FlightSQL Server mode: start a FlightSQL server |
76 | | - const DEFAULT_SERVER_ADDRESS: &str = "127.0.0.1:50051"; |
77 | | - info!("Starting FlightSQL server on {}", DEFAULT_SERVER_ADDRESS); |
78 | | - let session_state = session_state_builder.build()?; |
79 | | - let execution_ctx = ExecutionContext::try_new(&merged_exec_config, session_state)?; |
80 | | - if cli.run_ddl { |
81 | | - execution_ctx.execute_ddl().await; |
82 | | - } |
83 | | - let app_execution = AppExecution::new(execution_ctx); |
84 | | - let app = FlightSqlApp::try_new( |
85 | | - app_execution, |
86 | | - &cfg, |
87 | | - &cli.flightsql_host |
88 | | - .unwrap_or(DEFAULT_SERVER_ADDRESS.to_string()), |
89 | | - &cfg.flightsql_server.server_metrics_port, |
90 | | - ) |
91 | | - .await?; |
92 | | - app.run_app().await; |
93 | | - return Ok(()); |
| 58 | + flightsql_server::try_run(cli.clone(), cfg.clone()).await?; |
94 | 59 | } |
95 | 60 | if !cli.files.is_empty() || !cli.commands.is_empty() { |
96 | | - let merged_exec_config = merge_configs(cfg.shared.clone(), cfg.cli.execution.clone()); |
97 | | - let session_state_builder = |
98 | | - DftSessionStateBuilder::try_new(Some(merged_exec_config.clone()))? |
99 | | - .with_extensions() |
100 | | - .await?; |
101 | | - |
102 | | - // CLI mode: executing commands from files or CLI arguments |
103 | | - let session_state = session_state_builder.build()?; |
104 | | - let execution_ctx = ExecutionContext::try_new(&merged_exec_config, session_state)?; |
105 | | - #[allow(unused_mut)] |
106 | | - let mut app_execution = AppExecution::new(execution_ctx); |
107 | | - #[cfg(feature = "flightsql")] |
108 | | - { |
109 | | - if cli.flightsql { |
110 | | - let auth = AuthConfig { |
111 | | - basic_auth: cfg.flightsql_client.auth.basic_auth, |
112 | | - bearer_token: cfg.flightsql_client.auth.bearer_token, |
113 | | - }; |
114 | | - let flightsql_cfg = FlightSQLConfig::new( |
115 | | - cfg.flightsql_client.connection_url, |
116 | | - cfg.flightsql_client.benchmark_iterations, |
117 | | - auth, |
118 | | - ); |
119 | | - let flightsql_ctx = FlightSQLContext::new(flightsql_cfg); |
120 | | - flightsql_ctx |
121 | | - .create_client(cli.flightsql_host.clone()) |
122 | | - .await?; |
123 | | - app_execution.with_flightsql_ctx(flightsql_ctx); |
124 | | - } |
125 | | - } |
126 | | - let app = CliApp::new(app_execution, cli.clone()); |
127 | | - app.execute_files_or_commands().await?; |
| 61 | + cli::try_run(cli, cfg).await?; |
128 | 62 | } else { |
129 | | - let merged_exec_config = merge_configs(cfg.shared.clone(), cfg.tui.execution.clone()); |
130 | | - let session_state_builder = |
131 | | - DftSessionStateBuilder::try_new(Some(merged_exec_config.clone()))? |
132 | | - .with_extensions() |
133 | | - .await?; |
134 | | - let session_state = session_state_builder.build()?; |
135 | | - |
136 | | - // TUI mode: running the TUI |
137 | | - telemetry::initialize_logs()?; // use alternate logging for TUI |
138 | | - let state = AppState::new(cfg); |
139 | | - let execution_ctx = ExecutionContext::try_new(&merged_exec_config, session_state)?; |
140 | | - let app_execution = AppExecution::new(execution_ctx); |
141 | | - let app = App::new(state, cli, app_execution); |
142 | | - app.run_app().await?; |
| 63 | + tui::try_run(cli, cfg).await?; |
143 | 64 | } |
144 | 65 |
|
145 | 66 | Ok(()) |
|
0 commit comments