Skip to content

Commit ede5c37

Browse files
Reorg state and cfg some
1 parent 42fbe78 commit ede5c37

10 files changed

Lines changed: 129 additions & 85 deletions

File tree

Cargo.lock

Lines changed: 75 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ version = "0.2.2"
1717
arrow-flight = { version = "54.1.0", features = [
1818
"flight-sql-experimental",
1919
], optional = true }
20+
axum = { version = "0.8.1", optional = true }
2021
clap = { version = "4.5.27", features = ["derive"] }
2122
color-eyre = "0.6.3"
2223
crossterm = { version = "0.28.1", features = ["event-stream"] }
@@ -74,6 +75,7 @@ flightsql = [
7475
]
7576
functions-json = ["datafusion-app/functions-json"]
7677
functions-parquet = ["datafusion-app/functions-parquet"]
78+
http = ["axum"]
7779
hudi = ["datafusion-app/hudi"]
7880
huggingface = ["datafusion-app/huggingface"]
7981
iceberg = ["datafusion-app/iceberg"]

src/args.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ impl DftArgs {
120120

121121
#[derive(Clone, Debug, Subcommand)]
122122
pub enum Command {
123+
/// Start a HTTP server
124+
ServeHttp {
125+
#[clap(short, long)]
126+
config: Option<String>,
127+
},
128+
123129
/// Start a FlightSQL server
124130
ServeFlightSql {
125131
#[clap(short, long)]

src/config.rs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use std::path::PathBuf;
2222
use datafusion_app::config::ExecutionConfig;
2323
use directories::{ProjectDirs, UserDirs};
2424
use lazy_static::lazy_static;
25+
use log::{debug, error};
2526
use serde::Deserialize;
2627

2728
#[cfg(feature = "flightsql")]
@@ -188,28 +189,6 @@ fn default_paste() -> bool {
188189
false
189190
}
190191

191-
// #[cfg(feature = "flightsql")]
192-
// #[derive(Clone, Debug, Deserialize)]
193-
// pub struct FlightSQLConfig {
194-
// #[serde(default = "default_connection_url")]
195-
// pub connection_url: String,
196-
// #[serde(default = "default_benchmark_iterations")]
197-
// pub benchmark_iterations: usize,
198-
// #[serde(default = "default_server_metrics_port")]
199-
// pub server_metrics_port: String,
200-
// }
201-
//
202-
// #[cfg(feature = "flightsql")]
203-
// impl Default for FlightSQLConfig {
204-
// fn default() -> Self {
205-
// Self {
206-
// connection_url: default_connection_url(),
207-
// benchmark_iterations: default_benchmark_iterations(),
208-
// server_metrics_port: default_server_metrics_port(),
209-
// }
210-
// }
211-
// }
212-
213192
#[cfg(feature = "flightsql")]
214193
pub fn default_connection_url() -> String {
215194
"http://localhost:50051".to_string()
@@ -233,3 +212,29 @@ fn default_editor_config() -> EditorConfig {
233212
fn default_auth_config() -> AuthConfig {
234213
AuthConfig::default()
235214
}
215+
216+
pub fn create_config(config_path: PathBuf) -> AppConfig {
217+
if config_path.exists() {
218+
debug!("Config exists");
219+
let maybe_config_contents = std::fs::read_to_string(config_path);
220+
if let Ok(config_contents) = maybe_config_contents {
221+
let maybe_parsed_config: std::result::Result<AppConfig, toml::de::Error> =
222+
toml::from_str(&config_contents);
223+
match maybe_parsed_config {
224+
Ok(parsed_config) => {
225+
debug!("Parsed config: {:?}", parsed_config);
226+
parsed_config
227+
}
228+
Err(err) => {
229+
error!("Error parsing config: {:?}", err);
230+
AppConfig::default()
231+
}
232+
}
233+
} else {
234+
AppConfig::default()
235+
}
236+
} else {
237+
debug!("No config, using default");
238+
AppConfig::default()
239+
}
240+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,5 @@ impl FlightSqlApp {
195195
}
196196
}
197197
}
198+
199+
// pub fn run_flightsql_server(state: AppState) {}
File renamed without changes.

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub mod cli;
33
pub mod config;
44
pub mod execution;
55
#[cfg(feature = "flightsql")]
6-
pub mod server;
6+
pub mod flightsql_server;
77
pub mod telemetry;
88
pub mod test_utils;
99
pub mod tui;

src/main.rs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,15 @@ use color_eyre::Result;
2020
use datafusion_app::local::ExecutionContext;
2121
use datafusion_app::{config::merge_configs, extensions::DftSessionStateBuilder};
2222
use datafusion_dft::args::Command;
23+
use datafusion_dft::tui::state::AppState;
2324
use datafusion_dft::{
24-
args::DftArgs,
25-
cli::CliApp,
26-
execution::AppExecution,
27-
telemetry,
28-
tui::{state, App},
25+
args::DftArgs, cli::CliApp, config::create_config, execution::AppExecution, telemetry, tui::App,
2926
};
3027
#[cfg(feature = "flightsql")]
3128
use {
3229
datafusion_app::config::{AuthConfig, FlightSQLConfig},
3330
datafusion_app::flightsql::FlightSQLContext,
34-
datafusion_dft::server::FlightSqlApp,
31+
datafusion_dft::flightsql_server::FlightSqlApp,
3532
log::info,
3633
};
3734

@@ -66,44 +63,37 @@ async fn app_entry_point(cli: DftArgs) -> Result<()> {
6663
if should_init_env_logger(&cli) {
6764
env_logger::init();
6865
}
69-
let state = state::initialize(cli.config_path());
66+
let cfg = create_config(cli.config_path());
7067
#[cfg(feature = "flightsql")]
7168
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-
);
69+
let merged_exec_config =
70+
merge_configs(cfg.shared.clone(), cfg.flightsql_server.execution.clone());
7671
let session_state_builder =
7772
DftSessionStateBuilder::try_new(Some(merged_exec_config.clone()))?
7873
.with_extensions()
7974
.await?;
8075
// FlightSQL Server mode: start a FlightSQL server
8176
const DEFAULT_SERVER_ADDRESS: &str = "127.0.0.1:50051";
8277
info!("Starting FlightSQL server on {}", DEFAULT_SERVER_ADDRESS);
83-
let session_state = session_state_builder
84-
// .with_app_type(AppType::FlightSQLServer)
85-
.build()?;
78+
let session_state = session_state_builder.build()?;
8679
let execution_ctx = ExecutionContext::try_new(&merged_exec_config, session_state)?;
8780
if cli.run_ddl {
8881
execution_ctx.execute_ddl().await;
8982
}
9083
let app_execution = AppExecution::new(execution_ctx);
9184
let app = FlightSqlApp::try_new(
9285
app_execution,
93-
&state.config,
86+
&cfg,
9487
&cli.flightsql_host
9588
.unwrap_or(DEFAULT_SERVER_ADDRESS.to_string()),
96-
&state.config.flightsql_server.server_metrics_port,
89+
&cfg.flightsql_server.server_metrics_port,
9790
)
9891
.await?;
9992
app.run_app().await;
10093
return Ok(());
10194
}
10295
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-
);
96+
let merged_exec_config = merge_configs(cfg.shared.clone(), cfg.cli.execution.clone());
10797
let session_state_builder =
10898
DftSessionStateBuilder::try_new(Some(merged_exec_config.clone()))?
10999
.with_extensions()
@@ -118,12 +108,12 @@ async fn app_entry_point(cli: DftArgs) -> Result<()> {
118108
{
119109
if cli.flightsql {
120110
let auth = AuthConfig {
121-
basic_auth: state.config.flightsql_client.auth.basic_auth,
122-
bearer_token: state.config.flightsql_client.auth.bearer_token,
111+
basic_auth: cfg.flightsql_client.auth.basic_auth,
112+
bearer_token: cfg.flightsql_client.auth.bearer_token,
123113
};
124114
let flightsql_cfg = FlightSQLConfig::new(
125-
state.config.flightsql_client.connection_url,
126-
state.config.flightsql_client.benchmark_iterations,
115+
cfg.flightsql_client.connection_url,
116+
cfg.flightsql_client.benchmark_iterations,
127117
auth,
128118
);
129119
let flightsql_ctx = FlightSQLContext::new(flightsql_cfg);
@@ -136,10 +126,7 @@ async fn app_entry_point(cli: DftArgs) -> Result<()> {
136126
let app = CliApp::new(app_execution, cli.clone());
137127
app.execute_files_or_commands().await?;
138128
} else {
139-
let merged_exec_config = merge_configs(
140-
state.config.shared.clone(),
141-
state.config.tui.execution.clone(),
142-
);
129+
let merged_exec_config = merge_configs(cfg.shared.clone(), cfg.tui.execution.clone());
143130
let session_state_builder =
144131
DftSessionStateBuilder::try_new(Some(merged_exec_config.clone()))?
145132
.with_extensions()
@@ -148,7 +135,7 @@ async fn app_entry_point(cli: DftArgs) -> Result<()> {
148135

149136
// TUI mode: running the TUI
150137
telemetry::initialize_logs()?; // use alternate logging for TUI
151-
let state = state::initialize(cli.config_path());
138+
let state = AppState::new(cfg);
152139
let execution_ctx = ExecutionContext::try_new(&merged_exec_config, session_state)?;
153140
let app_execution = AppExecution::new(execution_ctx);
154141
let app = App::new(state, cli, app_execution);

0 commit comments

Comments
 (0)