risingwave_connector/
allow_alter_on_fly_fields.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// THIS FILE IS AUTO_GENERATED. DO NOT EDIT
16// UPDATE WITH: ./risedev generate-with-options
17
18#![rustfmt::skip]
19
20use std::collections::{HashMap, HashSet};
21use std::sync::LazyLock;
22use crate::error::ConnectorError;
23
24macro_rules! use_source_properties {
25    ({ $({ $variant_name:ident, $prop_name:ty, $split:ty }),* }) => {
26        $(
27            #[allow(unused_imports)]
28            pub(super) use $prop_name;
29        )*
30    };
31}
32
33mod source_properties {
34    use crate::for_all_sources;
35    use crate::source::base::SourceProperties;
36
37    for_all_sources!(use_source_properties);
38
39    /// Implements a function that maps a source name string to the Rust type name of the corresponding property type.
40    /// Usage: `impl_source_name_to_prop_type_name!();` will generate:
41    /// ```ignore
42    /// pub fn source_name_to_prop_type_name(source_name: &str) -> Option<&'static str>
43    /// ```
44    macro_rules! impl_source_name_to_prop_type_name_inner {
45        ({ $({$variant:ident, $prop_name:ty, $split:ty}),* }) => {
46            pub fn source_name_to_prop_type_name(source_name: &str) -> Option<&'static str> {
47                match source_name {
48                    $(
49                        <$prop_name>::SOURCE_NAME => Some(std::any::type_name::<$prop_name>()),
50                    )*
51                    _ => None,
52                }
53            }
54        };
55    }
56
57    macro_rules! impl_source_name_to_prop_type_name {
58        () => {
59            $crate::for_all_sources! { impl_source_name_to_prop_type_name_inner }
60        };
61    }
62
63    impl_source_name_to_prop_type_name!();
64}
65
66mod sink_properties {
67    use crate::use_all_sink_configs;
68    use crate::sink::Sink;
69    use crate::sink::file_sink::fs::FsSink;
70
71    use_all_sink_configs!();
72
73    macro_rules! impl_sink_name_to_config_type_name_inner {
74        ({ $({ $variant_name:ident, $sink_type:ty, $config_type:ty }),* }) => {
75            pub fn sink_name_to_config_type_name(sink_name: &str) -> Option<&'static str> {
76                match sink_name {
77                $(
78                    <$sink_type>::SINK_NAME => Some(std::any::type_name::<$config_type>()),
79                )*
80                    _ => None,
81                }
82            }
83        };
84    }
85
86    macro_rules! impl_sink_name_to_config_type_name {
87        () => {
88            $crate::for_all_sinks! { impl_sink_name_to_config_type_name_inner }
89        };
90    }
91
92    impl_sink_name_to_config_type_name!();
93}
94
95/// Map of source connector names to their `allow_alter_on_fly` field names
96pub static SOURCE_ALLOW_ALTER_ON_FLY_FIELDS: LazyLock<HashMap<String, HashSet<String>>> = LazyLock::new(|| {
97    use source_properties::*;
98    let mut map = HashMap::new();
99    // CDC Properties - added for schema.change.failure.policy
100    map.try_insert(
101        std::any::type_name::<MysqlCdcProperties>().to_owned(),
102        ["cdc.source.wait.streaming.start.timeout".to_owned()].into_iter().collect(),
103    ).unwrap();
104    map.try_insert(
105        std::any::type_name::<PostgresCdcProperties>().to_owned(),
106        ["cdc.source.wait.streaming.start.timeout".to_owned()].into_iter().collect(),
107    ).unwrap();
108    map.try_insert(
109        std::any::type_name::<SqlServerCdcProperties>().to_owned(),
110        ["cdc.source.wait.streaming.start.timeout".to_owned()].into_iter().collect(),
111    ).unwrap();
112
113    map.try_insert(
114        std::any::type_name::<MongodbCdcProperties>().to_owned(),
115        ["cdc.source.wait.streaming.start.timeout".to_owned()].into_iter().collect(),
116    ).unwrap();
117    // KafkaProperties
118    map.try_insert(
119        std::any::type_name::<KafkaProperties>().to_owned(),
120        [
121            "group.id.prefix".to_owned(),
122            "properties.sync.call.timeout".to_owned(),
123            "properties.security.protocol".to_owned(),
124            "properties.ssl.endpoint.identification.algorithm".to_owned(),
125            "properties.sasl.mechanism".to_owned(),
126            "properties.sasl.username".to_owned(),
127            "properties.sasl.password".to_owned(),
128            "properties.message.max.bytes".to_owned(),
129            "properties.receive.message.max.bytes".to_owned(),
130            "properties.statistics.interval.ms".to_owned(),
131            "properties.client.id".to_owned(),
132            "properties.enable.ssl.certificate.verification".to_owned(),
133            "properties.queued.min.messages".to_owned(),
134            "properties.queued.max.messages.kbytes".to_owned(),
135            "properties.fetch.wait.max.ms".to_owned(),
136            "properties.fetch.queue.backoff.ms".to_owned(),
137            "properties.fetch.max.bytes".to_owned(),
138            "properties.enable.auto.commit".to_owned(),
139        ].into_iter().collect(),
140    ).unwrap();
141    map
142});
143
144/// Map of sink connector names to their `allow_alter_on_fly` field names
145pub static SINK_ALLOW_ALTER_ON_FLY_FIELDS: LazyLock<HashMap<String, HashSet<String>>> = LazyLock::new(|| {
146    use sink_properties::*;
147    let mut map = HashMap::new();
148    // ClickHouseConfig
149    map.try_insert(
150        std::any::type_name::<ClickHouseConfig>().to_owned(),
151        [
152            "commit_checkpoint_interval".to_owned(),
153        ].into_iter().collect(),
154    ).unwrap();
155    // DeltaLakeConfig
156    map.try_insert(
157        std::any::type_name::<DeltaLakeConfig>().to_owned(),
158        [
159            "commit_checkpoint_interval".to_owned(),
160        ].into_iter().collect(),
161    ).unwrap();
162    // DorisConfig
163    map.try_insert(
164        std::any::type_name::<DorisConfig>().to_owned(),
165        [
166            "doris.stream_load.http.timeout.ms".to_owned(),
167        ].into_iter().collect(),
168    ).unwrap();
169    // IcebergConfig
170    map.try_insert(
171        std::any::type_name::<IcebergConfig>().to_owned(),
172        [
173            "commit_checkpoint_interval".to_owned(),
174            "enable_compaction".to_owned(),
175            "compaction_interval_sec".to_owned(),
176            "enable_snapshot_expiration".to_owned(),
177            "snapshot_expiration_max_age_millis".to_owned(),
178            "snapshot_expiration_retain_last".to_owned(),
179            "snapshot_expiration_clear_expired_files".to_owned(),
180            "snapshot_expiration_clear_expired_meta_data".to_owned(),
181            "max_snapshots_num_before_compaction".to_owned(),
182        ].into_iter().collect(),
183    ).unwrap();
184    // KafkaConfig
185    map.try_insert(
186        std::any::type_name::<KafkaConfig>().to_owned(),
187        [
188            "properties.sync.call.timeout".to_owned(),
189            "properties.security.protocol".to_owned(),
190            "properties.ssl.endpoint.identification.algorithm".to_owned(),
191            "properties.sasl.mechanism".to_owned(),
192            "properties.sasl.username".to_owned(),
193            "properties.sasl.password".to_owned(),
194            "properties.message.max.bytes".to_owned(),
195            "properties.receive.message.max.bytes".to_owned(),
196            "properties.statistics.interval.ms".to_owned(),
197            "properties.client.id".to_owned(),
198            "properties.enable.ssl.certificate.verification".to_owned(),
199            "properties.allow.auto.create.topics".to_owned(),
200            "properties.queue.buffering.max.messages".to_owned(),
201            "properties.queue.buffering.max.kbytes".to_owned(),
202            "properties.queue.buffering.max.ms".to_owned(),
203            "properties.enable.idempotence".to_owned(),
204            "properties.message.send.max.retries".to_owned(),
205            "properties.retry.backoff.ms".to_owned(),
206            "properties.batch.num.messages".to_owned(),
207            "properties.batch.size".to_owned(),
208            "properties.message.timeout.ms".to_owned(),
209            "properties.max.in.flight.requests.per.connection".to_owned(),
210            "properties.request.required.acks".to_owned(),
211        ].into_iter().collect(),
212    ).unwrap();
213    // SnowflakeV2Config
214    map.try_insert(
215        std::any::type_name::<SnowflakeV2Config>().to_owned(),
216        [
217            "commit_checkpoint_interval".to_owned(),
218        ].into_iter().collect(),
219    ).unwrap();
220    // StarrocksConfig
221    map.try_insert(
222        std::any::type_name::<StarrocksConfig>().to_owned(),
223        [
224            "starrocks.stream_load.http.timeout.ms".to_owned(),
225            "commit_checkpoint_interval".to_owned(),
226        ].into_iter().collect(),
227    ).unwrap();
228    map
229});
230
231/// Map of connection names to their `allow_alter_on_fly` field names
232pub static CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS: LazyLock<HashMap<String, HashSet<String>>> = LazyLock::new(|| {
233    use crate::connector_common::*;
234    let mut map = HashMap::new();
235    // KafkaConnection
236    map.try_insert(
237        std::any::type_name::<KafkaConnection>().to_owned(),
238        [
239            "properties.security.protocol".to_owned(),
240            "properties.ssl.endpoint.identification.algorithm".to_owned(),
241            "properties.sasl.mechanism".to_owned(),
242            "properties.sasl.username".to_owned(),
243            "properties.sasl.password".to_owned(),
244        ].into_iter().collect(),
245    ).unwrap();
246    map
247});
248
249/// Get all source connector names that have `allow_alter_on_fly` fields
250pub fn get_source_connectors_with_allow_alter_on_fly_fields() -> Vec<&'static str> {
251    SOURCE_ALLOW_ALTER_ON_FLY_FIELDS.keys().map(|s| s.as_str()).collect()
252}
253
254/// Get all sink connector names that have `allow_alter_on_fly` fields
255pub fn get_sink_connectors_with_allow_alter_on_fly_fields() -> Vec<&'static str> {
256    SINK_ALLOW_ALTER_ON_FLY_FIELDS.keys().map(|s| s.as_str()).collect()
257}
258
259/// Get all connection names that have `allow_alter_on_fly` fields
260pub fn get_connection_names_with_allow_alter_on_fly_fields() -> Vec<&'static str> {
261    CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS.keys().map(|s| s.as_str()).collect()
262}
263
264/// Checks if all given fields are allowed to be altered on the fly for the specified source connector.
265/// Returns Ok(()) if all fields are allowed, otherwise returns a `ConnectorError`.
266pub fn check_source_allow_alter_on_fly_fields(
267    connector_name: &str,
268    fields: &[String],
269) -> crate::error::ConnectorResult<()> {
270    // Convert connector name to the type name key
271    let Some(type_name) = source_properties::source_name_to_prop_type_name(connector_name) else {
272        return Err(ConnectorError::from(anyhow::anyhow!(
273            "Unknown source connector: {connector_name}"
274        )));
275    };
276    let Some(allowed_fields) = SOURCE_ALLOW_ALTER_ON_FLY_FIELDS.get(type_name) else {
277        return Err(ConnectorError::from(anyhow::anyhow!(
278            "No allow_alter_on_fly fields registered for connector: {connector_name}"
279        )));
280    };
281    for field in fields {
282        if !allowed_fields.contains(field) {
283            return Err(ConnectorError::from(anyhow::anyhow!(
284                "Field '{field}' is not allowed to be altered on the fly for connector: {connector_name}"
285            )));
286        }
287    }
288    Ok(())
289}
290
291pub fn check_connection_allow_alter_on_fly_fields(
292    connection_name: &str,
293    fields: &[String],
294) -> crate::error::ConnectorResult<()> {
295    use crate::source::connection_name_to_prop_type_name;
296
297    // Convert connection name to the type name key
298    let Some(type_name) = connection_name_to_prop_type_name(connection_name) else {
299        return Err(ConnectorError::from(anyhow::anyhow!(
300            "Unknown connection: {connection_name}"
301        )));
302    };
303    let Some(allowed_fields) = CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS.get(type_name) else {
304        return Err(ConnectorError::from(anyhow::anyhow!(
305            "No allow_alter_on_fly fields registered for connection: {connection_name}"
306        )));
307    };
308    for field in fields {
309        if !allowed_fields.contains(field) {
310            return Err(ConnectorError::from(anyhow::anyhow!(
311                "Field '{field}' is not allowed to be altered on the fly for connection: {connection_name}"
312            )));
313        }
314    }
315    Ok(())
316}
317
318/// Checks if all given fields are allowed to be altered on the fly for the specified sink connector.
319/// Returns Ok(()) if all fields are allowed, otherwise returns a `ConnectorError`.
320pub fn check_sink_allow_alter_on_fly_fields(
321    sink_name: &str,
322    fields: &[String],
323) -> crate::error::ConnectorResult<()> {
324    // Convert sink name to the type name key
325    let Some(type_name) = sink_properties::sink_name_to_config_type_name(sink_name) else {
326        return Err(ConnectorError::from(anyhow::anyhow!(
327            "Unknown sink connector: {sink_name}"
328        )));
329    };
330    let Some(allowed_fields) = SINK_ALLOW_ALTER_ON_FLY_FIELDS.get(type_name) else {
331        return Err(ConnectorError::from(anyhow::anyhow!(
332            "No allow_alter_on_fly fields registered for sink: {sink_name}"
333        )));
334    };
335    for field in fields {
336        if !allowed_fields.contains(field) {
337            return Err(ConnectorError::from(anyhow::anyhow!(
338                "Field '{field}' is not allowed to be altered on the fly for sink: {sink_name}"
339            )));
340        }
341    }
342    Ok(())
343}