ruanhang1993 commented on code in PR #3916:
URL: https://github.com/apache/flink-cdc/pull/3916#discussion_r2013473655
##########
flink-cdc-e2e-tests/flink-cdc-pipeline-e2e-tests/pom.xml:
##########
@@ -274,6 +276,36 @@ limitations under the License.
</outputDirectory>
</artifactItem>
+ <artifactItem>
+ <groupId>org.apache.flink</groupId>
+ <artifactId>flink-connector-jdbc</artifactId>
+ <version>${jdbc.version-1.19}</version>
+
<destFileName>jdbc-connector_1.19.1.jar</destFileName>
+ <type>jar</type>
+
<outputDirectory>${project.build.directory}/dependencies
+ </outputDirectory>
+ </artifactItem>
+
+ <artifactItem>
+ <groupId>org.apache.flink</groupId>
+ <artifactId>flink-connector-jdbc</artifactId>
+ <version>${jdbc.version-1.20}</version>
+
<destFileName>jdbc-connector_1.20.0.jar</destFileName>
+ <type>jar</type>
+
<outputDirectory>${project.build.directory}/dependencies
+ </outputDirectory>
+ </artifactItem>
+
+ <artifactItem>
+ <groupId>com.zaxxer</groupId>
+ <artifactId>HikariCP</artifactId>
+ <version>${hikari.version}</version>
+ <destFileName>HikariCP.jar</destFileName>
+ <type>jar</type>
+
<outputDirectory>${project.build.directory}/dependencies
+ </outputDirectory>
+ </artifactItem>
Review Comment:
Could `HikariCP` be packaged into jdbc pipeline connector?
##########
flink-cdc-e2e-tests/flink-cdc-pipeline-e2e-tests/src/test/java/org/apache/flink/cdc/pipeline/tests/MySqlToMySqlE2eITCase.java:
##########
@@ -0,0 +1,240 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.cdc.pipeline.tests;
+
+import org.apache.flink.cdc.common.test.utils.TestUtils;
+import org.apache.flink.cdc.common.utils.TestCaseUtils;
+import org.apache.flink.cdc.connectors.mysql.testutils.MySqlContainer;
+import org.apache.flink.cdc.connectors.mysql.testutils.MySqlVersion;
+import org.apache.flink.cdc.connectors.mysql.testutils.UniqueDatabase;
+import org.apache.flink.cdc.pipeline.tests.utils.PipelineTestEnvironment;
+
+import org.assertj.core.api.Assertions;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.lifecycle.Startables;
+
+import java.nio.file.Path;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static
org.apache.flink.cdc.connectors.mysql.sink.MySqlSinkTestBase.waitForMySqlContainerToBeReady;
+
+/** E2e test case from MySQL source to MySQL sink (JDBC). */
+public class MySqlToMySqlE2eITCase extends PipelineTestEnvironment {
Review Comment:
MySqlToJdbcMySqlE2eITCase
##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-jdbc/pom.xml:
##########
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.flink</groupId>
+ <artifactId>flink-cdc-pipeline-connectors</artifactId>
+ <version>${revision}</version>
+ </parent>
+
+ <properties>
+ <!-- JDBC connector for Flink 1.20 isn't released yet. -->
+ <flink.jdbc.connector.version>3.2.0-1.19</flink.jdbc.connector.version>
+ </properties>
+
+ <artifactId>flink-cdc-pipeline-connector-jdbc</artifactId>
Review Comment:
I think we should maintain the jdbc connector as `flink-connector-jdbc`. The
jdbc pipeline connector here is not a connector as it does not contain a
factory and we cannot find the factory by identifier `jdbc`.
Maybe we could rename this module as
`flink-cdc-pipeline-connector-jdbc-parent`. And it should contain different
modules as follows.
- flink-cdc-pipeline-connector-jdbc-parent
- flink-cdc-pipeline-connector-jdbc-core
- flink-cdc-pipeline-connector-jdbc-mysql
##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-jdbc/src/main/java/org/apache/flink/cdc/connectors/jdbc/catalog/JdbcCatalog.java:
##########
@@ -0,0 +1,289 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.cdc.connectors.jdbc.catalog;
+
+import org.apache.flink.cdc.common.event.AddColumnEvent;
+import org.apache.flink.cdc.common.event.AlterColumnTypeEvent;
+import org.apache.flink.cdc.common.event.CreateTableEvent;
+import org.apache.flink.cdc.common.event.DropColumnEvent;
+import org.apache.flink.cdc.common.event.DropTableEvent;
+import org.apache.flink.cdc.common.event.RenameColumnEvent;
+import org.apache.flink.cdc.common.event.TableId;
+import org.apache.flink.cdc.common.event.TruncateTableEvent;
+import org.apache.flink.cdc.common.schema.Schema;
+import org.apache.flink.cdc.common.types.DataType;
+import org.apache.flink.cdc.common.utils.Preconditions;
+import org.apache.flink.cdc.common.utils.StringUtils;
+import org.apache.flink.cdc.connectors.jdbc.config.JdbcSinkConfig;
+import org.apache.flink.cdc.connectors.jdbc.connection.JdbcConnectionFactory;
+import
org.apache.flink.cdc.connectors.jdbc.connection.JdbcConnectionPoolFactory;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Map;
+
+/** An abstract base class for various JDBC-like sinks. */
+public abstract class JdbcCatalog implements Serializable {
Review Comment:
The word `Catalog` is usually used in flink sql. `JdbcCatalog` is confused
for developers in flink cdc. Maybe use the name `JdbcDdlDialect`.
##########
flink-cdc-e2e-tests/flink-cdc-pipeline-e2e-tests/src/test/java/org/apache/flink/cdc/pipeline/tests/MySqlToMySqlE2eITCase.java:
##########
@@ -0,0 +1,240 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.cdc.pipeline.tests;
+
+import org.apache.flink.cdc.common.test.utils.TestUtils;
+import org.apache.flink.cdc.common.utils.TestCaseUtils;
+import org.apache.flink.cdc.connectors.mysql.testutils.MySqlContainer;
+import org.apache.flink.cdc.connectors.mysql.testutils.MySqlVersion;
+import org.apache.flink.cdc.connectors.mysql.testutils.UniqueDatabase;
+import org.apache.flink.cdc.pipeline.tests.utils.PipelineTestEnvironment;
+
+import org.assertj.core.api.Assertions;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.lifecycle.Startables;
+
+import java.nio.file.Path;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static
org.apache.flink.cdc.connectors.mysql.sink.MySqlSinkTestBase.waitForMySqlContainerToBeReady;
+
+/** E2e test case from MySQL source to MySQL sink (JDBC). */
+public class MySqlToMySqlE2eITCase extends PipelineTestEnvironment {
+ private static final Logger LOG =
LoggerFactory.getLogger(MySqlToMySqlE2eITCase.class);
+ public static final int TESTCASE_TIMEOUT_SECONDS = 60;
+ protected static final String TEST_USERNAME = "mysqluser";
+ protected static final String TEST_PASSWORD = "mysqlpw";
+ public static final String SOURCE_NETWORK_NAME = "mysqlsource";
+ public static final String SINK_NETWORK_NAME = "mysqlsink";
+ protected Path jdbcJar;
+
+ public static final MySqlContainer MYSQL_SOURCE =
+ (MySqlContainer)
+ new MySqlContainer(MySqlVersion.V8_0)
+ .withConfigurationOverride("docker/mysql/my.cnf")
+ .withSetupSQL("docker/mysql/setup.sql")
+ .withDatabaseName("flink-test")
+ .withUsername("flinkuser")
+ .withPassword("flinkpw")
+ .withNetwork(NETWORK)
+ .withNetworkAliases(SOURCE_NETWORK_NAME)
+ .withExposedPorts(3306)
+ .withLogConsumer(new Slf4jLogConsumer(LOG));
+
+ public static final MySqlContainer MYSQL_SINK =
+ (MySqlContainer)
+ new MySqlContainer(MySqlVersion.V8_0)
+ .withConfigurationOverride("docker/mysql/my.cnf")
+ .withSetupSQL("docker/mysql/setup.sql")
+ .withDatabaseName("flink-test")
+ .withUsername("flinkuser")
+ .withPassword("flinkpw")
+ .withNetwork(NETWORK)
+ .withNetworkAliases(SINK_NETWORK_NAME)
+ .withExposedPorts(3306)
+ .withLogConsumer(new Slf4jLogConsumer(LOG));
+
+ @BeforeClass
+ public static void initializeContainers() throws Exception {
+ Startables.deepStart(MYSQL_SOURCE, MYSQL_SINK).join();
+ LOG.info("Starting containers...");
+ waitForMySqlContainerToBeReady(MYSQL_SOURCE);
+ LOG.info("MySQL Source container started.");
+ waitForMySqlContainerToBeReady(MYSQL_SINK);
+ LOG.info("MySQL Sink container started.");
+ }
+
+ @AfterClass
+ public static void destroyContainers() {
+ if (MYSQL_SOURCE != null) {
+ MYSQL_SOURCE.stop();
+ }
+ if (MYSQL_SINK != null) {
+ MYSQL_SINK.stop();
+ }
+ }
+
+ protected final UniqueDatabase mysqlInventoryDatabase =
+ new UniqueDatabase(MYSQL_SOURCE, "mysql_inventory", TEST_USERNAME,
TEST_PASSWORD);
+
+ @Before
+ public void before() throws Exception {
+ super.before();
+ mysqlInventoryDatabase.createAndInitialize();
+ // Create sink database manually, as JDBC sink does not support DB
auto-creation
+ try (Connection conn =
+ DriverManager.getConnection(
+ MYSQL_SINK.getJdbcUrl(), TEST_USERNAME,
TEST_PASSWORD);
+ Statement stat = conn.createStatement()) {
+ stat.execute(
+ String.format("CREATE DATABASE %s;",
mysqlInventoryDatabase.getDatabaseName()));
+ }
+ jdbcJar = TestUtils.getResource(getJdbcConnectorResourceName());
+ }
+
+ protected String getJdbcConnectorResourceName() {
+ return String.format("jdbc-connector_%s.jar", flinkVersion);
+ }
+
+ @After
+ public void after() {
+ super.after();
+ mysqlInventoryDatabase.dropDatabase();
+ }
+
+ @Test
+ public void testSyncWholeDatabase() throws Exception {
+ String pipelineJob =
+ String.format(
+ "source:\n"
+ + " type: mysql\n"
+ + " hostname: %s\n"
+ + " port: 3306\n"
+ + " username: %s\n"
+ + " password: %s\n"
+ + " tables: %s.\\.*\n"
+ + " server-id: 5400-5404\n"
+ + " server-time-zone: UTC\n"
+ + " jdbc.properties.useSSL: false\n"
+ + " jdbc.properties.allowPublicKeyRetrieval:
true\n"
+ + "\n"
+ + "sink:\n"
+ + " type: mysql\n"
+ + " hostname: %s\n"
+ + " port: 3306\n"
+ + " username: %s\n"
+ + " password: %s\n"
+ + "\n"
+ + "pipeline:\n"
+ + " parallelism: %d",
+ SOURCE_NETWORK_NAME,
+ TEST_USERNAME,
+ TEST_PASSWORD,
+ mysqlInventoryDatabase.getDatabaseName(),
+ SINK_NETWORK_NAME,
+ TEST_USERNAME,
+ TEST_PASSWORD,
+ parallelism);
+
+ Path mysqlCdcJar =
TestUtils.getResource("mysql-cdc-pipeline-connector.jar");
+ Path mysqlDriverJar = TestUtils.getResource("mysql-driver.jar");
+ submitPipelineJob(pipelineJob, mysqlCdcJar, jdbcJar, mysqlDriverJar);
+ waitUntilJobRunning(Duration.ofSeconds(30));
+ LOG.info("Pipeline job is running");
+
+ validateSinkResult(
+ "products",
+ 7,
+ Arrays.asList(
+ "101 | scooter | Small 2-wheel scooter | 3.14 | red |
{\"key1\": \"value1\"} | {\"coordinates\":[1,1],\"type\":\"Point\",\"srid\":0}",
+ "102 | car battery | 12V car battery | 8.1 | white |
{\"key2\": \"value2\"} | {\"coordinates\":[2,2],\"type\":\"Point\",\"srid\":0}",
+ "103 | 12-pack drill bits | 12-pack of drill bits with
sizes ranging from #40 to #3 | 0.8 | red | {\"key3\": \"value3\"} |
{\"coordinates\":[3,3],\"type\":\"Point\",\"srid\":0}",
+ "104 | hammer | 12oz carpenter's hammer | 0.75 | white
| {\"key4\": \"value4\"} |
{\"coordinates\":[4,4],\"type\":\"Point\",\"srid\":0}",
+ "105 | hammer | 14oz carpenter's hammer | 0.875 | red
| {\"k1\": \"v1\", \"k2\": \"v2\"} |
{\"coordinates\":[5,5],\"type\":\"Point\",\"srid\":0}",
+ "106 | hammer | 16oz carpenter's hammer | 1.0 | null |
null | null",
+ "107 | rocks | box of assorted rocks | 5.3 | null |
null | null",
+ "108 | jacket | water resistent black wind breaker |
0.1 | null | null | null",
+ "109 | spare tire | 24 inch spare tire | 22.2 | null |
null | null"));
Review Comment:
Could you add some schema changes in the e2e test?
##########
flink-cdc-e2e-tests/flink-cdc-pipeline-e2e-tests/pom.xml:
##########
@@ -32,6 +32,8 @@ limitations under the License.
<flink-1.20>1.20.0</flink-1.20>
<flink-major-1.19>1.19</flink-major-1.19>
<flink-major-1.20>1.20</flink-major-1.20>
+ <jdbc.version-1.19>3.2.0-1.19</jdbc.version-1.19>
+ <jdbc.version-1.20>3.2.0-1.19</jdbc.version-1.20>
Review Comment:
Please add a TODO here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]