Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit fa1376d

Browse files
committed
handled file
1 parent 7cf812a commit fa1376d

5 files changed

Lines changed: 43 additions & 14 deletions

File tree

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateSchemaBundleRequest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@
1717
package com.google.cloud.bigtable.admin.v2.models;
1818

1919
import com.google.api.core.InternalApi;
20+
import com.google.bigtable.admin.v2.ProtoSchema;
2021
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
2122
import com.google.common.base.Objects;
2223
import com.google.common.base.Preconditions;
24+
import com.google.protobuf.ByteString;
25+
import java.io.IOException;
26+
import java.nio.file.Files;
27+
import java.nio.file.Path;
28+
import java.nio.file.Paths;
29+
2330
import javax.annotation.Nonnull;
2431

2532
/**
@@ -59,9 +66,14 @@ private CreateSchemaBundleRequest(@Nonnull String tableId, @Nonnull String schem
5966
*
6067
* @see SchemaBundleType for details.
6168
*/
62-
public CreateSchemaBundleRequest setProtoSchema(@Nonnull String protoFile) {
63-
Preconditions.checkNotNull(protoFile, "protoSchema must be set");
64-
69+
public CreateSchemaBundleRequest setProtoSchema(@Nonnull String protoSchemaFile)
70+
throws IOException {
71+
Preconditions.checkNotNull(protoSchemaFile, "protoSchema must be set");
72+
byte[] content = Files.readAllBytes(Paths.get(protoSchemaFile));
73+
requestBuilder.setSchemaBundle(
74+
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
75+
.setProtoSchema(
76+
ProtoSchema.newBuilder().setProtoDescriptors(ByteString.copyFrom(content))));
6577
return this;
6678
}
6779

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/UpdateSchemaBundleRequest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,18 @@
1717
package com.google.cloud.bigtable.admin.v2.models;
1818

1919
import com.google.api.core.InternalApi;
20+
import com.google.bigtable.admin.v2.ProtoSchema;
2021
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
2122
import com.google.common.base.Objects;
2223
import com.google.common.base.Preconditions;
24+
import com.google.protobuf.ByteString;
2325
import com.google.protobuf.FieldMask;
2426
import com.google.protobuf.util.FieldMaskUtil;
27+
import java.io.IOException;
28+
import java.nio.file.Files;
29+
import java.nio.file.Path;
30+
import java.nio.file.Paths;
31+
2532
import javax.annotation.Nonnull;
2633

2734
/**
@@ -74,8 +81,12 @@ private UpdateSchemaBundleRequest(
7481
}
7582

7683
/** Changes the deletion protection of an existing schema bundle. */
77-
public UpdateSchemaBundleRequest setProtoSchema(String protoSchemaFile) {
78-
// requestBuilder.getSchemaBundleBuilder().setDeletionProtection(deletionProtection);
84+
public UpdateSchemaBundleRequest setProtoSchema(String protoSchemaFile) throws IOException {
85+
byte[] content = Files.readAllBytes(Paths.get(protoSchemaFile));
86+
requestBuilder.setSchemaBundle(
87+
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
88+
.setProtoSchema(
89+
ProtoSchema.newBuilder().setProtoDescriptors(ByteString.copyFrom(content))));
7990
updateFieldMask(com.google.bigtable.admin.v2.SchemaBundle.PROTO_SCHEMA_FIELD_NUMBER);
8091
return this;
8192
}

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
import com.google.protobuf.util.Timestamps;
9999
import io.grpc.Status;
100100
import io.grpc.Status.Code;
101+
102+
import java.io.IOException;
101103
import java.util.List;
102104
import java.util.Map;
103105
import java.util.concurrent.ExecutionException;
@@ -1330,7 +1332,7 @@ public void testDeleteAuthorizedView() {
13301332
}
13311333

13321334
@Test
1333-
public void testCreateSchemaBundle() {
1335+
public void testCreateSchemaBundle() throws IOException {
13341336
// Setup
13351337
Mockito.when(mockStub.createSchemaBundleOperationCallable())
13361338
.thenReturn(mockCreateSchemaBundleOperationCallable);
@@ -1375,7 +1377,7 @@ public void testCreateSchemaBundle() {
13751377
}
13761378

13771379
@Test
1378-
public void testUpdateSchemaBundle() {
1380+
public void testUpdateSchemaBundle() throws IOException {
13791381
// Setup
13801382
Mockito.when(mockStub.updateSchemaBundleOperationCallable())
13811383
.thenReturn(mockUpdateSchemaBundleOperationCallable);

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateSchemaBundleRequestTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020

21+
import java.io.IOException;
22+
2123
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
2224
import com.google.protobuf.ByteString;
2325
import org.junit.Test;
@@ -32,7 +34,7 @@ public class CreateSchemaBundleRequestTest {
3234
private static final String SCHEMA_BUNDLE_ID = "my-schema-bundle";
3335

3436
@Test
35-
public void testToProto() {
37+
public void testToProto() throws IOException{
3638
CreateSchemaBundleRequest request =
3739
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID).setProtoSchema("file.pb");
3840

@@ -52,7 +54,7 @@ public void testToProto() {
5254
}
5355

5456
@Test
55-
public void testEquality() {
57+
public void testEquality() throws IOException{
5658
CreateSchemaBundleRequest request =
5759
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID).setProtoSchema("file.pb");
5860

@@ -67,7 +69,7 @@ public void testEquality() {
6769
}
6870

6971
@Test
70-
public void testHashCode() {
72+
public void testHashCode() throws IOException{
7173
CreateSchemaBundleRequest request =
7274
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID).setProtoSchema("file.pb");
7375

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/UpdateSchemaBundleRequestTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import static com.google.common.truth.Truth.assertThat;
2020

21+
import java.io.IOException;
22+
2123
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
2224
import com.google.protobuf.ByteString;
2325
import com.google.protobuf.FieldMask;
@@ -33,7 +35,7 @@ public class UpdateSchemaBundleRequestTest {
3335
private static final String SCHEMA_BUNDLE_ID = "my-schema-bundle";
3436

3537
@Test
36-
public void testToProto() {
38+
public void testToProto() throws IOException{
3739
UpdateSchemaBundleRequest request =
3840
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
3941
.setProtoSchema("file.pb")
@@ -58,7 +60,7 @@ public void testToProto() {
5860
}
5961

6062
@Test
61-
public void testUpdateProtoSchema() {
63+
public void testUpdateProtoSchema() throws IOException{
6264
com.google.bigtable.admin.v2.SchemaBundle existingSchemaBundle =
6365
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
6466
.setName(
@@ -83,7 +85,7 @@ public void testUpdateProtoSchema() {
8385
}
8486

8587
@Test
86-
public void testEquality() {
88+
public void testEquality() throws IOException{
8789
UpdateSchemaBundleRequest request =
8890
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID).setProtoSchema("file.pb");
8991

@@ -98,7 +100,7 @@ public void testEquality() {
98100
}
99101

100102
@Test
101-
public void testHashCode() {
103+
public void testHashCode() throws IOException{
102104
UpdateSchemaBundleRequest request =
103105
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID).setProtoSchema("file.pb");
104106

0 commit comments

Comments
 (0)