From 2081129c8406d48c1120ee5647611f0392fd148a Mon Sep 17 00:00:00 2001 From: Xiangpeng Hao Date: Thu, 26 Dec 2024 21:51:24 -0600 Subject: [PATCH] allow multiple queries --- index.html | 17 ++++ src/main.rs | 38 +++++---- src/query_input.rs | 2 +- src/query_results.rs | 199 +++++++++++++++++++++---------------------- 4 files changed, 139 insertions(+), 117 deletions(-) diff --git a/index.html b/index.html index f82f61f..f1cec4b 100644 --- a/index.html +++ b/index.html @@ -37,6 +37,23 @@ + diff --git a/src/main.rs b/src/main.rs index 33eed24..ad86c68 100644 --- a/src/main.rs +++ b/src/main.rs @@ -316,7 +316,13 @@ fn App() -> impl IntoView { } } set_query_results.update(|r| { - r.push(QueryResult::new(query, Arc::new(results), physical_plan)); + let id = r.len(); + r.push(QueryResult::new( + id, + query, + Arc::new(results), + physical_plan, + )); }); } Err(e) => set_error_message.set(Some(e)), @@ -374,7 +380,6 @@ fn App() -> impl IntoView { set_parquet_table=set_parquet_table /> -
{move || { error_message @@ -423,20 +428,21 @@ fn App() -> impl IntoView { }} - {move || { - view! { -
- {query_results - .get() - .into_iter() - .rev() - .map(|result| { - view! { } - }) - .collect_view()} -
- } - }} +
+ + +
+ } + } + /> + + +
{move || { diff --git a/src/query_input.rs b/src/query_input.rs index ce8157d..890453a 100644 --- a/src/query_input.rs +++ b/src/query_input.rs @@ -126,7 +126,7 @@ pub fn QueryInput( />
- "Query starts with 'SELECT' run as SQL, otherwise it is a question to be answered by AI generated SQL" + "Query begins with 'SELECT' runs as SQL, otherwise it is a question to be answered by AI generated SQL"
diff --git a/src/query_results.rs b/src/query_results.rs index ff8f013..e272bcc 100644 --- a/src/query_results.rs +++ b/src/query_results.rs @@ -100,6 +100,7 @@ pub(crate) fn export_to_parquet_inner(query_result: &[RecordBatch]) { #[derive(Debug, Clone)] pub(crate) struct QueryResult { + id: usize, sql_query: String, query_result: Arc>, physical_plan: Arc, @@ -107,31 +108,35 @@ pub(crate) struct QueryResult { impl QueryResult { pub fn new( + id: usize, sql_query: String, query_result: Arc>, physical_plan: Arc, ) -> Self { Self { + id, sql_query, query_result, physical_plan, } } + + pub(crate) fn id(&self) -> usize { + self.id + } } #[component] pub fn QueryResultView(result: QueryResult) -> impl IntoView { - let (active_tab, set_active_tab) = signal("results".to_string()); - + let (show_plan, set_show_plan) = signal(false); let query_result_clone1 = result.query_result.clone(); let query_result_clone2 = result.query_result.clone(); - let sql = result.sql_query.clone(); view! { -
+
-
+
{sql.clone()}
@@ -220,110 +225,104 @@ pub fn QueryResultView(result: QueryResult) -> impl IntoView { /> +
-
- - -
+ {move || { + show_plan() + .then(|| { + view! { +
+ +
+ } + }) + }} + + // Always show query results +
+ + + + {result + .query_result[0] + .schema() + .fields() + .iter() + .map(|field| { + view! { + + } + }) + .collect::>()} + + + + {(0..result.query_result[0].num_rows()) + .map(|row_idx| { + view! { + + {(0..result.query_result[0].num_columns()) + .map(|col_idx| { + let column = result.query_result[0].column(col_idx); + let cell_value = if column.is_null(row_idx) { + "NULL".to_string() + } else { + column.as_ref().value_to_string(row_idx) + }; - {move || match active_tab().as_str() { - "results" => { - view! { -
-
+
+ {field.name().clone()} +
+
+ {field.data_type().to_string()} +
+
- - - {result - .query_result[0] - .schema() - .fields() - .iter() - .map(|field| { view! { - + } }) .collect::>()} - - - {(0..result.query_result[0].num_rows()) - .map(|row_idx| { - view! { - - {(0..result.query_result[0].num_columns()) - .map(|col_idx| { - let column = result.query_result[0].column(col_idx); - let cell_value = if column.is_null(row_idx) { - "NULL".to_string() - } else { - column.as_ref().value_to_string(row_idx) - }; - - view! { - - } - }) - .collect::>()} - - } - }) - .collect::>()} - -
-
- {field.name().clone()} -
-
- {field.data_type().to_string()} -
-
+
{cell_value.clone()}
+
-
{cell_value.clone()}
-
-
- } - .into_any() - } - "physical_plan" => { - view! { }.into_any() - } - _ => view! {

"Invalid tab"

}.into_any(), - }} + } + }) + .collect::>()} + + +
} }