Skip to content

Commit

Permalink
make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
XiangpengHao committed Dec 14, 2024
1 parent bceb223 commit 992cb26
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 40 deletions.
8 changes: 4 additions & 4 deletions src/file_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ pub fn FileReader(
match active_tab.get().as_str() {
"file" => {
view! {
<div class=move || format!("{}", transition_class)>
<div class=move || transition_class.to_string()>
<div class="border-2 border-dashed border-gray-300 rounded-lg p-6 text-center space-y-4">
<div>
<input
Expand All @@ -288,7 +288,7 @@ pub fn FileReader(
}
"url" => {
view! {
<div class=move || format!("{}", transition_class)>
<div class=move || transition_class.to_string()>
<div class="h-full flex items-center">
<form on:submit=on_url_submit class="w-full">
<div class="flex space-x-2">
Expand Down Expand Up @@ -320,7 +320,7 @@ pub fn FileReader(
}
"s3" => {
view! {
<div class=move || format!("{}", transition_class)>
<div class=move || transition_class.to_string()>
<form on:submit=on_s3_submit class="space-y-4 w-full">
<div class="flex flex-wrap gap-4">
<div class="flex-1 min-w-[250px]">
Expand Down Expand Up @@ -370,7 +370,7 @@ pub fn FileReader(
}
.into_any()
}
_ => view! {}.into_any(),
_ => ().into_any(),
}
}}
</div>
Expand Down
32 changes: 18 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand All @@ -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");
Expand All @@ -265,15 +270,15 @@ 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| {
info.last_message_time = Some(use_timestamp()());
info.display_time.set("0s ago".to_string());
});

let message = serde_json::from_str::<WebSocketMessage>(&message).unwrap();
let message = serde_json::from_str::<WebSocketMessage>(message).unwrap();
match message {
WebSocketMessage::Sql { query } => {
// Send acknowledgment
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -504,10 +508,10 @@ fn App() -> impl IntoView {
}
.into_any()
} else {
view! {}.into_any()
().into_any()
}
}
None => view! {}.into_any(),
None => ().into_any(),
}
})
}}
Expand All @@ -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! {
Expand Down
6 changes: 3 additions & 3 deletions src/query_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -211,7 +211,7 @@ async fn generate_sql_via_claude(prompt: &str, api_key: &str) -> Result<String,
.set("anthropic-version", "2023-06-01")
.map_err(|e| format!("Failed to set Anthropic version: {:?}", e))?;
headers
.set("x-api-key", &api_key)
.set("x-api-key", api_key)
.map_err(|e| format!("Failed to set API key: {:?}", e))?;
headers
.set("anthropic-dangerous-direct-browser-access", "true")
Expand All @@ -224,7 +224,7 @@ async fn generate_sql_via_claude(prompt: &str, api_key: &str) -> Result<String,
opts.set_body(&JsValue::from_str(&body));

// Create Request
let request = Request::new_with_str_and_init(&url, &opts)
let request = Request::new_with_str_and_init(url, &opts)
.map_err(|e| format!("Request creation failed: {:?}", e))?;

// Send the request
Expand Down
6 changes: 3 additions & 3 deletions src/query_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use parquet::arrow::ArrowWriter;
use web_sys::js_sys;
use web_sys::wasm_bindgen::JsCast;

fn export_to_csv_inner(query_result: &Vec<RecordBatch>) {
fn export_to_csv_inner(query_result: &[RecordBatch]) {
let mut csv_data = String::new();
let headers: Vec<String> = query_result[0]
.schema()
Expand Down Expand Up @@ -53,7 +53,7 @@ fn export_to_csv_inner(query_result: &Vec<RecordBatch>) {
web_sys::Url::revoke_object_url(&url).unwrap();
}

fn export_to_parquet_inner(query_result: &Vec<RecordBatch>) {
fn export_to_parquet_inner(query_result: &[RecordBatch]) {
// Create an in-memory buffer to write the parquet data
let mut buf = Vec::new();

Expand Down Expand Up @@ -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)
}
Expand Down
36 changes: 22 additions & 14 deletions src/row_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,37 @@ fn stats_to_string(stats: Option<Statistics>) -> 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() {
Expand Down
3 changes: 1 addition & 2 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
];
Expand Down

0 comments on commit 992cb26

Please sign in to comment.