Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/view/providers/backups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl ViewProvider for BackupsViewProvider {
columns,
columns_to_compare: vec!["name"],
on_submit: Some(backups_logs_callback),
settings: HashMap::new(),
settings: HashMap::<&str, i32>::new(),
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/view/providers/dictionaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl ViewProvider for DictionariesViewProvider {
columns,
columns_to_compare: vec!["name"],
on_submit: Some(super::query_result_show_row),
settings: HashMap::new(),
settings: HashMap::<&str, i32>::new(),
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/view/providers/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl ViewProvider for ErrorsViewProvider {
columns,
columns_to_compare: vec!["name"],
on_submit: Some(errors_logs_callback),
settings: HashMap::from([("allow_introspection_functions", "1")]),
settings: HashMap::from([("allow_introspection_functions", 1)]),
},
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/view/providers/merges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ impl ViewProvider for MergesViewProvider {
columns,
columns_to_compare: vec!["database", "table", "part"],
on_submit: Some(merges_logs_callback),
settings: HashMap::new(),
// On 25.8 it fails with "No alias for subquery or table function in JOIN" w/ old analyzer
settings: HashMap::from([("allow_experimental_analyzer", 1)]),
},
);
}
Expand Down
51 changes: 46 additions & 5 deletions src/view/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,47 @@ pub fn query_result_show_logs_for_row(
siv.focus_name(view_name).unwrap();
}

pub struct RenderFromClickHouseQueryArguments<F> {
pub trait ClickHouseSettingValue {
fn format_for_query(&self) -> String;
}

impl ClickHouseSettingValue for &str {
fn format_for_query(&self) -> String {
format!("'{}'", self.replace('\'', "\\'"))
}
}

impl ClickHouseSettingValue for String {
fn format_for_query(&self) -> String {
format!("'{}'", self.replace('\'', "\\'"))
}
}

impl ClickHouseSettingValue for i32 {
fn format_for_query(&self) -> String {
self.to_string()
}
}

impl ClickHouseSettingValue for i64 {
fn format_for_query(&self) -> String {
self.to_string()
}
}

impl ClickHouseSettingValue for u32 {
fn format_for_query(&self) -> String {
self.to_string()
}
}

impl ClickHouseSettingValue for u64 {
fn format_for_query(&self) -> String {
self.to_string()
}
}

pub struct RenderFromClickHouseQueryArguments<F, T> {
pub context: ContextArc,
pub table: &'static str,
pub join: Option<String>,
Expand All @@ -149,14 +189,15 @@ pub struct RenderFromClickHouseQueryArguments<F> {
pub columns: Vec<&'static str>,
pub columns_to_compare: Vec<&'static str>,
pub on_submit: Option<F>,
pub settings: HashMap<&'static str, &'static str>,
pub settings: HashMap<&'static str, T>,
}

pub fn render_from_clickhouse_query<F>(
pub fn render_from_clickhouse_query<F, T>(
siv: &mut Cursive,
mut params: RenderFromClickHouseQueryArguments<F>,
mut params: RenderFromClickHouseQueryArguments<F, T>,
) where
F: Fn(&mut Cursive, Vec<&'static str>, view::QueryResultRow) + Send + Sync + 'static,
T: ClickHouseSettingValue,
{
use crate::view::Navigation;

Expand Down Expand Up @@ -192,7 +233,7 @@ pub fn render_from_clickhouse_query<F>(
params
.settings
.iter()
.map(|kv| format!("{}='{}'", kv.0, kv.1.replace('\'', "\\\'")))
.map(|kv| format!("{}={}", kv.0, kv.1.format_for_query()))
.collect::<Vec<String>>()
.join(",")
)
Expand Down
2 changes: 1 addition & 1 deletion src/view/providers/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl ViewProvider for MutationsViewProvider {
columns,
columns_to_compare: vec!["database", "table", "mutation_id"],
on_submit: Some(super::query_result_show_row),
settings: HashMap::new(),
settings: HashMap::<&str, i32>::new(),
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/view/providers/replicated_fetches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl ViewProvider for ReplicatedFetchesViewProvider {
columns,
columns_to_compare: vec!["database", "table", "part"],
on_submit: Some(super::query_result_show_row),
settings: HashMap::new(),
settings: HashMap::<&str, i32>::new(),
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/view/providers/replication_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl ViewProvider for ReplicationQueueViewProvider {
columns,
columns_to_compare: vec!["database", "table", "type"],
on_submit: Some(super::query_result_show_row),
settings: HashMap::new(),
settings: HashMap::<&str, i32>::new(),
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/view/providers/s3queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl ViewProvider for S3QueueViewProvider {
columns,
columns_to_compare: vec!["file_name"],
on_submit: Some(super::query_result_show_row),
settings: HashMap::new(),
settings: HashMap::<&str, i32>::new(),
},
);
}
Expand Down