Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,21 @@
import com.google.api.gax.rpc.ApiExceptions;
import com.google.api.gax.rpc.NotFoundException;
import com.google.bigtable.admin.v2.DeleteAppProfileRequest;
import com.google.bigtable.admin.v2.DeleteLogicalViewRequest;
import com.google.bigtable.admin.v2.DeleteMaterializedViewRequest;
import com.google.bigtable.admin.v2.GetAppProfileRequest;
import com.google.bigtable.admin.v2.GetLogicalViewRequest;
import com.google.bigtable.admin.v2.GetMaterializedViewRequest;
import com.google.bigtable.admin.v2.ListAppProfilesRequest;
import com.google.bigtable.admin.v2.ListLogicalViewsRequest;
import com.google.bigtable.admin.v2.ListMaterializedViewsRequest;
import com.google.bigtable.admin.v2.PartialUpdateClusterRequest;
import com.google.cloud.Policy;
import com.google.cloud.Policy.DefaultMarshaller;
import com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPage;
import com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListAppProfilesPagedResponse;
import com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListLogicalViewsPage;
import com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListLogicalViewsPagedResponse;
import com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListMaterializedViewsPage;
import com.google.cloud.bigtable.admin.v2.BaseBigtableInstanceAdminClient.ListMaterializedViewsPagedResponse;
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
Expand All @@ -41,13 +46,16 @@
import com.google.cloud.bigtable.admin.v2.models.CreateAppProfileRequest;
import com.google.cloud.bigtable.admin.v2.models.CreateClusterRequest;
import com.google.cloud.bigtable.admin.v2.models.CreateInstanceRequest;
import com.google.cloud.bigtable.admin.v2.models.CreateLogicalViewRequest;
import com.google.cloud.bigtable.admin.v2.models.CreateMaterializedViewRequest;
import com.google.cloud.bigtable.admin.v2.models.Instance;
import com.google.cloud.bigtable.admin.v2.models.LogicalView;
import com.google.cloud.bigtable.admin.v2.models.MaterializedView;
import com.google.cloud.bigtable.admin.v2.models.PartialListClustersException;
import com.google.cloud.bigtable.admin.v2.models.PartialListInstancesException;
import com.google.cloud.bigtable.admin.v2.models.UpdateAppProfileRequest;
import com.google.cloud.bigtable.admin.v2.models.UpdateInstanceRequest;
import com.google.cloud.bigtable.admin.v2.models.UpdateLogicalViewRequest;
import com.google.cloud.bigtable.admin.v2.models.UpdateMaterializedViewRequest;
import com.google.cloud.bigtable.admin.v2.stub.BigtableInstanceAdminStub;
import com.google.common.base.Verify;
Expand Down Expand Up @@ -1698,6 +1706,296 @@ public Void apply(Empty input) {
MoreExecutors.directExecutor());
}

/**
* Creates a new logical view.
*
* <p>Sample code:
*
* <pre>{@code
* LogicalView logicalView = client.createLogicalView(
* CreateLogicalViewRequest.of("my-instance", "my-new-logical-view")
* .setQuery(query)
* );
* }</pre>
*
* @see CreateLogicalViewRequest
*/
@SuppressWarnings("WeakerAccess")
public LogicalView createLogicalView(CreateLogicalViewRequest request) {
return ApiExceptions.callAndTranslateApiException(createLogicalViewAsync(request));
}

/**
* Asynchronously creates a new logical view.
*
* <p>Sample code:
*
* <pre>{@code
* ApiFuture<LogicalView> logicalViewFuture = client.createLogicalViewAsync(
* CreateLogicalViewRequest.of("my-instance", "my-new-logical-view")
* .setQuery(query)
* );
*
* LogicalView logicalView = logicalViewFuture.get();
* }</pre>
*
* @see CreateLogicalViewRequest
*/
@SuppressWarnings("WeakerAccess")
public ApiFuture<LogicalView> createLogicalViewAsync(CreateLogicalViewRequest request) {
return ApiFutures.transform(
stub.createLogicalViewOperationCallable().futureCall(request.toProto(projectId)),
new ApiFunction<com.google.bigtable.admin.v2.LogicalView, LogicalView>() {
@Override
public LogicalView apply(com.google.bigtable.admin.v2.LogicalView proto) {
return LogicalView.fromProto(proto);
}
},
MoreExecutors.directExecutor());
}

/**
* Gets the logical view by ID.
*
* <p>Sample code:
*
* <pre>{@code
* LogicalView logicalView = client.getLogicalView("my-instance", "my-logical-view");
* }</pre>
*
* @see LogicalView
*/
public LogicalView getLogicalView(String instanceId, String logicalViewId) {
return ApiExceptions.callAndTranslateApiException(
getLogicalViewAsync(instanceId, logicalViewId));
}

