Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ protected String getListDatabaseSql() {

@Override
protected String getListTableSql(String databaseName) {
return "SELECT TABLE_SCHEMA, TABLE_NAME FROM "
return "SELECT TABLE_SCHEMA, TABLE_NAME FROM ["
+ databaseName
+ ".INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'";
+ "].INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'";
}

@Override
Expand Down Expand Up @@ -144,12 +144,12 @@ protected String getDropTableSql(TablePath tablePath) {

@Override
protected String getCreateDatabaseSql(String databaseName) {
return String.format("CREATE DATABASE %s", databaseName);
return String.format("CREATE DATABASE [%s]", databaseName);
}

@Override
protected String getDropDatabaseSql(String databaseName) {
return String.format("DROP DATABASE %s;", databaseName);
return String.format("DROP DATABASE [%s];", databaseName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,4 +587,42 @@ protected static void disableDbCdc(Connection connection, String name) throws SQ
Objects.requireNonNull(name);
connection.createStatement().execute(DISABLE_DB_CDC.replace(STATEMENTS_PLACEHOLDER, name));
}

@TestTemplate
public void testDatabaseNameWithSpecialCharacters(TestContainer container) {
initializeSqlServerTable("test_db_name");

CompletableFuture<Void> executeJobFuture =
CompletableFuture.supplyAsync(
() -> {
try {
container.executeJob("/sqlservercdc_special_db_name.conf");
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
});

String sourceTable = "[test-db-name].dbo.simple_table";
String sinkTable = "[test-db-name].dbo.simple_table_sink";
String selectSql = "select id, name, value from %s order by id asc";

await().atMost(60000, TimeUnit.MILLISECONDS)
.untilAsserted(
() -> {
Assertions.assertIterableEquals(
querySql(selectSql, sourceTable),
querySql(selectSql, sinkTable));
});

executeSql("INSERT INTO [test-db-name].dbo.simple_table VALUES (4, 'test4', 400)");

await().atMost(60000, TimeUnit.MILLISECONDS)
.untilAsserted(
() -> {
Assertions.assertIterableEquals(
querySql(selectSql, sourceTable),
querySql(selectSql, sinkTable));
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--
-- Licensed to the Apache Software Foundation (ASF) under one or more
-- contributor license agreements. See the NOTICE file distributed with
-- this work for additional information regarding copyright ownership.
-- The ASF licenses this file to You under the Apache License, Version 2.0
-- (the "License"); you may not use this file except in compliance with
-- the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

-- ----------------------------------------------------------------------------------------------------------------
-- DATABASE: test-db-name (database name with hyphen to test special character handling)
-- ----------------------------------------------------------------------------------------------------------------
CREATE DATABASE [test-db-name];

USE [test-db-name];
EXEC sys.sp_cdc_enable_db;

CREATE TABLE simple_table (
id int NOT NULL,
name varchar(100),
value int,
PRIMARY KEY (id)
);

INSERT INTO simple_table VALUES (1, 'test1', 100);
INSERT INTO simple_table VALUES (2, 'test2', 200);
INSERT INTO simple_table VALUES (3, 'test3', 300);

EXEC sys.sp_cdc_enable_table @source_schema = 'dbo', @source_name = 'simple_table', @role_name = NULL, @supports_net_changes = 0;

CREATE TABLE simple_table_sink (
id int NOT NULL,
name varchar(100),
value int,
PRIMARY KEY (id)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

env {
# You can set engine configuration here
parallelism = 1
job.mode = "STREAMING"
checkpoint.interval = 5000
}

source {
# This is a example source plugin **only for test and demonstrate the feature source plugin**
SqlServer-CDC {
plugin_output = "customers"
username = "sa"
password = "Password!"
database-names = ["test-db-name"]
table-names = ["test-db-name.dbo.simple_table"]
url = "jdbc:sqlserver://sqlserver-host:1433;databaseName=test-db-name"

exactly_once = false
}
}

transform {
}

sink {
Jdbc {
plugin_input = "customers"
driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
url = "jdbc:sqlserver://sqlserver-host:1433;encrypt=false"
user = "sa"
password = "Password!"
generate_sink_sql = true
database = "test-db-name"
table = "dbo.simple_table_sink"
batch_size = 1
primary_keys = ["id"]
}
}