-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#3002] fix(jdbc-mysql): Fix MySQL list tables bugs. #3229
Conversation
Do we have a similar problem in PG and Doris? |
@@ -415,7 +416,8 @@ protected JdbcColumn getJdbcColumnFromTable(JdbcTable jdbcTable, String colName) | |||
"Column %s does not exist in table %s", colName, jdbcTable.name())); | |||
} | |||
|
|||
protected Connection getConnection(String catalog) throws SQLException { | |||
@VisibleForTesting | |||
public Connection getConnection(String catalog) throws SQLException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you verify whether the problem still exists if getConnection using setSchema(xx) not setCatalog(xx)?
Connection getConnection(String catalog) {
Connection connection = dataSource.getConnection();
connection.setCatalog(catalog);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noticed that getTables using connection.getSchema() to retrieve tables, the total JDBC logic is muddledness :(
protected ResultSet getTables(Connection connection) throws SQLException {
final DatabaseMetaData metaData = connection.getMetaData();
String databaseName = connection.getSchema();
return metaData.getTables(databaseName, databaseName, null, JdbcConnectorUtils.getTableTypes());
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noticed that getTables using connection.getSchema() to retrieve tables, the total JDBC logic is muddledness :(
protected ResultSet getTables(Connection connection) throws SQLException { final DatabaseMetaData metaData = connection.getMetaData(); String databaseName = connection.getSchema(); return metaData.getTables(databaseName, databaseName, null, JdbcConnectorUtils.getTableTypes()); }
I have removed the line String databaseName = connection.getSchema();
.
Root cause of this problem: String databaseName = connection.getSchema();
is always null.
please review it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you verify whether the problem still exists if getConnection using setSchema(xx) not setCatalog(xx)?
Connection getConnection(String catalog) { Connection connection = dataSource.getConnection(); connection.setCatalog(catalog); }
It's not work to use setSchema(xx)
;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you verify whether the problem still exists if getConnection using setSchema(xx) not setCatalog(xx)?
Connection getConnection(String catalog) { Connection connection = dataSource.getConnection(); connection.setCatalog(catalog); }It's not work to use
setSchema(xx)
;
when you test do you remove String databaseName = connection.getSchema();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you verify whether the problem still exists if getConnection using setSchema(xx) not setCatalog(xx)?
Connection getConnection(String catalog) { Connection connection = dataSource.getConnection(); connection.setCatalog(catalog); }It's not work to use
setSchema(xx)
;when you test do you remove
String databaseName = connection.getSchema();
No, the method:
protected ResultSet getTables(Connection connection) throws SQLException {
final DatabaseMetaData metaData = connection.getMetaData();
String databaseName = connection.getSchema();
// We need the database name here.
return metaData.getTables(databaseName, databaseName, null, JdbcConnectorUtils.getTableTypes());
}
The value of the schema name must be passed as a method parameter, otherwise we cannot remove it.
Yes, I have checked, the changes in the PR is in the module |
...om/datastrato/gravitino/catalog/postgresql/integration/test/PostgreSqlTableOperationsIT.java
Outdated
Show resolved
Hide resolved
...est/java/com/datastrato/gravitino/catalog/mysql/integration/test/MysqlTableOperationsIT.java
Outdated
Show resolved
Hide resolved
@yuqi1129 can you please move forward this PR? |
Yeah, A related PR has just been merged, I will rebase it soon. |
@danhuawang |
@danhuawang confirmed that the problem has been resolved by #3316 and the PR will be temporarily closed. |
What changes were proposed in this pull request?
Set the connection database to the database passed by the method when getting the JDBC connection.
Why are the changes needed?
connection.getSchema()
is null for MySQL and thus will cause the problem that list operation will get all tables in the MySQL instance NOT a specific database.Fix: #3002
Does this PR introduce any user-facing change?
N/A.
How was this patch tested?
New UT was added.