Skip to content

Commit

Permalink
Rename DefaultTableInfo to TableInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Feb 1, 2016
1 parent 36d9dc3 commit 4ee4554
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 101 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ must [supply credentials](#authentication) and a project ID if running this snip
```java
import com.google.gcloud.bigquery.BigQuery;
import com.google.gcloud.bigquery.BigQueryOptions;
import com.google.gcloud.bigquery.TableDefinition;
import com.google.gcloud.bigquery.Field;
import com.google.gcloud.bigquery.JobStatus;
import com.google.gcloud.bigquery.JobInfo;
import com.google.gcloud.bigquery.LoadJobConfiguration;
import com.google.gcloud.bigquery.Schema;
import com.google.gcloud.bigquery.TableId;
import com.google.gcloud.bigquery.TableInfo;
Expand All @@ -141,7 +143,7 @@ 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, DefaultTableDefinition.of(schema)));
bigquery.create(TableInfo.of(tableId, TableDefinition.of(schema)));
} else {
System.out.println("Loading data into table " + tableId);
LoadJobConfiguration configuration = LoadJobConfiguration.of(tableId, "gs://bucket/path");
Expand Down
8 changes: 4 additions & 4 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.DefaultTableDefinition;
import com.google.gcloud.bigquery.TableDefinition;
import com.google.gcloud.bigquery.Field;
import com.google.gcloud.bigquery.Schema;
import com.google.gcloud.bigquery.TableId;
Expand All @@ -126,7 +126,7 @@ Field stringField = Field.of("StringField", Field.Type.string());
// Table schema definition
Schema schema = Schema.of(stringField);
// Create a table
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(schema);
TableDefinition tableDefinition = TableDefinition.of(schema);
TableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, tableDefinition));
```

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.DefaultTableDefinition;
import com.google.gcloud.bigquery.TableDefinition;
import com.google.gcloud.bigquery.Field;
import com.google.gcloud.bigquery.FieldValue;
import com.google.gcloud.bigquery.InsertAllRequest;
Expand Down Expand Up @@ -241,7 +241,7 @@ public class GcloudBigQueryExample {
// Table schema definition
Schema schema = Schema.of(stringField);
// Create a table
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(schema);
TableDefinition tableDefinition = TableDefinition.of(schema);
TableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, tableDefinition));

