/** {@inheritDoc} */ @Override public Table getTable(String tableId) { GetTableRequest requestProto = GetTableRequest.newBuilder() .setName(instanceName.toTableNameStr(tableId)) .build(); return Table.fromProto(adminClient.getTable(requestProto)); }
@Override public boolean tableExists(String tableId) throws IOException { try (BigtableSession session = new BigtableSession(options)) { GetTableRequest getTable = GetTableRequest.newBuilder() .setName(options.getInstanceName().toTableNameStr(tableId)) .build(); session.getTableAdminClient().getTable(getTable); return true; } catch (StatusRuntimeException e) { if (e.getStatus().getCode() == Code.NOT_FOUND) { return false; } String message = String.format( "Error checking whether table %s (BigtableOptions %s) exists", tableId, options); LOG.error(message, e); throw new IOException(message, e); } }
/** {@inheritDoc} */ @Override public HTableDescriptor getTableDescriptor(TableName tableName) throws IOException { if (tableName == null) { return null; } String bigtableTableName = toBigtableName(tableName); GetTableRequest request = GetTableRequest.newBuilder().setName(bigtableTableName).build(); try { return tableAdapter.adapt(bigtableTableAdminClient.getTable(request)); } catch (Throwable throwable) { if (Status.fromThrowable(throwable).getCode() == Status.Code.NOT_FOUND) { throw new TableNotFoundException(tableName); } throw new IOException("Failed to getTableDescriptor() on " + tableName, throwable); } }
/** {@inheritDoc} */ @Override public HTableDescriptor getTableDescriptor(TableName tableName) throws IOException { if (tableName == null) { return null; } String bigtableTableName = toBigtableName(tableName); GetTableRequest request = GetTableRequest.newBuilder().setName(bigtableTableName).build(); try { return tableAdapter.adapt(bigtableTableAdminClient.getTable(request)); } catch (Throwable throwable) { if (Status.fromThrowable(throwable).getCode() == Status.Code.NOT_FOUND) { throw new TableNotFoundException(tableName); } throw new IOException("Failed to getTableDescriptor() on " + tableName, throwable); } }
/** Helper function to get a table. */ private Table getTable(String tableName) { GetTableRequest.Builder getTableRequestBuilder = GetTableRequest.newBuilder().setName(tableName); return tableAdminClient.getTable(getTableRequestBuilder.build()); }