class RenameTableOperation {

  public void execute(CloseableMetaStoreClient client, Table from, Table to) throws Exception {
    LOG
        .info("Renaming table {}.{} to {}.{}", from.getDbName(), from.getTableName(), to.getDbName(),
            to.getTableName());
    Table fromTable = client.getTable(from.getDbName(), from.getTableName());
    Table toTable = client.getTable(to.getDbName(), to.getTableName());
    String fromTableName = fromTable.getTableName();
    String toTableName = toTable.getTableName();
    String toDelete = toTableName + DELETE_ME;
    try {
      fromTable.setTableName(toTableName);
      toTable.setTableName(toDelete);
      client.alter_table(toTable.getDbName(), toTableName, toTable);
      client.alter_table(fromTable.getDbName(), fromTableName, fromTable);
    } finally {
      dropTableService.dropTable(client, toTable.getDbName(), toDelete);
    }
  }

  public  RenameTableOperation(DropTableService dropTableService);

}