// Define rows to insert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public abstract class BaseTableDefinition implements Serializable {
public enum Type {
/**
* A normal BigQuery table. Instances of {@code BaseTableDefinition} for this type are
* implemented by {@link DefaultTableDefinition}.
* implemented by {@link TableDefinition}.
*/
TABLE,

Expand Down Expand Up @@ -169,7 +169,7 @@ Table toPb() {
static <T extends BaseTableDefinition> T fromPb(Table tablePb) {
switch (Type.valueOf(tablePb.getType())) {
case TABLE:
return (T) DefaultTableDefinition.fromPb(tablePb);
return (T) TableDefinition.fromPb(tablePb);
case VIEW:
return (T) ViewDefinition.fromPb(tablePb);
case EXTERNAL:
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 DefaultTableDefinition extends BaseTableDefinition {
public class TableDefinition extends BaseTableDefinition {

private static final long serialVersionUID = 2113445776046717900L;

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

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

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

private Builder(DefaultTableDefinition tableDefinition) {
private Builder(TableDefinition tableDefinition) {
super(tableDefinition);
this.numBytes = tableDefinition.numBytes;
this.numRows = tableDefinition.numRows;
Expand Down Expand Up @@ -168,15 +168,15 @@ Builder streamingBuffer(StreamingBuffer streamingBuffer) {
}

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

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

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

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

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

@SuppressWarnings("unchecked")
static DefaultTableDefinition fromPb(Table tablePb) {
static TableDefinition fromPb(Table tablePb) {
return new Builder(tablePb).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import java.util.Objects;

/**
* Google BigQuery table information. Use {@link DefaultTableDefinition} to create simple BigQuery
* table. Use {@link ViewDefinition} to create a BigQuery view. Use {@link ExternalTableDefinition}
* to create a BigQuery a table backed by external data.
* Google BigQuery table information. Use {@link TableDefinition} to create simple BigQuery table.
* Use {@link ViewDefinition} to create a BigQuery view. Use {@link ExternalTableDefinition} to
* create a BigQuery a table backed by external data.
*
* @see <a href="https://cloud.google.com/bigquery/docs/tables">Managing Tables</a>
*/
Expand Down Expand Up @@ -171,7 +171,9 @@ public Builder tableId(TableId tableId) {
}

/**
* Sets the table definition.
* Sets the table definition. Use {@link TableDefinition} to create simple BigQuery table. Use
* {@link ViewDefinition} to create a BigQuery view. Use {@link ExternalTableDefinition} to
* create a BigQuery a table backed by external data.
*/
public Builder definition(BaseTableDefinition definition) {
this.definition = checkNotNull(definition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* System.out.println("Creating table " + tableId);
* Field integerField = Field.of("fieldName", Field.Type.integer());
* Schema schema = Schema.of(integerField);
* bigquery.create(TableInfo.of(tableId, DefaultTableDefinition.of(schema)));
* bigquery.create(TableInfo.of(tableId, TableDefinition.of(schema)));
* } else {
* System.out.println("Loading data into table " + tableId);
* LoadJobConfiguration configuration = LoadJobConfiguration.of(tableId, "gs://bucket/path");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ public class BigQueryImplTest {
.description("FieldDescription3")
.build();
private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA1, FIELD_SCHEMA2, FIELD_SCHEMA3);
private static final DefaultTableDefinition TABLE_TYPE = DefaultTableDefinition.of(TABLE_SCHEMA);
private static final TableInfo TABLE_INFO = TableInfo.of(TABLE_ID, TABLE_TYPE);
private static final TableInfo OTHER_TABLE_INFO = TableInfo.of(OTHER_TABLE_ID, TABLE_TYPE);
private static final TableDefinition TABLE_DEFINITION = TableDefinition.of(TABLE_SCHEMA);
private static final TableInfo TABLE_INFO = TableInfo.of(TABLE_ID, TABLE_DEFINITION);
private static final TableInfo OTHER_TABLE_INFO = TableInfo.of(OTHER_TABLE_ID, TABLE_DEFINITION);
private static final TableInfo TABLE_INFO_WITH_PROJECT =
TableInfo.of(TABLE_ID_WITH_PROJECT, TABLE_TYPE);
TableInfo.of(TABLE_ID_WITH_PROJECT, TABLE_DEFINITION);
private static final LoadJobConfiguration LOAD_JOB_CONFIGURATION =
LoadJobConfiguration.of(TABLE_ID, "URI");
private static final LoadJobConfiguration LOAD_JOB_CONFIGURATION_WITH_PROJECT =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public class DatasetTest {
private static final DatasetId DATASET_ID = DatasetId.of("dataset");
private static final DatasetInfo DATASET_INFO = DatasetInfo.builder(DATASET_ID).build();
private static final Field FIELD = Field.of("FieldName", Field.Type.integer());
private static final DefaultTableDefinition TABLE_DEFINITION =
DefaultTableDefinition.of(Schema.of(FIELD));
private static final TableDefinition TABLE_DEFINITION =
TableDefinition.of(Schema.of(FIELD));
private static final ViewDefinition VIEW_DEFINITION = ViewDefinition.of("QUERY");
private static final ExternalTableDefinition EXTERNAL_TABLE_DEFINITION =
ExternalTableDefinition.of(ImmutableList.of("URI"), Schema.of(), FormatOptions.csv());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,44 +257,44 @@ public void testGetNonExistingTable() {
public void testCreateAndGetTable() {
String tableName = "test_create_and_get_table";
TableId tableId = TableId.of(DATASET, tableName);
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA);
TableDefinition tableDefinition = TableDefinition.of(TABLE_SCHEMA);
TableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, tableDefinition));
assertNotNull(createdTableInfo);
assertEquals(DATASET, createdTableInfo.tableId().dataset());
assertEquals(tableName, createdTableInfo.tableId().table());
TableInfo remoteTableInfo = bigquery.getTable(DATASET, tableName);
assertNotNull(remoteTableInfo);
assertTrue(remoteTableInfo.definition() instanceof DefaultTableDefinition);
assertTrue(remoteTableInfo.definition() instanceof TableDefinition);
assertEquals(createdTableInfo.tableId(), remoteTableInfo.tableId());
assertEquals(BaseTableDefinition.Type.TABLE, remoteTableInfo.definition().type());
assertEquals(TABLE_SCHEMA, remoteTableInfo.definition().schema());
assertNotNull(remoteTableInfo.creationTime());
assertNotNull(remoteTableInfo.lastModifiedTime());
assertNotNull(remoteTableInfo.<DefaultTableDefinition>definition().numBytes());
assertNotNull(remoteTableInfo.<DefaultTableDefinition>definition().numRows());
assertNotNull(remoteTableInfo.<TableDefinition>definition().numBytes());
assertNotNull(remoteTableInfo.<TableDefinition>definition().numRows());
assertTrue(bigquery.delete(DATASET, tableName));
}

@Test
public void testCreateAndGetTableWithSelectedField() {
String tableName = "test_create_and_get_selected_fields_table";
TableId tableId = TableId.of(DATASET, tableName);
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA);
TableDefinition tableDefinition = TableDefinition.of(TABLE_SCHEMA);
TableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, tableDefinition));
assertNotNull(createdTableInfo);
assertEquals(DATASET, createdTableInfo.tableId().dataset());
assertEquals(tableName, createdTableInfo.tableId().table());
TableInfo remoteTableInfo = bigquery.getTable(DATASET, tableName,
TableOption.fields(TableField.CREATION_TIME));
assertNotNull(remoteTableInfo);
assertTrue(remoteTableInfo.definition() instanceof DefaultTableDefinition);
assertTrue(remoteTableInfo.definition() instanceof TableDefinition);
assertEquals(createdTableInfo.tableId(), remoteTableInfo.tableId());
assertEquals(BaseTableDefinition.Type.TABLE, remoteTableInfo.definition().type());
assertNotNull(remoteTableInfo.creationTime());
assertNull(remoteTableInfo.definition().schema());
assertNull(remoteTableInfo.lastModifiedTime());
assertNull(remoteTableInfo.<DefaultTableDefinition>definition().numBytes());
assertNull(remoteTableInfo.<DefaultTableDefinition>definition().numRows());
assertNull(remoteTableInfo.<TableDefinition>definition().numBytes());
assertNull(remoteTableInfo.<TableDefinition>definition().numRows());
assertTrue(bigquery.delete(DATASET, tableName));
}

Expand Down Expand Up @@ -409,7 +409,7 @@ public void testCreateViewTable() throws InterruptedException {
@Test
public void testListTables() {
String tableName = "test_list_tables";
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA);
TableDefinition tableDefinition = TableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition);
TableInfo createdTableInfo = bigquery.create(tableInfo);
assertNotNull(createdTableInfo);
Expand All @@ -428,7 +428,7 @@ public void testListTables() {
@Test
public void testUpdateTable() {
String tableName = "test_update_table";
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA);
TableDefinition tableDefinition = TableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition);
TableInfo createdTableInfo = bigquery.create(tableInfo);
assertNotNull(createdTableInfo);
Expand All @@ -444,27 +444,27 @@ public void testUpdateTable() {
@Test
public void testUpdateTableWithSelectedFields() {
String tableName = "test_update_with_selected_fields_table";
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA);
TableDefinition tableDefinition = TableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition);
TableInfo createdTableInfo = bigquery.create(tableInfo);
assertNotNull(createdTableInfo);
TableInfo updatedTableInfo = bigquery.update(tableInfo.toBuilder().description("newDescr")
.build(), TableOption.fields(TableField.DESCRIPTION));
assertTrue(updatedTableInfo.definition() instanceof DefaultTableDefinition);
assertTrue(updatedTableInfo.definition() instanceof TableDefinition);
assertEquals(DATASET, updatedTableInfo.tableId().dataset());
assertEquals(tableName, updatedTableInfo.tableId().table());
assertEquals("newDescr", updatedTableInfo.description());
assertNull(updatedTableInfo.definition().schema());
assertNull(updatedTableInfo.lastModifiedTime());
assertNull(updatedTableInfo.<DefaultTableDefinition>definition().numBytes());
assertNull(updatedTableInfo.<DefaultTableDefinition>definition().numRows());
assertNull(updatedTableInfo.<TableDefinition>definition().numBytes());
assertNull(updatedTableInfo.<TableDefinition>definition().numRows());
assertTrue(bigquery.delete(DATASET, tableName));
}

@Test
public void testUpdateNonExistingTable() {
TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, "test_update_non_existing_table"),
DefaultTableDefinition.of(SIMPLE_SCHEMA));
TableDefinition.of(SIMPLE_SCHEMA));
try {
bigquery.update(tableInfo);
fail("BigQueryException was expected");
Expand All @@ -484,7 +484,7 @@ public void testDeleteNonExistingTable() {
@Test
public void testInsertAll() {
String tableName = "test_insert_all_table";
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA);
TableDefinition tableDefinition = TableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition);
assertNotNull(bigquery.create(tableInfo));
InsertAllRequest request = InsertAllRequest.builder(tableInfo.tableId())
Expand Down Expand Up @@ -516,7 +516,7 @@ public void testInsertAll() {
@Test
public void testInsertAllWithSuffix() throws InterruptedException {
String tableName = "test_insert_all_with_suffix_table";
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA);
TableDefinition tableDefinition = TableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition);
assertNotNull(bigquery.create(tableInfo));
InsertAllRequest request = InsertAllRequest.builder(tableInfo.tableId())
Expand Down Expand Up @@ -557,7 +557,7 @@ public void testInsertAllWithSuffix() throws InterruptedException {
@Test
public void testInsertAllWithErrors() {
String tableName = "test_insert_all_with_errors_table";
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA);
TableDefinition tableDefinition = TableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition);
assertNotNull(bigquery.create(tableInfo));
InsertAllRequest request = InsertAllRequest.builder(tableInfo.tableId())
Expand Down Expand Up @@ -689,7 +689,7 @@ public void testCreateAndGetJob() throws InterruptedException {
String sourceTableName = "test_create_and_get_job_source_table";
String destinationTableName = "test_create_and_get_job_destination_table";
TableId sourceTable = TableId.of(DATASET, sourceTableName);
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA);
TableDefinition tableDefinition = TableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(sourceTable, tableDefinition);
TableInfo createdTableInfo = bigquery.create(tableInfo);
assertNotNull(createdTableInfo);
Expand Down Expand Up @@ -722,7 +722,7 @@ public void testCreateAndGetJobWithSelectedFields() throws InterruptedException
String sourceTableName = "test_create_and_get_job_with_selected_fields_source_table";
String destinationTableName = "test_create_and_get_job_with_selected_fields_destination_table";
TableId sourceTable = TableId.of(DATASET, sourceTableName);
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA);
TableDefinition tableDefinition = TableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(sourceTable, tableDefinition);
TableInfo createdTableInfo = bigquery.create(tableInfo);
assertNotNull(createdTableInfo);
Expand Down Expand Up @@ -762,7 +762,7 @@ public void testCopyJob() throws InterruptedException {
String sourceTableName = "test_copy_job_source_table";
String destinationTableName = "test_copy_job_destination_table";
TableId sourceTable = TableId.of(DATASET, sourceTableName);
DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA);
TableDefinition tableDefinition = TableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(sourceTable, tableDefinition);
TableInfo createdTableInfo = bigquery.create(tableInfo);
assertNotNull(createdTableInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class InsertAllRequestTest {
InsertAllRequest.RowToInsert.of("id2", CONTENT2));
private static final TableId TABLE_ID = TableId.of("dataset", "table");
private static final Schema TABLE_SCHEMA = Schema.of();
private static final BaseTableDefinition TABLE_TYPE = DefaultTableDefinition.of(TABLE_SCHEMA);
private static final TableInfo TABLE_INFO = TableInfo.of(TABLE_ID, TABLE_TYPE);
private static final BaseTableDefinition TABLE_DEFINITION = TableDefinition.of(TABLE_SCHEMA);
private static final TableInfo TABLE_INFO = TableInfo.of(TABLE_ID, TABLE_DEFINITION);
private static final boolean SKIP_INVALID_ROWS = true;
private static final boolean IGNORE_UNKNOWN_VALUES = false;
private static final String TEMPLATE_SUFFIX = "templateSuffix";
Expand Down
Loading

0 comments on commit 4ee4554

Please sign in to comment.