Skip to content

Commit 64029c9

Browse files
authored
test: Add ExecuteQuery integration test with Proto/Enum types (#2701)
Change-Id: I1f0e24fb27c719d96839687418dde54d50fbc841
1 parent e3e6e99 commit 64029c9

3 files changed

Lines changed: 39 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,8 +2091,7 @@ public List<String> apply(List<com.google.bigtable.admin.v2.SchemaBundle> protos
20912091
}
20922092

20932093
/**
2094-
* Deletes an schema bundle with the specified schema bundle ID in the specified table. Note that
2095-
* the deletion is prohibited if the schema bundle has deletion_protection field set to true.
2094+
* Deletes an schema bundle with the specified schema bundle ID in the specified table.
20962095
*
20972096
* <p>Sample code:
20982097
*
@@ -2106,8 +2105,7 @@ public void deleteSchemaBundle(String tableId, String schemaBundleId) {
21062105

21072106
/**
21082107
* Asynchronously deletes an schema bundle with the specified schema bundle ID in the specified
2109-
* table. Note that the deletion is prohibited if the schema bundle has deletion_protection field
2110-
* set to true.
2108+
* table.
21112109
*
21122110
* <p>Sample code:
21132111
*

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ public CreateSchemaBundleRequest setProtoSchemaFile(@Nonnull String protoSchemaF
6868
}
6969

7070
/** Sets the proto schema for this schema bundle. */
71-
public CreateSchemaBundleRequest setProtoSchema(@Nonnull ByteString protoSchema)
72-
throws IOException {
71+
public CreateSchemaBundleRequest setProtoSchema(@Nonnull ByteString protoSchema) {
7372
Preconditions.checkNotNull(protoSchema, "protoSchema must be set");
7473
requestBuilder.setSchemaBundle(
7574
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ExecuteQueryIT.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.junit.Assert.assertThrows;
2121

2222
import com.google.cloud.Date;
23+
import com.google.cloud.bigtable.admin.v2.models.CreateSchemaBundleRequest;
2324
import com.google.cloud.bigtable.data.v2.BigtableDataClient;
2425
import com.google.cloud.bigtable.data.v2.models.RowMutation;
2526
import com.google.cloud.bigtable.data.v2.models.TableId;
@@ -28,10 +29,14 @@
2829
import com.google.cloud.bigtable.data.v2.models.sql.ResultSet;
2930
import com.google.cloud.bigtable.data.v2.models.sql.SqlType;
3031
import com.google.cloud.bigtable.data.v2.models.sql.Struct;
32+
import com.google.cloud.bigtable.data.v2.test.AlbumProto.Album;
33+
import com.google.cloud.bigtable.data.v2.test.SingerProto.Genre;
34+
import com.google.cloud.bigtable.data.v2.test.SingerProto.Singer;
3135
import com.google.cloud.bigtable.test_helpers.env.AbstractTestEnv;
3236
import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv;
3337
import com.google.cloud.bigtable.test_helpers.env.TestEnvRule;
3438
import com.google.protobuf.ByteString;
39+
import com.google.protobuf.DescriptorProtos.FileDescriptorSet;
3540
import java.io.IOException;
3641
import java.time.Instant;
3742
import java.util.Arrays;
@@ -48,6 +53,8 @@
4853
@RunWith(JUnit4.class)
4954
public class ExecuteQueryIT {
5055

56+
public static String SCHEMA_BUNDLE_ID = "my_bundle";
57+
5158
@ClassRule public static TestEnvRule testEnvRule = new TestEnvRule();
5259
private static BigtableDataClient dataClient;
5360
private static String tableId;
@@ -155,14 +162,21 @@ public void withHistoryQuery() {
155162
@SuppressWarnings("DoubleBraceInitialization")
156163
@Test
157164
public void allTypes() {
165+
createTestSchemaBundle();
166+
Album album = Album.newBuilder().setTitle("Lover").build();
158167
PreparedStatement preparedStatement =
159168
dataClient.prepareStatement(
160169
"SELECT 'stringVal' AS strCol, b'foo' as bytesCol, 1 AS intCol, CAST(1.2 AS FLOAT32) as"
161170
+ " f32Col, CAST(1.3 AS FLOAT64) as f64Col, true as boolCol,"
162171
+ " TIMESTAMP_FROM_UNIX_MILLIS(1000) AS tsCol, DATE(2024, 06, 01) as dateCol,"
163172
+ " STRUCT(1 as a, \"foo\" as b) AS structCol, [1,2,3] AS arrCol, "
164173
+ cf
165-
+ " as mapCol FROM `"
174+
+ " as mapCol, "
175+
+ " CAST(b'\022\005Lover' AS "
176+
+ SCHEMA_BUNDLE_ID
177+
+ ".com.google.cloud.bigtable.data.v2.test.Album) as protoCol, CAST('JAZZ' AS "
178+
+ SCHEMA_BUNDLE_ID
179+
+ ".com.google.cloud.bigtable.data.v2.test.Genre) as enumCol FROM `"
166180
+ tableId
167181
+ "` WHERE _key='"
168182
+ uniquePrefix
@@ -213,9 +227,13 @@ public void allTypes() {
213227
put(ByteString.copyFromUtf8("qual3"), ByteString.copyFromUtf8("val3"));
214228
}
215229
});
216-
230+
assertThat(rs.getProtoMessage("protoCol", Album.getDefaultInstance())).isEqualTo(album);
231+
assertThat(rs.getProtoMessage(11, Album.getDefaultInstance())).isEqualTo(album);
232+
assertThat(rs.getProtoEnum("enumCol", Genre::forNumber)).isEqualTo(Genre.JAZZ);
233+
assertThat(rs.getProtoEnum(12, Genre::forNumber)).isEqualTo(Genre.JAZZ);
217234
assertThat(rs.next()).isFalse();
218235
}
236+
deleteTestSchemaBundle();
219237
}
220238

221239
@Test
@@ -380,4 +398,20 @@ public void testNullColumns() {
380398
assertThat(rs.next()).isFalse();
381399
}
382400
}
401+
402+
private static void deleteTestSchemaBundle() {
403+
testEnvRule.env().getTableAdminClient().deleteSchemaBundle(tableId, SCHEMA_BUNDLE_ID);
404+
}
405+
406+
private static void createTestSchemaBundle() {
407+
FileDescriptorSet fileDescriptorSet =
408+
FileDescriptorSet.newBuilder()
409+
.addFile(Singer.getDescriptor().getFile().toProto())
410+
.addFile(Album.getDescriptor().getFile().toProto())
411+
.build();
412+
CreateSchemaBundleRequest request =
413+
CreateSchemaBundleRequest.of(tableId, SCHEMA_BUNDLE_ID)
414+
.setProtoSchema(fileDescriptorSet.toByteString());
415+
testEnvRule.env().getTableAdminClient().createSchemaBundle(request);
416+
}
383417
}

0 commit comments

Comments
 (0)