Skip to content

Commit

Permalink
update to 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
XiangpengHao committed Dec 5, 2024
1 parent 06b1646 commit 6b49376
Show file tree
Hide file tree
Showing 9 changed files with 390 additions and 284 deletions.
511 changes: 311 additions & 200 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ console_error_panic_hook = "0.1.7"
datafusion = { version = "42.2.0", default-features = false, features = [
"parquet",
] }
leptos = { version = "0.6.15", features = ["csr", "nightly"] }
leptos = { version = "0.7", features = ["csr", "nightly"] }
parquet = { version = "53.2.0", features = [
"arrow",
"snap",
Expand Down
30 changes: 15 additions & 15 deletions src/file_reader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bytes::Bytes;
use leptos::*;
use leptos::prelude::*;
use leptos::wasm_bindgen::{prelude::Closure, JsCast};
use opendal::{services::S3, Operator};
use wasm_bindgen::{prelude::Closure, JsCast};
use wasm_bindgen_futures::JsFuture;
use web_sys::js_sys;

Expand Down Expand Up @@ -83,19 +83,19 @@ pub fn FileReader(
set_file_name: WriteSignal<String>,
) -> impl IntoView {
let default_url = "https://raw.githubusercontent.com/RobinL/iris_parquet/main/gridwatch/gridwatch_2023-01-08.parquet";
let (url, set_url) = create_signal(default_url.to_string());
let (active_tab, set_active_tab) = create_signal("file".to_string());
let (s3_endpoint, set_s3_endpoint) = create_signal(get_stored_value(
let (url, set_url) = signal(default_url.to_string());
let (active_tab, set_active_tab) = signal("file".to_string());
let (s3_endpoint, set_s3_endpoint) = signal(get_stored_value(
S3_ENDPOINT_KEY,
"https://s3.amazonaws.com",
));
let (s3_access_key_id, set_s3_access_key_id) =
create_signal(get_stored_value(S3_ACCESS_KEY_ID_KEY, ""));
let (s3_secret_key, set_s3_secret_key) = create_signal(get_stored_value(S3_SECRET_KEY_KEY, ""));
let (s3_bucket, set_s3_bucket) = create_signal(get_stored_value(S3_BUCKET_KEY, ""));
let (s3_region, set_s3_region) = create_signal(get_stored_value(S3_REGION_KEY, "us-east-1"));
let (s3_file_path, set_s3_file_path) = create_signal(get_stored_value(S3_FILE_PATH_KEY, ""));
let (is_folded, set_is_folded) = create_signal(false);
signal(get_stored_value(S3_ACCESS_KEY_ID_KEY, ""));
let (s3_secret_key, set_s3_secret_key) = signal(get_stored_value(S3_SECRET_KEY_KEY, ""));
let (s3_bucket, set_s3_bucket) = signal(get_stored_value(S3_BUCKET_KEY, ""));
let (s3_region, set_s3_region) = signal(get_stored_value(S3_REGION_KEY, "us-east-1"));
let (s3_file_path, set_s3_file_path) = signal(get_stored_value(S3_FILE_PATH_KEY, ""));
let (is_folded, set_is_folded) = signal(false);

let set_active_tab = move |tab: &str| {
if active_tab.get() == tab {
Expand Down Expand Up @@ -334,7 +334,7 @@ pub fn FileReader(
</div>
</div>
}
.into_view()
.into_any()
}
"url" => {
view! {
Expand Down Expand Up @@ -366,7 +366,7 @@ pub fn FileReader(
</div>
</div>
}
.into_view()
.into_any()
}
"s3" => {
view! {
Expand Down Expand Up @@ -452,9 +452,9 @@ pub fn FileReader(
</form>
</div>
}
.into_view()
.into_any()
}
_ => view! {}.into_view(),
_ => view! {}.into_any(),
}
}}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/info.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use leptos::*;
use leptos::prelude::*;

#[component]
pub fn InfoSection(parquet_info: super::ParquetInfo) -> impl IntoView {
Expand All @@ -15,7 +15,7 @@ pub fn InfoSection(parquet_info: super::ParquetInfo) -> impl IntoView {
let has_row_group_stats = parquet_info.has_row_group_stats;

// Create a signal for the selected row group
let (selected_row_group, set_selected_row_group) = create_signal(0);
let (selected_row_group, set_selected_row_group) = signal(0);

view! {
<div class="bg-white rounded-lg shadow-md p-6">
Expand Down
84 changes: 39 additions & 45 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::sync::Arc;

use arrow::datatypes::SchemaRef;
use bytes::Bytes;
use leptos::*;
use leptos::prelude::*;
use parquet::{
arrow::parquet_to_arrow_schema,
errors::ParquetError,
Expand Down Expand Up @@ -161,14 +161,20 @@ async fn execute_query_async(

#[component]
fn App() -> impl IntoView {
let (file_content, set_file_content) = create_signal(None::<ParquetInfo>);
let (error_message, set_error_message) = create_signal(Option::<String>::None);
let (file_bytes, set_file_bytes) = create_signal(None::<Bytes>);
let (user_query, set_user_query) = create_signal(String::new());
let (sql_query, set_sql_query) = create_signal(String::new());
let (query_result, set_query_result) = create_signal(Vec::<arrow::array::RecordBatch>::new());
let (file_name, set_file_name) = create_signal(String::from("uploaded"));
let (physical_plan, set_physical_plan) = create_signal(None::<Arc<dyn ExecutionPlan>>);
let (error_message, set_error_message) = signal(Option::<String>::None);
let (file_bytes, set_file_bytes) = signal(None::<Bytes>);
let (user_query, set_user_query) = signal(String::new());
let (sql_query, set_sql_query) = signal(String::new());
let (query_result, set_query_result) = signal(Vec::<arrow::array::RecordBatch>::new());
let (file_name, set_file_name) = signal(String::from("uploaded"));
let (physical_plan, set_physical_plan) = signal(None::<Arc<dyn ExecutionPlan>>);

let file_content = move || {
file_bytes
.get()
.map(|bytes| get_parquet_info(bytes.clone()).ok())
.flatten()
};

let execute_query = move |query: String| {
let bytes_opt = file_bytes.get();
Expand All @@ -181,7 +187,7 @@ fn App() -> impl IntoView {
}

if let Some(bytes) = bytes_opt {
let parquet_info = match file_content.get_untracked() {
let parquet_info = match file_content() {
Some(content) => content,
None => {
set_error_message.set(Some("Failed to get file schema".into()));
Expand All @@ -203,33 +209,21 @@ fn App() -> impl IntoView {
set_error_message.set(Some("No Parquet file loaded.".into()));
}
};

let on_bytes_load =
move |bytes: Bytes, file_content_setter: WriteSignal<Option<ParquetInfo>>| {
let parquet_info = get_parquet_info(bytes.clone());

match parquet_info {
Ok(info) => {
web_sys::console::log_1(&info.to_string().into());
file_content_setter.set(Some(info));
set_file_bytes.set(Some(bytes.clone()));
let default_query =
format!("select * from \"{}\" limit 10", file_name.get_untracked());
set_user_query.set(default_query.clone());
set_sql_query.set(default_query.clone());
execute_query(default_query);
}
Err(_e) => {
file_content_setter.set(None);
}
Effect::watch(
move || file_content(),
move |info, _, _| match info {
Some(info) => {
web_sys::console::log_1(&info.to_string().into());
let default_query =
format!("select * from \"{}\" limit 10", file_name.get_untracked());
set_user_query.set(default_query.clone());
set_sql_query.set(default_query.clone());
execute_query(default_query);
}
};

create_effect(move |_| {
if let Some(bytes) = file_bytes.get() {
on_bytes_load(bytes, set_file_content);
}
});
_ => {}
},
true,
);

view! {
<div class="container mx-auto px-4 py-8 max-w-6xl">
Expand Down Expand Up @@ -284,7 +278,7 @@ fn App() -> impl IntoView {
file_bytes
.get()
.map(|_| {
match file_content.get_untracked() {
match file_content() {
Some(info) => {
if info.row_group_count > 0 {
view! {
Expand All @@ -296,12 +290,12 @@ fn App() -> impl IntoView {
schema=info.schema
error_message=set_error_message
/>
}
}.into_any()
} else {
view! {}.into_view()
view! {}.into_any()
}
}
None => view! {}.into_view(),
None => view! {}.into_any(),
}
})
}}
Expand All @@ -310,7 +304,7 @@ fn App() -> impl IntoView {
{move || {
let result = query_result.get();
if result.is_empty() {
return view! {}.into_view();
return view! {}.into_any();
} else {
let physical_plan = physical_plan.get().unwrap();
view! {
Expand All @@ -321,13 +315,13 @@ fn App() -> impl IntoView {
physical_plan=physical_plan
/>
}
.into_view()
.into_any()
}
}}

<div class="mt-8">
{move || {
let info = file_content.get();
let info = file_content();
match info {
Some(info) => {
view! {
Expand All @@ -340,15 +334,15 @@ fn App() -> impl IntoView {
</div>
</div>
}
.into_view()
.into_any()
}
None => {
view! {
<div class="text-center text-gray-500 py-8">
"No file selected"
</div>
}
.into_view()
.into_any()
}
}
}}
Expand Down
12 changes: 6 additions & 6 deletions src/query_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use datafusion::{
},
prelude::SessionConfig,
};
use leptos::*;
use leptos::prelude::*;
use leptos::wasm_bindgen::{JsCast, JsValue};
use parquet::arrow::arrow_reader::ParquetRecordBatchReaderBuilder;
use serde_json::json;
use wasm_bindgen::{JsCast, JsValue};
use wasm_bindgen_futures::JsFuture;
use web_sys::{js_sys, Headers, Request, RequestInit, RequestMode, Response};

Expand Down Expand Up @@ -89,7 +89,7 @@ pub fn QueryInput(
execute_query: Arc<dyn Fn(String)>,
schema: SchemaRef,
) -> impl IntoView {
let (api_key, set_api_key) = create_signal({
let (api_key, set_api_key) = signal({
let window = web_sys::window().unwrap();
window
.local_storage()
Expand All @@ -100,15 +100,15 @@ pub fn QueryInput(
.unwrap_or_default()
});

create_effect(move |_| {
Effect::new(move |_| {
if let Some(window) = web_sys::window() {
if let Ok(Some(storage)) = window.local_storage() {
let _ = storage.set_item("claude_api_key", &api_key.get());
}
}
});

let (show_settings, set_show_settings) = create_signal(false);
let (show_settings, set_show_settings) = signal(false);

let key_down_schema = schema.clone();
let key_down_exec = execute_query.clone();
Expand Down Expand Up @@ -225,7 +225,7 @@ fn process_user_input(
);
web_sys::console::log_1(&prompt.clone().into());

spawn_local({
wasm_bindgen_futures::spawn_local({
let prompt = prompt.clone();
let api_key = api_key.clone();
async move {
Expand Down
17 changes: 9 additions & 8 deletions src/query_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use datafusion::{
ExecutionPlanVisitor,
},
};
use leptos::*;
use leptos::prelude::*;

#[component]
pub fn QueryResults(
Expand All @@ -19,7 +19,7 @@ pub fn QueryResults(
query_result: Vec<RecordBatch>,
physical_plan: Arc<dyn ExecutionPlan>,
) -> impl IntoView {
let (active_tab, set_active_tab) = create_signal("results".to_string());
let (active_tab, set_active_tab) = signal("results".to_string());

let sql = sql_query.clone();
view! {
Expand Down Expand Up @@ -77,8 +77,8 @@ pub fn QueryResults(
.map(|field| {
view! {
<th class="px-4 py-2 text-left border-b w-48 min-w-48 bg-gray-100">
<div class="truncate" title=field.name()>
{field.name()}
<div class="truncate" title=field.name().clone()>
{field.name().clone()}
</div>
</th>
}
Expand Down Expand Up @@ -106,7 +106,7 @@ pub fn QueryResults(
class="overflow-x-auto whitespace-nowrap"
title=cell_value.clone()
>
{cell_value}
{cell_value.clone()}
</div>
</td>
}
Expand All @@ -120,12 +120,12 @@ pub fn QueryResults(
</table>
</div>
}
.into_view()
.into_any()
}
"physical_plan" => {
view! { <PhysicalPlan physical_plan=physical_plan.clone() /> }.into_view()
view! { <PhysicalPlan physical_plan=physical_plan.clone() /> }.into_any()
}
_ => view! { <p>"Invalid tab"</p> }.into_view(),
_ => view! { <p>"Invalid tab"</p> }.into_any(),
}}
</div>
}
Expand Down Expand Up @@ -343,6 +343,7 @@ fn PlanNode(node: PlanNode) -> impl IntoView {
</div>
</div>
}
.into_any()
}

#[component]
Expand Down
6 changes: 3 additions & 3 deletions src/row_group.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use leptos::*;
use leptos::prelude::*;
use parquet::file::statistics::Statistics;

use crate::format_rows;
Expand Down Expand Up @@ -98,7 +98,7 @@ pub fn RowGroupSection(
selected_row_group: ReadSignal<usize>,
set_selected_row_group: WriteSignal<usize>,
) -> impl IntoView {
let (selected_column, set_selected_column) = create_signal(0);
let (selected_column, set_selected_column) = signal(0);

let parquet_info_clone = parquet_info.clone();
let row_group_info = move || {
Expand Down Expand Up @@ -219,7 +219,7 @@ pub fn RowGroupSection(
.map(|(i, field)| {
view! {
<option value=i.to_string() class="py-2">
{field.name()}
{field.name().clone()}
</option>
}
})
Expand Down
Loading

0 comments on commit 6b49376

Please sign in to comment.