use of com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCheckTableStatement in project Mycat2 by MyCATApache.
the class MySQLCheckHandler method onExecute.
@Override
protected Future<Void> onExecute(SQLRequest<MySqlCheckTableStatement> request, MycatDataContext dataContext, Response response) {
ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
resultSetBuilder.addColumnInfo("TABLE", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("OP", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("MSG_TYPE", JDBCType.VARCHAR);
resultSetBuilder.addColumnInfo("MSG_TEXT", JDBCType.VARCHAR);
MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
JdbcConnectionManager jdbcConnectionManager = MetaClusterCurrent.wrapper(JdbcConnectionManager.class);
List<Throwable> throwables = Collections.synchronizedList(new LinkedList<>());
MySqlCheckTableStatement ast = request.getAst();
for (SQLExprTableSource table : ast.getTables()) {
resolveSQLExprTableSource(table, dataContext);
String schemaName = SQLUtils.normalize(table.getSchema());
String tableName = SQLUtils.normalize(table.getTableName());
TableHandler tableHandler = metadataManager.getTable(schemaName, tableName);
Set<String> errorInfo = new HashSet<>();
switch(tableHandler.getType()) {
case SHARDING:
{
ShardingTableHandler shardingTableHandler = (ShardingTableHandler) tableHandler;
errorInfo = check(metadataManager, jdbcConnectionManager, throwables, shardingTableHandler.dataNodes().parallelStream());
break;
}
case GLOBAL:
{
GlobalTableHandler globalTableHandler = (GlobalTableHandler) tableHandler;
errorInfo = check(metadataManager, jdbcConnectionManager, throwables, globalTableHandler.getGlobalDataNode().parallelStream());
break;
}
case NORMAL:
{
break;
}
case CUSTOM:
{
break;
}
default:
throw new IllegalStateException("Unexpected value: " + tableHandler.getType());
}
resultSetBuilder.addObjectRowPayload(Arrays.asList(table.toString(), "check", errorInfo.isEmpty() ? "Ok" : "Error", String.join(",", errorInfo)));
}
return response.sendResultSet(resultSetBuilder.build());
}
Aggregations