From 3621bec97d5e949cd8f9947b6f28a3c9669b365a Mon Sep 17 00:00:00 2001 From: Jerry Shao Date: Mon, 13 May 2024 10:43:10 +0800 Subject: [PATCH] [#3326] feat(jdbc-doris): output the alter status of table into the log (#3357) ### What changes were proposed in this pull request? Output the alter status of table into the log ### Why are the changes needed? Fix: #3326 ### Does this PR introduce _any_ user-facing change? N/A ### How was this patch tested? Manual, check log Co-authored-by: Kang --- .../doris/operation/DorisTableOperations.java | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/catalogs/catalog-jdbc-doris/src/main/java/com/datastrato/gravitino/catalog/doris/operation/DorisTableOperations.java b/catalogs/catalog-jdbc-doris/src/main/java/com/datastrato/gravitino/catalog/doris/operation/DorisTableOperations.java index afa168c33e5..27dd6912865 100644 --- a/catalogs/catalog-jdbc-doris/src/main/java/com/datastrato/gravitino/catalog/doris/operation/DorisTableOperations.java +++ b/catalogs/catalog-jdbc-doris/src/main/java/com/datastrato/gravitino/catalog/doris/operation/DorisTableOperations.java @@ -249,7 +249,6 @@ protected List getIndexes(Connection connection, String databaseName, Str protected void correctJdbcTableFields( Connection connection, String databaseName, String tableName, JdbcTable.Builder tableBuilder) throws SQLException { - if (StringUtils.isNotEmpty(tableBuilder.comment())) { return; } @@ -271,6 +270,48 @@ protected void correctJdbcTableFields( } catch (SQLException e) { throw exceptionMapper.toGravitinoException(e); } + + getTableStatus(connection, databaseName, tableName); + } + + protected void getTableStatus(Connection connection, String databaseName, String tableName) { + // sql is `SHOW ALTER TABLE COLUMN WHERE TableName = 'test_table'` + // database name must be specified in connection, so the SQL do not need to specify database + // name + String sql = + String.format( + "SHOW ALTER TABLE COLUMN WHERE TableName = '%s' ORDER BY JobId DESC limit 1", + tableName); + + // Just print each column name and type from resultSet + // TODO: add to table properties or other fields + try (PreparedStatement preparedStatement = connection.prepareStatement(sql); + ResultSet resultSet = preparedStatement.executeQuery()) { + + StringBuilder jobStatus = new StringBuilder(); + while (resultSet.next()) { + int columnCount = resultSet.getMetaData().getColumnCount(); + for (int i = 1; i <= columnCount; i++) { + jobStatus + .append(resultSet.getMetaData().getColumnName(i)) + .append(" : ") + .append(resultSet.getString(i)) + .append(", "); + } + jobStatus.append(" | "); + } + + if (jobStatus.length() > 0) { + LOG.info( + "Table {}.{} schema-change execution status: {}", + databaseName, + tableName, + jobStatus.toString()); + } + + } catch (SQLException e) { + throw exceptionMapper.toGravitinoException(e); + } } @Override