Skip to content

Commit

Permalink
Merge pull request #482 from mziccard/bigquery
Browse files Browse the repository at this point in the history
Make checkstyle happy, remove StreamingBuffer from external tables
  • Loading branch information
ajkannan committed Dec 17, 2015
2 parents 814264a + f569bdd commit 433c286
Show file tree
Hide file tree
Showing 21 changed files with 184 additions and 171 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ public enum Role {
* Can read, query, copy or export tables in the dataset.
*/
READER,

/**
* Same as {@link #READER} plus can edit or append data in the dataset.
*/
WRITER,

/**
* Same as {@link #WRITER} plus can update and delete the dataset.
*/
Expand All @@ -61,7 +63,7 @@ public enum Role {
/**
* Base class for BigQuery entities that can be grant access to the dataset.
*/
public static abstract class Entity implements Serializable {
public abstract static class Entity implements Serializable {

private static final long serialVersionUID = 8111776788607959944L;

Expand Down Expand Up @@ -132,14 +134,14 @@ public String domain() {
}

@Override
public boolean equals(Object o) {
if (this == o) {
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
Domain domainEntity = (Domain) o;
Domain domainEntity = (Domain) obj;
return Objects.equals(type(), domainEntity.type())
&& Objects.equals(domain, domainEntity.domain());
}
Expand Down Expand Up @@ -196,14 +198,14 @@ public String identifier() {
}

@Override
public boolean equals(Object o) {
if (this == o) {
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
Group group = (Group) o;
Group group = (Group) obj;
return Objects.equals(type(), group.type()) && Objects.equals(identifier, group.identifier);
}

Expand Down Expand Up @@ -288,14 +290,14 @@ public String email() {
}

@Override
public boolean equals(Object o) {
if (this == o) {
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
User user = (User) o;
User user = (User) obj;
return Objects.equals(type(), user.type()) && Objects.equals(email, user.email);
}

Expand Down Expand Up @@ -341,14 +343,14 @@ public TableId id() {
}

@Override
public boolean equals(Object o) {
if (this == o) {
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
View view = (View) o;
View view = (View) obj;
return Objects.equals(type(), view.type()) && Objects.equals(id, view.id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.client.util.Data;
import com.google.api.services.bigquery.model.Streamingbuffer;
import com.google.api.services.bigquery.model.Table;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;

import java.io.Serializable;
import java.math.BigInteger;
Expand Down Expand Up @@ -63,12 +63,14 @@ public enum Type {
* A normal BigQuery table.
*/
TABLE,

/**
* A virtual table defined by a SQL query.
*
* @see <a href="https://cloud.google.com/bigquery/querying-data#views">Views</a>
*/
VIEW,

/**
* A BigQuery table backed by external data.
*
Expand All @@ -78,79 +80,6 @@ public enum Type {
EXTERNAL
}

/**
* Google BigQuery Table's Streaming Buffer information. This class contains information on a
* table's streaming buffer as the estimated size in number of rows/bytes.
*/
public static class StreamingBuffer implements Serializable {

private static final long serialVersionUID = -6713971364725267597L;
private final long estimatedRows;
private final long estimatedBytes;
private final long oldestEntryTime;

StreamingBuffer(long estimatedRows, long estimatedBytes, long oldestEntryTime) {
this.estimatedRows = estimatedRows;
this.estimatedBytes = estimatedBytes;
this.oldestEntryTime = oldestEntryTime;
}

/**
* Returns a lower-bound estimate of the number of rows currently in the streaming buffer.
*/
public long estimatedRows() {
return estimatedRows;
}

/**
* Returns a lower-bound estimate of the number of bytes currently in the streaming buffer.
*/
public long estimatedBytes() {
return estimatedBytes;
}

/**
* Returns the timestamp of the oldest entry in the streaming buffer, in milliseconds since
* epoch.
*/
public long oldestEntryTime() {
return oldestEntryTime;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("estimatedRows", estimatedRows)
.add("estimatedBytes", estimatedBytes)
.add("oldestEntryTime", oldestEntryTime)
.toString();
}

@Override
public int hashCode() {
return Objects.hash(estimatedRows, estimatedBytes, oldestEntryTime);
}

@Override
public boolean equals(Object obj) {
return obj instanceof StreamingBuffer
&& Objects.equals(toPb(), ((StreamingBuffer) obj).toPb());
}

public Streamingbuffer toPb() {
return new Streamingbuffer()
.setEstimatedBytes(BigInteger.valueOf(estimatedBytes))
.setEstimatedRows(BigInteger.valueOf(estimatedRows))
.setOldestEntryTime(BigInteger.valueOf(oldestEntryTime));
}

static StreamingBuffer fromPb(Streamingbuffer streamingBufferPb) {
return new StreamingBuffer(streamingBufferPb.getEstimatedRows().longValue(),
streamingBufferPb.getEstimatedBytes().longValue(),
streamingBufferPb.getOldestEntryTime().longValue());
}
}

private final String etag;
private final String id;
private final String selfLink;
Expand All @@ -165,7 +94,7 @@ static StreamingBuffer fromPb(Streamingbuffer streamingBufferPb) {
private final Long expirationTime;
private final Long lastModifiedTime;

public static abstract class Builder<T extends BaseTableInfo, B extends Builder<T, B>> {
public abstract static class Builder<T extends BaseTableInfo, B extends Builder<T, B>> {

private String etag;
private String id;
Expand Down Expand Up @@ -429,7 +358,7 @@ public Long lastModifiedTime() {
*/
public abstract Builder toBuilder();

protected MoreObjects.ToStringHelper toStringHelper() {
ToStringHelper toStringHelper() {
return MoreObjects.toStringHelper(this)
.add("tableId", tableId)
.add("type", type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ public Integer skipLeadingRows() {
return skipLeadingRows;
}

/**
* Returns a builder for the {@code CsvOptions} object.
*/
public Builder toBuilder() {
return new Builder()
.allowJaggedRows(allowJaggedRows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class DatasetId implements Serializable {
private final String dataset;

/**
* Returns project's user-defined id
* Returns project's user-defined id.
*/
public String project() {
return project;
Expand Down Expand Up @@ -81,11 +81,11 @@ public String toString() {
return toPb().toString();
}

public DatasetReference toPb() {
DatasetReference toPb() {
return new DatasetReference().setProjectId(project).setDatasetId(dataset);
}

public static DatasetId fromPb(DatasetReference datasetRef) {
static DatasetId fromPb(DatasetReference datasetRef) {
return new DatasetId(
datasetRef.getProjectId(),
datasetRef.getDatasetId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ static DatasetInfo fromPb(Dataset datasetPb) {
builder.acl(Lists.transform(datasetPb.getAccess(),
new Function<Dataset.Access, Acl>() {
@Override
public Acl apply(Dataset.Access f) {
return Acl.fromPb(f);
public Acl apply(Dataset.Access accessPb) {
return Acl.fromPb(accessPb);
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,31 @@
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.services.bigquery.model.Table;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;

/**
* Google BigQuery External Table information. BigQuery's external tables are tables whose data
* reside outside of BigQuery but can be queried as normal BigQuery tables. External tables are
* experimental and might be subject to change or removed.
*
* @see <a href="https://cloud.google.com/bigquery/federated-data-sources">Federated Data
* Sources</a>
* @see <a href="https://cloud.google.com/bigquery/federated-data-sources">Federated Data Sources
* </a>
*/
public class ExternalTableInfo extends BaseTableInfo {

private static final long serialVersionUID = -5893406738246214865L;

private final ExternalDataConfiguration configuration;
private final StreamingBuffer streamingBuffer;

public static final class Builder extends BaseTableInfo.Builder<ExternalTableInfo, Builder> {

private ExternalDataConfiguration configuration;
private StreamingBuffer streamingBuffer;

private Builder() {}

private Builder(ExternalTableInfo tableInfo) {
super(tableInfo);
this.configuration = tableInfo.configuration;
this.streamingBuffer = tableInfo.streamingBuffer;
}

protected Builder(Table tablePb) {
Expand All @@ -55,9 +52,6 @@ protected Builder(Table tablePb) {
this.configuration =
ExternalDataConfiguration.fromPb(tablePb.getExternalDataConfiguration());
}
if (tablePb.getStreamingBuffer() != null) {
this.streamingBuffer = StreamingBuffer.fromPb(tablePb.getStreamingBuffer());
}
}

/**
Expand All @@ -71,11 +65,6 @@ public Builder configuration(ExternalDataConfiguration configuration) {
return self();
}

Builder streamingBuffer(StreamingBuffer streamingBuffer) {
this.streamingBuffer = streamingBuffer;
return self();
}

/**
* Creates a {@code ExternalTableInfo} object.
*/
Expand All @@ -88,26 +77,17 @@ public ExternalTableInfo build() {
private ExternalTableInfo(Builder builder) {
super(builder);
this.configuration = builder.configuration;
this.streamingBuffer = builder.streamingBuffer;
}

/**
* Returns the data format, location and other properties of a table stored outside of BigQuery.
* This property is experimental and might be subject to change or removed.
*
* @see <a href="https://cloud.google.com/bigquery/federated-data-sources">Federated Data
* Sources</a>
* @see <a href="https://cloud.google.com/bigquery/federated-data-sources">Federated Data Sources
* </a>
*/
public ExternalDataConfiguration configuration() {
return configuration;
};

/**
* Returns information on the table's streaming buffer if any exists. Returns {@code null} if no
* streaming buffer exists.
*/
public StreamingBuffer streamingBuffer() {
return streamingBuffer;
}

/**
Expand All @@ -119,19 +99,14 @@ public Builder toBuilder() {
}

@Override
protected MoreObjects.ToStringHelper toStringHelper() {
return super.toStringHelper()
.add("configuration", configuration)
.add("streamingBuffer", streamingBuffer);
ToStringHelper toStringHelper() {
return super.toStringHelper().add("configuration", configuration);
}

@Override
Table toPb() {
Table tablePb = super.toPb();
tablePb.setExternalDataConfiguration(configuration.toPb());
if (streamingBuffer != null) {
tablePb.setStreamingBuffer(streamingBuffer.toPb());
}
return tablePb;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
import java.util.Objects;

/**
* Google BigQuery Table field. A table field has a name, a value, a mode and possibly a description.
* Supported types are: {@link Type#integer()}, {@link Type#bool()}, {@link Type#string()},
* {@link Type#floatingPoint()}, {@link Type#timestamp()} and {@link Type#record(Field...)}. One or
* more fields form a table's schema.
* Google BigQuery Table field. A table field has a name, a value, a mode and possibly a
* description. Supported types are: {@link Type#integer()}, {@link Type#bool()},
* {@link Type#string()}, {@link Type#floatingPoint()}, {@link Type#timestamp()} and
* {@link Type#record(Field...)}. One or more fields form a table's schema.
*/
public class Field implements Serializable {

Expand Down
Loading

0 comments on commit 433c286

Please sign in to comment.