kriti-sc commented on code in PR #2886: URL: https://github.com/apache/iggy/pull/2886#discussion_r3343170884
########## core/connectors/sinks/clickhouse_sink/src/body.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. + */ + +//! HTTP request body builders for each INSERT format. +//! +//! Each function accepts a slice of [`ConsumedMessage`]s and returns the raw +//! bytes that will be sent to ClickHouse. Payloads of the wrong type for the +//! chosen format are skipped with a warning rather than erroring, so a mixed +//! batch never causes a complete failure. + +use crate::StringFormat; +use crate::schema::Column; +use iggy_connector_sdk::{ConsumedMessage, Error, Payload}; +use tracing::warn; + +// ─── Body builders ─────────────────────────────────────────────────────────── + +/// Build a newline-delimited JSON body for `FORMAT JSONEachRow`. +/// Each `Payload::Json` message becomes one line. Other payload types are skipped. +pub(crate) fn build_json_body(messages: &[ConsumedMessage]) -> Vec<u8> { + let mut buf = Vec::with_capacity(messages.len() * 64); + for msg in messages { + match &msg.payload { Review Comment: This is intentional. Correctly parsing `Payload:Json` & `Payload::Text` is driven by the config. When input is `Payload:Json`, the config should have `InsertFormat::JSONEachRow`, and for `Payload::Text`, the config should have `InsertFormat::JSONEachRow, StringFormar::JSONEachRow`. Lmk @hubcio -- 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]
