Skip to main content

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// This file is rewritten by `tests::test_allow_alter_on_fly_fields_rust_up_to_date` with
18// `UPDATE_EXPECT=1`.
19// To update content, change source/sink/connection WITH options definitions (for example,
20// `#[with_option(allow_alter_on_fly)]` on struct fields), then run `./risedev generate-with-options`.
21// `./risedev generate-with-options` runs three UPDATE_EXPECT tests:
22// 1) refresh `with_options_{source,sink,connection}.yaml`;
23// 2) regenerate this file from those YAML files;
24// 3) regenerate the Iceberg Engine option classifier.
25
26#![rustfmt::skip]
27
28use std::collections::{HashMap, HashSet};
29use std::sync::LazyLock;
30use crate::error::ConnectorError;
31use crate::sink::remote::JdbcSink;
32use crate::sink::Sink;
33
34macro_rules! use_source_properties {
35    ({ $({ $variant_name:ident, $prop_name:ty, $split:ty }),* }) => {
36        $(
37            #[allow(unused_imports)]
38            pub(super) use $prop_name;
39        )*
40    };
41}
42
43mod source_properties {
44    use crate::for_all_sources;
45    use crate::source::base::SourceProperties;
46
47    for_all_sources!(use_source_properties);
48
49    /// Implements a function that maps a source name string to the Rust type name of the corresponding property type.
50    /// Usage: `impl_source_name_to_prop_type_name!();` will generate:
51    /// ```ignore
52    /// pub fn source_name_to_prop_type_name(source_name: &str) -> Option<&'static str>
53    /// ```
54    macro_rules! impl_source_name_to_prop_type_name_inner {
55        ({ $({$variant:ident, $prop_name:ty, $split:ty}),* }) => {
56            pub fn source_name_to_prop_type_name(source_name: &str) -> Option<&'static str> {
57                match source_name {
58                    $(
59                        <$prop_name>::SOURCE_NAME => Some(std::any::type_name::<$prop_name>()),
60                    )*
61                    _ => None,
62                }
63            }
64        };
65    }
66
67    macro_rules! impl_source_name_to_prop_type_name {
68        () => {
69            $crate::for_all_sources! { impl_source_name_to_prop_type_name_inner }
70        };
71    }
72
73    impl_source_name_to_prop_type_name!();
74}
75
76mod sink_properties {
77    use crate::use_all_sink_configs;
78    use crate::sink::Sink;
79    use crate::sink::file_sink::fs::FsSink;
80
81    use_all_sink_configs!();
82
83    macro_rules! impl_sink_name_to_config_type_name_inner {
84        ({ $({ $variant_name:ident, $sink_type:ty, $config_type:ty }),* }) => {
85            pub fn sink_name_to_config_type_name(sink_name: &str) -> Option<&'static str> {
86                match sink_name {
87                $(
88                    <$sink_type>::SINK_NAME => Some(std::any::type_name::<$config_type>()),
89                )*
90                    _ => None,
91                }
92            }
93        };
94    }
95
96    macro_rules! impl_sink_name_to_config_type_name {
97        () => {
98            $crate::for_all_sinks! { impl_sink_name_to_config_type_name_inner }
99        };
100    }
101
102    impl_sink_name_to_config_type_name!();
103}
104
105/// Map of source connector names to their `allow_alter_on_fly` field names
106pub static SOURCE_ALLOW_ALTER_ON_FLY_FIELDS: LazyLock<HashMap<String, HashSet<String>>> = LazyLock::new(|| {
107    use source_properties::*;
108    let mut map = HashMap::new();
109    // CDC Properties - added for schema.change.failure.policy
110    map.try_insert(
111        std::any::type_name::<MysqlCdcProperties>().to_owned(),
112        [
113            "cdc.source.wait.streaming.start.timeout".to_owned(),
114            "debezium.max.queue.size".to_owned(),
115            "debezium.queue.memory.ratio".to_owned(),
116            "hostname".to_owned(),
117            "port".to_owned(),
118            "password".to_owned(),
119        ].into_iter().collect(),
120    ).unwrap();
121    map.try_insert(
122        std::any::type_name::<PostgresCdcProperties>().to_owned(),
123        [
124            "cdc.source.wait.streaming.start.timeout".to_owned(),
125            "debezium.max.queue.size".to_owned(),
126            "debezium.queue.memory.ratio".to_owned(),
127            "debezium.heartbeat.interval.ms".to_owned(),
128            "hostname".to_owned(),
129            "port".to_owned(),
130            "password".to_owned(),
131        ].into_iter().collect(),
132    ).unwrap();
133    map.try_insert(
134        std::any::type_name::<SqlServerCdcProperties>().to_owned(),
135        [
136            "cdc.source.wait.streaming.start.timeout".to_owned(),
137            "debezium.max.queue.size".to_owned(),
138            "debezium.queue.memory.ratio".to_owned(),
139            "hostname".to_owned(),
140            "port".to_owned(),
141            "password".to_owned(),
142        ].into_iter().collect(),
143    ).unwrap();
144
145    map.try_insert(
146        std::any::type_name::<MongodbCdcProperties>().to_owned(),
147        [
148            "cdc.source.wait.streaming.start.timeout".to_owned(),
149            "debezium.max.queue.size".to_owned(),
150            "debezium.queue.memory.ratio".to_owned(),
151        ].into_iter().collect(),
152    ).unwrap();
153    // KafkaProperties
154    map.try_insert(
155        std::any::type_name::<KafkaProperties>().to_owned(),
156        [
157            "group.id.prefix".to_owned(),
158            "properties.sync.call.timeout".to_owned(),
159            "properties.security.protocol".to_owned(),
160            "properties.ssl.endpoint.identification.algorithm".to_owned(),
161            "properties.ssl.ca.location".to_owned(),
162            "properties.ssl.ca.pem".to_owned(),
163            "properties.ssl.certificate.location".to_owned(),
164            "properties.ssl.certificate.pem".to_owned(),
165            "properties.ssl.key.location".to_owned(),
166            "properties.ssl.key.pem".to_owned(),
167            "properties.ssl.key.password".to_owned(),
168            "properties.sasl.mechanism".to_owned(),
169            "properties.sasl.username".to_owned(),
170            "properties.sasl.password".to_owned(),
171            "properties.message.max.bytes".to_owned(),
172            "properties.receive.message.max.bytes".to_owned(),
173            "properties.statistics.interval.ms".to_owned(),
174            "properties.client.id".to_owned(),
175            "properties.enable.ssl.certificate.verification".to_owned(),
176            "properties.reconnect.backoff.ms".to_owned(),
177            "properties.reconnect.backoff.max.ms".to_owned(),
178            "properties.socket.connection.setup.timeout.ms".to_owned(),
179            "properties.retry.backoff.ms".to_owned(),
180            "properties.retry.backoff.max.ms".to_owned(),
181            "properties.queued.min.messages".to_owned(),
182            "properties.queued.max.messages.kbytes".to_owned(),
183            "properties.fetch.wait.max.ms".to_owned(),
184            "properties.fetch.queue.backoff.ms".to_owned(),
185            "properties.fetch.max.bytes".to_owned(),
186            "properties.enable.auto.commit".to_owned(),
187            "properties.auto.commit.interval.ms".to_owned(),
188        ].into_iter().collect(),
189    ).unwrap();
190    // PubsubProperties
191    map.try_insert(
192        std::any::type_name::<PubsubProperties>().to_owned(),
193        [
194            "pubsub.ack_deadline_seconds".to_owned(),
195        ].into_iter().collect(),
196    ).unwrap();
197    // PulsarProperties
198    map.try_insert(
199        std::any::type_name::<PulsarProperties>().to_owned(),
200        [
201            "pulsar.operation.retry.max.retries".to_owned(),
202            "pulsar.operation.retry.delay".to_owned(),
203        ].into_iter().collect(),
204    ).unwrap();
205    map
206});
207
208/// Map of sink connector names to their `allow_alter_on_fly` field names
209pub static SINK_ALLOW_ALTER_ON_FLY_FIELDS: LazyLock<HashMap<String, HashSet<String>>> = LazyLock::new(|| {
210    use sink_properties::*;
211    let mut map = HashMap::new();
212    // ClickHouseConfig
213    map.try_insert(
214        std::any::type_name::<ClickHouseConfig>().to_owned(),
215        [
216            "commit_checkpoint_interval".to_owned(),
217        ].into_iter().collect(),
218    ).unwrap();
219    // DeltaLakeConfig
220    map.try_insert(
221        std::any::type_name::<DeltaLakeConfig>().to_owned(),
222        [
223            "commit_checkpoint_interval".to_owned(),
224        ].into_iter().collect(),
225    ).unwrap();
226    // DorisConfig
227    map.try_insert(
228        std::any::type_name::<DorisConfig>().to_owned(),
229        [
230            "doris.stream_load.http.timeout.ms".to_owned(),
231        ].into_iter().collect(),
232    ).unwrap();
233    // ElasticSearchConfig
234    map.try_insert(
235        std::any::type_name::<ElasticSearchConfig>().to_owned(),
236        [
237            "batch_num_messages".to_owned(),
238            "batch_size_kb".to_owned(),
239            "concurrent_requests".to_owned(),
240        ].into_iter().collect(),
241    ).unwrap();
242    // IcebergConfig
243    map.try_insert(
244        std::any::type_name::<IcebergConfig>().to_owned(),
245        [
246            "commit_checkpoint_interval".to_owned(),
247            "enable_compaction".to_owned(),
248            "compaction_interval_sec".to_owned(),
249            "enable_snapshot_expiration".to_owned(),
250            "snapshot_expiration_max_age_millis".to_owned(),
251            "snapshot_expiration_retain_last".to_owned(),
252            "snapshot_expiration_clear_expired_files".to_owned(),
253            "snapshot_expiration_clear_expired_meta_data".to_owned(),
254            "enable_manifest_rewrite".to_owned(),
255            "manifest_rewrite_target_size_bytes".to_owned(),
256            "manifest_rewrite_min_count_to_merge".to_owned(),
257            "compaction.max_snapshots_num".to_owned(),
258            "compaction.small_files_threshold_mb".to_owned(),
259            "compaction.delete_files_count_threshold".to_owned(),
260            "compaction.trigger_snapshot_count".to_owned(),
261            "compaction.target_file_size_mb".to_owned(),
262            "compaction.type".to_owned(),
263            "compaction.write_parquet_compression".to_owned(),
264            "compaction.write_parquet_max_row_group_rows".to_owned(),
265            "compaction.write_parquet_max_row_group_bytes".to_owned(),
266        ].into_iter().collect(),
267    ).unwrap();
268    // KafkaConfig
269    map.try_insert(
270        std::any::type_name::<KafkaConfig>().to_owned(),
271        [
272            "properties.sync.call.timeout".to_owned(),
273            "properties.security.protocol".to_owned(),
274            "properties.ssl.endpoint.identification.algorithm".to_owned(),
275            "properties.ssl.ca.location".to_owned(),
276            "properties.ssl.ca.pem".to_owned(),
277            "properties.ssl.certificate.location".to_owned(),
278            "properties.ssl.certificate.pem".to_owned(),
279            "properties.ssl.key.location".to_owned(),
280            "properties.ssl.key.pem".to_owned(),
281            "properties.ssl.key.password".to_owned(),
282            "properties.sasl.mechanism".to_owned(),
283            "properties.sasl.username".to_owned(),
284            "properties.sasl.password".to_owned(),
285            "properties.message.max.bytes".to_owned(),
286            "properties.receive.message.max.bytes".to_owned(),
287            "properties.statistics.interval.ms".to_owned(),
288            "properties.client.id".to_owned(),
289            "properties.enable.ssl.certificate.verification".to_owned(),
290            "properties.reconnect.backoff.ms".to_owned(),
291            "properties.reconnect.backoff.max.ms".to_owned(),
292            "properties.socket.connection.setup.timeout.ms".to_owned(),
293            "properties.retry.backoff.ms".to_owned(),
294            "properties.retry.backoff.max.ms".to_owned(),
295            "properties.allow.auto.create.topics".to_owned(),
296            "properties.queue.buffering.max.messages".to_owned(),
297            "properties.queue.buffering.max.kbytes".to_owned(),
298            "properties.queue.buffering.max.ms".to_owned(),
299            "properties.enable.idempotence".to_owned(),
300            "properties.message.send.max.retries".to_owned(),
301            "properties.batch.num.messages".to_owned(),
302            "properties.batch.size".to_owned(),
303            "properties.message.timeout.ms".to_owned(),
304            "properties.max.in.flight.requests.per.connection".to_owned(),
305            "properties.request.required.acks".to_owned(),
306        ].into_iter().collect(),
307    ).unwrap();
308    // OpenSearchConfig
309    map.try_insert(
310        std::any::type_name::<OpenSearchConfig>().to_owned(),
311        [
312            "batch_num_messages".to_owned(),
313            "batch_size_kb".to_owned(),
314            "concurrent_requests".to_owned(),
315        ].into_iter().collect(),
316    ).unwrap();
317    // PulsarConfig
318    map.try_insert(
319        std::any::type_name::<PulsarConfig>().to_owned(),
320        [
321            "properties.routing.mode".to_owned(),
322            "properties.routing_mode".to_owned(),
323            "routing_mode".to_owned(),
324            "pulsar.routing_mode".to_owned(),
325            "pulsar.routing.mode".to_owned(),
326            "pulsar.properties.routing.mode".to_owned(),
327            "pulsar.properties.routing_mode".to_owned(),
328        ].into_iter().collect(),
329    ).unwrap();
330    // SnowflakeV2Config
331    map.try_insert(
332        std::any::type_name::<SnowflakeV2Config>().to_owned(),
333        [
334            "commit_checkpoint_interval".to_owned(),
335        ].into_iter().collect(),
336    ).unwrap();
337    // StarrocksConfig
338    map.try_insert(
339        std::any::type_name::<StarrocksConfig>().to_owned(),
340        [
341            "starrocks.stream_load.http.timeout.ms".to_owned(),
342            "commit_checkpoint_interval".to_owned(),
343            "starrocks.max_batch_size_bytes".to_owned(),
344        ].into_iter().collect(),
345    ).unwrap();
346    // TurbopufferConfig
347    map.try_insert(
348        std::any::type_name::<TurbopufferConfig>().to_owned(),
349        [
350            "write_batch_size".to_owned(),
351            "max_linger_second".to_owned(),
352        ].into_iter().collect(),
353    ).unwrap();
354    // Jdbc
355    map.try_insert(
356        JdbcSink::SINK_NAME.to_owned(),
357        [
358            "jdbc.url".to_owned(),
359            "user".to_owned(),
360            "password".to_owned(),
361        ].into_iter().collect(),
362    ).unwrap();
363    map
364});
365
366/// Map of connection names to their `allow_alter_on_fly` field names
367pub static CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS: LazyLock<HashMap<String, HashSet<String>>> = LazyLock::new(|| {
368    use crate::connector_common::*;
369    let mut map = HashMap::new();
370    // KafkaConnection
371    map.try_insert(
372        std::any::type_name::<KafkaConnection>().to_owned(),
373        [
374            "properties.security.protocol".to_owned(),
375            "properties.ssl.endpoint.identification.algorithm".to_owned(),
376            "properties.ssl.ca.location".to_owned(),
377            "properties.ssl.ca.pem".to_owned(),
378            "properties.ssl.certificate.location".to_owned(),
379            "properties.ssl.certificate.pem".to_owned(),
380            "properties.ssl.key.location".to_owned(),
381            "properties.ssl.key.pem".to_owned(),
382            "properties.ssl.key.password".to_owned(),
383            "properties.sasl.mechanism".to_owned(),
384            "properties.sasl.username".to_owned(),
385            "properties.sasl.password".to_owned(),
386        ].into_iter().collect(),
387    ).unwrap();
388    // Jdbc
389    map.try_insert(
390        JdbcSink::SINK_NAME.to_owned(),
391        [
392            "jdbc.url".to_owned(),
393            "user".to_owned(),
394            "password".to_owned(),
395        ].into_iter().collect(),
396    ).unwrap();
397    map
398});
399
400/// Get all source connector names that have `allow_alter_on_fly` fields
401pub fn get_source_connectors_with_allow_alter_on_fly_fields() -> Vec<&'static str> {
402    SOURCE_ALLOW_ALTER_ON_FLY_FIELDS.keys().map(|s| s.as_str()).collect()
403}
404
405/// Get all sink connector names that have `allow_alter_on_fly` fields
406pub fn get_sink_connectors_with_allow_alter_on_fly_fields() -> Vec<&'static str> {
407    SINK_ALLOW_ALTER_ON_FLY_FIELDS.keys().map(|s| s.as_str()).collect()
408}
409
410/// Get all connection names that have `allow_alter_on_fly` fields
411pub fn get_connection_names_with_allow_alter_on_fly_fields() -> Vec<&'static str> {
412    CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS.keys().map(|s| s.as_str()).collect()
413}
414
415/// Checks if all given fields are allowed to be altered on the fly for the specified source connector.
416/// Returns Ok(()) if all fields are allowed, otherwise returns a `ConnectorError`.
417pub fn check_source_allow_alter_on_fly_fields(
418    connector_name: &str,
419    fields: &[String],
420) -> crate::error::ConnectorResult<()> {
421    // Convert connector name to the type name key
422    let Some(type_name) = source_properties::source_name_to_prop_type_name(connector_name) else {
423        return Err(ConnectorError::from(anyhow::anyhow!(
424            "Unknown source connector: {connector_name}"
425        )));
426    };
427    let Some(allowed_fields) = SOURCE_ALLOW_ALTER_ON_FLY_FIELDS.get(type_name) else {
428    return Err(ConnectorError::from(anyhow::anyhow!(
429        "No allow_alter_on_fly fields registered for connector: {connector_name}"
430    )));
431    };
432    for field in fields {
433        if !allowed_fields.contains(field) {
434            return Err(ConnectorError::from(anyhow::anyhow!(
435                "Field '{field}' is not allowed to be altered on the fly for connector: {connector_name}"
436            )));
437        }
438    }
439    Ok(())
440}
441
442pub fn check_connection_allow_alter_on_fly_fields(
443    connection_name: &str,
444    fields: &[String],
445) -> crate::error::ConnectorResult<()> {
446    use crate::source::connection_name_to_prop_type_name;
447
448    // Convert connection name to the type name key
449    let Some(type_name) = connection_name_to_prop_type_name(connection_name) else {
450        return Err(ConnectorError::from(anyhow::anyhow!(
451            "Unknown connection: {connection_name}"
452        )));
453    };
454    let Some(allowed_fields) = CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS.get(type_name) else {
455        return Err(ConnectorError::from(anyhow::anyhow!(
456            "No allow_alter_on_fly fields registered for connection: {connection_name}"
457        )));
458    };
459    for field in fields {
460        if !allowed_fields.contains(field) {
461            return Err(ConnectorError::from(anyhow::anyhow!(
462                "Field '{field}' is not allowed to be altered on the fly for connection: {connection_name}"
463            )));
464        }
465    }
466    Ok(())
467}
468
469/// Checks if all given fields are allowed to be altered on the fly for the specified sink connector.
470/// Returns Ok(()) if all fields are allowed, otherwise returns a `ConnectorError`.
471pub fn check_sink_allow_alter_on_fly_fields(
472    sink_name: &str,
473    fields: &[String],
474) -> crate::error::ConnectorResult<()> {
475    // TODO(#24846): JDBC sink currently uses `()` as sink config type in `for_all_sinks!`,
476    // so it cannot have an isolated key in `SINK_ALLOW_ALTER_ON_FLY_FIELDS`.
477    // Reuse the JDBC entry in `CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS` for now.
478    // TODO(#24846): remove this special case after JDBC sink has a dedicated config type
479    // and allow-alter fields are generated directly into `SINK_ALLOW_ALTER_ON_FLY_FIELDS`.
480    let allowed_fields = if sink_name == JdbcSink::SINK_NAME {
481        CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS.get(JdbcSink::SINK_NAME)
482    } else {
483        // Convert sink name to the type name key
484        let Some(type_name) = sink_properties::sink_name_to_config_type_name(sink_name) else {
485            return Err(ConnectorError::from(anyhow::anyhow!(
486                "Unknown sink connector: {sink_name}"
487            )));
488        };
489        SINK_ALLOW_ALTER_ON_FLY_FIELDS.get(type_name)
490    };
491    let Some(allowed_fields) = allowed_fields else {
492        return Err(ConnectorError::from(anyhow::anyhow!(
493            "No allow_alter_on_fly fields registered for sink: {sink_name}"
494        )));
495    };
496    for field in fields {
497        if !allowed_fields.contains(field) {
498            return Err(ConnectorError::from(anyhow::anyhow!(
499                "Field '{field}' is not allowed to be altered on the fly for sink: {sink_name}"
500            )));
501        }
502    }
503    Ok(())
504}