1#![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 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
105pub 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 map.try_insert(
111 std::any::type_name::<KafkaProperties>().to_owned(),
112 [
113 "group.id.prefix".to_owned(),
114 "properties.sync.call.timeout".to_owned(),
115 "properties.security.protocol".to_owned(),
116 "properties.ssl.endpoint.identification.algorithm".to_owned(),
117 "properties.ssl.ca.location".to_owned(),
118 "properties.ssl.ca.pem".to_owned(),
119 "properties.ssl.certificate.location".to_owned(),
120 "properties.ssl.certificate.pem".to_owned(),
121 "properties.ssl.key.location".to_owned(),
122 "properties.ssl.key.pem".to_owned(),
123 "properties.ssl.key.password".to_owned(),
124 "properties.sasl.mechanism".to_owned(),
125 "properties.sasl.username".to_owned(),
126 "properties.sasl.password".to_owned(),
127 "properties.sasl.kerberos.service.name".to_owned(),
128 "properties.sasl.kerberos.keytab".to_owned(),
129 "properties.sasl.kerberos.principal".to_owned(),
130 "properties.sasl.kerberos.min.time.before.relogin".to_owned(),
131 "properties.sasl.oauthbearer.config".to_owned(),
132 "properties.sasl.oauthbearer.method".to_owned(),
133 "properties.sasl.oauthbearer.client.id".to_owned(),
134 "properties.sasl.oauthbearer.client.secret".to_owned(),
135 "properties.sasl.oauthbearer.token.endpoint.url".to_owned(),
136 "properties.sasl.oauthbearer.scope".to_owned(),
137 "properties.sasl.oauthbearer.extensions".to_owned(),
138 "properties.message.max.bytes".to_owned(),
139 "properties.receive.message.max.bytes".to_owned(),
140 "properties.statistics.interval.ms".to_owned(),
141 "properties.client.id".to_owned(),
142 "properties.enable.ssl.certificate.verification".to_owned(),
143 "properties.reconnect.backoff.ms".to_owned(),
144 "properties.reconnect.backoff.max.ms".to_owned(),
145 "properties.socket.connection.setup.timeout.ms".to_owned(),
146 "properties.retry.backoff.ms".to_owned(),
147 "properties.retry.backoff.max.ms".to_owned(),
148 "properties.queued.min.messages".to_owned(),
149 "properties.queued.max.messages.kbytes".to_owned(),
150 "properties.fetch.wait.max.ms".to_owned(),
151 "properties.fetch.queue.backoff.ms".to_owned(),
152 "properties.fetch.max.bytes".to_owned(),
153 "properties.enable.auto.commit".to_owned(),
154 "properties.auto.commit.interval.ms".to_owned(),
155 ].into_iter().collect(),
156 ).unwrap();
157 map.try_insert(
159 std::any::type_name::<PubsubProperties>().to_owned(),
160 [
161 "pubsub.ack_deadline_seconds".to_owned(),
162 "pubsub.max_outstanding_messages".to_owned(),
163 "pubsub.max_outstanding_bytes".to_owned(),
164 ].into_iter().collect(),
165 ).unwrap();
166 map.try_insert(
168 std::any::type_name::<PulsarProperties>().to_owned(),
169 [
170 "pulsar.operation.retry.max.retries".to_owned(),
171 "pulsar.operation.retry.delay".to_owned(),
172 ].into_iter().collect(),
173 ).unwrap();
174 map
175});
176
177pub static SINK_ALLOW_ALTER_ON_FLY_FIELDS: LazyLock<HashMap<String, HashSet<String>>> = LazyLock::new(|| {
179 use sink_properties::*;
180 let mut map = HashMap::new();
181 map.try_insert(
183 std::any::type_name::<BigQueryConfig>().to_owned(),
184 [
185 "bigquery.change_sequence_number".to_owned(),
186 ].into_iter().collect(),
187 ).unwrap();
188 map.try_insert(
190 std::any::type_name::<ClickHouseConfig>().to_owned(),
191 [
192 "commit_checkpoint_interval".to_owned(),
193 ].into_iter().collect(),
194 ).unwrap();
195 map.try_insert(
197 std::any::type_name::<DeltaLakeConfig>().to_owned(),
198 [
199 "commit_checkpoint_interval".to_owned(),
200 ].into_iter().collect(),
201 ).unwrap();
202 map.try_insert(
204 std::any::type_name::<DorisConfig>().to_owned(),
205 [
206 "doris.stream_load.http.timeout.ms".to_owned(),
207 ].into_iter().collect(),
208 ).unwrap();
209 map.try_insert(
211 std::any::type_name::<ElasticSearchConfig>().to_owned(),
212 [
213 "batch_num_messages".to_owned(),
214 "batch_size_kb".to_owned(),
215 "concurrent_requests".to_owned(),
216 ].into_iter().collect(),
217 ).unwrap();
218 map.try_insert(
220 std::any::type_name::<IcebergConfig>().to_owned(),
221 [
222 "commit_checkpoint_interval".to_owned(),
223 "enable_compaction".to_owned(),
224 "compaction_interval_sec".to_owned(),
225 "enable_snapshot_expiration".to_owned(),
226 "snapshot_expiration_max_age_millis".to_owned(),
227 "snapshot_expiration_retain_last".to_owned(),
228 "snapshot_expiration_clear_expired_files".to_owned(),
229 "snapshot_expiration_clear_expired_meta_data".to_owned(),
230 "enable_manifest_rewrite".to_owned(),
231 "manifest_rewrite_target_size_bytes".to_owned(),
232 "manifest_rewrite_min_count_to_merge".to_owned(),
233 "enable_orphan_file_cleanup".to_owned(),
234 "orphan_file_cleanup_min_age_millis".to_owned(),
235 "compaction.max_snapshots_num".to_owned(),
236 "compaction.small_files_threshold_mb".to_owned(),
237 "compaction.delete_files_count_threshold".to_owned(),
238 "compaction.delete_ratio_percent".to_owned(),
239 "compaction.trigger_snapshot_count".to_owned(),
240 "compaction.target_file_size_mb".to_owned(),
241 "compaction.type".to_owned(),
242 "compaction.write_parquet_compression".to_owned(),
243 "compaction.write_parquet_max_row_group_rows".to_owned(),
244 "compaction.write_parquet_max_row_group_bytes".to_owned(),
245 ].into_iter().collect(),
246 ).unwrap();
247 map.try_insert(
249 std::any::type_name::<KafkaConfig>().to_owned(),
250 [
251 "properties.sync.call.timeout".to_owned(),
252 "properties.security.protocol".to_owned(),
253 "properties.ssl.endpoint.identification.algorithm".to_owned(),
254 "properties.ssl.ca.location".to_owned(),
255 "properties.ssl.ca.pem".to_owned(),
256 "properties.ssl.certificate.location".to_owned(),
257 "properties.ssl.certificate.pem".to_owned(),
258 "properties.ssl.key.location".to_owned(),
259 "properties.ssl.key.pem".to_owned(),
260 "properties.ssl.key.password".to_owned(),
261 "properties.sasl.mechanism".to_owned(),
262 "properties.sasl.username".to_owned(),
263 "properties.sasl.password".to_owned(),
264 "properties.sasl.kerberos.service.name".to_owned(),
265 "properties.sasl.kerberos.keytab".to_owned(),
266 "properties.sasl.kerberos.principal".to_owned(),
267 "properties.sasl.kerberos.min.time.before.relogin".to_owned(),
268 "properties.sasl.oauthbearer.config".to_owned(),
269 "properties.sasl.oauthbearer.method".to_owned(),
270 "properties.sasl.oauthbearer.client.id".to_owned(),
271 "properties.sasl.oauthbearer.client.secret".to_owned(),
272 "properties.sasl.oauthbearer.token.endpoint.url".to_owned(),
273 "properties.sasl.oauthbearer.scope".to_owned(),
274 "properties.sasl.oauthbearer.extensions".to_owned(),
275 "properties.message.max.bytes".to_owned(),
276 "properties.receive.message.max.bytes".to_owned(),
277 "properties.statistics.interval.ms".to_owned(),
278 "properties.client.id".to_owned(),
279 "properties.enable.ssl.certificate.verification".to_owned(),
280 "properties.reconnect.backoff.ms".to_owned(),
281 "properties.reconnect.backoff.max.ms".to_owned(),
282 "properties.socket.connection.setup.timeout.ms".to_owned(),
283 "properties.retry.backoff.ms".to_owned(),
284 "properties.retry.backoff.max.ms".to_owned(),
285 "properties.allow.auto.create.topics".to_owned(),
286 "properties.queue.buffering.max.messages".to_owned(),
287 "properties.queue.buffering.max.kbytes".to_owned(),
288 "properties.queue.buffering.max.ms".to_owned(),
289 "properties.enable.idempotence".to_owned(),
290 "properties.message.send.max.retries".to_owned(),
291 "properties.batch.num.messages".to_owned(),
292 "properties.batch.size".to_owned(),
293 "properties.message.timeout.ms".to_owned(),
294 "properties.max.in.flight.requests.per.connection".to_owned(),
295 "properties.request.required.acks".to_owned(),
296 ].into_iter().collect(),
297 ).unwrap();
298 map.try_insert(
300 std::any::type_name::<LanceDbConfig>().to_owned(),
301 [
302 "commit_checkpoint_interval".to_owned(),
303 ].into_iter().collect(),
304 ).unwrap();
305 map.try_insert(
307 std::any::type_name::<OpenSearchConfig>().to_owned(),
308 [
309 "batch_num_messages".to_owned(),
310 "batch_size_kb".to_owned(),
311 "concurrent_requests".to_owned(),
312 ].into_iter().collect(),
313 ).unwrap();
314 map.try_insert(
316 std::any::type_name::<PulsarConfig>().to_owned(),
317 [
318 "properties.routing.mode".to_owned(),
319 "properties.routing_mode".to_owned(),
320 "routing_mode".to_owned(),
321 "pulsar.routing_mode".to_owned(),
322 "pulsar.routing.mode".to_owned(),
323 "pulsar.properties.routing.mode".to_owned(),
324 "pulsar.properties.routing_mode".to_owned(),
325 ].into_iter().collect(),
326 ).unwrap();
327 map.try_insert(
329 std::any::type_name::<SnowflakeV2Config>().to_owned(),
330 [
331 "commit_checkpoint_interval".to_owned(),
332 ].into_iter().collect(),
333 ).unwrap();
334 map.try_insert(
336 std::any::type_name::<StarrocksConfig>().to_owned(),
337 [
338 "starrocks.stream_load.http.timeout.ms".to_owned(),
339 "commit_checkpoint_interval".to_owned(),
340 "starrocks.max_batch_size_bytes".to_owned(),
341 "starrocks.max_transaction_size_bytes".to_owned(),
342 "starrocks.ignore_json_size".to_owned(),
343 "starrocks.load_mem_limit".to_owned(),
344 "starrocks.transaction_timeout_seconds".to_owned(),
345 ].into_iter().collect(),
346 ).unwrap();
347 map.try_insert(
349 std::any::type_name::<TurbopufferConfig>().to_owned(),
350 [
351 "write_batch_size".to_owned(),
352 "max_linger_second".to_owned(),
353 ].into_iter().collect(),
354 ).unwrap();
355 map.try_insert(
357 JdbcSink::SINK_NAME.to_owned(),
358 [
359 "jdbc.url".to_owned(),
360 "user".to_owned(),
361 "password".to_owned(),
362 ].into_iter().collect(),
363 ).unwrap();
364 map
365});
366
367pub static CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS: LazyLock<HashMap<String, HashSet<String>>> = LazyLock::new(|| {
369 use crate::connector_common::*;
370 let mut map = HashMap::new();
371 map.try_insert(
373 std::any::type_name::<KafkaConnection>().to_owned(),
374 [
375 "properties.security.protocol".to_owned(),
376 "properties.ssl.endpoint.identification.algorithm".to_owned(),
377 "properties.ssl.ca.location".to_owned(),
378 "properties.ssl.ca.pem".to_owned(),
379 "properties.ssl.certificate.location".to_owned(),
380 "properties.ssl.certificate.pem".to_owned(),
381 "properties.ssl.key.location".to_owned(),
382 "properties.ssl.key.pem".to_owned(),
383 "properties.ssl.key.password".to_owned(),
384 "properties.sasl.mechanism".to_owned(),
385 "properties.sasl.username".to_owned(),
386 "properties.sasl.password".to_owned(),
387 "properties.sasl.kerberos.service.name".to_owned(),
388 "properties.sasl.kerberos.keytab".to_owned(),
389 "properties.sasl.kerberos.principal".to_owned(),
390 "properties.sasl.kerberos.min.time.before.relogin".to_owned(),
391 "properties.sasl.oauthbearer.config".to_owned(),
392 "properties.sasl.oauthbearer.method".to_owned(),
393 "properties.sasl.oauthbearer.client.id".to_owned(),
394 "properties.sasl.oauthbearer.client.secret".to_owned(),
395 "properties.sasl.oauthbearer.token.endpoint.url".to_owned(),
396 "properties.sasl.oauthbearer.scope".to_owned(),
397 "properties.sasl.oauthbearer.extensions".to_owned(),
398 ].into_iter().collect(),
399 ).unwrap();
400 map.try_insert(
402 JdbcSink::SINK_NAME.to_owned(),
403 [
404 "jdbc.url".to_owned(),
405 "user".to_owned(),
406 "password".to_owned(),
407 ].into_iter().collect(),
408 ).unwrap();
409 map
410});
411
412pub fn get_source_connectors_with_allow_alter_on_fly_fields() -> Vec<&'static str> {
414 SOURCE_ALLOW_ALTER_ON_FLY_FIELDS.keys().map(|s| s.as_str()).collect()
415}
416
417pub fn get_sink_connectors_with_allow_alter_on_fly_fields() -> Vec<&'static str> {
419 SINK_ALLOW_ALTER_ON_FLY_FIELDS.keys().map(|s| s.as_str()).collect()
420}
421
422pub fn get_connection_names_with_allow_alter_on_fly_fields() -> Vec<&'static str> {
424 CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS.keys().map(|s| s.as_str()).collect()
425}
426
427pub fn check_source_allow_alter_on_fly_fields(
430 connector_name: &str,
431 fields: &[String],
432) -> crate::error::ConnectorResult<()> {
433 let Some(type_name) = source_properties::source_name_to_prop_type_name(connector_name) else {
435 return Err(ConnectorError::from(anyhow::anyhow!(
436 "Unknown source connector: {connector_name}"
437 )));
438 };
439 let Some(allowed_fields) = SOURCE_ALLOW_ALTER_ON_FLY_FIELDS.get(type_name) else {
440 return Err(ConnectorError::from(anyhow::anyhow!(
441 "No allow_alter_on_fly fields registered for connector: {connector_name}"
442 )));
443 };
444 for field in fields {
445 if !allowed_fields.contains(field) {
446 return Err(ConnectorError::from(anyhow::anyhow!(
447 "Field '{field}' is not allowed to be altered on the fly for connector: {connector_name}"
448 )));
449 }
450 }
451 Ok(())
452}
453
454pub fn check_connection_allow_alter_on_fly_fields(
455 connection_name: &str,
456 fields: &[String],
457) -> crate::error::ConnectorResult<()> {
458 use crate::source::connection_name_to_prop_type_name;
459
460 let Some(type_name) = connection_name_to_prop_type_name(connection_name) else {
462 return Err(ConnectorError::from(anyhow::anyhow!(
463 "Unknown connection: {connection_name}"
464 )));
465 };
466 let Some(allowed_fields) = CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS.get(type_name) else {
467 return Err(ConnectorError::from(anyhow::anyhow!(
468 "No allow_alter_on_fly fields registered for connection: {connection_name}"
469 )));
470 };
471 for field in fields {
472 if !allowed_fields.contains(field) {
473 return Err(ConnectorError::from(anyhow::anyhow!(
474 "Field '{field}' is not allowed to be altered on the fly for connection: {connection_name}"
475 )));
476 }
477 }
478 Ok(())
479}
480
481pub fn check_sink_allow_alter_on_fly_fields(
484 sink_name: &str,
485 fields: &[String],
486) -> crate::error::ConnectorResult<()> {
487 let allowed_fields = if sink_name == JdbcSink::SINK_NAME {
493 CONNECTION_ALLOW_ALTER_ON_FLY_FIELDS.get(JdbcSink::SINK_NAME)
494 } else {
495 let Some(type_name) = sink_properties::sink_name_to_config_type_name(sink_name) else {
497 return Err(ConnectorError::from(anyhow::anyhow!(
498 "Unknown sink connector: {sink_name}"
499 )));
500 };
501 SINK_ALLOW_ALTER_ON_FLY_FIELDS.get(type_name)
502 };
503 let Some(allowed_fields) = allowed_fields else {
504 return Err(ConnectorError::from(anyhow::anyhow!(
505 "No allow_alter_on_fly fields registered for sink: {sink_name}"
506 )));
507 };
508 for field in fields {
509 if !allowed_fields.contains(field) {
510 return Err(ConnectorError::from(anyhow::anyhow!(
511 "Field '{field}' is not allowed to be altered on the fly for sink: {sink_name}"
512 )));
513 }
514 }
515 Ok(())
516}