/**
* Asynchronously gets the logical view by ID.
*
* <p>Sample code:
*
* <pre>{@code
* ApiFuture<LogicalView> logicalViewFuture = client.getLogicalViewAsync("my-instance", "my-logical-view");
*
* LogicalView logicalView = logicalViewFuture.get();
* }</pre>
*
* @see LogicalView
*/
@SuppressWarnings("WeakerAccess")
public ApiFuture<LogicalView> getLogicalViewAsync(String instanceId, String logicalViewId) {
String name = NameUtil.formatLogicalViewName(projectId, instanceId, logicalViewId);

GetLogicalViewRequest request = GetLogicalViewRequest.newBuilder().setName(name).build();

return ApiFutures.transform(
stub.getLogicalViewCallable().futureCall(request),
new ApiFunction<com.google.bigtable.admin.v2.LogicalView, LogicalView>() {
@Override
public LogicalView apply(com.google.bigtable.admin.v2.LogicalView proto) {
return LogicalView.fromProto(proto);
}
},
MoreExecutors.directExecutor());
}

/**
* Lists all logical views of the specified instance.
*
* <p>Sample code:
*
* <pre>{@code
* List<LogicalView> logicalViews = client.listLogicalViews("my-instance");
* }</pre>
*
* @see LogicalView
*/
@SuppressWarnings("WeakerAccess")
public List<LogicalView> listLogicalViews(String instanceId) {
return ApiExceptions.callAndTranslateApiException(listLogicalViewsAsync(instanceId));
}

/**
* Asynchronously lists all logical views of the specified instance.
*
* <p>Sample code:
*
* <pre>{@code
* ApiFuture<List<LogicalView>> logicalViewsFuture = client.listLogicalViewsAsync("my-instance");
*
* List<LogicalView> logicalViews = logicalViewFuture.get();
* }</pre>
*
* @see LogicalView
*/
@SuppressWarnings("WeakerAccess")
public ApiFuture<List<LogicalView>> listLogicalViewsAsync(String instanceId) {
String instanceName = NameUtil.formatInstanceName(projectId, instanceId);

ListLogicalViewsRequest request =
ListLogicalViewsRequest.newBuilder().setParent(instanceName).build();

// TODO(igorbernstein2): try to upstream pagination spooling or figure out a way to expose the
// paginated responses while maintaining the wrapper facade.

// Fetches the first page.
ApiFuture<ListLogicalViewsPage> firstPageFuture =
ApiFutures.transform(
stub.listLogicalViewsPagedCallable().futureCall(request),
new ApiFunction<ListLogicalViewsPagedResponse, ListLogicalViewsPage>() {
@Override
public ListLogicalViewsPage apply(ListLogicalViewsPagedResponse response) {
return response.getPage();
}
},
MoreExecutors.directExecutor());

// Fetches the rest of the pages by chaining the futures.
ApiFuture<List<com.google.bigtable.admin.v2.LogicalView>> allProtos =
ApiFutures.transformAsync(
firstPageFuture,
new ApiAsyncFunction<
ListLogicalViewsPage, List<com.google.bigtable.admin.v2.LogicalView>>() {
List<com.google.bigtable.admin.v2.LogicalView> responseAccumulator =
Lists.newArrayList();

@Override
public ApiFuture<List<com.google.bigtable.admin.v2.LogicalView>> apply(
ListLogicalViewsPage page) {
// Add all entries from the page
responseAccumulator.addAll(Lists.newArrayList(page.getValues()));

// If this is the last page, just return the accumulated responses.
if (!page.hasNextPage()) {
return ApiFutures.immediateFuture(responseAccumulator);
}

// Otherwise fetch the next page.
return ApiFutures.transformAsync(
page.getNextPageAsync(), this, MoreExecutors.directExecutor());
}
},
MoreExecutors.directExecutor());

// Wraps all of the accumulated protos.
return ApiFutures.transform(
allProtos,
new ApiFunction<List<com.google.bigtable.admin.v2.LogicalView>, List<LogicalView>>() {
@Override
public List<LogicalView> apply(List<com.google.bigtable.admin.v2.LogicalView> input) {
List<LogicalView> results = Lists.newArrayListWithCapacity(input.size());
for (com.google.bigtable.admin.v2.LogicalView logicalView : input) {
results.add(LogicalView.fromProto(logicalView));
}
return results;
}
},
MoreExecutors.directExecutor());
}

