diff --git a/src/file_reader.rs b/src/file_reader.rs index f6901be..50163fd 100644 --- a/src/file_reader.rs +++ b/src/file_reader.rs @@ -263,7 +263,7 @@ pub fn FileReader( match active_tab.get().as_str() { "file" => { view! { -
+
{ view! { -
+
@@ -320,7 +320,7 @@ pub fn FileReader( } "s3" => { view! { -
+
@@ -370,7 +370,7 @@ pub fn FileReader( } .into_any() } - _ => view! {}.into_any(), + _ => ().into_any(), } }}
diff --git a/src/main.rs b/src/main.rs index 6696532..5826c02 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,7 +71,7 @@ impl ParquetInfo { metadata.file_metadata().key_value_metadata(), )?; let first_row_group = metadata.row_groups().first(); - let first_column = first_row_group.map(|rg| rg.columns().first()).flatten(); + let first_column = first_row_group.and_then(|rg| rg.columns().first()); Ok(Self { file_size: compressed_size, @@ -228,6 +228,12 @@ impl ConnectionInfo { } } +impl Default for ConnectionInfo { + fn default() -> Self { + Self::new() + } +} + impl Display for ConnectionInfo { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.display_time.get()) @@ -250,8 +256,7 @@ fn App() -> impl IntoView { let parquet_info = Memo::new(move |_| { file_bytes .get() - .map(|bytes| get_parquet_info(bytes.clone()).ok()) - .flatten() + .and_then(|bytes| get_parquet_info(bytes.clone()).ok()) }); let ws_url = get_stored_value(WS_ENDPOINT_KEY, "ws://localhost:12306"); @@ -265,7 +270,7 @@ fn App() -> impl IntoView { let send = Arc::new(send); Effect::watch( - move || message.get(), + message, move |message, _, _| { if let Some(message) = message { set_connection_info.update(|info| { @@ -273,7 +278,7 @@ fn App() -> impl IntoView { info.display_time.set("0s ago".to_string()); }); - let message = serde_json::from_str::(&message).unwrap(); + let message = serde_json::from_str::(message).unwrap(); match message { WebSocketMessage::Sql { query } => { // Send acknowledgment @@ -321,21 +326,20 @@ fn App() -> impl IntoView { ); Effect::watch( - move || parquet_info(), - move |info, _, _| match info { - Some(info) => { + parquet_info, + move |info, _, _| { + if let Some(info) = info { logging::log!("{}", info.to_string()); let default_query = format!("select * from \"{}\" limit 10", file_name.get_untracked()); set_user_input.set(default_query); } - _ => {} }, true, ); Effect::watch( - move || user_input.get(), + user_input, move |user_input, _, _| { let user_input = user_input.clone(); let api_key = api_key.clone(); @@ -366,7 +370,7 @@ fn App() -> impl IntoView { ); Effect::watch( - move || sql_query.get(), + sql_query, move |query, _, _| { let bytes_opt = file_bytes.get(); let table_name = file_name.get(); @@ -504,10 +508,10 @@ fn App() -> impl IntoView { } .into_any() } else { - view! {}.into_any() + ().into_any() } } - None => view! {}.into_any(), + None => ().into_any(), } }) }} @@ -516,7 +520,7 @@ fn App() -> impl IntoView { {move || { let result = query_result.get(); if result.is_empty() { - return view! {}.into_any(); + ().into_any() } else { let physical_plan = physical_plan.get().unwrap(); view! { diff --git a/src/query_input.rs b/src/query_input.rs index 0258cb3..29537c6 100644 --- a/src/query_input.rs +++ b/src/query_input.rs @@ -66,7 +66,7 @@ pub(crate) async fn execute_query_inner( ctx.register_table(table_name, Arc::new(streaming_table))?; - let plan = ctx.sql(&query).await?; + let plan = ctx.sql(query).await?; let (state, plan) = plan.into_parts(); let plan = state.optimize(&plan)?; @@ -211,7 +211,7 @@ async fn generate_sql_via_claude(prompt: &str, api_key: &str) -> Result Result) { +fn export_to_csv_inner(query_result: &[RecordBatch]) { let mut csv_data = String::new(); let headers: Vec = query_result[0] .schema() @@ -53,7 +53,7 @@ fn export_to_csv_inner(query_result: &Vec) { web_sys::Url::revoke_object_url(&url).unwrap(); } -fn export_to_parquet_inner(query_result: &Vec) { +fn export_to_parquet_inner(query_result: &[RecordBatch]) { // Create an in-memory buffer to write the parquet data let mut buf = Vec::new(); @@ -361,7 +361,7 @@ struct DisplayPlan<'a> { plan: &'a dyn ExecutionPlan, } -impl<'a> std::fmt::Display for DisplayPlan<'a> { +impl std::fmt::Display for DisplayPlan<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.plan.fmt_as(DisplayFormatType::Default, f) } diff --git a/src/row_group.rs b/src/row_group.rs index a49f61f..aac11f1 100644 --- a/src/row_group.rs +++ b/src/row_group.rs @@ -57,29 +57,37 @@ fn stats_to_string(stats: Option) -> String { } } Statistics::ByteArray(s) => { - s.min_opt() - .and_then(|min| min.as_utf8().ok()) - .map(|min_utf8| parts.push(format!("min: {:?}", min_utf8))); - s.max_opt() - .and_then(|max| max.as_utf8().ok()) - .map(|max_utf8| parts.push(format!("max: {:?}", max_utf8))); + if let Some(min) = s.min_opt() { + if let Ok(min_utf8) = min.as_utf8() { + parts.push(format!("min: {:?}", min_utf8)); + } + } + if let Some(max) = s.max_opt() { + if let Ok(max_utf8) = max.as_utf8() { + parts.push(format!("max: {:?}", max_utf8)); + } + } } Statistics::FixedLenByteArray(s) => { - s.min_opt() - .and_then(|min| min.as_utf8().ok()) - .map(|min_utf8| parts.push(format!("min: {:?}", min_utf8))); - s.max_opt() - .and_then(|max| max.as_utf8().ok()) - .map(|max_utf8| parts.push(format!("max: {:?}", max_utf8))); + if let Some(min) = s.min_opt() { + if let Ok(min_utf8) = min.as_utf8() { + parts.push(format!("min: {:?}", min_utf8)); + } + } + if let Some(max) = s.max_opt() { + if let Ok(max_utf8) = max.as_utf8() { + parts.push(format!("max: {:?}", max_utf8)); + } + } } } if let Some(null_count) = stats.null_count_opt() { - parts.push(format!("nulls: {}", format_rows(null_count as u64))); + parts.push(format!("nulls: {}", format_rows(null_count))); } if let Some(distinct_count) = stats.distinct_count_opt() { - parts.push(format!("distinct: {}", format_rows(distinct_count as u64))); + parts.push(format!("distinct: {}", format_rows(distinct_count))); } if parts.is_empty() { diff --git a/src/schema.rs b/src/schema.rs index 25fbc7a..2c52079 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -31,8 +31,7 @@ pub fn SchemaSection(parquet_info: super::ParquetInfo) -> impl IntoView { metadata .row_groups() .first() - .map(|rg| rg.columns().first().map(|c| c.compression())) - .flatten(), + .and_then(|rg| rg.columns().first().map(|c| c.compression())) ); schema.fields.len() ];