Skip to content

Commit

Permalink
Fix mode's nullability by internally storing a string
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Dec 4, 2015
1 parent ae2a484 commit 338ede1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ com.google.api.services.bigquery.model.ExternalDataConfiguration toPb() {
if (sourceUris != null) {
externalConfigurationPb.setSourceUris(sourceUris);
}
if (formatOptions instanceof CsvOptions) {
if (formatOptions != null && FormatOptions.CSV.equals(formatOptions.type())) {
externalConfigurationPb.setCsvOptions(((CsvOptions) formatOptions).toPb());
}
return externalConfigurationPb;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,19 @@ public boolean equals(Object obj) {
* than one value.
*/
public enum Mode {
NULLABLE, REQUIRED, REPEATED, NOT_SET
NULLABLE, REQUIRED, REPEATED
}

private final String name;
private final Type type;
private final Mode mode;
private final String mode;
private final String description;

public static final class Builder {

private String name;
private Type type;
private Mode mode;
private String mode;
private String description;

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

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

/**
Expand Down Expand Up @@ -329,7 +329,7 @@ TableFieldSchema toPb() {
fieldSchemaPb.setName(name);
fieldSchemaPb.setType(type.value().name());
if (mode != null) {
fieldSchemaPb.setMode(mode == Mode.NOT_SET ? Data.<String>nullOf(String.class) : mode.name());
fieldSchemaPb.setMode(mode);
}
if (description != null) {
fieldSchemaPb.setDescription(description);
Expand Down

0 comments on commit 338ede1

Please sign in to comment.