Search in sources :

Example 1 with GetTableRequest

use of com.google.bigtable.admin.v2.GetTableRequest in project beam by apache.

the class BigtableServiceImpl method tableExists.

@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);
    }
}
Also used : GetTableRequest(com.google.bigtable.admin.v2.GetTableRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) BigtableSession(com.google.cloud.bigtable.grpc.BigtableSession) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException)

Aggregations

GetTableRequest (com.google.bigtable.admin.v2.GetTableRequest)1 BigtableSession (com.google.cloud.bigtable.grpc.BigtableSession)1 ByteString (com.google.protobuf.ByteString)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 IOException (java.io.IOException)1