risingwave_connector/source/cdc/
sql_server.rs1use std::collections::BTreeMap;
16
17use risingwave_common::license::{Feature, FeatureNotAvailable};
18use risingwave_pb::secret::PbSecretRef;
19
20use crate::error::ConnectorResult;
21use crate::source::cdc::external::{DATABASE_NAME_KEY, SchemaTableName};
22use crate::source::cdc::{
23 CdcSourceDdlValidator, CdcSourceExternalTableIdentifier, CdcSourceRuntimeFlags,
24 CdcSourceTypeTrait, SqlServer, check_alter_with_options_inner, check_common_with_options,
25 split_quoted_identifier_inner,
26};
27
28impl CdcSourceRuntimeFlags for SqlServer {
31 const CAN_BACKFILL: bool = true;
32 const NEEDS_NON_EMPTY_INITIAL_OFFSET: bool = true;
33 }
37
38impl CdcSourceDdlValidator for SqlServer {
41 fn check_and_fill_create_with_options(
42 props: &mut BTreeMap<String, String>,
43 secret_refs: &BTreeMap<String, PbSecretRef>,
44 ) -> ConnectorResult<()> {
45 check_common_with_options::<Self>(props, secret_refs)?;
46 if !props.contains_key("schema.name") {
47 props.insert("schema.name".into(), "dbo".into());
49 }
50 Ok(())
51 }
52
53 fn check_license() -> Result<(), FeatureNotAvailable> {
54 Feature::SqlServerCdcSource.check_available()
55 }
56
57 fn check_alter_with_options(
58 props: &BTreeMap<String, String>,
59 secret_refs: &BTreeMap<String, PbSecretRef>,
60 ) -> ConnectorResult<()> {
61 check_common_with_options::<Self>(props, secret_refs)?;
62 check_alter_with_options_inner(
63 Self::CDC_CONNECTOR_NAME,
64 props,
65 secret_refs,
66 &[
67 "cdc.source.wait.streaming.start.timeout",
68 "debezium.max.queue.size",
69 "debezium.queue.memory.ratio",
70 "hostname",
71 "port",
72 "password",
73 ],
74 )
75 }
76}
77
78impl CdcSourceExternalTableIdentifier for SqlServer {
81 fn canonical_name(connect_properties: &BTreeMap<String, String>) -> String {
86 let SchemaTableName {
87 schema_name,
88 table_name,
89 } = SchemaTableName::from_properties(connect_properties);
90 let database_name = connect_properties
91 .get(DATABASE_NAME_KEY)
92 .map(String::as_str)
93 .unwrap_or_default();
94 format!("{database_name}.{schema_name}.{table_name}")
95 }
96
97 fn split_quoted_identifier(name: &str) -> Option<Vec<String>> {
98 split_quoted_identifier_inner(name, '[', ']')
99 }
100}