Skip to content

Commit

Permalink
Make FormatOptions.csv return CsvOptions, remove getters from Externa…
Browse files Browse the repository at this point in the history
…lDataConfiguration
  • Loading branch information
mziccard committed Dec 3, 2015
1 parent f84a3b1 commit bd58ee5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public Builder toBuilder() {
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("type", type())
.add("allowJaggedRows", allowJaggedRows)
.add("allowQuotedNewLines", allowQuotedNewLines)
.add("encoding", encoding)
Expand All @@ -214,8 +215,8 @@ public String toString() {

@Override
public int hashCode() {
return Objects.hash(allowJaggedRows, allowQuotedNewLines, encoding, fieldDelimiter, quote,
skipLeadingRows);
return Objects.hash(type(), allowJaggedRows, allowQuotedNewLines, encoding, fieldDelimiter,
quote, skipLeadingRows);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ public String compression() {
* Returns whether BigQuery should allow extra values that are not represented in the table
* schema. If true, the extra values are ignored. If false, records with extra columns are treated
* as bad records, and if there are too many bad records, an invalid error is returned in the job
* result. The default value is false. The value of {@link #format()} determines what BigQuery
* treats as an extra value.
* result. The default value is false. The value of {@link #formatOptions()} determines what
* BigQuery treats as an extra value.
*
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/tables#externalDataConfiguration.ignoreUnknownValues">
* Ignore Unknown Values</a>
Expand All @@ -204,16 +204,6 @@ public Schema schema() {
return schema;
}

/**
* Returns the source format of the external data.
*
* <a href="https://cloud.google.com/bigquery/docs/reference/v2/tables#externalDataConfiguration.sourceFormat">
* Source Format</a>
*/
public String format() {
return formatOptions.type();
}

/**
* Returns the fully-qualified URIs that point to your data in Google Cloud Storage. Each URI can
* contain one '*' wildcard character that must come after the bucket's name. Size limits
Expand All @@ -227,11 +217,12 @@ public List<String> sourceUris() {
}

/**
* Returns additional properties used to parse CSV data (used when {@link #format()} is set to
* CSV). Returns {@code null} if not set.
* Returns the source format, and possibly some parsing options, of the external data. Supported
* formats are {@code CSV} and {@code NEWLINE_DELIMITED_JSON}.
*/
public CsvOptions csvOptions() {
return formatOptions instanceof CsvOptions ? (CsvOptions) formatOptions : null;
@SuppressWarnings("unchecked")
public <F extends FormatOptions> F formatOptions() {
return (F) formatOptions;
}

/**
Expand Down Expand Up @@ -292,8 +283,8 @@ com.google.api.services.bigquery.model.ExternalDataConfiguration toPb() {
if (sourceUris != null) {
externalConfigurationPb.setSourceUris(sourceUris);
}
if (csvOptions() != null) {
externalConfigurationPb.setCsvOptions(csvOptions().toPb());
if (formatOptions instanceof CsvOptions) {
externalConfigurationPb.setCsvOptions(((CsvOptions) formatOptions).toPb());
}
return externalConfigurationPb;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public boolean equals(Object obj) {
/**
* Default options for CSV format.
*/
public static FormatOptions csv() {
return new FormatOptions(CSV);
public static CsvOptions csv() {
return CsvOptions.builder().build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class ExternalDataConfigurationTest {
.description("FieldDescription3")
.build();
private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA1, FIELD_SCHEMA2, FIELD_SCHEMA3);
private static final String SOURCE_FORMAT = "CSV";
private static final Integer MAX_BAD_RECORDS = 42;
private static final Boolean IGNORE_UNKNOWN_VALUES = true;
private static final String COMPRESSION = "GZIP";
Expand Down Expand Up @@ -76,11 +75,10 @@ public void testToBuilderIncomplete() {
@Test
public void testBuilder() {
assertEquals(COMPRESSION, CONFIGURATION.compression());
assertEquals(CSV_OPTIONS, CONFIGURATION.csvOptions());
assertEquals(CSV_OPTIONS, CONFIGURATION.formatOptions());
assertEquals(IGNORE_UNKNOWN_VALUES, CONFIGURATION.ignoreUnknownValues());
assertEquals(MAX_BAD_RECORDS, CONFIGURATION.maxBadRecords());
assertEquals(TABLE_SCHEMA, CONFIGURATION.schema());
assertEquals(SOURCE_FORMAT, CONFIGURATION.format());
assertEquals(SOURCE_URIS, CONFIGURATION.sourceUris());
}

Expand All @@ -96,11 +94,10 @@ private void compareConfiguration(ExternalDataConfiguration expected,
ExternalDataConfiguration value) {
assertEquals(expected, value);
assertEquals(expected.compression(), value.compression());
assertEquals(expected.csvOptions(), value.csvOptions());
assertEquals(expected.formatOptions(), value.formatOptions());
assertEquals(expected.ignoreUnknownValues(), value.ignoreUnknownValues());
assertEquals(expected.maxBadRecords(), value.maxBadRecords());
assertEquals(expected.schema(), value.schema());
assertEquals(expected.format(), value.format());
assertEquals(expected.sourceUris(), value.sourceUris());
}
}

0 comments on commit bd58ee5

Please sign in to comment.