diff --git a/catalogs/catalog-jdbc-mysql/src/main/java/com/datastrato/gravitino/catalog/mysql/operation/MysqlTableOperations.java b/catalogs/catalog-jdbc-mysql/src/main/java/com/datastrato/gravitino/catalog/mysql/operation/MysqlTableOperations.java index bae9f3744cb..e1fcd293cf0 100644 --- a/catalogs/catalog-jdbc-mysql/src/main/java/com/datastrato/gravitino/catalog/mysql/operation/MysqlTableOperations.java +++ b/catalogs/catalog-jdbc-mysql/src/main/java/com/datastrato/gravitino/catalog/mysql/operation/MysqlTableOperations.java @@ -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; @@ -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); @@ -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 listTables(String databaseName) throws NoSuchSchemaException { try (Connection connection = getConnection(databaseName)) {