public final class BigtableTableAdminClient extends Object implements AutoCloseable
Provides access to the table schemas only, not the data stored within the tables.
See the individual methods for example code.
Sample code to get started:
try(BigtableTableAdminClient client = BigtableTableAdminClient.create("[PROJECT]", "[INSTANCE]")) {
CreateTable request =
CreateTableRequest.of("my-table")
.addFamily("cf1")
.addFamily("cf2", GCRULES.maxVersions(10))
.addSplit(ByteString.copyFromUtf8("b"))
.addSplit(ByteString.copyFromUtf8("q"));
client.createTable(request);
}
Note: close() needs to be called on the client object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
This class can be customized by passing in a custom instance of BigtableTableAdminSettings to create(). For example:
To customize credentials:
BigtableTableAdminSettings tableAdminSettings = BigtableTableAdminSettings.newBuilder()
.setProjectId("[PROJECT]")
.setInstanceId("[INSTANCE]")
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
BigtableTableAdminClient client =
BigtableTableAdminClient.create(tableAdminSettings);
To customize the endpoint:
BigtableTableAdminSettings tableAdminSettings = BigtableTableAdminSettings.newBuilder()
.setProjectId("[PROJECT]")
.setInstanceId("[INSTANCE]")
.setEndpoint(myEndpoint).build();
BigtableTableAdminClient client = BigtableTableAdminClient.create(tableAdminSettings);
Modifier and Type | Method and Description |
---|---|
void |
awaitReplication(String tableId)
Blocks until replication has caught up to the point this method was called.
|
ApiFuture<Void> |
awaitReplicationAsync(String tableId)
Returns a future that is resolved when replication has caught up to the point this method was
called.
|
void |
close() |
static BigtableTableAdminClient |
create(BigtableTableAdminSettings settings)
Constructs an instance of BigtableTableAdminClient with the given settings.
|
static BigtableTableAdminClient |
create(com.google.bigtable.admin.v2.InstanceName instanceName)
Deprecated.
Please
create(String, String) . |
static BigtableTableAdminClient |
create(String projectId,
String instanceId)
Constructs an instance of BigtableTableAdminClient with the given project and instance ids.
|
static BigtableTableAdminClient |
create(String projectId,
String instanceId,
EnhancedBigtableTableAdminStub stub)
Constructs an instance of BigtableTableAdminClient with the given instanceName and stub.
|
Table |
createTable(CreateTableRequest request)
Creates a new table with the specified configuration
|
ApiFuture<Table> |
createTableAsync(CreateTableRequest request)
Creates a new table with the specified configuration asynchronously
|
void |
deleteTable(String tableId)
Deletes the table specified by tableId
|
ApiFuture<Void> |
deleteTableAsync(String tableId)
Asynchronously deletes the table specified by tableId.
|
void |
dropAllRows(String tableId)
Drops all data in the table
|
ApiFuture<Void> |
dropAllRowsAsync(String tableId)
Asynchornously drops all data in the table.
|
void |
dropRowRange(String tableId,
ByteString rowKeyPrefix)
Drops rows by the specified key prefix and tableId
|
void |
dropRowRange(String tableId,
String rowKeyPrefix)
Drops rows by the specified key prefix and tableId
|
ApiFuture<Void> |
dropRowRangeAsync(String tableId,
ByteString rowKeyPrefix)
Drops rows by the specified key prefix and tableId asynchronously
|
ApiFuture<Void> |
dropRowRangeAsync(String tableId,
String rowKeyPrefix)
Drops rows by the specified key prefix and tableId asynchronously
|
boolean |
exists(String tableId)
Checks if the table specified by the tableId exists
|
ApiFuture<Boolean> |
existsAsync(String tableId)
Asynchronously checks if the table specified by the tableId exists
|
String |
getInstanceId()
Gets the id of the instance whose tables this client manages.
|
com.google.bigtable.admin.v2.InstanceName |
getInstanceName()
Deprecated.
Please use
getProjectId() and getInstanceId() . |
String |
getProjectId()
Gets the project id of the instance whose tables this client manages.
|
Table |
getTable(String tableId)
Gets the table metadata by tableId.
|
ApiFuture<Table> |
getTableAsync(String tableId)
Asynchronously gets the table metadata by tableId.
|
List<String> |
listTables()
Lists all table ids in the instance.
|
ApiFuture<List<String>> |
listTablesAsync()
Asynchronously lists all table ids in the instance.
|
Table |
modifyFamilies(ModifyColumnFamiliesRequest request)
Creates, Updates and drops ColumnFamilies as per the request.
|
ApiFuture<Table> |
modifyFamiliesAsync(ModifyColumnFamiliesRequest request)
Asynchronously creates, updates and drops ColumnFamilies as per the request.
|
public static BigtableTableAdminClient create(@Nonnull String projectId, @Nonnull String instanceId) throws IOException
IOException
@Deprecated public static BigtableTableAdminClient create(@Nonnull com.google.bigtable.admin.v2.InstanceName instanceName) throws IOException
create(String, String)
.IOException
public static BigtableTableAdminClient create(@Nonnull BigtableTableAdminSettings settings) throws IOException
IOException
public static BigtableTableAdminClient create(@Nonnull String projectId, @Nonnull String instanceId, @Nonnull EnhancedBigtableTableAdminStub stub)
public String getProjectId()
public String getInstanceId()
@Deprecated public com.google.bigtable.admin.v2.InstanceName getInstanceName()
getProjectId()
and getInstanceId()
.public void close()
close
in interface AutoCloseable
public Table createTable(CreateTableRequest request)
Sample code:
Table table = client.createTable(
CreateTableRequest.of("my-table")
.addFamily("cf2", GCRULES.maxVersions(1)
);
for available options.
public ApiFuture<Table> createTableAsync(CreateTableRequest request)
Sample code:
ApiFuture<Table> tableFuture = client.createTableAsync(
CreateTableRequest.of("my-table")
.addFamily("cf", GCRules.GCRULES.maxVersions(1))
);
ApiFutures.addCallback(
tableFuture,
new ApiFutureCallback<Table>() {
public void onSuccess(Table table) {
System.out.println("Created table: " + table.getTableName());
}
public void onFailure(Throwable t) {
t.printStackTrace();
}
},
MoreExecutors.directExecutor()
);
for available options.
public Table modifyFamilies(ModifyColumnFamiliesRequest request)
Sample code:
Table modifiedTable = client.modifyFamilies(
ModifyColumnFamiliesRequest.of(tableId)
.addFamily("cf1")
.addFamily("cf2", GCRULES.maxAge(Duration.ofSeconds(1000, 20000)))
.updateFamily(
"cf3",
GCRULES.union()
.rule(GCRULES.maxAge(Duration.ofSeconds(100)))
.rule(GCRULES.maxVersions(1))
)
.addFamily(
"cf4",
GCRULES.intersection()
.rule(GCRULES.maxAge(Duration.ofSeconds(2000)))
.rule(GCRULES.maxVersions(10))
)
.dropFamily("cf5")
);
System.out.println("Resulting families:");
for (ColumnFamily cf : modifiedTable.getColumnFamilies()) {
System.out.println(cf.getId());
}
for available options.
public ApiFuture<Table> modifyFamiliesAsync(ModifyColumnFamiliesRequest request)
Sample code:
ApiFuture<Table> modifiedTableFuture = client.modifyFamiliesAsync(
ModifyColumnFamiliesRequest.of(tableId)
.addFamily("cf1")
.addFamily("cf2", GCRULES.maxAge(Duration.ofSeconds(1000, 20000)))
.updateFamily(
"cf3",
GCRULES.union()
.rule(GCRULES.maxAge(Duration.ofSeconds(100)))
.rule(GCRULES.maxVersions(1))
)
.addFamily(
"cf4",
GCRULES.intersection()
.rule(GCRULES.maxAge(Duration.ofSeconds(2000)))
.rule(GCRULES.maxVersions(10))
)
.dropFamily("cf5")
);
ApiFutures.addCallback(
modifiedTableFuture,
new ApiFutureCallback<Table>() {
public void onSuccess(Table table) {
System.out.println("Modified table: " + table.getTableName());
System.out.println("Resulting families:");
for (ColumnFamily cf : modifiedTable.getColumnFamilies()) {
System.out.println(cf.getId());
}
}
public void onFailure(Throwable t) {
t.printStackTrace();
}
},
MoreExecutors.directExecutor()
);
for available options.
public void deleteTable(String tableId)
Sample code:
client.deleteTable("my-table");
public ApiFuture<Void> deleteTableAsync(String tableId)
Sample code:
ApiFuture<Void> future = client.deleteTableAsync("my-table");
ApiFutures.addCallback(
future,
new ApiFutureCallback<Void>() {
public void onSuccess(Void ignored) {
System.out.println("Successfully deleted the table");
}
public void onFailure(Throwable t) {
t.printStackTrace();
}
},
MoreExecutors.directExecutor()
);
public boolean exists(String tableId)
Sample code:
if(client.exists("my-table")) {
System.out.println("Table exists");
}
public ApiFuture<Boolean> existsAsync(String tableId)
Sample code:
ApiFuture<Boolean> found = client.existsAsync("my-table");
ApiFutures.addCallback(
found,
new ApiFutureCallback<Boolean>() {
public void onSuccess(Boolean found) {
if (found) {
System.out.println("Table exists");
} else {
System.out.println("Table not found");
}
}
public void onFailure(Throwable t) {
t.printStackTrace();
}
},
MoreExecutors.directExecutor()
);
public Table getTable(String tableId)
Sample code:
Table table = client.getTable("my-table");
System.out.println("Got metadata for table: " + table.getId());
System.out.println("Column families:");
for (ColumnFamily cf : table.getColumnFamilies()) {
System.out.println(cf.getId());
}
public ApiFuture<Table> getTableAsync(String tableId)
Sample code:
ApiFuture<Table> tableFuture = client.getTableAsync("my-table");
ApiFutures.addCallback(
tableFuture,
new ApiFutureCallback<Table>() {
public void onSuccess(Table table) {
System.out.println("Got metadata for table: " + table.getId());
System.out.println("Column families:");
for (ColumnFamily cf : table.getColumnFamilies()) {
System.out.println(cf.getId());
}
}
public void onFailure(Throwable t) {
t.printStackTrace();
}
},
MoreExecutors.directExecutor()
);
public List<String> listTables()
Sample code:
List<String> tableIds = client.listTables();
for(String tableId: tableIds) {
System.out.println(name.getTable());
}
public ApiFuture<List<String>> listTablesAsync()
Sample code:
ApiFuture<List<String>> listFuture = client.listTables();
ApiFutures.addCallback(
listFuture,
new ApiFutureCallback<List<String>>() {
public void onSuccess(List<String> tableIds) {
System.out.println("Got list of tables:");
for (String tableId : tableIds) {
System.out.println(tableId);
}
}
public void onFailure(Throwable t) {
t.printStackTrace();
}
},
MoreExecutors.directExecutor()
);
public void dropRowRange(String tableId, String rowKeyPrefix)
Please note that this method is considered part of the admin API and is rate limited.
Sample code:
client.dropRowRange("my-table", "prefix");
public ApiFuture<Void> dropRowRangeAsync(String tableId, String rowKeyPrefix)
Please note that this method is considered part of the admin API and is rate limited.
Sample code:
ApiFuture<Void> dropFuture = client.dropRowRangeAsync("my-table", "prefix");
ApiFutures.addCallback(
dropFuture,
new ApiFutureCallback<Void>() {
public void onSuccess(Void tableNames) {
System.out.println("Successfully dropped row range.");
}
public void onFailure(Throwable t) {
t.printStackTrace();
}
},
MoreExecutors.directExecutor()
);
public void dropRowRange(String tableId, ByteString rowKeyPrefix)
Please note that this method is considered part of the admin API and is rate limited.
Sample code:
client.dropRowRange("my-table", ByteString.copyFromUtf8("prefix"));
public ApiFuture<Void> dropRowRangeAsync(String tableId, ByteString rowKeyPrefix)
Please note that this method is considered part of the admin API and is rate limited.
Sample code:
ApiFuture<Void> dropFuture = client.dropRowRangeAsync("my-table", ByteString.copyFromUtf8("prefix"));
ApiFutures.addCallback(
dropFuture,
new ApiFutureCallback<Void>() {
public void onSuccess(Void tableNames) {
System.out.println("Successfully dropped row range.");
}
public void onFailure(Throwable t) {
t.printStackTrace();
}
},
MoreExecutors.directExecutor()
);
public void dropAllRows(String tableId)
Sample code:
client.dropAllRows("my-table");
public ApiFuture<Void> dropAllRowsAsync(String tableId)
Sample code:
ApiFuture<Void> dropFuture = client.dropAllRowsAsync("my-table");
ApiFutures.addCallback(
dropFuture,
new ApiFutureCallback<Void>() {
public void onSuccess(Void tableNames) {
System.out.println("Successfully dropped all data");
}
public void onFailure(Throwable t) {
t.printStackTrace();
}
},
MoreExecutors.directExecutor()
);
public void awaitReplication(String tableId)
Sample code
client.awaitReplication("my-table");
PollException
- when polling exceeds the total timeoutpublic ApiFuture<Void> awaitReplicationAsync(String tableId)
Sample code:
ApiFuture<Void> replicationFuture = client.awaitReplicationAsync("my-table");
ApiFutures.addCallback(
replicationFuture,
new ApiFutureCallback<Void>() {
public void onSuccess(Table table) {
System.out.println("All clusters are now consistent");
}
public void onFailure(Throwable t) {
t.printStackTrace();
}
},
MoreExecutors.directExecutor()
);
Copyright © 2019 Google LLC. All rights reserved.