[
https://issues.apache.org/jira/browse/FLINK-27794?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
dusukang updated FLINK-27794:
-----------------------------
Description:
I want to use MysqlCatalog to get the primary key of the database table `user`.
The database table creation statement is as follows
{code:java}
CREATE TABLE flinksql_test.`user` (
`uid` bigint(20) NOT NULL,
`uname` varchar(36) DEFAULT NULL,
`others` varchar(128) DEFAULT NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; {code}
This is my test code:
{code:java}
import org.apache.flink.connector.jdbc.catalog.MySqlCatalog;
import org.apache.flink.table.api.Schema;
import org.apache.flink.table.catalog.CatalogBaseTable;
import org.apache.flink.table.catalog.ObjectPath;
import org.apache.flink.table.catalog.exceptions.TableNotExistException;import
java.util.Optional;public class Demo02 {
public static void main(String[] args) throws TableNotExistException {
MySqlCatalog mySqlCatalog = new MySqlCatalog("mysql-catalog",
"flinksql_test",
"root",
"123456789",
String.format("jdbc:mysql://127.0.0.1:3306"));
CatalogBaseTable table = mySqlCatalog.getTable(new
ObjectPath("flinksql_test", "user"));
Optional<Schema.UnresolvedPrimaryKey> primaryKey = table
.getUnresolvedSchema()
.getPrimaryKey();
System.out.println(primaryKey);
}
} {code}
The obtained primary key is (Host,User), the primary key from Database is (uid)
was:
I want to use MysqlCatalog to get the primary key of the database table `user`.
The database table creation statement is as follows
{code:java}
CREATE TABLE flinksql_test.`user` (
`uid` bigint(20) NOT NULL,
`uname` varchar(36) DEFAULT NULL,
`others` varchar(128) DEFAULT NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; {code}
This is my test code:
{code:java}
import org.apache.flink.connector.jdbc.catalog.MySqlCatalog;
import org.apache.flink.table.api.Schema;
import org.apache.flink.table.catalog.CatalogBaseTable;
import org.apache.flink.table.catalog.ObjectPath;
import org.apache.flink.table.catalog.exceptions.TableNotExistException;import
java.util.Optional;public class Demo02 {
public static void main(String[] args) throws TableNotExistException {
MySqlCatalog mySqlCatalog = new MySqlCatalog("mysql-catalog",
"flinksql_test",
"root",
"123456789",
String.format("jdbc:mysql://127.0.0.1:3306"));
CatalogBaseTable table = mySqlCatalog.getTable(new
ObjectPath("flinksql_test", "user"));
Optional<Schema.UnresolvedPrimaryKey> primaryKey = table
.getUnresolvedSchema()
.getPrimaryKey();
System.out.println(primaryKey);
}
} {code}
The obtained primary key is (Host,User), the primary key from Database is (uid)
> The primary key obtained from MySQL is incorrect by using MysqlCatalog
> ----------------------------------------------------------------------
>
> Key: FLINK-27794
> URL: https://issues.apache.org/jira/browse/FLINK-27794
> Project: Flink
> Issue Type: Bug
> Components: Connectors / JDBC
> Affects Versions: 1.15.0
> Reporter: dusukang
> Priority: Major
>
> I want to use MysqlCatalog to get the primary key of the database table
> `user`. The database table creation statement is as follows
> {code:java}
> CREATE TABLE flinksql_test.`user` (
> `uid` bigint(20) NOT NULL,
> `uname` varchar(36) DEFAULT NULL,
> `others` varchar(128) DEFAULT NULL,
> PRIMARY KEY (`uid`)
> ) ENGINE=InnoDB DEFAULT CHARSET=utf8; {code}
>
> This is my test code:
> {code:java}
> import org.apache.flink.connector.jdbc.catalog.MySqlCatalog;
> import org.apache.flink.table.api.Schema;
> import org.apache.flink.table.catalog.CatalogBaseTable;
> import org.apache.flink.table.catalog.ObjectPath;
> import
> org.apache.flink.table.catalog.exceptions.TableNotExistException;import
> java.util.Optional;public class Demo02 {
> public static void main(String[] args) throws TableNotExistException {
> MySqlCatalog mySqlCatalog = new MySqlCatalog("mysql-catalog",
> "flinksql_test",
> "root",
> "123456789",
> String.format("jdbc:mysql://127.0.0.1:3306"));
> CatalogBaseTable table = mySqlCatalog.getTable(new
> ObjectPath("flinksql_test", "user"));
> Optional<Schema.UnresolvedPrimaryKey> primaryKey = table
> .getUnresolvedSchema()
> .getPrimaryKey();
> System.out.println(primaryKey);
> }
> } {code}
> The obtained primary key is (Host,User), the primary key from Database is
> (uid)
>
>
>
>
--
This message was sent by Atlassian Jira
(v8.20.7#820007)