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

Commit 7529c2c

Browse files
committed
fix: load jobs preserve ascii control characters configuration
1 parent 8aabfa7 commit 7529c2c

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/LoadJobConfiguration.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ private Builder(com.google.api.services.bigquery.model.JobConfiguration configur
228228
CsvOptions.newBuilder()
229229
.setEncoding(loadConfigurationPb.getEncoding())
230230
.setFieldDelimiter(loadConfigurationPb.getFieldDelimiter())
231+
.setPreserveAsciiControlCharacters(
232+
loadConfigurationPb.getPreserveAsciiControlCharacters())
231233
.setQuote(loadConfigurationPb.getQuote());
232234
if (loadConfigurationPb.getAllowJaggedRows() != null) {
233235
builder.setAllowJaggedRows(loadConfigurationPb.getAllowJaggedRows());
@@ -907,6 +909,7 @@ com.google.api.services.bigquery.model.JobConfiguration toPb() {
907909
.setAllowJaggedRows(csvOptions.allowJaggedRows())
908910
.setAllowQuotedNewlines(csvOptions.allowQuotedNewLines())
909911
.setEncoding(csvOptions.getEncoding())
912+
.setPreserveAsciiControlCharacters(csvOptions.getPreserveAsciiControlCharacters())
910913
.setQuote(csvOptions.getQuote());
911914
if (csvOptions.getSkipLeadingRows() != null) {
912915
// todo(mziccard) remove checked cast or comment when #1044 is closed

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/LoadJobConfigurationTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class LoadJobConfigurationTest {
3838
.setAllowJaggedRows(true)
3939
.setAllowQuotedNewLines(false)
4040
.setEncoding(StandardCharsets.UTF_8)
41+
.setPreserveAsciiControlCharacters(true)
4142
.build();
4243
private static final TableId TABLE_ID = TableId.of("dataset", "table");
4344
private static final CreateDisposition CREATE_DISPOSITION = CreateDisposition.CREATE_IF_NEEDED;

google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/it/ITBigQueryTest.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ public class ITBigQueryTest {
613613
private static final String LOAD_FILE_LARGE = "load_large.csv";
614614

615615
private static final String LOAD_FILE_FLEXIBLE_COLUMN_NAME = "load_flexible_column_name.csv";
616+
private static final String LOAD_FILE_NULL = "load_null.csv";
616617
private static final String JSON_LOAD_FILE = "load.json";
617618
private static final String JSON_LOAD_FILE_BQ_RESULTSET = "load_bq_resultset.json";
618619
private static final String JSON_LOAD_FILE_SIMPLE = "load_simple.json";
@@ -628,6 +629,7 @@ public class ITBigQueryTest {
628629
private static final TableId TABLE_ID_FASTQUERY_BQ_RESULTSET =
629630
TableId.of(DATASET, "fastquery_testing_bq_resultset");
630631
private static final String CSV_CONTENT = "StringValue1\nStringValue2\n";
632+
private static final String CSV_CONTENT_NULL = "String\0Value1\n";
631633
private static final String CSV_CONTENT_FLEXIBLE_COLUMN = "name,&ampersand\nrow_name,1";
632634

633635
private static final String JSON_CONTENT =
@@ -1080,6 +1082,11 @@ public static void beforeClass() throws InterruptedException, IOException {
10801082
storage.create(
10811083
BlobInfo.newBuilder(BUCKET, LOAD_FILE).setContentType("text/plain").build(),
10821084
CSV_CONTENT.getBytes(StandardCharsets.UTF_8));
1085+
storage.create(
1086+
BlobInfo.newBuilder(BUCKET, LOAD_FILE_NULL)
1087+
.setContentType("text/plain")
1088+
.build(),
1089+
CSV_CONTENT_NULL.getBytes(StandardCharsets.UTF_8));
10831090
storage.create(
10841091
BlobInfo.newBuilder(BUCKET, LOAD_FILE_FLEXIBLE_COLUMN_NAME)
10851092
.setContentType("text/plain")
@@ -6600,9 +6607,9 @@ public void testLocation() throws Exception {
66006607
}
66016608

66026609
@Test
6603-
public void testPreserveAsciiControlCharacters()
6610+
public void testWriteChannelPreserveAsciiControlCharacters()
66046611
throws InterruptedException, IOException, TimeoutException {
6605-
String destinationTableName = "test_preserve_ascii_control_characters";
6612+
String destinationTableName = "test_write_channel_preserve_ascii_control_characters";
66066613
TableId tableId = TableId.of(DATASET, destinationTableName);
66076614
WriteChannelConfiguration configuration =
66086615
WriteChannelConfiguration.newBuilder(tableId)
@@ -6625,6 +6632,27 @@ public void testPreserveAsciiControlCharacters()
66256632
assertTrue(bigquery.delete(tableId));
66266633
}
66276634

6635+
@Test
6636+
public void testLoadJobPreserveAsciiControlCharacters()
6637+
throws InterruptedException {
6638+
String destinationTableName = "test_load_job_preserve_ascii_control_characters";
6639+
TableId destinationTable = TableId.of(DATASET, destinationTableName);
6640+
6641+
try {
6642+
LoadJobConfiguration configuration =
6643+
LoadJobConfiguration.newBuilder(destinationTable, "gs://" + BUCKET + "/" + LOAD_FILE_NULL)
6644+
.setFormatOptions(
6645+
CsvOptions.newBuilder().setPreserveAsciiControlCharacters(true).build())
6646+
.setSchema(SIMPLE_SCHEMA)
6647+
.build();
6648+
Job remoteLoadJob = bigquery.create(JobInfo.of(configuration));
6649+
remoteLoadJob = remoteLoadJob.waitFor();
6650+
assertNull(remoteLoadJob.getStatus().getError());
6651+
} finally {
6652+
assertTrue(bigquery.delete(destinationTable));
6653+
}
6654+
}
6655+
66286656
@Test
66296657
public void testReferenceFileSchemaUriForAvro() {
66306658
try {

0 commit comments

Comments
 (0)