Skip to content

Commit 763ead9

Browse files
committed
update PR feedback
1 parent e8f9472 commit 763ead9

4 files changed

Lines changed: 83 additions & 41 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* Google BigQuery options for Cloud Datastore backup.
2525
*/
2626
public final class DatastoreBackupOptions extends FormatOptions {
27-
private List<String> projectionFields;
27+
private final List<String> projectionFields;
2828

2929
public static final class Builder {
3030
private List<String> projectionFields;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public static final class Builder implements LoadConfiguration.Builder {
5555
private Integer maxBadRecords;
5656
private Schema schema;
5757
private Boolean ignoreUnknownValues;
58-
private List<String> projectionFields;
5958

6059
private Builder() {}
6160

@@ -108,7 +107,11 @@ private Builder(com.google.api.services.bigquery.model.JobConfiguration configur
108107
this.schema = Schema.fromPb(loadConfigurationPb.getSchema());
109108
}
110109
this.ignoreUnknownValues = loadConfigurationPb.getIgnoreUnknownValues();
111-
this.projectionFields = loadConfigurationPb.getProjectionFields();
110+
if (loadConfigurationPb.getProjectionFields() != null) {
111+
this.formatOptions = DatastoreBackupOptions.newBuilder()
112+
.setProjectionFields(loadConfigurationPb.getProjectionFields())
113+
.build();
114+
}
112115
}
113116

114117

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

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class LoadJobConfigurationTest {
4646
.build();
4747
private static final List<String> SOURCE_URIS = ImmutableList.of("uri1", "uri2");
4848
private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA);
49-
private static final LoadJobConfiguration LOAD_CONFIGURATION =
49+
private static final LoadJobConfiguration LOAD_CONFIGURATION_CSV =
5050
LoadJobConfiguration.newBuilder(TABLE_ID, SOURCE_URIS)
5151
.setCreateDisposition(CREATE_DISPOSITION)
5252
.setWriteDisposition(WRITE_DISPOSITION)
@@ -55,16 +55,38 @@ public class LoadJobConfigurationTest {
5555
.setMaxBadRecords(MAX_BAD_RECORDS)
5656
.setSchema(TABLE_SCHEMA)
5757
.build();
58+
private static final DatastoreBackupOptions BACKUP_OPTIONS = DatastoreBackupOptions.newBuilder()
59+
.setProjectionFields(ImmutableList.of("field_1", "field_2"))
60+
.build();
61+
private static final LoadJobConfiguration LOAD_CONFIGURATION_BACKUP =
62+
LoadJobConfiguration.newBuilder(TABLE_ID, SOURCE_URIS)
63+
.setCreateDisposition(CREATE_DISPOSITION)
64+
.setWriteDisposition(WRITE_DISPOSITION)
65+
.setFormatOptions(BACKUP_OPTIONS)
66+
.setIgnoreUnknownValues(IGNORE_UNKNOWN_VALUES)
67+
.setMaxBadRecords(MAX_BAD_RECORDS)
68+
.setSchema(TABLE_SCHEMA)
69+
.build();
5870

5971
@Test
6072
public void testToBuilder() {
61-
compareLoadJobConfiguration(LOAD_CONFIGURATION, LOAD_CONFIGURATION.toBuilder().build());
62-
LoadJobConfiguration configuration = LOAD_CONFIGURATION.toBuilder()
73+
compareLoadJobConfiguration(
74+
LOAD_CONFIGURATION_CSV, LOAD_CONFIGURATION_CSV.toBuilder().build());
75+
LoadJobConfiguration configurationCSV = LOAD_CONFIGURATION_CSV.toBuilder()
76+
.setDestinationTable(TableId.of("dataset", "newTable"))
77+
.build();
78+
assertEquals("newTable", configurationCSV.getDestinationTable().getTable());
79+
configurationCSV = configurationCSV.toBuilder().setDestinationTable(TABLE_ID).build();
80+
compareLoadJobConfiguration(LOAD_CONFIGURATION_CSV, configurationCSV);
81+
82+
compareLoadJobConfiguration(
83+
LOAD_CONFIGURATION_BACKUP, LOAD_CONFIGURATION_BACKUP.toBuilder().build());
84+
LoadJobConfiguration configurationBackup = LOAD_CONFIGURATION_BACKUP.toBuilder()
6385
.setDestinationTable(TableId.of("dataset", "newTable"))
6486
.build();
65-
assertEquals("newTable", configuration.getDestinationTable().getTable());
66-
configuration = configuration.toBuilder().setDestinationTable(TABLE_ID).build();
67-
compareLoadJobConfiguration(LOAD_CONFIGURATION, configuration);
87+
assertEquals("newTable", configurationBackup.getDestinationTable().getTable());
88+
configurationBackup = configurationBackup.toBuilder().setDestinationTable(TABLE_ID).build();
89+
compareLoadJobConfiguration(LOAD_CONFIGURATION_BACKUP, configurationBackup);
6890
}
6991

7092
@Test
@@ -95,21 +117,21 @@ public void testToBuilderIncomplete() {
95117

96118
@Test
97119
public void testToPbAndFromPb() {
98-
compareLoadJobConfiguration(LOAD_CONFIGURATION,
99-
LoadJobConfiguration.fromPb(LOAD_CONFIGURATION.toPb()));
120+
compareLoadJobConfiguration(LOAD_CONFIGURATION_CSV,
121+
LoadJobConfiguration.fromPb(LOAD_CONFIGURATION_CSV.toPb()));
100122
LoadJobConfiguration configuration = LoadJobConfiguration.of(TABLE_ID, SOURCE_URIS);
101123
compareLoadJobConfiguration(configuration, LoadJobConfiguration.fromPb(configuration.toPb()));
102124
}
103125

104126
@Test
105127
public void testSetProjectId() {
106-
LoadConfiguration configuration = LOAD_CONFIGURATION.setProjectId("p");
128+
LoadConfiguration configuration = LOAD_CONFIGURATION_CSV.setProjectId("p");
107129
assertEquals("p", configuration.getDestinationTable().getProject());
108130
}
109131

110132
@Test
111133
public void testGetType() {
112-
assertEquals(JobConfiguration.Type.LOAD, LOAD_CONFIGURATION.getType());
134+
assertEquals(JobConfiguration.Type.LOAD, LOAD_CONFIGURATION_CSV.getType());
113135
}
114136

115137
private void compareLoadJobConfiguration(LoadJobConfiguration expected,

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

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.junit.Test;
2727

2828
import java.nio.charset.StandardCharsets;
29-
import java.util.List;
3029

3130
public class WriteChannelConfigurationTest {
3231

@@ -46,7 +45,7 @@ public class WriteChannelConfigurationTest {
4645
.setDescription("FieldDescription")
4746
.build();
4847
private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA);
49-
private static final WriteChannelConfiguration LOAD_CONFIGURATION =
48+
private static final WriteChannelConfiguration LOAD_CONFIGURATION_CSV =
5049
WriteChannelConfiguration.newBuilder(TABLE_ID)
5150
.setCreateDisposition(CREATE_DISPOSITION)
5251
.setWriteDisposition(WRITE_DISPOSITION)
@@ -56,15 +55,28 @@ public class WriteChannelConfigurationTest {
5655
.setSchema(TABLE_SCHEMA)
5756
.build();
5857

58+
private static final DatastoreBackupOptions BACKUP_OPTIONS = DatastoreBackupOptions.newBuilder()
59+
.setProjectionFields(ImmutableList.of("field_1", "field_2"))
60+
.build();
61+
private static final WriteChannelConfiguration LOAD_CONFIGURATION_BACKUP =
62+
WriteChannelConfiguration.newBuilder(TABLE_ID)
63+
.setCreateDisposition(CREATE_DISPOSITION)
64+
.setWriteDisposition(WRITE_DISPOSITION)
65+
.setFormatOptions(BACKUP_OPTIONS)
66+
.setIgnoreUnknownValues(IGNORE_UNKNOWN_VALUES)
67+
.setMaxBadRecords(MAX_BAD_RECORDS)
68+
.setSchema(TABLE_SCHEMA)
69+
.build();
70+
5971
@Test
6072
public void testToBuilder() {
61-
compareLoadConfiguration(LOAD_CONFIGURATION, LOAD_CONFIGURATION.toBuilder().build());
62-
WriteChannelConfiguration configuration = LOAD_CONFIGURATION.toBuilder()
73+
compareLoadConfiguration(LOAD_CONFIGURATION_CSV, LOAD_CONFIGURATION_CSV.toBuilder().build());
74+
WriteChannelConfiguration configuration = LOAD_CONFIGURATION_CSV.toBuilder()
6375
.setDestinationTable(TableId.of("dataset", "newTable"))
6476
.build();
6577
assertEquals("newTable", configuration.getDestinationTable().getTable());
6678
configuration = configuration.toBuilder().setDestinationTable(TABLE_ID).build();
67-
compareLoadConfiguration(LOAD_CONFIGURATION, configuration);
79+
compareLoadConfiguration(LOAD_CONFIGURATION_CSV, configuration);
6880
}
6981

7082
@Test
@@ -85,38 +97,43 @@ public void testToBuilderIncomplete() {
8597

8698
@Test
8799
public void testBuilder() {
88-
assertEquals(TABLE_ID, LOAD_CONFIGURATION.getDestinationTable());
89-
assertEquals(CREATE_DISPOSITION, LOAD_CONFIGURATION.getCreateDisposition());
90-
assertEquals(WRITE_DISPOSITION, LOAD_CONFIGURATION.getWriteDisposition());
91-
assertEquals(CSV_OPTIONS, LOAD_CONFIGURATION.getCsvOptions());
92-
assertEquals(FORMAT, LOAD_CONFIGURATION.getFormat());
93-
assertEquals(IGNORE_UNKNOWN_VALUES, LOAD_CONFIGURATION.ignoreUnknownValues());
94-
assertEquals(MAX_BAD_RECORDS, LOAD_CONFIGURATION.getMaxBadRecords());
95-
assertEquals(TABLE_SCHEMA, LOAD_CONFIGURATION.getSchema());
96-
WriteChannelConfiguration loadConfiguration =
100+
assertEquals(TABLE_ID, LOAD_CONFIGURATION_CSV.getDestinationTable());
101+
assertEquals(CREATE_DISPOSITION, LOAD_CONFIGURATION_CSV.getCreateDisposition());
102+
assertEquals(WRITE_DISPOSITION, LOAD_CONFIGURATION_CSV.getWriteDisposition());
103+
assertEquals(CSV_OPTIONS, LOAD_CONFIGURATION_CSV.getCsvOptions());
104+
assertEquals(FORMAT, LOAD_CONFIGURATION_CSV.getFormat());
105+
assertEquals(IGNORE_UNKNOWN_VALUES, LOAD_CONFIGURATION_CSV.ignoreUnknownValues());
106+
assertEquals(MAX_BAD_RECORDS, LOAD_CONFIGURATION_CSV.getMaxBadRecords());
107+
assertEquals(TABLE_SCHEMA, LOAD_CONFIGURATION_CSV.getSchema());
108+
assertEquals(BACKUP_OPTIONS, LOAD_CONFIGURATION_BACKUP.getDatastoreBackupOptions());
109+
110+
WriteChannelConfiguration.Builder builder =
97111
WriteChannelConfiguration.newBuilder(TABLE_ID, CSV_OPTIONS)
98112
.setCreateDisposition(CREATE_DISPOSITION)
99113
.setWriteDisposition(WRITE_DISPOSITION)
100114
.setIgnoreUnknownValues(IGNORE_UNKNOWN_VALUES)
101115
.setMaxBadRecords(MAX_BAD_RECORDS)
102-
.setSchema(TABLE_SCHEMA)
103-
.build();
104-
assertEquals(TABLE_ID, loadConfiguration.getDestinationTable());
105-
assertEquals(CREATE_DISPOSITION, loadConfiguration.getCreateDisposition());
106-
assertEquals(WRITE_DISPOSITION, loadConfiguration.getWriteDisposition());
107-
assertEquals(CSV_OPTIONS, loadConfiguration.getCsvOptions());
108-
assertEquals(FORMAT, loadConfiguration.getFormat());
109-
assertEquals(IGNORE_UNKNOWN_VALUES, loadConfiguration.ignoreUnknownValues());
110-
assertEquals(MAX_BAD_RECORDS, loadConfiguration.getMaxBadRecords());
111-
assertEquals(TABLE_SCHEMA, loadConfiguration.getSchema());
112-
}
116+
.setSchema(TABLE_SCHEMA);
117+
WriteChannelConfiguration loadConfigurationCSV = builder.build();
118+
assertEquals(TABLE_ID, loadConfigurationCSV.getDestinationTable());
119+
assertEquals(CREATE_DISPOSITION, loadConfigurationCSV.getCreateDisposition());
120+
assertEquals(WRITE_DISPOSITION, loadConfigurationCSV.getWriteDisposition());
121+
assertEquals(CSV_OPTIONS, loadConfigurationCSV.getCsvOptions());
122+
assertEquals(FORMAT, loadConfigurationCSV.getFormat());
123+
assertEquals(IGNORE_UNKNOWN_VALUES, loadConfigurationCSV.ignoreUnknownValues());
124+
assertEquals(MAX_BAD_RECORDS, loadConfigurationCSV.getMaxBadRecords());
125+
assertEquals(TABLE_SCHEMA, loadConfigurationCSV.getSchema());
113126

127+
builder.setFormatOptions(BACKUP_OPTIONS);
128+
WriteChannelConfiguration loadConfigurationBackup = builder.build();
129+
assertEquals(BACKUP_OPTIONS, loadConfigurationBackup.getDatastoreBackupOptions());
130+
}
114131

115132
@Test
116133
public void testToPbAndFromPb() {
117-
assertNull(LOAD_CONFIGURATION.toPb().getLoad().getSourceUris());
118-
compareLoadConfiguration(LOAD_CONFIGURATION,
119-
WriteChannelConfiguration.fromPb(LOAD_CONFIGURATION.toPb()));
134+
assertNull(LOAD_CONFIGURATION_CSV.toPb().getLoad().getSourceUris());
135+
compareLoadConfiguration(LOAD_CONFIGURATION_CSV,
136+
WriteChannelConfiguration.fromPb(LOAD_CONFIGURATION_CSV.toPb()));
120137
WriteChannelConfiguration configuration = WriteChannelConfiguration.of(TABLE_ID);
121138
compareLoadConfiguration(configuration, WriteChannelConfiguration.fromPb(configuration.toPb()));
122139
}

0 commit comments

Comments
 (0)