Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmturner committed Aug 27, 2024
1 parent 5dbc36f commit 8e48c70
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 37 deletions.
30 changes: 2 additions & 28 deletions src/app/handlers/flightsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
use std::sync::Arc;
use std::time::{Duration, Instant};

use color_eyre::eyre::eyre;
use datafusion::arrow::array::RecordBatch;
use log::{error, info};
use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use ratatui::crossterm::event::{KeyCode, KeyEvent};
use tokio_stream::StreamExt;
use tonic::IntoRequest;

Expand Down Expand Up @@ -76,7 +75,7 @@ pub fn normal_mode_handler(app: &mut App, key: KeyEvent) {
tokio::spawn(async move {
let mut query =
FlightSQLQuery::new(sql.clone(), None, None, None, Duration::default());
let start = std::time::Instant::now();
let start = Instant::now();
if let Some(ref mut c) = *client.lock().await {
info!("Sending query");
let flight_info = c.execute(sql, None).await.unwrap();
Expand Down Expand Up @@ -120,31 +119,6 @@ pub fn normal_mode_handler(app: &mut App, key: KeyEvent) {
}

let _ = _event_tx.send(AppEvent::FlightSQLQueryResult(query));

// match ctx.sql(&sql).await {
// Ok(df) => match df.collect().await {
// Ok(res) => {
// let elapsed = start.elapsed();
// let rows: usize = res.iter().map(|r| r.num_rows()).sum();
// query.set_results(Some(res));
// query.set_num_rows(Some(rows));
// query.set_elapsed_time(elapsed);
// }
// Err(e) => {
// error!("Error collecting results: {:?}", e);
// let elapsed = start.elapsed();
// query.set_error(Some(e.to_string()));
// query.set_elapsed_time(elapsed);
// }
// },
// Err(e) => {
// error!("Error creating dataframe: {:?}", e);
// let elapsed = start.elapsed();
// query.set_error(Some(e.to_string()));
// query.set_elapsed_time(elapsed);
// }
// }
// let _ = _event_tx.send(AppEvent::QueryResult(query));
});
}
_ => {}
Expand Down
25 changes: 17 additions & 8 deletions src/app/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ fn context_tab_key_event_handler(_app: &mut App, _key: KeyEvent) {}
fn logs_tab_app_event_handler(app: &mut App, event: AppEvent) {
match event {
AppEvent::Key(key) => logs_tab_key_event_handler(app, key),
AppEvent::QueryResult(r) => {
app.state.sql_tab.set_query(r);
app.state.sql_tab.refresh_query_results_state();
}
// AppEvent::QueryResult(r) => {
// app.state.sql_tab.set_query(r);
// app.state.sql_tab.refresh_query_results_state();
// }
AppEvent::Tick => {}
AppEvent::Error => {}
_ => {}
Expand All @@ -120,10 +120,10 @@ fn logs_tab_app_event_handler(app: &mut App, event: AppEvent) {
fn context_tab_app_event_handler(app: &mut App, event: AppEvent) {
match event {
AppEvent::Key(key) => context_tab_key_event_handler(app, key),
AppEvent::QueryResult(r) => {
app.state.sql_tab.set_query(r);
app.state.sql_tab.refresh_query_results_state();
}
// AppEvent::QueryResult(r) => {
// app.state.sql_tab.set_query(r);
// app.state.sql_tab.refresh_query_results_state();
// }
AppEvent::Tick => {}
AppEvent::Error => {}
_ => {}
Expand Down Expand Up @@ -163,6 +163,15 @@ pub fn app_event_handler(app: &mut App, event: AppEvent) -> Result<()> {
});
})
}
AppEvent::QueryResult(r) => {
app.state.sql_tab.set_query(r);
app.state.sql_tab.refresh_query_results_state();
}
#[cfg(feature = "flightsql")]
AppEvent::FlightSQLQueryResult(r) => {
app.state.flightsql_tab.set_query(r);
app.state.flightsql_tab.refresh_query_results_state();
}
#[cfg(feature = "flightsql")]
AppEvent::EstablishFlightSQLConnection => {
let url = app.state.config.flightsql.connection_url.clone();
Expand Down
3 changes: 2 additions & 1 deletion src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ impl<'app> App<'app> {

#[cfg(feature = "flightsql")]
pub fn establish_flightsql_connection(&self) {
self.app_event_tx
let _ = self
.app_event_tx
.send(AppEvent::EstablishFlightSQLConnection);
}

Expand Down

0 comments on commit 8e48c70

Please sign in to comment.