Skip to content

Commit bd58ee5

Browse files
committed
Make FormatOptions.csv return CsvOptions, remove getters from ExternalDataConfiguration
1 parent f84a3b1 commit bd58ee5

File tree

4 files changed

+16
-27
lines changed

4 files changed

+16
-27
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public Builder toBuilder() {
203203
@Override
204204
public String toString() {
205205
return MoreObjects.toStringHelper(this)
206+
.add("type", type())
206207
.add("allowJaggedRows", allowJaggedRows)
207208
.add("allowQuotedNewLines", allowQuotedNewLines)
208209
.add("encoding", encoding)
@@ -214,8 +215,8 @@ public String toString() {
214215

215216
@Override
216217
public int hashCode() {
217-
return Objects.hash(allowJaggedRows, allowQuotedNewLines, encoding, fieldDelimiter, quote,
218-
skipLeadingRows);
218+
return Objects.hash(type(), allowJaggedRows, allowQuotedNewLines, encoding, fieldDelimiter,
219+
quote, skipLeadingRows);
219220
}
220221

221222
@Override

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ public String compression() {
179179
* Returns whether BigQuery should allow extra values that are not represented in the table
180180
* schema. If true, the extra values are ignored. If false, records with extra columns are treated
181181
* as bad records, and if there are too many bad records, an invalid error is returned in the job
182-
* result. The default value is false. The value of {@link #format()} determines what BigQuery
183-
* treats as an extra value.
182+
* result. The default value is false. The value of {@link #formatOptions()} determines what
183+
* BigQuery treats as an extra value.
184184
*
185185
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/tables#externalDataConfiguration.ignoreUnknownValues">
186186
* Ignore Unknown Values</a>
@@ -204,16 +204,6 @@ public Schema schema() {
204204
return schema;
205205
}
206206

207-
/**
208-
* Returns the source format of the external data.
209-
*
210-
* <a href="https://cloud.google.com/bigquery/docs/reference/v2/tables#externalDataConfiguration.sourceFormat">
211-
* Source Format</a>
212-
*/
213-
public String format() {
214-
return formatOptions.type();
215-
}
216-
217207
/**
218208
* Returns the fully-qualified URIs that point to your data in Google Cloud Storage. Each URI can
219209
* contain one '*' wildcard character that must come after the bucket's name. Size limits
@@ -227,11 +217,12 @@ public List<String> sourceUris() {
227217
}
228218

229219
/**
230-
* Returns additional properties used to parse CSV data (used when {@link #format()} is set to
231-
* CSV). Returns {@code null} if not set.
220+
* Returns the source format, and possibly some parsing options, of the external data. Supported
221+
* formats are {@code CSV} and {@code NEWLINE_DELIMITED_JSON}.
232222
*/
233-
public CsvOptions csvOptions() {
234-
return formatOptions instanceof CsvOptions ? (CsvOptions) formatOptions : null;
223+
@SuppressWarnings("unchecked")
224+
public <F extends FormatOptions> F formatOptions() {
225+
return (F) formatOptions;
235226
}
236227

237228
/**
@@ -292,8 +283,8 @@ com.google.api.services.bigquery.model.ExternalDataConfiguration toPb() {
292283
if (sourceUris != null) {
293284
externalConfigurationPb.setSourceUris(sourceUris);
294285
}
295-
if (csvOptions() != null) {
296-
externalConfigurationPb.setCsvOptions(csvOptions().toPb());
286+
if (formatOptions instanceof CsvOptions) {
287+
externalConfigurationPb.setCsvOptions(((CsvOptions) formatOptions).toPb());
297288
}
298289
return externalConfigurationPb;
299290
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public boolean equals(Object obj) {
6363
/**
6464
* Default options for CSV format.
6565
*/
66-
public static FormatOptions csv() {
67-
return new FormatOptions(CSV);
66+
public static CsvOptions csv() {
67+
return CsvOptions.builder().build();
6868
}
6969

7070
/**

gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ExternalDataConfigurationTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class ExternalDataConfigurationTest {
4343
.description("FieldDescription3")
4444
.build();
4545
private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA1, FIELD_SCHEMA2, FIELD_SCHEMA3);
46-
private static final String SOURCE_FORMAT = "CSV";
4746
private static final Integer MAX_BAD_RECORDS = 42;
4847
private static final Boolean IGNORE_UNKNOWN_VALUES = true;
4948
private static final String COMPRESSION = "GZIP";
@@ -76,11 +75,10 @@ public void testToBuilderIncomplete() {
7675
@Test
7776
public void testBuilder() {
7877
assertEquals(COMPRESSION, CONFIGURATION.compression());
79-
assertEquals(CSV_OPTIONS, CONFIGURATION.csvOptions());
78+
assertEquals(CSV_OPTIONS, CONFIGURATION.formatOptions());
8079
assertEquals(IGNORE_UNKNOWN_VALUES, CONFIGURATION.ignoreUnknownValues());
8180
assertEquals(MAX_BAD_RECORDS, CONFIGURATION.maxBadRecords());
8281
assertEquals(TABLE_SCHEMA, CONFIGURATION.schema());
83-
assertEquals(SOURCE_FORMAT, CONFIGURATION.format());
8482
assertEquals(SOURCE_URIS, CONFIGURATION.sourceUris());
8583
}
8684

@@ -96,11 +94,10 @@ private void compareConfiguration(ExternalDataConfiguration expected,
9694
ExternalDataConfiguration value) {
9795
assertEquals(expected, value);
9896
assertEquals(expected.compression(), value.compression());
99-
assertEquals(expected.csvOptions(), value.csvOptions());
97+
assertEquals(expected.formatOptions(), value.formatOptions());
10098
assertEquals(expected.ignoreUnknownValues(), value.ignoreUnknownValues());
10199
assertEquals(expected.maxBadRecords(), value.maxBadRecords());
102100
assertEquals(expected.schema(), value.schema());
103-
assertEquals(expected.format(), value.format());
104101
assertEquals(expected.sourceUris(), value.sourceUris());
105102
}
106103
}

0 commit comments

Comments
 (0)