From 8d4a3c573e11c56b84d6286b122a9861ef496260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karolis=20Gudi=C5=A1kis?= Date: Sat, 23 Mar 2024 10:11:25 +0200 Subject: [PATCH] feat: Add options to clickhouse client (#2465) * feat: Add options to clickhouse client * fix test --- dozer-sink-clickhouse/src/client.rs | 8 +++++++- dozer-sink-clickhouse/src/tests.rs | 1 + dozer-types/src/models/sink.rs | 1 + json_schemas/dozer.json | 17 +++++++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/dozer-sink-clickhouse/src/client.rs b/dozer-sink-clickhouse/src/client.rs index 9e46d372ea..3e2ae5ae3e 100644 --- a/dozer-sink-clickhouse/src/client.rs +++ b/dozer-sink-clickhouse/src/client.rs @@ -30,8 +30,14 @@ impl ClickhouseClient { None => config.user.to_string(), }; + let options = config + .options + .iter() + .map(|(k, v)| format!("{}={}", k, v)) + .collect::>() + .join("&"); let url = format!( - "{}://{}@{}:{}/{}", + "{}://{}@{}:{}/{}?{options}", config.scheme, user_password, config.host, config.port, config.database ); debug!("{url}"); diff --git a/dozer-sink-clickhouse/src/tests.rs b/dozer-sink-clickhouse/src/tests.rs index f2cfa184ff..aad238db07 100644 --- a/dozer-sink-clickhouse/src/tests.rs +++ b/dozer-sink-clickhouse/src/tests.rs @@ -20,6 +20,7 @@ fn get_sink_config() -> ClickhouseSinkConfig { database: "default".to_string(), host: "localhost".to_string(), port: 9000, + options: vec![], } } diff --git a/dozer-types/src/models/sink.rs b/dozer-types/src/models/sink.rs index 51809482e3..89aa653017 100644 --- a/dozer-types/src/models/sink.rs +++ b/dozer-types/src/models/sink.rs @@ -200,6 +200,7 @@ pub struct ClickhouseSinkConfig { pub scheme: String, #[serde(default = "ClickhouseSinkConfig::default_database")] pub database: String, + pub options: Vec<(String, String)>, pub source_table_name: String, pub sink_table_name: String, pub create_table_options: Option, diff --git a/json_schemas/dozer.json b/json_schemas/dozer.json index 34fc3bf3a1..77be0c2804 100644 --- a/json_schemas/dozer.json +++ b/json_schemas/dozer.json @@ -409,6 +409,7 @@ "ClickhouseSinkConfig": { "type": "object", "required": [ + "options", "sink_table_name", "source_table_name" ], @@ -431,6 +432,22 @@ "default": "0.0.0.0", "type": "string" }, + "options": { + "type": "array", + "items": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "string" + } + ], + "maxItems": 2, + "minItems": 2 + } + }, "password": { "default": null, "type": [