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

Commit adcb9bb

Browse files
authored
fix: Add a e2e test on byte string array and remove a impossible case for byte array conversion (#1546)
1 parent da852ac commit adcb9bb

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

google-cloud-bigquerystorage/src/main/java/com/google/cloud/bigquery/storage/v1/JsonToProtoMessage.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,6 @@ private static void fillRepeatedField(
441441
+ index
442442
+ "] could not be converted to byte[]."));
443443
}
444-
} else if (val instanceof ByteString) {
445-
protoMsg.addRepeatedField(fieldDescriptor, ((ByteString) val).toByteArray());
446-
return;
447444
} else {
448445
fail = true;
449446
}

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.cloud.bigquery.storage.v1.*;
3030
import com.google.cloud.bigquery.testing.RemoteBigQueryHelper;
3131
import com.google.common.collect.ImmutableList;
32+
import com.google.protobuf.ByteString;
3233
import com.google.protobuf.Descriptors;
3334
import com.google.protobuf.Descriptors.DescriptorValidationException;
3435
import 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

Comments
 (0)