Skip to content

Commit

Permalink
Update BigQuery dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Jun 10, 2016
1 parent 3b35a9e commit 27836e4
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 30 deletions.
2 changes: 1 addition & 1 deletion gcloud-java-bigquery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-bigquery</artifactId>
<version>v2-rev270-1.21.0</version>
<version>v2-rev303-1.22.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class CsvOptions extends FormatOptions {
private final String encoding;
private final String fieldDelimiter;
private final String quote;
private final Integer skipLeadingRows;
private final Long skipLeadingRows;

public static final class Builder {

Expand All @@ -43,18 +43,27 @@ public static final class Builder {
private String encoding;
private String fieldDelimiter;
private String quote;
private Integer skipLeadingRows;
private Long skipLeadingRows;

private Builder() {}

private Builder(CsvOptions csvOptions) {
this.allowJaggedRows = csvOptions.allowJaggedRows;
this.allowQuotedNewLines = csvOptions.allowQuotedNewLines;
this.encoding = csvOptions.encoding;
this.fieldDelimiter = csvOptions.fieldDelimiter;
this.quote = csvOptions.quote;
this.skipLeadingRows = csvOptions.skipLeadingRows;
}

/**
* Set whether BigQuery should accept rows that are missing trailing optional columns. If
* {@code true}, BigQuery treats missing trailing columns as null values. If {@code false},
* records with missing trailing columns are treated as bad records, and if there are too many
* bad records, an invalid error is returned in the job result. By default, rows with missing
* trailing columns are considered bad records.
*/
public Builder allowJaggedRows(Boolean allowJaggedRows) {
public Builder allowJaggedRows(boolean allowJaggedRows) {
this.allowJaggedRows = allowJaggedRows;
return this;
}
Expand All @@ -63,7 +72,7 @@ public Builder allowJaggedRows(Boolean allowJaggedRows) {
* Sets whether BigQuery should allow quoted data sections that contain newline characters in a
* CSV file. By default quoted newline are not allowed.
*/
public Builder allowQuotedNewLines(Boolean allowQuotedNewLines) {
public Builder allowQuotedNewLines(boolean allowQuotedNewLines) {
this.allowQuotedNewLines = allowQuotedNewLines;
return this;
}
Expand Down Expand Up @@ -104,7 +113,7 @@ public Builder fieldDelimiter(String fieldDelimiter) {
* string to ISO-8859-1 encoding, and then uses the first byte of the encoded string to split
* the data in its raw, binary state. The default value is a double-quote ('"'). If your data
* does not contain quoted sections, set the property value to an empty string. If your data
* contains quoted newline characters, you must also set {@link #allowQuotedNewLines(Boolean)}
* contains quoted newline characters, you must also set {@link #allowQuotedNewLines(boolean)}
* property to {@code true}.
*/
public Builder quote(String quote) {
Expand All @@ -117,7 +126,7 @@ public Builder quote(String quote) {
* data. The default value is 0. This property is useful if you have header rows in the file
* that should be skipped.
*/
public Builder skipLeadingRows(Integer skipLeadingRows) {
public Builder skipLeadingRows(long skipLeadingRows) {
this.skipLeadingRows = skipLeadingRows;
return this;
}
Expand Down Expand Up @@ -186,21 +195,15 @@ public String quote() {
* Returns the number of rows at the top of a CSV file that BigQuery will skip when reading the
* data.
*/
public Integer skipLeadingRows() {
public Long skipLeadingRows() {
return skipLeadingRows;
}

/**
* Returns a builder for the {@code CsvOptions} object.
*/
public Builder toBuilder() {
return new Builder()
.allowJaggedRows(allowJaggedRows)
.allowQuotedNewLines(allowQuotedNewLines)
.encoding(encoding)
.fieldDelimiter(fieldDelimiter)
.quote(quote)
.skipLeadingRows(skipLeadingRows);
return new Builder(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.api.services.bigquery.model.JobConfigurationLoad;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Ints;

import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -97,12 +98,18 @@ private Builder(com.google.api.services.bigquery.model.JobConfiguration configur
|| loadConfigurationPb.getQuote() != null
|| loadConfigurationPb.getSkipLeadingRows() != null) {
CsvOptions.Builder builder = CsvOptions.builder()
.allowJaggedRows(loadConfigurationPb.getAllowJaggedRows())
.allowQuotedNewLines(loadConfigurationPb.getAllowQuotedNewlines())
.encoding(loadConfigurationPb.getEncoding())
.fieldDelimiter(loadConfigurationPb.getFieldDelimiter())
.quote(loadConfigurationPb.getQuote())
.skipLeadingRows(loadConfigurationPb.getSkipLeadingRows());
.quote(loadConfigurationPb.getQuote());
if (loadConfigurationPb.getAllowJaggedRows() != null) {
builder.allowJaggedRows(loadConfigurationPb.getAllowJaggedRows());
}
if (loadConfigurationPb.getAllowQuotedNewlines() != null) {
builder.allowQuotedNewLines(loadConfigurationPb.getAllowQuotedNewlines());
}
if (loadConfigurationPb.getSkipLeadingRows() != null) {
builder.skipLeadingRows(loadConfigurationPb.getSkipLeadingRows());
}
this.formatOptions = builder.build();
}
this.maxBadRecords = loadConfigurationPb.getMaxBadRecords();
Expand Down Expand Up @@ -300,8 +307,11 @@ com.google.api.services.bigquery.model.JobConfiguration toPb() {
.setAllowJaggedRows(csvOptions.allowJaggedRows())
.setAllowQuotedNewlines(csvOptions.allowQuotedNewLines())
.setEncoding(csvOptions.encoding())
.setQuote(csvOptions.quote())
.setSkipLeadingRows(csvOptions.skipLeadingRows());
.setQuote(csvOptions.quote());
if (csvOptions.skipLeadingRows() != null) {
// todo(mziccard) remove checked cast or comment when #1044 is closed
loadConfigurationPb.setSkipLeadingRows(Ints.checkedCast(csvOptions.skipLeadingRows()));
}
}
if (schema != null) {
loadConfigurationPb.setSchema(schema.toPb());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.cloud.bigquery.JobInfo.WriteDisposition;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Ints;

import java.io.Serializable;
import java.util.List;
Expand Down Expand Up @@ -90,12 +91,18 @@ private Builder(com.google.api.services.bigquery.model.JobConfiguration configur
|| loadConfigurationPb.getQuote() != null
|| loadConfigurationPb.getSkipLeadingRows() != null) {
CsvOptions.Builder builder = CsvOptions.builder()
.allowJaggedRows(loadConfigurationPb.getAllowJaggedRows())
.allowQuotedNewLines(loadConfigurationPb.getAllowQuotedNewlines())
.encoding(loadConfigurationPb.getEncoding())
.fieldDelimiter(loadConfigurationPb.getFieldDelimiter())
.quote(loadConfigurationPb.getQuote())
.skipLeadingRows(loadConfigurationPb.getSkipLeadingRows());
.quote(loadConfigurationPb.getQuote());
if (loadConfigurationPb.getAllowJaggedRows() != null) {
builder.allowJaggedRows(loadConfigurationPb.getAllowJaggedRows());
}
if (loadConfigurationPb.getAllowQuotedNewlines() != null) {
builder.allowQuotedNewLines(loadConfigurationPb.getAllowQuotedNewlines());
}
if (loadConfigurationPb.getSkipLeadingRows() != null) {
builder.skipLeadingRows(loadConfigurationPb.getSkipLeadingRows());
}
this.formatOptions = builder.build();
}
this.maxBadRecords = loadConfigurationPb.getMaxBadRecords();
Expand Down Expand Up @@ -271,8 +278,11 @@ com.google.api.services.bigquery.model.JobConfiguration toPb() {
.setAllowJaggedRows(csvOptions.allowJaggedRows())
.setAllowQuotedNewlines(csvOptions.allowQuotedNewLines())
.setEncoding(csvOptions.encoding())
.setQuote(csvOptions.quote())
.setSkipLeadingRows(csvOptions.skipLeadingRows());
.setQuote(csvOptions.quote());
if (csvOptions.skipLeadingRows() != null) {
// todo(mziccard) remove checked cast or comment when #1044 is closed
loadConfigurationPb.setSkipLeadingRows(Ints.checkedCast(csvOptions.skipLeadingRows()));
}
}
if (schema != null) {
loadConfigurationPb.setSchema(schema.toPb());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CsvOptionsTest {
private static final Charset ENCODING = StandardCharsets.UTF_8;
private static final String FIELD_DELIMITER = ",";
private static final String QUOTE = "\"";
private static final Integer SKIP_LEADING_ROWS = 42;
private static final long SKIP_LEADING_ROWS = 42L;
private static final CsvOptions CSV_OPTIONS = CsvOptions.builder()
.allowJaggedRows(ALLOW_JAGGED_ROWS)
.allowQuotedNewLines(ALLOW_QUOTED_NEWLINE)
Expand Down Expand Up @@ -65,7 +65,7 @@ public void testBuilder() {
assertEquals(ENCODING.name(), CSV_OPTIONS.encoding());
assertEquals(FIELD_DELIMITER, CSV_OPTIONS.fieldDelimiter());
assertEquals(QUOTE, CSV_OPTIONS.quote());
assertEquals(SKIP_LEADING_ROWS, CSV_OPTIONS.skipLeadingRows());
assertEquals(SKIP_LEADING_ROWS, (long) CSV_OPTIONS.skipLeadingRows());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class SerializationTest extends BaseSerializationTest {
.encoding(StandardCharsets.ISO_8859_1)
.fieldDelimiter(",")
.quote("\"")
.skipLeadingRows(42)
.skipLeadingRows(42L)
.build();
private static final Field FIELD_SCHEMA1 =
Field.builder("StringField", Field.Type.string())
Expand Down

0 comments on commit 27836e4

Please sign in to comment.