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        [
103            "cdc.source.wait.streaming.start.timeout".to_owned(),
104            "debezium.max.queue.size".to_owned(),
105        ].into_iter().collect(),
106    ).unwrap();
107    map.try_insert(
108        std::any::type_name::<PostgresCdcProperties>().to_owned(),
109        [
110            "cdc.source.wait.streaming.start.timeout".to_owned(),
111            "debezium.max.queue.size".to_owned(),
112        ].into_iter().collect(),
113    ).unwrap();
114    map.try_insert(
115        std::any::type_name::<SqlServerCdcProperties>().to_owned(),
116        [
117            "cdc.source.wait.streaming.start.timeout".to_owned(),
118            "debezium.max.queue.size".to_owned(),
119        ].into_iter().collect(),
120    ).unwrap();
121
122    map.try_insert(
123        std::any::type_name::<MongodbCdcProperties>().to_owned(),
124        [
125            "cdc.source.wait.streaming.start.timeout".to_owned(),
126            "debezium.max.queue.size".to_owned(),
127        ].into_iter().collect(),
128    ).unwrap();
129    // KafkaProperties
130    map.try_insert(
131        std::any::type_name::<KafkaProperties>().to_owned(),
132        [
133            "group.id.prefix".to_owned(),
134            "properties.sync.call.timeout".to_owned(),
135            "properties.security.protocol".to_owned(),
136            "properties.ssl.endpoint.identification.algorithm".to_owned(),
137            "properties.sasl.mechanism".to_owned(),
138            "properties.sasl.username".to_owned(),
139            "properties.sasl.password".to_owned(),
140            "properties.message.max.bytes".to_owned(),
141            "properties.receive.message.max.bytes".to_owned(),
142            "properties.statistics.interval.ms".to_owned(),
143            "properties.client.id".to_owned(),
144            "properties.enable.ssl.certificate.verification".to_owned(),
145            "properties.queued.min.messages".to_owned(),
146            "properties.queued.max.messages.kbytes".to_owned(),
147            "properties.fetch.wait.max.ms".to_owned(),
148            "properties.fetch.queue.backoff.ms".to_owned(),
149            "properties.fetch.max.bytes".to_owned(),
150            "properties.enable.auto.commit".to_owned(),
151        ].into_iter().collect(),
152    ).unwrap();
153    map
154});
155
156/// Map of sink connector names to their `allow_alter_on_fly` field names
157pub static SINK_ALLOW_ALTER_ON_FLY_FIELDS: LazyLock<HashMap<String, HashSet<String>>> = LazyLock::new(|| {
158    use sink_properties::*;
159    let mut map = HashMap::new();
160    // ClickHouseConfig
161    map.try_insert(
162        std::any::type_name::<ClickHouseConfig>().to_owned(),
163        [
164            "commit_checkpoint_interval".to_owned(),
165        ].into_iter().collect(),
166    ).unwrap();
167    // DeltaLakeConfig
168    map.try_insert(
169        std::any::type_name::<DeltaLakeConfig>().to_owned(),
170        [
171            "commit_checkpoint_interval".to_owned(),
172        ].into_iter().collect(),
173    ).unwrap();
174    // DorisConfig
175    map.try_insert(
176        std::any::type_name::<DorisConfig>().to_owned(),
177        [
178            "doris.stream_load.http.timeout.ms".to_owned(),
179        ].into_iter().collect(),
180    ).unwrap();
181    // IcebergConfig
182    map.try_insert(
183        std::any::type_name::<IcebergConfig>().to_owned(),
184        [
185            "commit_checkpoint_interval".to_owned(),
186            "enable_compaction".to_owned(),
187            "compaction_interval_sec".to_owned(),
188            "enable_snapshot_expiration".to_owned(),
189            "snapshot_expiration_max_age_millis".to_owned(),
190            "snapshot_expiration_retain_last".to_owned(),
191            "snapshot_expiration_clear_expired_files".to_owned(),
192            "snapshot_expiration_clear_expired_meta_data".to_owned(),
193            "compaction.max_snapshots_num".to_owned(),
194            "compaction.small_files_threshold_mb".to_owned(),
195            "compaction.delete_files_count_threshold".to_owned(),
196            "compaction.trigger_snapshot_count".to_owned(),
197            "compaction.target_file_size_mb".to_owned(),
198            "compaction.type".to_owned(),
199        ].into_iter().collect(),
200    ).unwrap();
201    // KafkaConfig
202    map.try_insert(
203        std::any::type_name::<KafkaConfig>().to_owned(),
204        [
205            "properties.sync.call.timeout".to_owned(),
206            "properties.security.protocol".to_owned(),
207            "properties.ssl.endpoint.identification.algorithm".to_owned(),
208            "properties.sasl.mechanism".to_owned(),
209            "properties.sasl.username".to_owned(),
210            "properties.sasl.password".to_owned(),
211            "properties.message.max.bytes".to_owned(),
212            "properties.receive.message.max.bytes".to_owned(),
213            "properties.statistics.interval.ms".to_owned(),
214            "properties.client.id".to_owned(),
215            "properties.enable.ssl.certificate.verification".to_owned(),
216            "properties.allow.auto.create.topics".to_owned(),
217            "properties.queue.buffering.max.messages".to_owned(),
218            "properties.queue.buffering.max.kbytes".to_owned(),
219            "properties.queue.buffering.max.ms".to_owned(),
220            "properties.enable.idempotence".to_owned(),
221            "properties.message.send.max.retries".to_owned(),
222            "properties.retry.backoff.ms".to_owned(),
223            "properties.batch.num.messages".to_owned(),
224            "properties.batch.size".to_owned(),
225            "properties.message.timeout.ms".to_owned(),
226            "properties.max.in.flight.requests.per.connection".to_owned(),
227            "properties.request.required.acks".to_owned(),
228        ].into_iter().collect(),
229    ).unwrap();
230    // SnowflakeV2Config
231    map.try_insert(
232        std::any::type_name::<SnowflakeV2Config>().to_owned(),
233        [
234            "commit_checkpoint_interval".to_owned(),
235        ].into_iter().collect(),
236    ).unwrap();
237    // StarrocksConfig
238    map.try_insert(
239        std::any::type_name::<StarrocksConfig>().to_owned(),
240        [
241            "starrocks.stream_load.http.timeout.ms".to_owned(),
242            "commit_checkpoint_interval".to_owned(),
243        ].into_iter().collect(),
244    ).unwrap();
245    map
246});
247
248/// Map of connection names to their `allow_alter_on_fly` field names
249pub static CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS: LazyLock<HashMap<String, HashSet<String>>> = LazyLock::new(|| {
250    use crate::connector_common::*;
251    let mut map = HashMap::new();
252    // KafkaConnection
253    map.try_insert(
254        std::any::type_name::<KafkaConnection>().to_owned(),
255        [
256            "properties.security.protocol".to_owned(),
257            "properties.ssl.endpoint.identification.algorithm".to_owned(),
258            "properties.sasl.mechanism".to_owned(),
259            "properties.sasl.username".to_owned(),
260            "properties.sasl.password".to_owned(),
261        ].into_iter().collect(),
262    ).unwrap();
263    map
264});
265
266/// Get all source connector names that have `allow_alter_on_fly` fields
267pub fn get_source_connectors_with_allow_alter_on_fly_fields() -> Vec<&'static str> {
268    SOURCE_ALLOW_ALTER_ON_FLY_FIELDS.keys().map(|s| s.as_str()).collect()
269}
270
271/// Get all sink connector names that have `allow_alter_on_fly` fields
272pub fn get_sink_connectors_with_allow_alter_on_fly_fields() -> Vec<&'static str> {
273    SINK_ALLOW_ALTER_ON_FLY_FIELDS.keys().map(|s| s.as_str()).collect()
274}
275
276/// Get all connection names that have `allow_alter_on_fly` fields
277pub fn get_connection_names_with_allow_alter_on_fly_fields() -> Vec<&'static str> {
278    CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS.keys().map(|s| s.as_str()).collect()
279}
280
281/// Checks if all given fields are allowed to be altered on the fly for the specified source connector.
282/// Returns Ok(()) if all fields are allowed, otherwise returns a `ConnectorError`.
283pub fn check_source_allow_alter_on_fly_fields(
284    connector_name: &str,
285    fields: &[String],
286) -> crate::error::ConnectorResult<()> {
287    // Convert connector name to the type name key
288    let Some(type_name) = source_properties::source_name_to_prop_type_name(connector_name) else {
289        return Err(ConnectorError::from(anyhow::anyhow!(
290            "Unknown source connector: {connector_name}"
291        )));
292    };
293    let Some(allowed_fields) = SOURCE_ALLOW_ALTER_ON_FLY_FIELDS.get(type_name) else {
294        return Err(ConnectorError::from(anyhow::anyhow!(
295            "No allow_alter_on_fly fields registered for connector: {connector_name}"
296        )));
297    };
298    for field in fields {
299        if !allowed_fields.contains(field) {
300            return Err(ConnectorError::from(anyhow::anyhow!(
301                "Field '{field}' is not allowed to be altered on the fly for connector: {connector_name}"
302            )));
303        }
304    }
305    Ok(())
306}
307
308pub fn check_connection_allow_alter_on_fly_fields(
309    connection_name: &str,
310    fields: &[String],
311) -> crate::error::ConnectorResult<()> {
312    use crate::source::connection_name_to_prop_type_name;
313
314    // Convert connection name to the type name key
315    let Some(type_name) = connection_name_to_prop_type_name(connection_name) else {
316        return Err(ConnectorError::from(anyhow::anyhow!(
317            "Unknown connection: {connection_name}"
318        )));
319    };
320    let Some(allowed_fields) = CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS.get(type_name) else {
321        return Err(ConnectorError::from(anyhow::anyhow!(
322            "No allow_alter_on_fly fields registered for connection: {connection_name}"
323        )));
324    };
325    for field in fields {
326        if !allowed_fields.contains(field) {
327            return Err(ConnectorError::from(anyhow::anyhow!(
328                "Field '{field}' is not allowed to be altered on the fly for connection: {connection_name}"
329            )));
330        }
331    }
332    Ok(())
333}
334
335/// Checks if all given fields are allowed to be altered on the fly for the specified sink connector.
336/// Returns Ok(()) if all fields are allowed, otherwise returns a `ConnectorError`.
337pub fn check_sink_allow_alter_on_fly_fields(
338    sink_name: &str,
339    fields: &[String],
340) -> crate::error::ConnectorResult<()> {
341    // Convert sink name to the type name key
342    let Some(type_name) = sink_properties::sink_name_to_config_type_name(sink_name) else {
343        return Err(ConnectorError::from(anyhow::anyhow!(
344            "Unknown sink connector: {sink_name}"
345        )));
346    };
347    let Some(allowed_fields) = SINK_ALLOW_ALTER_ON_FLY_FIELDS.get(type_name) else {
348        return Err(ConnectorError::from(anyhow::anyhow!(
349            "No allow_alter_on_fly fields registered for sink: {sink_name}"
350        )));
351    };
352    for field in fields {
353        if !allowed_fields.contains(field) {
354            return Err(ConnectorError::from(anyhow::anyhow!(
355                "Field '{field}' is not allowed to be altered on the fly for sink: {sink_name}"
356            )));
357        }
358    }
359    Ok(())
360}