You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "zhuangchong (via GitHub)" <gi...@apache.org> on 2024/01/18 06:12:29 UTC

[PR] [cdc] Added postgresql table cdc synchronization action [incubator-paimon]

zhuangchong opened a new pull request, #2734:
URL: https://github.com/apache/incubator-paimon/pull/2734

   <!-- Please specify the module before the PR name: [core] ... or [flink] ... -->
   
   ### Purpose
   
   <!-- Linking this pull request to the issue -->
   Added postgresql table cdc synchronization action
   
   <!-- What is the purpose of the change -->
   
   ### Tests
   
   <!-- List UT and IT cases to verify this change -->
   
   ### API and Format
   
   <!-- Does this change affect API or storage format -->
   
   ### Documentation
   
   <!-- Does this change introduce a new feature -->
   


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [cdc] Added postgresql table cdc synchronization action [incubator-paimon]

Posted by "zhuangchong (via GitHub)" <gi...@apache.org>.
zhuangchong commented on code in PR #2734:
URL: https://github.com/apache/incubator-paimon/pull/2734#discussion_r1464326458


##########
paimon-flink/paimon-flink-cdc/src/test/resources/postgres/sync_table_setup.sql:
##########
@@ -0,0 +1,291 @@
+-- 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.
+
+-- In production you would almost certainly limit the replication user must be on the follower (slave) machine,
+-- to prevent other clients accessing the log from other machines. For example, 'replicator'@'follower.acme.com'.
+-- However, in this database we'll grant the test user 'paimonuser' all privileges:
+--
+
+-- ################################################################################
+--  PostgresSyncTableActionITCase
+-- ################################################################################
+
+CREATE DATABASE paimon_sync_table;
+
+\c paimon_sync_table;

Review Comment:
   It is the script syntax for PG to switch databases. It is used to switch databases and can run normally.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [cdc] Added postgresql table cdc synchronization action [incubator-paimon]

Posted by "zhuangchong (via GitHub)" <gi...@apache.org>.
zhuangchong commented on code in PR #2734:
URL: https://github.com/apache/incubator-paimon/pull/2734#discussion_r1464327079


