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