|
20 | 20 | import static org.junit.Assert.assertThrows; |
21 | 21 |
|
22 | 22 | import com.google.cloud.Date; |
| 23 | +import com.google.cloud.bigtable.admin.v2.models.CreateSchemaBundleRequest; |
23 | 24 | import com.google.cloud.bigtable.data.v2.BigtableDataClient; |
24 | 25 | import com.google.cloud.bigtable.data.v2.models.RowMutation; |
25 | 26 | import com.google.cloud.bigtable.data.v2.models.TableId; |
|
28 | 29 | import com.google.cloud.bigtable.data.v2.models.sql.ResultSet; |
29 | 30 | import com.google.cloud.bigtable.data.v2.models.sql.SqlType; |
30 | 31 | 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; |
31 | 35 | import com.google.cloud.bigtable.test_helpers.env.AbstractTestEnv; |
32 | 36 | import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv; |
33 | 37 | import com.google.cloud.bigtable.test_helpers.env.TestEnvRule; |
34 | 38 | import com.google.protobuf.ByteString; |
| 39 | +import com.google.protobuf.DescriptorProtos.FileDescriptorSet; |
35 | 40 | import java.io.IOException; |
36 | 41 | import java.time.Instant; |
37 | 42 | import java.util.Arrays; |
|
48 | 53 | @RunWith(JUnit4.class) |
49 | 54 | public class ExecuteQueryIT { |
50 | 55 |
|
| 56 | + public static String SCHEMA_BUNDLE_ID = "my_bundle"; |
| 57 | + |
51 | 58 | @ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); |
52 | 59 | private static BigtableDataClient dataClient; |
53 | 60 | private static String tableId; |
@@ -155,14 +162,21 @@ public void withHistoryQuery() { |
155 | 162 | @SuppressWarnings("DoubleBraceInitialization") |
156 | 163 | @Test |
157 | 164 | public void allTypes() { |
| 165 | + createTestSchemaBundle(); |
| 166 | + Album album = Album.newBuilder().setTitle("Lover").build(); |
158 | 167 | PreparedStatement preparedStatement = |
159 | 168 | dataClient.prepareStatement( |
160 | 169 | "SELECT 'stringVal' AS strCol, b'foo' as bytesCol, 1 AS intCol, CAST(1.2 AS FLOAT32) as" |
161 | 170 | + " f32Col, CAST(1.3 AS FLOAT64) as f64Col, true as boolCol," |
162 | 171 | + " TIMESTAMP_FROM_UNIX_MILLIS(1000) AS tsCol, DATE(2024, 06, 01) as dateCol," |
163 | 172 | + " STRUCT(1 as a, \"foo\" as b) AS structCol, [1,2,3] AS arrCol, " |
164 | 173 | + 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 `" |
166 | 180 | + tableId |
167 | 181 | + "` WHERE _key='" |
168 | 182 | + uniquePrefix |
@@ -213,9 +227,13 @@ public void allTypes() { |
213 | 227 | put(ByteString.copyFromUtf8("qual3"), ByteString.copyFromUtf8("val3")); |
214 | 228 | } |
215 | 229 | }); |
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); |
217 | 234 | assertThat(rs.next()).isFalse(); |
218 | 235 | } |
| 236 | + deleteTestSchemaBundle(); |
219 | 237 | } |
220 | 238 |
|
221 | 239 | @Test |
@@ -380,4 +398,20 @@ public void testNullColumns() { |
380 | 398 | assertThat(rs.next()).isFalse(); |
381 | 399 | } |
382 | 400 | } |
| 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 | + } |
383 | 417 | } |
0 commit comments