Merge pull request #18 from agnosticeng/udfs

feat: support udfs
This commit is contained in:
Didier Franc
2024-12-13 16:57:15 +01:00
committed by GitHub
2 changed files with 20 additions and 1 deletions

View File

@@ -9,4 +9,19 @@ pub fn setup_clickhouse(path: &PathBuf) {
} else {
fs::create_dir_all(&path).expect("Failed to create directory");
}
let path_str = path.to_str().unwrap();
let xml_content = format!(
r#"<clickhouse>
<user_defined_executable_functions_config>{path_str}/user_defined/*.xml</user_defined_executable_functions_config>
<user_scripts_path>{path_str}/bin</user_scripts_path>
<user_defined_path>{path_str}/user_defined</user_defined_path>
</clickhouse>"#
);
let config_path = path.join("config.xml");
if !config_path.exists() {
fs::write(config_path, xml_content).expect("Failed to write config file");
}
}

View File

@@ -1,21 +1,25 @@
use crate::chdb::{arg::Arg, format, lib};
use std::borrow::Cow;
use std::sync::Mutex;
use tauri::State;
use crate::AppState;
use crate::{chdb, AppState};
use String;
#[tauri::command]
pub async fn query(query: String, state: State<'_, Mutex<AppState>>) -> Result<String, String> {
let state = state.lock().unwrap();
let config_path = state.clickhouse_dir.join("config.xml".to_string());
let args = vec![
// Arg::LogLevel(chdb::log_level::LogLevel::Trace),
Arg::OutputFormat(format::OutputFormat::JSON),
Arg::Custom(
"path".into(),
Some(state.clickhouse_dir.display().to_string().into()),
),
Arg::ConfigFilePath(Cow::Borrowed(config_path.to_str().unwrap())),
];
return match lib::execute(&query, Some(&args)) {