Skip to content

Commit

Permalink
[#3326] feat(jdbc-doris): output the alter status of table into the l…
Browse files Browse the repository at this point in the history
…og (#3332)

### 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
  • Loading branch information
zhoukangcn authored and web-flow committed May 13, 2024
1 parent 636a43e commit 7f08e75
Showing 1 changed file with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ protected List<Index> 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;
}
Expand All @@ -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
Expand Down

0 comments on commit 7f08e75

Please sign in to comment.