Skip to content

Commit 338ede1

Browse files
committed
Fix mode's nullability by internally storing a string
1 parent ae2a484 commit 338ede1

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExternalDataConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ com.google.api.services.bigquery.model.ExternalDataConfiguration toPb() {
283283
if (sourceUris != null) {
284284
externalConfigurationPb.setSourceUris(sourceUris);
285285
}
286-
if (formatOptions instanceof CsvOptions) {
286+
if (formatOptions != null && FormatOptions.CSV.equals(formatOptions.type())) {
287287
externalConfigurationPb.setCsvOptions(((CsvOptions) formatOptions).toPb());
288288
}
289289
return externalConfigurationPb;

gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Field.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,19 @@ public boolean equals(Object obj) {
182182
* than one value.
183183
*/
184184
public enum Mode {
185-
NULLABLE, REQUIRED, REPEATED, NOT_SET
185+
NULLABLE, REQUIRED, REPEATED
186186
}
187187

188188
private final String name;
189189
private final Type type;
190-
private final Mode mode;
190+
private final String mode;
191191
private final String description;
192192

193193
public static final class Builder {
194194

195195
private String name;
196196
private Type type;
197-
private Mode mode;
197+
private String mode;
198198
private String description;
199199

200200
private Builder() {}
@@ -231,7 +231,7 @@ public Builder type(Type type) {
231231
* Sets the mode of the field. When not specified {@link Mode#NULLABLE} is used.
232232
*/
233233
public Builder mode(Mode mode) {
234-
this.mode = firstNonNull(mode, Mode.NOT_SET);
234+
this.mode = mode != null ? mode.name() : Data.<String>nullOf(String.class);
235235
return this;
236236
}
237237

@@ -279,7 +279,7 @@ public Type type() {
279279
* Returns the field mode. By default {@link Mode#NULLABLE} is used.
280280
*/
281281
public Mode mode() {
282-
return mode == Mode.NOT_SET ? null : mode;
282+
return mode != null ? Mode.valueOf(mode) : null;
283283
}
284284

285285
/**
@@ -329,7 +329,7 @@ TableFieldSchema toPb() {
329329
fieldSchemaPb.setName(name);
330330
fieldSchemaPb.setType(type.value().name());
331331
if (mode != null) {
332-
fieldSchemaPb.setMode(mode == Mode.NOT_SET ? Data.<String>nullOf(String.class) : mode.name());
332+
fieldSchemaPb.setMode(mode);
333333
}
334334
if (description != null) {
335335
fieldSchemaPb.setDescription(description);

0 commit comments

Comments
 (0)