hubcio commented on code in PR #2886: URL: https://github.com/apache/iggy/pull/2886#discussion_r3044798718
########## core/connectors/sinks/clickhouse_sink/src/lib.rs: ########## @@ -0,0 +1,286 @@ +/* Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +use humantime::Duration as HumanDuration; +use iggy_connector_sdk::{Error, sink_connector}; +use serde::{Deserialize, Serialize}; +use std::str::FromStr; +use std::time::Duration; +use tokio::sync::Mutex; + +mod binary; +mod body; +mod client; +mod schema; +mod sink; + +sink_connector!(ClickHouseSink); + +const DEFAULT_DATABASE: &str = "default"; +const DEFAULT_USERNAME: &str = "default"; +const DEFAULT_PASSWORD: &str = ""; +const DEFAULT_TIMEOUT_SECONDS: u64 = 30; +const DEFAULT_MAX_RETRIES: u32 = 3; +const DEFAULT_RETRY_DELAY: &str = "1s"; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ClickHouseSinkConfig { + pub url: String, + pub database: Option<String>, + pub username: Option<String>, + pub password: Option<String>, + pub table: String, + /// "json_each_row" (default), "row_binary", or "string" + pub insert_format: Option<String>, + /// "json_each_row" (default), "csv", or "tsv" — only used when insert_format = "string" + pub string_format: Option<String>, + pub timeout_seconds: Option<u64>, + pub max_retries: Option<u32>, + pub retry_delay: Option<String>, + pub verbose_logging: Option<bool>, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub enum InsertFormat { + #[default] + JsonEachRow, + RowBinary, + StringPassthrough, +} + +impl InsertFormat { + fn from_config(s: Option<&str>) -> Self { Review Comment: when crashing due to invalid config, it's always best to do it as soon as possible. is there anything wrong with requiring users to explicitly provide it? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
