Skip to content

Commit

Permalink
Merge branch 'main' into issue-1503
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqi1129 authored Jan 25, 2024
2 parents b1c6ced + 99b9661 commit d1d8780
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.datastrato.gravitino.rel.expressions.transforms.Transform;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
Expand Down Expand Up @@ -49,6 +50,11 @@ public JdbcTable load(String databaseName, String tableName) throws NoSuchTableE
String.format("Table %s does not exist in %s.", tableName, databaseName));
}
String comment = table.getString("REMARKS");
if (StringUtils.isEmpty(comment)) {
// In Mysql version 5.7, the comment field value cannot be obtained in the driver API.
LOG.warn("Not found comment in mysql driver api. Will try to get comment from sql");
comment = loadCommentFromSql(connection, tableName);
}

// 2.Get column information
ResultSet columns = metaData.getColumns(databaseName, null, tableName, null);
Expand Down Expand Up @@ -84,6 +90,18 @@ public JdbcTable load(String databaseName, String tableName) throws NoSuchTableE
}
}

private String loadCommentFromSql(Connection connection, String tableName) throws SQLException {
try (PreparedStatement statement = connection.prepareStatement("SHOW TABLE STATUS LIKE ?")) {
statement.setString(1, tableName);
try (ResultSet resultSet = statement.executeQuery()) {
if (!resultSet.next()) {
return null;
}
return resultSet.getString("COMMENT");
}
}
}

@Override
public List<String> listTables(String databaseName) throws NoSuchSchemaException {
try (Connection connection = getConnection(databaseName)) {
Expand Down

0 comments on commit d1d8780

Please sign in to comment.