-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exists method added #3769
Exists method added #3769
Conversation
* }</pre> | ||
*/ | ||
public boolean exists(String tableId) { | ||
List<TableName> tableNames = this.listTables(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
String table = tableName.toString(); | ||
String separator = "/"; | ||
int index = table.lastIndexOf(separator); | ||
String name = table.substring(index + separator.length()); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
boolean found = adminClient.exists(TABLE_NAME.getTable()); | ||
|
||
// Verify | ||
Assert.assertTrue(found); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
...ble-admin/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java
Show resolved
Hide resolved
return ApiFutures.transform(listTablesAsync(), new ApiFunction<List<TableName>, Boolean>() { | ||
@Override public Boolean apply(List<TableName> tableNames) { | ||
for(TableName tableName : tableNames) { | ||
if(tableName.getTable().equalsIgnoreCase(tableId)) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return listTablesAsync(com.google.bigtable.admin.v2.Table.View.NAME_ONLY); | ||
} | ||
|
||
public ApiFuture<List<TableName>> listTablesAsync(com.google.bigtable.admin.v2.Table.View view) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
public ApiFuture<Boolean> existsAsync(final String tableId) { | ||
return ApiFutures.transform(listTablesAsync(), new ApiFunction<List<TableName>, Boolean>() { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good, just needs some stylistic fixes
...igtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java
Show resolved
Hide resolved
.setName(TABLE_NAME.toString()) | ||
.build(); | ||
|
||
Mockito.when(mockGetTableCallable.futureCall(Matchers.any(GetTableRequest.class))).thenReturn(ApiFutures.immediateFuture(expectedResponse)); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
import com.google.bigtable.admin.v2.GetTableRequest; | ||
import com.google.bigtable.admin.v2.InstanceName; | ||
import com.google.bigtable.admin.v2.ListTablesRequest; | ||
import com.google.bigtable.admin.v2.*; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -184,6 +182,7 @@ public void testGetTable() { | |||
// Setup | |||
GetTableRequest expectedRequest = GetTableRequest.newBuilder() | |||
.setName(TABLE_NAME.toString()) | |||
.setView(com.google.bigtable.admin.v2.Table.View.SCHEMA_VIEW) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
...ble-admin/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last nit about sample code, but this LGTM
* found, | ||
* new ApiFutureCallback<Boolean>() { | ||
* public void onSuccess(Boolean found) { | ||
* System.out.println("Table exists"); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
60e99f2
to
35da0af
Compare
new NotFoundException("fake error", null, GrpcStatusCode.of(Status.Code.NOT_FOUND), false); | ||
|
||
Mockito.when(mockGetTableCallable.futureCall(Matchers.any(GetTableRequest.class))) | ||
.thenReturn(ApiFutures.immediateFailedFuture(exception)); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@elisheva-qlogic, there's a compilation failure:
It looks like a merge conflict with PR #3809 |
I think I fixed the issue |
exists method added in BigtableTableAdminClient to check if table exists #3636