ryerraguntla commented on code in PR #4043: URL: https://github.com/apache/iggy/pull/4043#discussion_r3967781481
########## gateways/kafka/src/bridge/topic_map.rs: ########## @@ -0,0 +1,203 @@ +// 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 std::collections::HashMap; +use std::path::Path; + +use serde::Deserialize; + +use crate::bridge::error::BridgeError; + +/// Explicit Kafka-topic → Iggy stream/topic override. Absent entries fall back to +/// [`TopicMapping::default_stream`] plus the Kafka topic name unchanged - see +/// [`TopicMapping::resolve`]. +#[derive(Debug, Clone, Deserialize, PartialEq, Eq)] +pub struct TopicOverride { + pub stream: String, + pub topic: String, +} + +/// Kafka topic name → Iggy stream/topic mapping, loaded from TOML. +/// +/// Default rule (no override): the Iggy stream is [`default_stream`](Self::default_stream) and +/// the Iggy topic name is the Kafka topic name unchanged. A gateway that fronts a single Kafka +/// "cluster" for one Iggy stream never needs an override entry at all. +#[derive(Debug, Clone, Deserialize, Default, PartialEq, Eq)] +pub struct TopicMapping { + pub default_stream: String, + #[serde(default)] + pub topics: HashMap<String, TopicOverride>, +} + +impl TopicMapping { + /// Resolves a Kafka topic name to `(iggy_stream, iggy_topic)`. + #[must_use] + pub fn resolve(&self, kafka_topic: &str) -> (String, String) { + self.topics.get(kafka_topic).map_or_else( Review Comment: yes it is silent today. An override that renames `orders` → `orders_v2` collides with a Kafka topic that is actually named `orders_v2` and falls through to the default rule. Will reject a mapping where two Kafka names resolve to the same `(stream, topic)` pair at `from_toml_str` time (and the same check on the env-built map if we ever add overrides there). That keeps overrides as renames without silent merge.Added new tests. -- 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]
