Skip to content

Commit

Permalink
Rename TableType to TableDefinition and other minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Feb 1, 2016
1 parent c010bc8 commit 3474f3b
Show file tree
Hide file tree
Showing 25 changed files with 307 additions and 292 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ Here is a code snippet showing a simple usage example from within Compute/App En
must [supply credentials](#authentication) and a project ID if running this snippet elsewhere.
```java
import com.google.gcloud.bigquery.BaseTableInfo;
import com.google.gcloud.bigquery.BigQuery;
import com.google.gcloud.bigquery.BigQueryOptions;
import com.google.gcloud.bigquery.Field;
Expand All @@ -137,12 +136,12 @@ import com.google.gcloud.bigquery.TableInfo;
BigQuery bigquery = BigQueryOptions.defaultInstance().service();
TableId tableId = TableId.of("dataset", "table");
BaseTableInfo info = bigquery.getTable(tableId);
TableInfo info = bigquery.getTable(tableId);
if (info == null) {
System.out.println("Creating table " + tableId);
Field integerField = Field.of("fieldName", Field.Type.integer());
Schema schema = Schema.of(integerField);
bigquery.create(TableInfo.of(tableId, DefaultTableType.of(schema)));
bigquery.create(TableInfo.of(tableId, DefaultTableDefinition.of(schema)));
} else {
System.out.println("Loading data into table " + tableId);
LoadJobConfiguration configuration = LoadJobConfiguration.of(tableId, "gs://bucket/path");
Expand Down
12 changes: 6 additions & 6 deletions gcloud-java-bigquery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ are created from a BigQuery SQL query. In this code snippet we show how to creat
with only one string field. Add the following imports at the top of your file:

```java
import com.google.gcloud.bigquery.DefaultTableType;
import com.google.gcloud.bigquery.DefaultTableDefinition;
import com.google.gcloud.bigquery.Field;
import com.google.gcloud.bigquery.Schema;
import com.google.gcloud.bigquery.TableId;
Expand All @@ -126,8 +126,8 @@ Field stringField = Field.of("StringField", Field.Type.string());
// Table schema definition
Schema schema = Schema.of(stringField);
// Create a table
DefaultTableType tableType = DefaultTableType.of(schema);
TableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, tableType));
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(schema);
TableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, tableDefinition));
```

#### Loading data into a table
Expand Down Expand Up @@ -208,7 +208,7 @@ display on your webpage.
import com.google.gcloud.bigquery.BigQuery;
import com.google.gcloud.bigquery.BigQueryOptions;
import com.google.gcloud.bigquery.DatasetInfo;
import com.google.gcloud.bigquery.DefaultTableType;
import com.google.gcloud.bigquery.DefaultTableDefinition;
import com.google.gcloud.bigquery.Field;
import com.google.gcloud.bigquery.FieldValue;
import com.google.gcloud.bigquery.InsertAllRequest;
Expand Down Expand Up @@ -241,8 +241,8 @@ public class GcloudBigQueryExample {
// Table schema definition
Schema schema = Schema.of(stringField);
// Create a table
DefaultTableType tableType = DefaultTableType.of(schema);
TableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, tableType));
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(schema);
TableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, tableDefinition));

// Define rows to insert
Map<String, Object> firstRow = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Base class for a Google BigQuery table type.
*/
public abstract class BaseTableType implements Serializable{
public abstract class BaseTableDefinition implements Serializable {

private static final long serialVersionUID = -374760330662959529L;

Expand All @@ -36,22 +36,22 @@ public abstract class BaseTableType implements Serializable{
*/
public enum Type {
/**
* A normal BigQuery table. Instances of {@code BaseTableType} for this type are implemented by
* {@link DefaultTableType}.
* A normal BigQuery table. Instances of {@code BaseTableDefinition} for this type are
* implemented by {@link DefaultTableDefinition}.
*/
TABLE,

/**
* A virtual table defined by a SQL query. Instances of {@code BaseTableType} for this type are
* implemented by {@link ViewType}.
* A virtual table defined by a SQL query. Instances of {@code BaseTableDefinition} for this
* type are implemented by {@link ViewDefinition}.
*
* @see <a href="https://cloud.google.com/bigquery/querying-data#views">Views</a>
*/
VIEW,

/**
* A BigQuery table backed by external data. Instances of {@code BaseTableType} for this type
* are implemented by {@link ExternalTableType}.
* A BigQuery table backed by external data. Instances of {@code BaseTableDefinition} for this
* type are implemented by {@link ExternalTableDefinition}.
*
* @see <a href="https://cloud.google.com/bigquery/federated-data-sources">Federated Data
* Sources</a>
Expand All @@ -68,7 +68,7 @@ public enum Type {
* @param <T> the table type class
* @param <B> the table type builder
*/
public abstract static class Builder<T extends BaseTableType, B extends Builder<T, B>> {
public abstract static class Builder<T extends BaseTableDefinition, B extends Builder<T, B>> {

private Type type;
private Schema schema;
Expand All @@ -77,9 +77,9 @@ public abstract static class Builder<T extends BaseTableType, B extends Builder<
this.type = type;
}

Builder(BaseTableType tableType) {
this.type = tableType.type;
this.schema = tableType.schema;
Builder(BaseTableDefinition tableDefinition) {
this.type = tableDefinition.type;
this.schema = tableDefinition.schema;
}

Builder(Table tablePb) {
Expand Down Expand Up @@ -113,7 +113,7 @@ public B schema(Schema schema) {
public abstract T build();
}

BaseTableType(Builder builder) {
BaseTableDefinition(Builder builder) {
this.type = builder.type;
this.schema = builder.schema;
}
Expand Down Expand Up @@ -152,7 +152,7 @@ final int baseHashCode() {
return Objects.hash(type);
}

final boolean baseEquals(BaseTableType jobConfiguration) {
final boolean baseEquals(BaseTableDefinition jobConfiguration) {
return Objects.equals(toPb(), jobConfiguration.toPb());
}

Expand All @@ -166,14 +166,14 @@ Table toPb() {
}

@SuppressWarnings("unchecked")
static <T extends BaseTableType> T fromPb(Table tablePb) {
static <T extends BaseTableDefinition> T fromPb(Table tablePb) {
switch (Type.valueOf(tablePb.getType())) {
case TABLE:
return (T) DefaultTableType.fromPb(tablePb);
return (T) DefaultTableDefinition.fromPb(tablePb);
case VIEW:
return (T) ViewType.fromPb(tablePb);
return (T) ViewDefinition.fromPb(tablePb);
case EXTERNAL:
return (T) ExternalTableType.fromPb(tablePb);
return (T) ExternalTableDefinition.fromPb(tablePb);
default:
// never reached
throw new IllegalArgumentException("Format " + tablePb.getType() + " is not supported");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private CsvOptions(Builder builder) {
* Returns 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 the number of bad
* records exceeds {@link ExternalTableType#maxBadRecords()}, an invalid error is returned
* records exceeds {@link ExternalTableDefinition#maxBadRecords()}, an invalid error is returned
* in the job result.
*/
public Boolean allowJaggedRows() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public Table get(String table, BigQuery.TableOption... options) {
* @return a {@code Table} object for the created table
* @throws BigQueryException upon failure
*/
public Table create(String table, BaseTableType type, BigQuery.TableOption... options) {
public Table create(String table, BaseTableDefinition type, BigQuery.TableOption... options) {
TableInfo tableInfo = TableInfo.of(TableId.of(info.datasetId().dataset(), table), type);
return new Table(bigquery, bigquery.create(tableInfo, options));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*
* @see <a href="https://cloud.google.com/bigquery/docs/tables">Managing Tables</a>
*/
public class DefaultTableType extends BaseTableType {
public class DefaultTableDefinition extends BaseTableDefinition {

private static final long serialVersionUID = 2113445776046717900L;

Expand Down Expand Up @@ -115,7 +115,8 @@ static StreamingBuffer fromPb(Streamingbuffer streamingBufferPb) {
}
}

public static final class Builder extends BaseTableType.Builder<DefaultTableType, Builder> {
public static final class Builder
extends BaseTableDefinition.Builder<DefaultTableDefinition, Builder> {

private Long numBytes;
private Long numRows;
Expand All @@ -126,12 +127,12 @@ private Builder() {
super(Type.TABLE);
}

private Builder(DefaultTableType tableType) {
super(tableType);
this.numBytes = tableType.numBytes;
this.numRows = tableType.numRows;
this.location = tableType.location;
this.streamingBuffer = tableType.streamingBuffer;
private Builder(DefaultTableDefinition tableDefinition) {
super(tableDefinition);
this.numBytes = tableDefinition.numBytes;
this.numRows = tableDefinition.numRows;
this.location = tableDefinition.location;
this.streamingBuffer = tableDefinition.streamingBuffer;
}

private Builder(Table tablePb) {
Expand Down Expand Up @@ -167,15 +168,15 @@ Builder streamingBuffer(StreamingBuffer streamingBuffer) {
}

/**
* Creates a {@code DefaultTableType} object.
* Creates a {@code DefaultTableDefinition} object.
*/
@Override
public DefaultTableType build() {
return new DefaultTableType(this);
public DefaultTableDefinition build() {
return new DefaultTableDefinition(this);
}
}

private DefaultTableType(Builder builder) {
private DefaultTableDefinition(Builder builder) {
super(builder);
this.numBytes = builder.numBytes;
this.numRows = builder.numRows;
Expand Down Expand Up @@ -228,12 +229,12 @@ public static Builder builder() {
*
* @param schema the schema of the table
*/
public static DefaultTableType of(Schema schema) {
public static DefaultTableDefinition of(Schema schema) {
return builder().schema(schema).build();
}

/**
* Returns a builder for the {@code DefaultTableType} object.
* Returns a builder for the {@code DefaultTableDefinition} object.
*/
@Override
public Builder toBuilder() {
Expand All @@ -251,7 +252,7 @@ ToStringHelper toStringHelper() {

@Override
public boolean equals(Object obj) {
return obj instanceof DefaultTableType && baseEquals((DefaultTableType) obj);
return obj instanceof DefaultTableDefinition && baseEquals((DefaultTableDefinition) obj);
}

@Override
Expand All @@ -274,7 +275,7 @@ Table toPb() {
}

@SuppressWarnings("unchecked")
static DefaultTableType fromPb(Table tablePb) {
static DefaultTableDefinition fromPb(Table tablePb) {
return new Builder(tablePb).build();
}
}
Loading

0 comments on commit 3474f3b

Please sign in to comment.