Skip to content

feat(bigtable): Add support for Logical Views in Admin API #2519

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

Merged
merged 8 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat(bigtable): Add admin support for Logical Views
  • Loading branch information
ron-gal committed Mar 13, 2025
commit 676bcc3399239f7cd45eaee830d286c91e21b86a
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@
import javax.annotation.Nonnull;

/**
* A class that wraps the {@link com.google.bigtable.admin.v2.LogicalView} protocol buffer
* object.
* A class that wraps the {@link com.google.bigtable.admin.v2.LogicalView} protocol buffer object.
*
* <p>A LogicalView represents subsets of a particular table based on rules. The access to each
* LogicalView can be configured separately from the Table.
*
* <p>Users can perform read/write operation on a LogicalView by providing a logicalView
* id besides a table id, in which case the semantics remain identical as reading/writing on a Table
* except that visibility is restricted to the subset of the Table that the LogicalView
* represents.
* <p>Users can perform read/write operation on a LogicalView by providing a logicalView id besides
* a table id, in which case the semantics remain identical as reading/writing on a Table except
* that visibility is restricted to the subset of the Table that the LogicalView represents.
*/
public final class LogicalView {
private final com.google.bigtable.admin.v2.LogicalView proto;
Expand All @@ -43,8 +41,7 @@ public final class LogicalView {
* to be used by applications.
*/
@InternalApi
public static LogicalView fromProto(
@Nonnull com.google.bigtable.admin.v2.LogicalView proto) {
public static LogicalView fromProto(@Nonnull com.google.bigtable.admin.v2.LogicalView proto) {
return new LogicalView(proto);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public UpdateLogicalViewRequest setQuery(String query) {

private void updateFieldMask(int fieldNumber) {
FieldMask newMask =
FieldMaskUtil.fromFieldNumbers(
com.google.bigtable.admin.v2.LogicalView.class, fieldNumber);
FieldMaskUtil.fromFieldNumbers(com.google.bigtable.admin.v2.LogicalView.class, fieldNumber);
requestBuilder.setUpdateMask(FieldMaskUtil.union(requestBuilder.getUpdateMask(), newMask));
}

Expand All @@ -110,8 +109,7 @@ public int hashCode() {
* not meant to be used by applications.
*/
@InternalApi
public com.google.bigtable.admin.v2.UpdateLogicalViewRequest toProto(
@Nonnull String projectId) {
public com.google.bigtable.admin.v2.UpdateLogicalViewRequest toProto(@Nonnull String projectId) {
requestBuilder
.getLogicalViewBuilder()
.setName(NameUtil.formatLogicalViewName(projectId, instanceId, logicalViewId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,33 @@ public class CreateLogicalViewRequestTest {
public void testToProto() {
String query = "SELECT * FROM Table";
CreateLogicalViewRequest request =
CreateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID)
.setQuery(query);
CreateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID).setQuery(query);

com.google.bigtable.admin.v2.CreateLogicalViewRequest requestProto =
com.google.bigtable.admin.v2.CreateLogicalViewRequest.newBuilder()
.setParent(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID))
.setLogicalViewId(LOGICAL_VIEW_ID)
.setLogicalView(
com.google.bigtable.admin.v2.LogicalView.newBuilder()
.setQuery(query))
.setLogicalView(com.google.bigtable.admin.v2.LogicalView.newBuilder().setQuery(query))
.build();
assertThat(request.toProto(PROJECT_ID)).isEqualTo(requestProto);
}

@Test
public void testEquality() {
CreateLogicalViewRequest request =
CreateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID)
.setQuery("test 1");
CreateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID).setQuery("test 1");

assertThat(request)
.isEqualTo(
CreateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID)
.setQuery("test 1"));
.isEqualTo(CreateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID).setQuery("test 1"));

assertThat(request)
.isNotEqualTo(
CreateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID)
.setQuery("test 2"));
.isNotEqualTo(CreateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID).setQuery("test 2"));
}

@Test
public void testHashCode() {
CreateLogicalViewRequest request =
CreateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID)
.setQuery("test 1");
CreateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID).setQuery("test 1");

assertThat(request.hashCode())
.isEqualTo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public class LogicalViewTest {

@Test
public void testFromProto() {
LogicalViewName logicalViewName =
LogicalViewName.of(PROJECT_ID, INSTANCE_ID, LOGICAL_VIEW_ID);
LogicalViewName logicalViewName = LogicalViewName.of(PROJECT_ID, INSTANCE_ID, LOGICAL_VIEW_ID);

com.google.bigtable.admin.v2.LogicalView logicalViewProto =
com.google.bigtable.admin.v2.LogicalView.newBuilder()
Expand Down Expand Up @@ -66,8 +65,7 @@ public void testRequiresName() {

@Test
public void testEquality() {
LogicalViewName logicalViewName =
LogicalViewName.of(PROJECT_ID, INSTANCE_ID, LOGICAL_VIEW_ID);
LogicalViewName logicalViewName = LogicalViewName.of(PROJECT_ID, INSTANCE_ID, LOGICAL_VIEW_ID);
com.google.bigtable.admin.v2.LogicalView proto =
com.google.bigtable.admin.v2.LogicalView.newBuilder()
.setName(logicalViewName.toString())
Expand All @@ -87,8 +85,7 @@ public void testEquality() {

@Test
public void testHashCode() {
LogicalViewName logicalViewName =
LogicalViewName.of(PROJECT_ID, INSTANCE_ID, LOGICAL_VIEW_ID);
LogicalViewName logicalViewName = LogicalViewName.of(PROJECT_ID, INSTANCE_ID, LOGICAL_VIEW_ID);
com.google.bigtable.admin.v2.LogicalView proto =
com.google.bigtable.admin.v2.LogicalView.newBuilder()
.setName(logicalViewName.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ public class UpdateLogicalViewRequestTest {
@Test
public void testToProto() {
UpdateLogicalViewRequest request =
UpdateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID)
.setQuery("query 1");
UpdateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID).setQuery("query 1");

com.google.bigtable.admin.v2.UpdateLogicalViewRequest requestProto =
com.google.bigtable.admin.v2.UpdateLogicalViewRequest.newBuilder()
.setLogicalView(
com.google.bigtable.admin.v2.LogicalView.newBuilder()
.setQuery("query 1")
.setQuery("query 1")
.setName(
NameUtil.formatLogicalViewName(
PROJECT_ID, INSTANCE_ID, LOGICAL_VIEW_ID)))
NameUtil.formatLogicalViewName(PROJECT_ID, INSTANCE_ID, LOGICAL_VIEW_ID)))
.setUpdateMask(FieldMask.newBuilder().addPaths("query").build())
.build();
assertThat(request.toProto(PROJECT_ID)).isEqualTo(requestProto);
Expand All @@ -52,36 +50,31 @@ public void testToProto() {
@Test
public void testEquality() {
UpdateLogicalViewRequest request =
UpdateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID)
.setQuery("query 1");
UpdateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID).setQuery("query 1");

assertThat(request)
.isEqualTo(
UpdateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID)
.setQuery("query 1"));
.isEqualTo(UpdateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID).setQuery("query 1"));

assertThat(request)
.isNotEqualTo(
UpdateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID)
.setQuery("query 2"));
UpdateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID).setQuery("query 2"));
}

@Test
public void testHashCode() {
UpdateLogicalViewRequest request =
UpdateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID)
.setQuery("query 1");
UpdateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID).setQuery("query 1");

assertThat(request.hashCode())
.isEqualTo(
UpdateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID)
.setQuery("query 1")
.setQuery("query 1")
.hashCode());

assertThat(request.hashCode())
.isNotEqualTo(
UpdateLogicalViewRequest.of(INSTANCE_ID, LOGICAL_VIEW_ID)
.setQuery("query 2")
.setQuery("query 2")
.hashCode());
}
}
Loading