##########
paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/action/cdc/mysql/MySqlActionITCaseBase.java:
##########
@@ -84,6 +84,11 @@ protected Map<String, String> getBasicMySqlConfig() {
         config.put("password", PASSWORD);
         // see mysql/my.cnf in test resources
         config.put("server-time-zone", ZoneId.of("America/New_York").toString());
+
+        // TODO When setting the parameter scan.newly-added-table.enabled=true in version 2.4.2, the
+        // Insert data inserted after the newly created table cannot be captured. When set to false,
+        // the mysql cdc works normally.
+        config.put("scan.newly-added-table.enabled", "false");

Review Comment:
   The upgrade of mysql cdc to 2.4.2 is due to the incompatibility between the versions of debezium, the dependency package of pgcdc and mysql cdc. The method for pgcdc to use incremental snapshots is only available in version 2.4.x, so the versions of mysqlcdc and pgcdc are both setup 2.4.2



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [cdc] Added postgresql table cdc synchronization action [incubator-paimon]

Posted by "zhuangchong (via GitHub)" <gi...@apache.org>.
zhuangchong commented on code in PR #2734:
URL: https://github.com/apache/incubator-paimon/pull/2734#discussion_r1458377879


##########
paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/postgres/PostgresSyncTableActionFactory.java:
##########
@@ -0,0 +1,171 @@
+/*
+ * 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.paimon.flink.action.cdc.postgres;
+
+import org.apache.paimon.flink.action.Action;
+import org.apache.paimon.flink.action.ActionFactory;
+import org.apache.paimon.flink.action.MultipleParameterToolAdapter;
+import org.apache.paimon.flink.action.cdc.TypeMapping;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+
+import java.util.ArrayList;
+import java.util.Optional;
+
+import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.COMPUTED_COLUMN;
+import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.METADATA_COLUMN;
+import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.PARTITION_KEYS;
+import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.POSTGRES_CONF;
+import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.PRIMARY_KEYS;
+import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.TYPE_MAPPING;
+
+/** Factory to create {@link PostgresSyncTableAction}. */
+public class PostgresSyncTableActionFactory implements ActionFactory {
+
+    public static final String IDENTIFIER = "postgres_sync_table";
+
+    @Override
+    public String identifier() {
+        return IDENTIFIER;
+    }
+
+    @Override
+    public Optional<Action> create(MultipleParameterToolAdapter params) {
+        Tuple3<String, String, String> tablePath = getTablePath(params);
+        checkRequiredArgument(params, POSTGRES_CONF);
+
+        PostgresSyncTableAction action =
+                new PostgresSyncTableAction(
+                        tablePath.f0,
+                        tablePath.f1,
+                        tablePath.f2,
+                        optionalConfigMap(params, CATALOG_CONF),
+                        optionalConfigMap(params, POSTGRES_CONF));
+
+        action.withTableConfig(optionalConfigMap(params, TABLE_CONF));
+
+        if (params.has(PARTITION_KEYS)) {
+            action.withPartitionKeys(params.get(PARTITION_KEYS).split(","));
+        }
+
+        if (params.has(PRIMARY_KEYS)) {
+            action.withPrimaryKeys(params.get(PRIMARY_KEYS).split(","));
+        }
+
+        if (params.has(COMPUTED_COLUMN)) {
+            action.withComputedColumnArgs(
+                    new ArrayList<>(params.getMultiParameter(COMPUTED_COLUMN)));
+        }
+
+        if (params.has(METADATA_COLUMN)) {
+            action.withMetadataColumns(new ArrayList<>(params.getMultiParameter(METADATA_COLUMN)));
+        }
+
+        if (params.has(TYPE_MAPPING)) {
+            String[] options = params.get(TYPE_MAPPING).split(",");
+            action.withTypeMapping(TypeMapping.parse(options));
+        }
+
+        return Optional.of(action);

Review Comment:
   done.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [cdc] Added postgresql table cdc synchronization action [incubator-paimon]

Posted by "TaoZex (via GitHub)" <gi...@apache.org>.
TaoZex commented on code in PR #2734:
URL: https://github.com/apache/incubator-paimon/pull/2734#discussion_r1457616715


##########
paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/postgres/PostgresActionUtils.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.paimon.flink.action.cdc.postgres;
+
+import org.apache.paimon.catalog.Identifier;
+import org.apache.paimon.flink.action.cdc.TypeMapping;
+import org.apache.paimon.flink.action.cdc.schema.JdbcSchemaUtils;
+import org.apache.paimon.flink.action.cdc.schema.JdbcSchemasInfo;
+import org.apache.paimon.options.OptionsUtils;
+import org.apache.paimon.schema.Schema;
+
+import com.ververica.cdc.connectors.base.options.StartupOptions;
+import com.ververica.cdc.connectors.base.source.jdbc.JdbcIncrementalSource;
+import com.ververica.cdc.connectors.postgres.source.PostgresSourceBuilder;
+import com.ververica.cdc.connectors.postgres.source.PostgresSourceBuilder.PostgresIncrementalSource;
+import com.ververica.cdc.connectors.postgres.source.config.PostgresSourceOptions;
+import com.ververica.cdc.debezium.JsonDebeziumDeserializationSchema;
+import com.ververica.cdc.debezium.table.DebeziumOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.kafka.connect.json.JsonConverterConfig;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.function.Predicate;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static org.apache.paimon.flink.action.cdc.postgres.PostgresTypeUtils.toPaimonTypeVisitor;
+
+/** Utils for Postgres Action. */
+public class PostgresActionUtils {
+
+    static Connection getConnection(Configuration postgresConfig) throws Exception {
+        String url =
+                String.format(
+                        "jdbc:postgresql://%s:%d/%s",
+                        postgresConfig.get(PostgresSourceOptions.HOSTNAME),
+                        postgresConfig.get(PostgresSourceOptions.PG_PORT),
+                        postgresConfig.get(PostgresSourceOptions.DATABASE_NAME));
+
+        return DriverManager.getConnection(
+                url,
+                postgresConfig.get(PostgresSourceOptions.USERNAME),
+                postgresConfig.get(PostgresSourceOptions.PASSWORD));
+    }
+
+    public static JdbcSchemasInfo getPostgresTableInfos(
+            Configuration postgresConfig,
+            Predicate<String> monitorTablePredication,
+            List<Identifier> excludedTables,
+            TypeMapping typeMapping)
+            throws Exception {
+
+        String databaseName = postgresConfig.get(PostgresSourceOptions.DATABASE_NAME);
+        Pattern schemaPattern =
+                Pattern.compile(postgresConfig.get(PostgresSourceOptions.SCHEMA_NAME));
+        JdbcSchemasInfo jdbcSchemasInfo = new JdbcSchemasInfo();
+        try (Connection conn = PostgresActionUtils.getConnection(postgresConfig)) {
+            DatabaseMetaData metaData = conn.getMetaData();
+            try (ResultSet schemas = metaData.getSchemas()) {
+                while (schemas.next()) {
+                    String schemaName = schemas.getString("TABLE_SCHEM");
+                    Matcher schemaMatcher = schemaPattern.matcher(schemaName);
+                    if (!schemaMatcher.matches()) {
+                        continue;
+                    }
+                    try (ResultSet tables =
+                            metaData.getTables(
+                                    databaseName, schemaName, "%", new String[] {"TABLE"})) {
+                        while (tables.next()) {
+                            String tableName = tables.getString("TABLE_NAME");
+                            String tableComment = tables.getString("REMARKS");
+                            Identifier identifier = Identifier.create(databaseName, tableName);
+                            if (monitorTablePredication.test(tableName)) {
+                                Schema schema =
+                                        JdbcSchemaUtils.buildSchema(
+                                                metaData,
+                                                databaseName,
+                                                schemaName,
+                                                tableName,
+                                                tableComment,
+                                                typeMapping,
+                                                toPaimonTypeVisitor());
+                                jdbcSchemasInfo.addSchema(identifier, schemaName, schema);
+                            } else {
+                                excludedTables.add(identifier);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        return jdbcSchemasInfo;
+    }
+
+    public static JdbcIncrementalSource<String> buildPostgresSource(
+            Configuration postgresConfig, String[] schemaList, String[] tableList) {
+        PostgresSourceBuilder<String> sourceBuilder = PostgresIncrementalSource.builder();
+
+        sourceBuilder
+                .hostname(postgresConfig.get(PostgresSourceOptions.HOSTNAME))
+                .port(postgresConfig.get(PostgresSourceOptions.PG_PORT))
+                .database(postgresConfig.get(PostgresSourceOptions.DATABASE_NAME))
+                .schemaList(schemaList)
+                .tableList(tableList)
+                .slotName(postgresConfig.get(PostgresSourceOptions.SLOT_NAME))
+                .username(postgresConfig.get(PostgresSourceOptions.USERNAME))
+                .password(postgresConfig.get(PostgresSourceOptions.PASSWORD));
+
+        // use pgoutput for PostgreSQL 10+
+        postgresConfig
+                .getOptional(PostgresSourceOptions.DECODING_PLUGIN_NAME)
+                .ifPresent(sourceBuilder::decodingPluginName);
+
+        // PostgreSQL CDC using increment snapshot, splitSize is used instead of fetchSize (as in
+        // JDBC
+        // connector). splitSize is the number of records in each snapshot split.
+        postgresConfig
+                .getOptional(PostgresSourceOptions.SCAN_INCREMENTAL_SNAPSHOT_CHUNK_SIZE)
+                .ifPresent(sourceBuilder::splitSize);
+        postgresConfig
+                .getOptional(PostgresSourceOptions.CONNECT_TIMEOUT)
+                .ifPresent(sourceBuilder::connectTimeout);
+        postgresConfig
+                .getOptional(PostgresSourceOptions.CONNECT_MAX_RETRIES)
+                .ifPresent(sourceBuilder::connectMaxRetries);
+        postgresConfig
+                .getOptional(PostgresSourceOptions.CONNECTION_POOL_SIZE)
+                .ifPresent(sourceBuilder::connectionPoolSize);
+        postgresConfig
+                .getOptional(PostgresSourceOptions.HEARTBEAT_INTERVAL)
+                .ifPresent(sourceBuilder::heartbeatInterval);
+
+        String startupMode = postgresConfig.get(PostgresSourceOptions.SCAN_STARTUP_MODE);
+
+        if ("initial".equalsIgnoreCase(startupMode)) {
+            sourceBuilder.startupOptions(StartupOptions.initial());
+        } else if ("earliest-offset".equalsIgnoreCase(startupMode)) {
+            sourceBuilder.startupOptions(StartupOptions.earliest());
+        } else if ("latest-offset".equalsIgnoreCase(startupMode)) {
+            sourceBuilder.startupOptions(StartupOptions.latest());
+        } else if ("specific-offset".equalsIgnoreCase(startupMode)) {
+            String file =
+                    postgresConfig.get(PostgresSourceOptions.SCAN_STARTUP_SPECIFIC_OFFSET_FILE);
+            Integer pos =
+                    postgresConfig.get(PostgresSourceOptions.SCAN_STARTUP_SPECIFIC_OFFSET_POS);
+            sourceBuilder.startupOptions(StartupOptions.specificOffset(file, pos));
+        } else if ("timestamp".equalsIgnoreCase(startupMode)) {
+            sourceBuilder.startupOptions(
+                    StartupOptions.timestamp(
+                            postgresConfig.get(
+                                    PostgresSourceOptions.SCAN_STARTUP_TIMESTAMP_MILLIS)));
+        }

Review Comment:
   See :https://github.com/ververica/flink-cdc-connectors/blob/e3d6c7e0aa9b9b8e573311b879f8854d7c88f88f/flink-cdc-connect/flink-cdc-source-connectors/flink-connector-postgres-cdc/src/main/java/com/ververica/cdc/connectors/postgres/table/PostgreSQLTableFactory.java#L207
   
   ![1705591868234_3D7D86A9-CCCA-435c-BE61-2B716751BA11](https://github.com/apache/incubator-paimon/assets/45089228/29e4e162-9281-4ee6-84a9-56a5e4688c52)
   
   Some start modes are not implemented in flink cdc, please fix it.
   



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [cdc] Added postgresql table cdc synchronization action [incubator-paimon]

Posted by "TaoZex (via GitHub)" <gi...@apache.org>.
TaoZex commented on code in PR #2734:
URL: https://github.com/apache/incubator-paimon/pull/2734#discussion_r1457533131


##########
paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/postgres/PostgresSyncTableActionFactory.java:
##########
@@ -0,0 +1,171 @@
+/*
+ * 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.paimon.flink.action.cdc.postgres;
+
+import org.apache.paimon.flink.action.Action;
+import org.apache.paimon.flink.action.ActionFactory;
+import org.apache.paimon.flink.action.MultipleParameterToolAdapter;
+import org.apache.paimon.flink.action.cdc.TypeMapping;
+
+import org.apache.flink.api.java.tuple.Tuple3;
+
+import java.util.ArrayList;
+import java.util.Optional;
+
+import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.COMPUTED_COLUMN;
+import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.METADATA_COLUMN;
+import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.PARTITION_KEYS;
+import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.POSTGRES_CONF;
+import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.PRIMARY_KEYS;
+import static org.apache.paimon.flink.action.cdc.CdcActionCommonUtils.TYPE_MAPPING;
+
+/** Factory to create {@link PostgresSyncTableAction}. */
+public class PostgresSyncTableActionFactory implements ActionFactory {
+
+    public static final String IDENTIFIER = "postgres_sync_table";
+
+    @Override
+    public String identifier() {
+        return IDENTIFIER;
+    }
+
+    @Override
+    public Optional<Action> create(MultipleParameterToolAdapter params) {
+        Tuple3<String, String, String> tablePath = getTablePath(params);
+        checkRequiredArgument(params, POSTGRES_CONF);
+
+        PostgresSyncTableAction action =
+                new PostgresSyncTableAction(
+                        tablePath.f0,
+                        tablePath.f1,
+                        tablePath.f2,
+                        optionalConfigMap(params, CATALOG_CONF),
+                        optionalConfigMap(params, POSTGRES_CONF));
+
+        action.withTableConfig(optionalConfigMap(params, TABLE_CONF));
+
+        if (params.has(PARTITION_KEYS)) {
+            action.withPartitionKeys(params.get(PARTITION_KEYS).split(","));
+        }
+
+        if (params.has(PRIMARY_KEYS)) {
+            action.withPrimaryKeys(params.get(PRIMARY_KEYS).split(","));
+        }
+
+        if (params.has(COMPUTED_COLUMN)) {
+            action.withComputedColumnArgs(
+                    new ArrayList<>(params.getMultiParameter(COMPUTED_COLUMN)));
+        }
+
+        if (params.has(METADATA_COLUMN)) {
+            action.withMetadataColumns(new ArrayList<>(params.getMultiParameter(METADATA_COLUMN)));
+        }
+
+        if (params.has(TYPE_MAPPING)) {
+            String[] options = params.get(TYPE_MAPPING).split(",");
+            action.withTypeMapping(TypeMapping.parse(options));
+        }
+
+        return Optional.of(action);

Review Comment:
   How about wrapping this part, which is common to sync table action.



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [cdc] Added postgresql table cdc synchronization action [incubator-paimon]

Posted by "yuzelin (via GitHub)" <gi...@apache.org>.
yuzelin commented on code in PR #2734:
URL: https://github.com/apache/incubator-paimon/pull/2734#discussion_r1463237393


##########
paimon-flink/paimon-flink-cdc/src/test/resources/postgres/sync_table_setup.sql:
##########
@@ -0,0 +1,291 @@
+-- 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.
+
+-- In production you would almost certainly limit the replication user must be on the follower (slave) machine,
+-- to prevent other clients accessing the log from other machines. For example, 'replicator'@'follower.acme.com'.
+-- However, in this database we'll grant the test user 'paimonuser' all privileges:
+--
+
+-- ################################################################################
+--  PostgresSyncTableActionITCase
+-- ################################################################################
+
+CREATE DATABASE paimon_sync_table;
+
+\c paimon_sync_table;

Review Comment:
   I'm not familiar with PG. Is this `\c paimon_sync_table` PG sql syntax?



##########
paimon-flink/paimon-flink-cdc/src/test/java/org/apache/paimon/flink/action/cdc/mysql/MySqlActionITCaseBase.java:
##########
@@ -84,6 +84,11 @@ protected Map<String, String> getBasicMySqlConfig() {
         config.put("password", PASSWORD);
         // see mysql/my.cnf in test resources
         config.put("server-time-zone", ZoneId.of("America/New_York").toString());
+
+        // TODO When setting the parameter scan.newly-added-table.enabled=true in version 2.4.2, the
+        // Insert data inserted after the newly created table cannot be captured. When set to false,
+        // the mysql cdc works normally.
+        config.put("scan.newly-added-table.enabled", "false");

Review Comment:
   Yes you're right. Can we use pgcdc-2.4.2 and mysql-cdc 2.3.0?



##########
paimon-flink/paimon-flink-cdc/pom.xml:
##########
@@ -35,7 +35,7 @@ under the License.
 
     <properties>
         <flink.version>1.17.2</flink.version>
-        <flink.mysql.cdc.version>2.3.0</flink.mysql.cdc.version>
+        <flink.cdc.version>2.4.2</flink.cdc.version>

Review Comment:
   Please don't change mysql-cdc-version. There are some known issue with mysql-cdc 2.4.x .



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [cdc] Added postgresql table cdc synchronization action [incubator-paimon]

Posted by "zhuangchong (via GitHub)" <gi...@apache.org>.
zhuangchong commented on code in PR #2734:
URL: https://github.com/apache/incubator-paimon/pull/2734#discussion_r1458377712


##########
paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/action/cdc/postgres/PostgresActionUtils.java:
##########
@@ -0,0 +1,199 @@
+/*
+ * 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.paimon.flink.action.cdc.postgres;
+
+import org.apache.paimon.catalog.Identifier;
+import org.apache.paimon.flink.action.cdc.TypeMapping;
+import org.apache.paimon.flink.action.cdc.schema.JdbcSchemaUtils;
+import org.apache.paimon.flink.action.cdc.schema.JdbcSchemasInfo;
+import org.apache.paimon.options.OptionsUtils;
+import org.apache.paimon.schema.Schema;
+
+import com.ververica.cdc.connectors.base.options.StartupOptions;
+import com.ververica.cdc.connectors.base.source.jdbc.JdbcIncrementalSource;
+import com.ververica.cdc.connectors.postgres.source.PostgresSourceBuilder;
+import com.ververica.cdc.connectors.postgres.source.PostgresSourceBuilder.PostgresIncrementalSource;
+import com.ververica.cdc.connectors.postgres.source.config.PostgresSourceOptions;
+import com.ververica.cdc.debezium.JsonDebeziumDeserializationSchema;
+import com.ververica.cdc.debezium.table.DebeziumOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.kafka.connect.json.JsonConverterConfig;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.function.Predicate;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static org.apache.paimon.flink.action.cdc.postgres.PostgresTypeUtils.toPaimonTypeVisitor;
+
+/** Utils for Postgres Action. */
+public class PostgresActionUtils {
+
+    static Connection getConnection(Configuration postgresConfig) throws Exception {
+        String url =
+                String.format(
+                        "jdbc:postgresql://%s:%d/%s",
+                        postgresConfig.get(PostgresSourceOptions.HOSTNAME),
+                        postgresConfig.get(PostgresSourceOptions.PG_PORT),
+                        postgresConfig.get(PostgresSourceOptions.DATABASE_NAME));
+
+        return DriverManager.getConnection(
+                url,
+                postgresConfig.get(PostgresSourceOptions.USERNAME),
+                postgresConfig.get(PostgresSourceOptions.PASSWORD));
+    }
+
+    public static JdbcSchemasInfo getPostgresTableInfos(
+            Configuration postgresConfig,
+            Predicate<String> monitorTablePredication,
+            List<Identifier> excludedTables,
+            TypeMapping typeMapping)
+            throws Exception {
+
+        String databaseName = postgresConfig.get(PostgresSourceOptions.DATABASE_NAME);
+        Pattern schemaPattern =
+                Pattern.compile(postgresConfig.get(PostgresSourceOptions.SCHEMA_NAME));
+        JdbcSchemasInfo jdbcSchemasInfo = new JdbcSchemasInfo();
+        try (Connection conn = PostgresActionUtils.getConnection(postgresConfig)) {
+            DatabaseMetaData metaData = conn.getMetaData();
+            try (ResultSet schemas = metaData.getSchemas()) {
+                while (schemas.next()) {
+                    String schemaName = schemas.getString("TABLE_SCHEM");
+                    Matcher schemaMatcher = schemaPattern.matcher(schemaName);
+                    if (!schemaMatcher.matches()) {
+                        continue;
+                    }
+                    try (ResultSet tables =
+                            metaData.getTables(
+                                    databaseName, schemaName, "%", new String[] {"TABLE"})) {
+                        while (tables.next()) {
+                            String tableName = tables.getString("TABLE_NAME");
+                            String tableComment = tables.getString("REMARKS");
+                            Identifier identifier = Identifier.create(databaseName, tableName);
+                            if (monitorTablePredication.test(tableName)) {
+                                Schema schema =
+                                        JdbcSchemaUtils.buildSchema(
+                                                metaData,
+                                                databaseName,
+                                                schemaName,
+                                                tableName,
+                                                tableComment,
+                                                typeMapping,
+                                                toPaimonTypeVisitor());
+                                jdbcSchemasInfo.addSchema(identifier, schemaName, schema);
+                            } else {
+                                excludedTables.add(identifier);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        return jdbcSchemasInfo;
+    }
+
+    public static JdbcIncrementalSource<String> buildPostgresSource(
+            Configuration postgresConfig, String[] schemaList, String[] tableList) {
+        PostgresSourceBuilder<String> sourceBuilder = PostgresIncrementalSource.builder();
+
+        sourceBuilder
+                .hostname(postgresConfig.get(PostgresSourceOptions.HOSTNAME))
+                .port(postgresConfig.get(PostgresSourceOptions.PG_PORT))
+                .database(postgresConfig.get(PostgresSourceOptions.DATABASE_NAME))
+                .schemaList(schemaList)
+                .tableList(tableList)
+                .slotName(postgresConfig.get(PostgresSourceOptions.SLOT_NAME))
+                .username(postgresConfig.get(PostgresSourceOptions.USERNAME))
+                .password(postgresConfig.get(PostgresSourceOptions.PASSWORD));
+
+        // use pgoutput for PostgreSQL 10+
+        postgresConfig
+                .getOptional(PostgresSourceOptions.DECODING_PLUGIN_NAME)
+                .ifPresent(sourceBuilder::decodingPluginName);
+
+        // PostgreSQL CDC using increment snapshot, splitSize is used instead of fetchSize (as in
+        // JDBC
+        // connector). splitSize is the number of records in each snapshot split.
+        postgresConfig
+                .getOptional(PostgresSourceOptions.SCAN_INCREMENTAL_SNAPSHOT_CHUNK_SIZE)
+                .ifPresent(sourceBuilder::splitSize);
+        postgresConfig
+                .getOptional(PostgresSourceOptions.CONNECT_TIMEOUT)
+                .ifPresent(sourceBuilder::connectTimeout);
+        postgresConfig
+                .getOptional(PostgresSourceOptions.CONNECT_MAX_RETRIES)
+                .ifPresent(sourceBuilder::connectMaxRetries);
+        postgresConfig
+                .getOptional(PostgresSourceOptions.CONNECTION_POOL_SIZE)
+                .ifPresent(sourceBuilder::connectionPoolSize);
+        postgresConfig
+                .getOptional(PostgresSourceOptions.HEARTBEAT_INTERVAL)
+                .ifPresent(sourceBuilder::heartbeatInterval);
+
+        String startupMode = postgresConfig.get(PostgresSourceOptions.SCAN_STARTUP_MODE);
+
+        if ("initial".equalsIgnoreCase(startupMode)) {
+            sourceBuilder.startupOptions(StartupOptions.initial());
+        } else if ("earliest-offset".equalsIgnoreCase(startupMode)) {
+            sourceBuilder.startupOptions(StartupOptions.earliest());
+        } else if ("latest-offset".equalsIgnoreCase(startupMode)) {
+            sourceBuilder.startupOptions(StartupOptions.latest());
+        } else if ("specific-offset".equalsIgnoreCase(startupMode)) {
+            String file =
+                    postgresConfig.get(PostgresSourceOptions.SCAN_STARTUP_SPECIFIC_OFFSET_FILE);
+            Integer pos =
+                    postgresConfig.get(PostgresSourceOptions.SCAN_STARTUP_SPECIFIC_OFFSET_POS);
+            sourceBuilder.startupOptions(StartupOptions.specificOffset(file, pos));
+        } else if ("timestamp".equalsIgnoreCase(startupMode)) {
+            sourceBuilder.startupOptions(
+                    StartupOptions.timestamp(
+                            postgresConfig.get(
+                                    PostgresSourceOptions.SCAN_STARTUP_TIMESTAMP_MILLIS)));
+        }

Review Comment:
   Thanks @TaoZex, done. 



-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [cdc] Added postgresql table cdc synchronization action [incubator-paimon]

Posted by "yuzelin (via GitHub)" <gi...@apache.org>.
yuzelin merged PR #2734:
URL: https://github.com/apache/incubator-paimon/pull/2734


-- 
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: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org