2929import com .google .cloud .bigquery .storage .v1 .*;
3030import com .google .cloud .bigquery .testing .RemoteBigQueryHelper ;
3131import com .google .common .collect .ImmutableList ;
32+ import com .google .protobuf .ByteString ;
3233import com .google .protobuf .Descriptors ;
3334import com .google .protobuf .Descriptors .DescriptorValidationException ;
3435import java .io .IOException ;
@@ -327,11 +328,18 @@ public void testJsonStreamWriterWithDefaultStream()
327328 .setMode (TableFieldSchema .Mode .NULLABLE )
328329 .setName ("test_datetime" )
329330 .build ();
331+ TableFieldSchema TEST_REPEATED_BYTESTRING =
332+ TableFieldSchema .newBuilder ()
333+ .setType (TableFieldSchema .Type .BYTES )
334+ .setMode (TableFieldSchema .Mode .REPEATED )
335+ .setName ("test_bytestring_repeated" )
336+ .build ();
330337 TableSchema tableSchema =
331338 TableSchema .newBuilder ()
332339 .addFields (0 , TEST_STRING )
333340 .addFields (1 , TEST_DATE )
334341 .addFields (2 , TEST_NUMERIC )
342+ .addFields (3 , TEST_REPEATED_BYTESTRING )
335343 .build ();
336344 TableInfo tableInfo =
337345 TableInfo .newBuilder (
@@ -347,8 +355,13 @@ public void testJsonStreamWriterWithDefaultStream()
347355 .build (),
348356 com .google .cloud .bigquery .Field .newBuilder (
349357 "test_datetime" , StandardSQLTypeName .DATETIME )
358+ .build (),
359+ com .google .cloud .bigquery .Field .newBuilder (
360+ "test_bytestring_repeated" , StandardSQLTypeName .BYTES )
361+ .setMode (Field .Mode .REPEATED )
350362 .build ())))
351363 .build ();
364+
352365 bigquery .create (tableInfo );
353366 TableName parent = TableName .of (ServiceOptions .getDefaultProjectId (), DATASET , tableName );
354367 try (JsonStreamWriter jsonStreamWriter =
@@ -371,6 +384,13 @@ public void testJsonStreamWriterWithDefaultStream()
371384 row1 .put (
372385 "test_datetime" ,
373386 CivilTimeEncoder .encodePacked64DatetimeMicros (LocalDateTime .of (2020 , 10 , 1 , 12 , 0 )));
387+ row1 .put (
388+ "test_bytestring_repeated" ,
389+ new JSONArray (
390+ new byte [][] {
391+ ByteString .copyFromUtf8 ("a" ).toByteArray (),
392+ ByteString .copyFromUtf8 ("b" ).toByteArray ()
393+ }));
374394 JSONArray jsonArr1 = new JSONArray (new JSONObject [] {row1 });
375395
376396 ApiFuture <AppendRowsResponse > response1 = jsonStreamWriter .append (jsonArr1 , -1 );
@@ -405,6 +425,8 @@ public void testJsonStreamWriterWithDefaultStream()
405425 assertEquals ("aaa" , currentRow .get (0 ).getStringValue ());
406426 assertEquals ("-9000000" , currentRow .get (1 ).getRepeatedValue ().get (1 ).getStringValue ());
407427 assertEquals ("2020-10-01T12:00:00" , currentRow .get (2 ).getStringValue ());
428+ assertEquals (2 , currentRow .get (3 ).getRepeatedValue ().size ());
429+ assertEquals ("Yg==" , currentRow .get (3 ).getRepeatedValue ().get (1 ).getStringValue ());
408430 assertEquals ("bbb" , iter .next ().get (0 ).getStringValue ());
409431 assertEquals ("ccc" , iter .next ().get (0 ).getStringValue ());
410432 assertEquals ("ddd" , iter .next ().get (0 ).getStringValue ());
0 commit comments