in flink-doris-connector/src/main/java/org/apache/doris/flink/tools/cdc/sqlserver/SqlServerDatabaseSync.java [130:215]
public DataStreamSource<String> buildCdcSource(StreamExecutionEnvironment env) {
String databaseName = config.get(JdbcSourceOptions.DATABASE_NAME);
String schemaName = config.get(JdbcSourceOptions.SCHEMA_NAME);
Preconditions.checkNotNull(databaseName, "database-name in sqlserver is required");
Preconditions.checkNotNull(schemaName, "schema-name in sqlserver is required");
String tableName = config.get(JdbcSourceOptions.TABLE_NAME);
String hostname = config.get(JdbcSourceOptions.HOSTNAME);
int port = config.getInteger(PORT, 1433);
String username = config.get(JdbcSourceOptions.USERNAME);
String password = config.get(JdbcSourceOptions.PASSWORD);
StartupOptions startupOptions = StartupOptions.initial();
String startupMode = config.get(JdbcSourceOptions.SCAN_STARTUP_MODE);
if (DatabaseSyncConfig.SCAN_STARTUP_MODE_VALUE_INITIAL.equalsIgnoreCase(startupMode)) {
startupOptions = StartupOptions.initial();
} else if (DatabaseSyncConfig.SCAN_STARTUP_MODE_VALUE_LATEST_OFFSET.equalsIgnoreCase(
startupMode)) {
startupOptions = StartupOptions.latest();
}
// debezium properties set
Properties debeziumProperties = new Properties();
debeziumProperties.putAll(SqlServerDateConverter.DEFAULT_PROPS);
debeziumProperties.put(DatabaseSyncConfig.DECIMAL_HANDLING_MODE, "string");
for (Map.Entry<String, String> entry : config.toMap().entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (key.startsWith(DebeziumOptions.DEBEZIUM_OPTIONS_PREFIX)) {
debeziumProperties.put(
key.substring(DebeziumOptions.DEBEZIUM_OPTIONS_PREFIX.length()), value);
}
}
DebeziumDeserializationSchema<String> schema;
if (ignoreDefaultValue) {
schema = new DorisJsonDebeziumDeserializationSchema();
} else {
Map<String, Object> customConverterConfigs = new HashMap<>();
customConverterConfigs.put(JsonConverterConfig.DECIMAL_FORMAT_CONFIG, "numeric");
schema = new JsonDebeziumDeserializationSchema(false, customConverterConfigs);
}
if (config.getBoolean(SourceOptions.SCAN_INCREMENTAL_SNAPSHOT_ENABLED, false)) {
JdbcIncrementalSource<String> incrSource =
SqlServerSourceBuilder.SqlServerIncrementalSource.<String>builder()
.hostname(hostname)
.port(port)
.databaseList(databaseName)
.tableList(tableName)
.username(username)
.password(password)
.startupOptions(startupOptions)
.deserializer(schema)
.includeSchemaChanges(true)
.debeziumProperties(debeziumProperties)
.splitSize(config.get(SCAN_INCREMENTAL_SNAPSHOT_CHUNK_SIZE))
.splitMetaGroupSize(config.get(CHUNK_META_GROUP_SIZE))
.fetchSize(config.get(SCAN_SNAPSHOT_FETCH_SIZE))
.connectTimeout(config.get(CONNECT_TIMEOUT))
.connectionPoolSize(config.get(CONNECTION_POOL_SIZE))
.connectMaxRetries(config.get(CONNECT_MAX_RETRIES))
.distributionFactorUpper(
config.get(SPLIT_KEY_EVEN_DISTRIBUTION_FACTOR_UPPER_BOUND))
.distributionFactorLower(
config.get(SPLIT_KEY_EVEN_DISTRIBUTION_FACTOR_LOWER_BOUND))
.build();
return env.fromSource(
incrSource, WatermarkStrategy.noWatermarks(), "SqlServer IncrSource");
} else {
DebeziumSourceFunction<String> sqlServerSource =
SqlServerSource.<String>builder()
.hostname(hostname)
.port(port)
.database(databaseName)
.tableList(tableName)
.username(username)
.password(password)
.debeziumProperties(debeziumProperties)
.startupOptions(startupOptions)
.deserializer(schema)
.build();
return env.addSource(sqlServerSource, "SqlServer Source");
}
}