You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/05/30 08:07:28 UTC

[GitHub] [flink] fsk119 commented on a diff in pull request #19741: [FLINK-27794][connector/jdbc] The primary key obtained from MySQL is incorrect by using MysqlCatalog

fsk119 commented on code in PR #19741:
URL: https://github.com/apache/flink/pull/19741#discussion_r884449039


##########
flink-connectors/flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/catalog/AbstractJdbcCatalog.java:
##########
@@ -149,7 +149,7 @@ protected Optional<UniqueConstraint> getPrimaryKey(
         // According to the Javadoc of java.sql.DatabaseMetaData#getPrimaryKeys,
         // the returned primary key columns are ordered by COLUMN_NAME, not by KEY_SEQ.
         // We need to sort them based on the KEY_SEQ value.
-        ResultSet rs = metaData.getPrimaryKeys(null, schema, table);
+        ResultSet rs = metaData.getPrimaryKeys(schema, schema, table);

Review Comment:
   In the SQL world, catalog and schema are different things.  We can not mix them up. You can refer to the doc to see the difference[1]. In the MySql world, they has the same meaning[2]. 
   But in the PostgreSQL, catalog has many schemas[3].
   
   
   Therefore, I think you should do as the schema and let the specified catalog to determine the catalog of the specified table.
   
   
   
   [1] https://stackoverflow.com/questions/7022755/whats-the-difference-between-a-catalog-and-a-schema-in-a-relational-database 
   [2] https://dev.mysql.com/doc/connector-odbc/en/connector-odbc-usagenotes-functionality-catalog-schema.html
   [3] https://stackoverflow.com/questions/48312675/how-can-i-show-the-catalogs-and-schemas-in-postgresql



##########
flink-connectors/flink-connector-jdbc/src/main/java/org/apache/flink/connector/jdbc/catalog/MySqlCatalog.java:
##########
@@ -152,7 +152,7 @@ protected String getTableName(ObjectPath tablePath) {
 
     @Override
     protected String getSchemaName(ObjectPath tablePath) {
-        return null;
+        return tablePath.getDatabaseName();

Review Comment:
   Please add some comments to tell others that the schema is equal to the database[1].
   
   [1] https://dev.mysql.com/doc/connector-odbc/en/connector-odbc-usagenotes-functionality-catalog-schema.html



-- 
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@flink.apache.org

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