/**
* Updates an existing logical view.
*
* <p>Sample code:
*
* <pre>{@code
* LogicalView existingLogicalView = client.getLogicalView("my-instance", "my-logical-view");
*
* LogicalView updatedLogicalView = client.updateLogicalView(
* UpdateLogicalViewRequest.of(existingLogicalView)
* .setQuery(query)
* );
* }</pre>
*
* @see UpdateLogicalViewRequest
*/
@SuppressWarnings("WeakerAccess")
public LogicalView updateLogicalView(UpdateLogicalViewRequest request) {
return ApiExceptions.callAndTranslateApiException(updateLogicalViewAsync(request));
}

/**
* Asynchronously updates an existing logical view.
*
* <p>Sample code:
*
* <pre>{@code
* ApiFuture<LogicalView> existingLogicalViewFuture = client.getLogicalViewAsync("my-instance", "my-logical-view");
*
* ApiFuture<LogicalView> updatedLogicalViewFuture = ApiFutures.transformAsync(
* existingLogicalViewFuture,
* new ApiAsyncFunction<LogicalView, LogicalView>() {
* public ApiFuture<LogicalView> apply(LogicalView existingLogicalView) {
* return client.updateLogicalViewAsync(
* UpdateLogicalViewRequest.of(existingLogicalView)
* .setQuery(query)
* );
* }
* },
* MoreExecutors.directExecutor()
* );
*
* ApiFuture<LogicalView> logicalView = updatedLogicalViewFuture.get();
* }</pre>
*
* @see UpdateLogicalViewRequest
*/
@SuppressWarnings("WeakerAccess")
public ApiFuture<LogicalView> updateLogicalViewAsync(UpdateLogicalViewRequest request) {
return ApiFutures.transform(
stub.updateLogicalViewOperationCallable().futureCall(request.toProto(projectId)),
new ApiFunction<com.google.bigtable.admin.v2.LogicalView, LogicalView>() {
@Override
public LogicalView apply(com.google.bigtable.admin.v2.LogicalView proto) {
return LogicalView.fromProto(proto);
}
},
MoreExecutors.directExecutor());
}

/**
* Deletes the specified logical view.
*
* <p>Sample code:
*
* <pre>{@code
* client.deleteLogicalView("my-instance", "my-logical-view");
* }</pre>
*/
@SuppressWarnings("WeakerAccess")
public void deleteLogicalView(String instanceId, String logicalViewId) {
ApiExceptions.callAndTranslateApiException(deleteLogicalViewAsync(instanceId, logicalViewId));
}

/**
* Asynchronously deletes the specified logical view.
*
* <p>Sample code:
*
* <pre>{@code
* ApiFuture<Void> deleteFuture = client.deleteLogicalViewAsync("my-instance", "my-logical-view");
*
* deleteFuture.get();
* }</pre>
*/
@SuppressWarnings("WeakerAccess")
public ApiFuture<Void> deleteLogicalViewAsync(String instanceId, String logicalViewId) {

String name = NameUtil.formatLogicalViewName(projectId, instanceId, logicalViewId);
DeleteLogicalViewRequest request = DeleteLogicalViewRequest.newBuilder().setName(name).build();

return ApiFutures.transform(
stub.deleteLogicalViewCallable().futureCall(request),
new ApiFunction<Empty, Void>() {
@Override
public Void apply(Empty input) {
return null;
}
},
MoreExecutors.directExecutor());
}

/**
* Simple adapter to expose {@link DefaultMarshaller} to this class. It enables this client to
* convert to/from IAM wrappers and protobufs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public String toString() {
.add("listMaterializedViewsSettings", stubSettings.listMaterializedViewsSettings())
.add("updateMaterializedViewSettings", stubSettings.updateMaterializedViewSettings())
.add("deleteMaterializedViewSettings", stubSettings.deleteMaterializedViewSettings())
.add("createLogicalViewSettings", stubSettings.createLogicalViewSettings())
.add("getLogicalViewSettings", stubSettings.getLogicalViewSettings())
.add("listLogicalViewsSettings", stubSettings.listLogicalViewsSettings())
.add("updateLogicalViewSettings", stubSettings.updateLogicalViewSettings())
.add("deleteLogicalViewSettings", stubSettings.deleteLogicalViewSettings())
.add("stubSettings", stubSettings)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public static String formatMaterializedViewName(
return formatInstanceName(projectId, instanceId) + "/materializedViews/" + materializedViewId;
}

public static String formatLogicalViewName(
@Nonnull String projectId, @Nonnull String instanceId, @Nonnull String logicalViewId) {
return formatInstanceName(projectId, instanceId) + "/logicalViews/" + logicalViewId;
}

public static String formatLocationName(String projectId, String zone) {
return formatProjectName(projectId) + "/locations/" + zone;
}
Expand Down
Loading