From 085903ae55a6ef6bedb5a8dfd03dce378dd25a41 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 1 Feb 2016 20:22:40 +0100 Subject: [PATCH] Rename DefaultTableDefinition to TableDefinition --- README.md | 4 +- gcloud-java-bigquery/README.md | 8 ++-- .../gcloud/bigquery/BaseTableDefinition.java | 4 +- ...leDefinition.java => TableDefinition.java} | 22 +++++----- .../com/google/gcloud/bigquery/TableInfo.java | 10 +++-- .../google/gcloud/bigquery/package-info.java | 2 +- .../gcloud/bigquery/BigQueryImplTest.java | 8 ++-- .../google/gcloud/bigquery/DatasetTest.java | 4 +- .../gcloud/bigquery/ITBigQueryTest.java | 42 +++++++++---------- .../gcloud/bigquery/InsertAllRequestTest.java | 4 +- .../gcloud/bigquery/SerializationTest.java | 27 ++++++------ ...tionTest.java => TableDefinitionTest.java} | 41 +++++++++--------- .../google/gcloud/bigquery/TableInfoTest.java | 20 ++++----- .../com/google/gcloud/bigquery/TableTest.java | 4 +- .../gcloud/examples/BigQueryExample.java | 6 +-- 15 files changed, 105 insertions(+), 101 deletions(-) rename gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/{DefaultTableDefinition.java => TableDefinition.java} (91%) rename gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/{DefaultTableDefinitionTest.java => TableDefinitionTest.java} (67%) diff --git a/README.md b/README.md index 4c35daa67e87..c98949371215 100644 --- a/README.md +++ b/README.md @@ -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; @@ -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"); diff --git a/gcloud-java-bigquery/README.md b/gcloud-java-bigquery/README.md index 636573bfaa18..11550b8c2351 100644 --- a/gcloud-java-bigquery/README.md +++ b/gcloud-java-bigquery/README.md @@ -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; @@ -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)); ``` @@ -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; @@ -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 diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BaseTableDefinition.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BaseTableDefinition.java index 0282ff6bf0d0..908bb1199d36 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BaseTableDefinition.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BaseTableDefinition.java @@ -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, @@ -169,7 +169,7 @@ Table toPb() { static 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: diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/DefaultTableDefinition.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/TableDefinition.java similarity index 91% rename from gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/DefaultTableDefinition.java rename to gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/TableDefinition.java index 6462969488c6..1a82fd6756be 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/DefaultTableDefinition.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/TableDefinition.java @@ -33,7 +33,7 @@ * * @see Managing Tables */ -public class DefaultTableDefinition extends BaseTableDefinition { +public class TableDefinition extends BaseTableDefinition { private static final long serialVersionUID = 2113445776046717900L; @@ -116,7 +116,7 @@ static StreamingBuffer fromPb(Streamingbuffer streamingBufferPb) { } public static final class Builder - extends BaseTableDefinition.Builder { + extends BaseTableDefinition.Builder { private Long numBytes; private Long numRows; @@ -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; @@ -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; @@ -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() { @@ -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 @@ -275,7 +275,7 @@ Table toPb() { } @SuppressWarnings("unchecked") - static DefaultTableDefinition fromPb(Table tablePb) { + static TableDefinition fromPb(Table tablePb) { return new Builder(tablePb).build(); } } diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/TableInfo.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/TableInfo.java index 7e99e2850bdd..a2e3049f2188 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/TableInfo.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/TableInfo.java @@ -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 Managing Tables */ @@ -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); diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/package-info.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/package-info.java index c0cfb279cbcf..05024b46860f 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/package-info.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/package-info.java @@ -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"); diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/BigQueryImplTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/BigQueryImplTest.java index c0aa518a3270..20104bf5d857 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/BigQueryImplTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/BigQueryImplTest.java @@ -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 = diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DatasetTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DatasetTest.java index fcc9d0c5cc45..837736f5a395 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DatasetTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DatasetTest.java @@ -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()); diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ITBigQueryTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ITBigQueryTest.java index 20aaba7dd293..ec921d5cf68f 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ITBigQueryTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ITBigQueryTest.java @@ -257,21 +257,21 @@ 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.definition().numBytes()); - assertNotNull(remoteTableInfo.definition().numRows()); + assertNotNull(remoteTableInfo.definition().numBytes()); + assertNotNull(remoteTableInfo.definition().numRows()); assertTrue(bigquery.delete(DATASET, tableName)); } @@ -279,7 +279,7 @@ public void testCreateAndGetTable() { 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()); @@ -287,14 +287,14 @@ public void testCreateAndGetTableWithSelectedField() { 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.definition().numBytes()); - assertNull(remoteTableInfo.definition().numRows()); + assertNull(remoteTableInfo.definition().numBytes()); + assertNull(remoteTableInfo.definition().numRows()); assertTrue(bigquery.delete(DATASET, tableName)); } @@ -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); @@ -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); @@ -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.definition().numBytes()); - assertNull(updatedTableInfo.definition().numRows()); + assertNull(updatedTableInfo.definition().numBytes()); + assertNull(updatedTableInfo.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"); @@ -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()) @@ -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()) @@ -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()) @@ -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); @@ -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); @@ -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); diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/InsertAllRequestTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/InsertAllRequestTest.java index acfba8b6d0f6..a0b931805645 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/InsertAllRequestTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/InsertAllRequestTest.java @@ -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"; diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/SerializationTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/SerializationTest.java index 12f7c184087a..50880f15c603 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/SerializationTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/SerializationTest.java @@ -25,7 +25,7 @@ import com.google.gcloud.RestorableState; import com.google.gcloud.RetryParams; import com.google.gcloud.WriteChannel; -import com.google.gcloud.bigquery.DefaultTableDefinition.StreamingBuffer; +import com.google.gcloud.bigquery.TableDefinition.StreamingBuffer; import org.junit.Test; @@ -99,7 +99,7 @@ public class SerializationTest { private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA1, FIELD_SCHEMA2, FIELD_SCHEMA3); private static final StreamingBuffer STREAMING_BUFFER = new StreamingBuffer(1L, 2L, 3L); private static final List SOURCE_URIS = ImmutableList.of("uri1", "uri2"); - private static final ExternalTableDefinition EXTERNAL_TABLE_TYPE = + private static final ExternalTableDefinition EXTERNAL_TABLE_DEFINITION = ExternalTableDefinition.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS) .ignoreUnknownValues(true) .maxBadRecords(42) @@ -108,26 +108,26 @@ public class SerializationTest { new UserDefinedFunction.InlineFunction("inline"); private static final UserDefinedFunction URI_FUNCTION = new UserDefinedFunction.UriFunction("URI"); - private static final BaseTableDefinition TABLE_TYPE = DefaultTableDefinition.builder() + private static final BaseTableDefinition TABLE_DEFINITION = TableDefinition.builder() .schema(TABLE_SCHEMA) .location(LOCATION) .streamingBuffer(STREAMING_BUFFER) .build(); - private static final TableInfo TABLE_INFO = TableInfo.builder(TABLE_ID, TABLE_TYPE) + private static final TableInfo TABLE_INFO = TableInfo.builder(TABLE_ID, TABLE_DEFINITION) .creationTime(CREATION_TIME) .description(DESCRIPTION) .etag(ETAG) .id(ID) .build(); - private static final BaseTableDefinition VIEW_TYPE = ViewDefinition.of("QUERY"); - private static final TableInfo VIEW_INFO = TableInfo.builder(TABLE_ID, VIEW_TYPE) + private static final BaseTableDefinition VIEW_DEFINITION = ViewDefinition.of("QUERY"); + private static final TableInfo VIEW_INFO = TableInfo.builder(TABLE_ID, VIEW_DEFINITION) .creationTime(CREATION_TIME) .description(DESCRIPTION) .etag(ETAG) .id(ID) .build(); private static final TableInfo EXTERNAL_TABLE_INFO = - TableInfo.builder(TABLE_ID, EXTERNAL_TABLE_TYPE) + TableInfo.builder(TABLE_ID, EXTERNAL_TABLE_DEFINITION) .creationTime(CREATION_TIME) .description(DESCRIPTION) .etag(ETAG) @@ -246,12 +246,13 @@ public void testServiceOptions() throws Exception { @Test public void testModelAndRequests() throws Exception { Serializable[] objects = {DOMAIN_ACCESS, GROUP_ACCESS, USER_ACCESS, VIEW_ACCESS, DATASET_ID, - DATASET_INFO, TABLE_ID, CSV_OPTIONS, STREAMING_BUFFER, TABLE_TYPE, EXTERNAL_TABLE_TYPE, - VIEW_TYPE, TABLE_SCHEMA, TABLE_INFO, VIEW_INFO, EXTERNAL_TABLE_INFO, INLINE_FUNCTION, - URI_FUNCTION, JOB_STATISTICS, EXTRACT_STATISTICS, LOAD_STATISTICS, QUERY_STATISTICS, - BIGQUERY_ERROR, JOB_STATUS, JOB_ID, COPY_JOB_CONFIGURATION, EXTRACT_JOB_CONFIGURATION, - LOAD_CONFIGURATION, LOAD_JOB_CONFIGURATION, QUERY_JOB_CONFIGURATION, JOB_INFO, - INSERT_ALL_REQUEST, INSERT_ALL_RESPONSE, FIELD_VALUE, QUERY_REQUEST, QUERY_RESPONSE, + DATASET_INFO, TABLE_ID, CSV_OPTIONS, STREAMING_BUFFER, TABLE_DEFINITION, + EXTERNAL_TABLE_DEFINITION, VIEW_DEFINITION, TABLE_SCHEMA, TABLE_INFO, VIEW_INFO, + EXTERNAL_TABLE_INFO, INLINE_FUNCTION, URI_FUNCTION, JOB_STATISTICS, EXTRACT_STATISTICS, + LOAD_STATISTICS, QUERY_STATISTICS, BIGQUERY_ERROR, JOB_STATUS, JOB_ID, + COPY_JOB_CONFIGURATION, EXTRACT_JOB_CONFIGURATION, LOAD_CONFIGURATION, + LOAD_JOB_CONFIGURATION, QUERY_JOB_CONFIGURATION, JOB_INFO, INSERT_ALL_REQUEST, + INSERT_ALL_RESPONSE, FIELD_VALUE, QUERY_REQUEST, QUERY_RESPONSE, BigQuery.DatasetOption.fields(), BigQuery.DatasetDeleteOption.deleteContents(), BigQuery.DatasetListOption.all(), BigQuery.TableOption.fields(), BigQuery.TableListOption.maxResults(42L), BigQuery.JobOption.fields(), diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DefaultTableDefinitionTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/TableDefinitionTest.java similarity index 67% rename from gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DefaultTableDefinitionTest.java rename to gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/TableDefinitionTest.java index d595d7bb4a6c..57884d337279 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DefaultTableDefinitionTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/TableDefinitionTest.java @@ -19,11 +19,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import com.google.gcloud.bigquery.DefaultTableDefinition.StreamingBuffer; +import com.google.gcloud.bigquery.TableDefinition.StreamingBuffer; import org.junit.Test; -public class DefaultTableDefinitionTest { +public class TableDefinitionTest { private static final Field FIELD_SCHEMA1 = Field.builder("StringField", Field.Type.string()) @@ -45,8 +45,8 @@ public class DefaultTableDefinitionTest { private static final Long NUM_ROWS = 43L; private static final String LOCATION = "US"; private static final StreamingBuffer STREAMING_BUFFER = new StreamingBuffer(1L, 2L, 3L); - private static final DefaultTableDefinition DEFAULT_TABLE_DEFINITION = - DefaultTableDefinition.builder() + private static final TableDefinition TABLE_DEFINITION = + TableDefinition.builder() .location(LOCATION) .numBytes(NUM_BYTES) .numRows(NUM_ROWS) @@ -56,45 +56,44 @@ public class DefaultTableDefinitionTest { @Test public void testToBuilder() { - compareDefaultTableDefinition(DEFAULT_TABLE_DEFINITION, - DEFAULT_TABLE_DEFINITION.toBuilder().build()); - DefaultTableDefinition tableDefinition = DEFAULT_TABLE_DEFINITION.toBuilder() + compareTableDefinition(TABLE_DEFINITION, + TABLE_DEFINITION.toBuilder().build()); + TableDefinition tableDefinition = TABLE_DEFINITION.toBuilder() .location("EU") .build(); assertEquals("EU", tableDefinition.location()); tableDefinition = tableDefinition.toBuilder() .location(LOCATION) .build(); - compareDefaultTableDefinition(DEFAULT_TABLE_DEFINITION, tableDefinition); + compareTableDefinition(TABLE_DEFINITION, tableDefinition); } @Test public void testToBuilderIncomplete() { - DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA); + TableDefinition tableDefinition = TableDefinition.of(TABLE_SCHEMA); assertEquals(tableDefinition, tableDefinition.toBuilder().build()); } @Test public void testBuilder() { - assertEquals(BaseTableDefinition.Type.TABLE, DEFAULT_TABLE_DEFINITION.type()); - assertEquals(TABLE_SCHEMA, DEFAULT_TABLE_DEFINITION.schema()); - assertEquals(LOCATION, DEFAULT_TABLE_DEFINITION.location()); - assertEquals(NUM_BYTES, DEFAULT_TABLE_DEFINITION.numBytes()); - assertEquals(NUM_ROWS, DEFAULT_TABLE_DEFINITION.numRows()); - assertEquals(STREAMING_BUFFER, DEFAULT_TABLE_DEFINITION.streamingBuffer()); + assertEquals(BaseTableDefinition.Type.TABLE, TABLE_DEFINITION.type()); + assertEquals(TABLE_SCHEMA, TABLE_DEFINITION.schema()); + assertEquals(LOCATION, TABLE_DEFINITION.location()); + assertEquals(NUM_BYTES, TABLE_DEFINITION.numBytes()); + assertEquals(NUM_ROWS, TABLE_DEFINITION.numRows()); + assertEquals(STREAMING_BUFFER, TABLE_DEFINITION.streamingBuffer()); } @Test public void testToAndFromPb() { assertTrue( - BaseTableDefinition.fromPb(DEFAULT_TABLE_DEFINITION.toPb()) - instanceof DefaultTableDefinition); - compareDefaultTableDefinition(DEFAULT_TABLE_DEFINITION, - BaseTableDefinition.fromPb(DEFAULT_TABLE_DEFINITION.toPb())); + BaseTableDefinition.fromPb(TABLE_DEFINITION.toPb()) + instanceof TableDefinition); + compareTableDefinition(TABLE_DEFINITION, + BaseTableDefinition.fromPb(TABLE_DEFINITION.toPb())); } - private void compareDefaultTableDefinition(DefaultTableDefinition expected, - DefaultTableDefinition value) { + private void compareTableDefinition(TableDefinition expected, TableDefinition value) { assertEquals(expected, value); assertEquals(expected.schema(), value.schema()); assertEquals(expected.type(), value.type()); diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/TableInfoTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/TableInfoTest.java index 615d401ae1fb..4187451889f0 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/TableInfoTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/TableInfoTest.java @@ -55,9 +55,9 @@ public class TableInfoTest { private static final Long NUM_BYTES = 42L; private static final Long NUM_ROWS = 43L; private static final String LOCATION = "US"; - private static final DefaultTableDefinition.StreamingBuffer STREAMING_BUFFER = - new DefaultTableDefinition.StreamingBuffer(1L, 2L, 3L); - private static final DefaultTableDefinition DEFAULT_TABLE_TYPE = DefaultTableDefinition.builder() + private static final TableDefinition.StreamingBuffer STREAMING_BUFFER = + new TableDefinition.StreamingBuffer(1L, 2L, 3L); + private static final TableDefinition TABLE_DEFINITION = TableDefinition.builder() .location(LOCATION) .numBytes(NUM_BYTES) .numRows(NUM_ROWS) @@ -70,7 +70,7 @@ public class TableInfoTest { private static final Boolean IGNORE_UNKNOWN_VALUES = true; private static final String COMPRESSION = "GZIP"; private static final CsvOptions CSV_OPTIONS = CsvOptions.builder().build(); - private static final ExternalTableDefinition EXTERNAL_TABLE_TYPE = + private static final ExternalTableDefinition EXTERNAL_TABLE_DEFINITION = ExternalTableDefinition.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS) .compression(COMPRESSION) .ignoreUnknownValues(IGNORE_UNKNOWN_VALUES) @@ -83,7 +83,7 @@ public class TableInfoTest { private static final ViewDefinition VIEW_TYPE = ViewDefinition.builder(VIEW_QUERY, USER_DEFINED_FUNCTIONS).build(); - private static final TableInfo TABLE_INFO = TableInfo.builder(TABLE_ID, DEFAULT_TABLE_TYPE) + private static final TableInfo TABLE_INFO = TableInfo.builder(TABLE_ID, TABLE_DEFINITION) .creationTime(CREATION_TIME) .description(DESCRIPTION) .etag(ETAG) @@ -104,7 +104,7 @@ public class TableInfoTest { .selfLink(SELF_LINK) .build(); private static final TableInfo EXTERNAL_TABLE_INFO = - TableInfo.builder(TABLE_ID, EXTERNAL_TABLE_TYPE) + TableInfo.builder(TABLE_ID, EXTERNAL_TABLE_DEFINITION) .creationTime(CREATION_TIME) .description(DESCRIPTION) .etag(ETAG) @@ -132,11 +132,11 @@ public void testToBuilder() { @Test public void testToBuilderIncomplete() { - TableInfo tableInfo = TableInfo.of(TABLE_ID, DEFAULT_TABLE_TYPE); + TableInfo tableInfo = TableInfo.of(TABLE_ID, TABLE_DEFINITION); assertEquals(tableInfo, tableInfo.toBuilder().build()); tableInfo = TableInfo.of(TABLE_ID, VIEW_TYPE); assertEquals(tableInfo, tableInfo.toBuilder().build()); - tableInfo = TableInfo.of(TABLE_ID, EXTERNAL_TABLE_TYPE); + tableInfo = TableInfo.of(TABLE_ID, EXTERNAL_TABLE_DEFINITION); assertEquals(tableInfo, tableInfo.toBuilder().build()); } @@ -150,7 +150,7 @@ public void testBuilder() { assertEquals(FRIENDLY_NAME, TABLE_INFO.friendlyName()); assertEquals(ID, TABLE_INFO.id()); assertEquals(LAST_MODIFIED_TIME, TABLE_INFO.lastModifiedTime()); - assertEquals(DEFAULT_TABLE_TYPE, TABLE_INFO.definition()); + assertEquals(TABLE_DEFINITION, TABLE_INFO.definition()); assertEquals(SELF_LINK, TABLE_INFO.selfLink()); assertEquals(TABLE_ID, VIEW_INFO.tableId()); assertEquals(VIEW_TYPE, VIEW_INFO.definition()); @@ -171,7 +171,7 @@ public void testBuilder() { assertEquals(FRIENDLY_NAME, EXTERNAL_TABLE_INFO.friendlyName()); assertEquals(ID, EXTERNAL_TABLE_INFO.id()); assertEquals(LAST_MODIFIED_TIME, EXTERNAL_TABLE_INFO.lastModifiedTime()); - assertEquals(EXTERNAL_TABLE_TYPE, EXTERNAL_TABLE_INFO.definition()); + assertEquals(EXTERNAL_TABLE_DEFINITION, EXTERNAL_TABLE_INFO.definition()); assertEquals(SELF_LINK, EXTERNAL_TABLE_INFO.selfLink()); } diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/TableTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/TableTest.java index 48bdde5867fb..84f22672659e 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/TableTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/TableTest.java @@ -55,8 +55,8 @@ public class TableTest { private static final JobInfo EXTRACT_JOB_INFO = JobInfo.of(ExtractJobConfiguration.of(TABLE_ID1, ImmutableList.of("URI"), "CSV")); private static final Field FIELD = Field.of("FieldName", Field.Type.integer()); - private static final BaseTableDefinition TABLE_TYPE = DefaultTableDefinition.of(Schema.of(FIELD)); - private static final TableInfo TABLE_INFO = TableInfo.of(TABLE_ID1, TABLE_TYPE); + private static final BaseTableDefinition TABLE_DEFINITION = TableDefinition.of(Schema.of(FIELD)); + private static final TableInfo TABLE_INFO = TableInfo.of(TABLE_ID1, TABLE_DEFINITION); private static final List ROWS_TO_INSERT = ImmutableList.of( RowToInsert.of("id1", ImmutableMap.of("key", "val1")), RowToInsert.of("id2", ImmutableMap.of("key", "val2"))); diff --git a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/BigQueryExample.java b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/BigQueryExample.java index 1f8648623d40..5e2f6199f87e 100644 --- a/gcloud-java-examples/src/main/java/com/google/gcloud/examples/BigQueryExample.java +++ b/gcloud-java-examples/src/main/java/com/google/gcloud/examples/BigQueryExample.java @@ -24,7 +24,7 @@ import com.google.gcloud.bigquery.CopyJobConfiguration; import com.google.gcloud.bigquery.DatasetId; import com.google.gcloud.bigquery.DatasetInfo; -import com.google.gcloud.bigquery.DefaultTableDefinition; +import com.google.gcloud.bigquery.TableDefinition; import com.google.gcloud.bigquery.ExternalTableDefinition; import com.google.gcloud.bigquery.ExtractJobConfiguration; import com.google.gcloud.bigquery.Field; @@ -435,7 +435,7 @@ static Schema parseSchema(String[] args, int start, int end) { /** * This class demonstrates how to create a simple BigQuery Table (i.e. a table created from a - * {@link DefaultTableDefinition}). + * {@link TableDefinition}). * * @see Tables: insert * @@ -447,7 +447,7 @@ TableInfo parse(String... args) throws Exception { String dataset = args[0]; String table = args[1]; TableId tableId = TableId.of(dataset, table); - return TableInfo.of(tableId, DefaultTableDefinition.of(parseSchema(args, 2, args.length))); + return TableInfo.of(tableId, TableDefinition.of(parseSchema(args, 2, args.length))); } throw new IllegalArgumentException("Missing required arguments."); }