From 04fbf41041c7704dc13e821f80baa6e9401eb3fa Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Mon, 1 Feb 2016 09:51:08 +0100 Subject: [PATCH] Rename TableType to TableDefinition and other minor fixes --- README.md | 5 +- gcloud-java-bigquery/README.md | 12 +-- ...ableType.java => BaseTableDefinition.java} | 34 +++---- .../com/google/gcloud/bigquery/BigQuery.java | 10 +- .../google/gcloud/bigquery/CsvOptions.java | 2 +- .../com/google/gcloud/bigquery/Dataset.java | 2 +- ...eType.java => DefaultTableDefinition.java} | 33 ++++--- ...Type.java => ExternalTableDefinition.java} | 62 ++++++------ .../bigquery/QueryJobConfiguration.java | 16 +-- .../com/google/gcloud/bigquery/TableInfo.java | 44 ++++----- .../{ViewType.java => ViewDefinition.java} | 36 +++---- .../google/gcloud/bigquery/package-info.java | 2 +- .../gcloud/bigquery/BigQueryImplTest.java | 2 +- .../google/gcloud/bigquery/DatasetTest.java | 9 +- ...t.java => DefaultTableDefinitionTest.java} | 58 ++++++----- ....java => ExternalTableDefinitionTest.java} | 52 +++++----- .../gcloud/bigquery/ITBigQueryTest.java | 98 +++++++++---------- .../gcloud/bigquery/InsertAllRequestTest.java | 2 +- .../google/gcloud/bigquery/JobInfoTest.java | 6 +- .../bigquery/QueryJobConfigurationTest.java | 6 +- .../gcloud/bigquery/SerializationTest.java | 10 +- .../google/gcloud/bigquery/TableInfoTest.java | 26 ++--- .../com/google/gcloud/bigquery/TableTest.java | 2 +- ...wTypeTest.java => ViewDefinitionTest.java} | 32 +++--- .../WriteChannelConfigurationTest.java | 22 +++-- .../gcloud/examples/BigQueryExample.java | 26 ++--- 26 files changed, 312 insertions(+), 297 deletions(-) rename gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/{BaseTableType.java => BaseTableDefinition.java} (79%) rename gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/{DefaultTableType.java => DefaultTableDefinition.java} (88%) rename gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/{ExternalTableType.java => ExternalTableDefinition.java} (88%) rename gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/{ViewType.java => ViewDefinition.java} (84%) rename gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/{DefaultTableTypeTest.java => DefaultTableDefinitionTest.java} (58%) rename gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/{ExternalTableTypeTest.java => ExternalTableDefinitionTest.java} (58%) rename gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/{ViewTypeTest.java => ViewDefinitionTest.java} (58%) diff --git a/README.md b/README.md index cb8d3b4afd8d..4c35daa67e87 100644 --- a/README.md +++ b/README.md @@ -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; @@ -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"); diff --git a/gcloud-java-bigquery/README.md b/gcloud-java-bigquery/README.md index 0b77a3907337..e11699a660d6 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.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; @@ -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 @@ -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; @@ -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 firstRow = new HashMap<>(); diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BaseTableType.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BaseTableDefinition.java similarity index 79% rename from gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BaseTableType.java rename to gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BaseTableDefinition.java index f61953e9fe03..0282ff6bf0d0 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BaseTableType.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BaseTableDefinition.java @@ -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; @@ -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 Views */ 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 Federated Data * Sources @@ -68,7 +68,7 @@ public enum Type { * @param the table type class * @param the table type builder */ - public abstract static class Builder> { + public abstract static class Builder> { private Type type; private Schema schema; @@ -77,9 +77,9 @@ public abstract static class Builder T fromPb(Table tablePb) { + static 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"); diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQuery.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQuery.java index 2dea48214ef0..53a07e8a67c3 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQuery.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/BigQuery.java @@ -276,7 +276,7 @@ private TableOption(BigQueryRpc.Option option, Object value) { * Returns an option to specify the table's fields to be returned by the RPC call. If this * option is not provided all table's fields are returned. {@code TableOption.fields} can be * used to specify only the fields of interest. {@link TableInfo#tableId()} and - * {@link TableInfo#type()} are always returned, even if not specified. + * {@link TableInfo#definition()} are always returned, even if not specified. */ public static TableOption fields(TableField... fields) { return new TableOption(BigQueryRpc.Option.FIELDS, TableField.selector(fields)); @@ -563,7 +563,7 @@ TableInfo getTable(TableId tableId, TableOption... options) /** * Lists the tables in the dataset. This method returns partial information on each table * ({@link TableInfo#tableId()}, {@link TableInfo#friendlyName()}, - * {@link TableInfo#id()} and {@link TableInfo#type()}). To get complete information use + * {@link TableInfo#id()} and {@link TableInfo#definition()}). To get complete information use * either {@link #getTable(TableId, TableOption...)} or * {@link #getTable(String, String, TableOption...)}. * @@ -574,9 +574,9 @@ Page listTables(String datasetId, TableListOption... options) /** * Lists the tables in the dataset. This method returns partial information on each table - * ({@link TableInfo#tableId()}, {@link TableInfo#friendlyName()}, - * {@link TableInfo#id()} and {@link TableInfo#type()}). To get complete information use - * either {@link #getTable(TableId, TableOption...)} or + * ({@link TableInfo#tableId()}, {@link TableInfo#friendlyName()}, {@link TableInfo#id()} and + * {@link TableInfo#definition()}). To get complete information use either + * {@link #getTable(TableId, TableOption...)} or * {@link #getTable(String, String, TableOption...)}. * * @throws BigQueryException upon failure diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/CsvOptions.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/CsvOptions.java index 4799612ef287..9576e7d75640 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/CsvOptions.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/CsvOptions.java @@ -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() { diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Dataset.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Dataset.java index 2aabcf85a275..8ba25af11e2e 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Dataset.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/Dataset.java @@ -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)); } diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/DefaultTableType.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/DefaultTableDefinition.java similarity index 88% rename from gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/DefaultTableType.java rename to gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/DefaultTableDefinition.java index a8b0b30d2db6..6462969488c6 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/DefaultTableType.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/DefaultTableDefinition.java @@ -33,7 +33,7 @@ * * @see Managing Tables */ -public class DefaultTableType extends BaseTableType { +public class DefaultTableDefinition extends BaseTableDefinition { private static final long serialVersionUID = 2113445776046717900L; @@ -115,7 +115,8 @@ static StreamingBuffer fromPb(Streamingbuffer streamingBufferPb) { } } - public static final class Builder extends BaseTableType.Builder { + public static final class Builder + extends BaseTableDefinition.Builder { private Long numBytes; private Long numRows; @@ -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) { @@ -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; @@ -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() { @@ -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 @@ -274,7 +275,7 @@ Table toPb() { } @SuppressWarnings("unchecked") - static DefaultTableType fromPb(Table tablePb) { + static DefaultTableDefinition fromPb(Table tablePb) { return new Builder(tablePb).build(); } } diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExternalTableType.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExternalTableDefinition.java similarity index 88% rename from gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExternalTableType.java rename to gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExternalTableDefinition.java index a9fe31ebb96a..52384ae08cc3 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExternalTableType.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ExternalTableDefinition.java @@ -35,19 +35,21 @@ * @see Federated Data Sources * */ -public class ExternalTableType extends BaseTableType { +public class ExternalTableDefinition extends BaseTableDefinition { - static final Function FROM_EXTERNAL_DATA_FUNCTION = - new Function() { + static final Function + FROM_EXTERNAL_DATA_FUNCTION = + new Function() { @Override - public ExternalTableType apply(ExternalDataConfiguration pb) { - return ExternalTableType.fromExternalDataConfiguration(pb); + public ExternalTableDefinition apply(ExternalDataConfiguration pb) { + return ExternalTableDefinition.fromExternalDataConfiguration(pb); } }; - static final Function TO_EXTERNAL_DATA_FUNCTION = - new Function() { + static final Function + TO_EXTERNAL_DATA_FUNCTION = + new Function() { @Override - public ExternalDataConfiguration apply(ExternalTableType tableInfo) { + public ExternalDataConfiguration apply(ExternalTableDefinition tableInfo) { return tableInfo.toExternalDataConfigurationPb(); } }; @@ -60,7 +62,8 @@ public ExternalDataConfiguration apply(ExternalTableType tableInfo) { private final Boolean ignoreUnknownValues; private final String compression; - public static final class Builder extends BaseTableType.Builder { + public static final class Builder + extends BaseTableDefinition.Builder { private List sourceUris; private FormatOptions formatOptions; @@ -72,13 +75,13 @@ private Builder() { super(Type.EXTERNAL); } - private Builder(ExternalTableType tableType) { - super(tableType); - this.sourceUris = tableType.sourceUris; - this.formatOptions = tableType.formatOptions; - this.maxBadRecords = tableType.maxBadRecords; - this.ignoreUnknownValues = tableType.ignoreUnknownValues; - this.compression = tableType.compression; + private Builder(ExternalTableDefinition tableDefinition) { + super(tableDefinition); + this.sourceUris = tableDefinition.sourceUris; + this.formatOptions = tableDefinition.formatOptions; + this.maxBadRecords = tableDefinition.maxBadRecords; + this.ignoreUnknownValues = tableDefinition.ignoreUnknownValues; + this.compression = tableDefinition.compression; } private Builder(Table tablePb) { @@ -163,15 +166,15 @@ public Builder compression(String compression) { } /** - * Creates a {@code ExternalTableType} object. + * Creates an {@code ExternalTableDefinition} object. */ @Override - public ExternalTableType build() { - return new ExternalTableType(this); + public ExternalTableDefinition build() { + return new ExternalTableDefinition(this); } } - private ExternalTableType(Builder builder) { + private ExternalTableDefinition(Builder builder) { super(builder); this.compression = builder.compression; this.ignoreUnknownValues = builder.ignoreUnknownValues; @@ -234,7 +237,7 @@ public F formatOptions() { } /** - * Returns a builder for the {@code ExternalTableType} object. + * Returns a builder for the {@code ExternalTableDefinition} object. */ @Override public Builder toBuilder() { @@ -253,7 +256,7 @@ ToStringHelper toStringHelper() { @Override public boolean equals(Object obj) { - return obj instanceof ExternalTableType && baseEquals((ExternalTableType) obj); + return obj instanceof ExternalTableDefinition && baseEquals((ExternalTableDefinition) obj); } @Override @@ -297,7 +300,7 @@ com.google.api.services.bigquery.model.ExternalDataConfiguration toExternalDataC } /** - * Creates a builder for an ExternalTableType object. + * Creates a builder for an ExternalTableDefinition object. * * @param sourceUris the fully-qualified URIs that point to your data in Google Cloud Storage. * Each URI can contain one '*' wildcard character that must come after the bucket's name. @@ -316,7 +319,7 @@ public static Builder builder(List sourceUris, Schema schema, FormatOpti } /** - * Creates a builder for an ExternalTableType object. + * Creates a builder for an ExternalTableDefinition object. * * @param sourceUri a fully-qualified URI that points to your data in Google Cloud Storage. The * URI can contain one '*' wildcard character that must come after the bucket's name. Size @@ -334,7 +337,7 @@ public static Builder builder(String sourceUri, Schema schema, FormatOptions for } /** - * Creates an ExternalTableType object. + * Creates an ExternalTableDefinition object. * * @param sourceUris the fully-qualified URIs that point to your data in Google Cloud Storage. * Each URI can contain one '*' wildcard character that must come after the bucket's name. @@ -348,7 +351,8 @@ public static Builder builder(String sourceUri, Schema schema, FormatOptions for * @see * Source Format */ - public static ExternalTableType of(List sourceUris, Schema schema, FormatOptions format) { + public static ExternalTableDefinition of(List sourceUris, Schema schema, + FormatOptions format) { return builder(sourceUris, schema, format).build(); } @@ -366,16 +370,16 @@ public static ExternalTableType of(List sourceUris, Schema schema, Forma * @see * Source Format */ - public static ExternalTableType of(String sourceUri, Schema schema, FormatOptions format) { + public static ExternalTableDefinition of(String sourceUri, Schema schema, FormatOptions format) { return builder(sourceUri, schema, format).build(); } @SuppressWarnings("unchecked") - static ExternalTableType fromPb(Table tablePb) { + static ExternalTableDefinition fromPb(Table tablePb) { return new Builder(tablePb).build(); } - static ExternalTableType fromExternalDataConfiguration( + static ExternalTableDefinition fromExternalDataConfiguration( ExternalDataConfiguration externalDataConfiguration) { Builder builder = new Builder(); if (externalDataConfiguration.getSourceUris() != null) { diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/QueryJobConfiguration.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/QueryJobConfiguration.java index 000f71b8c067..94c16de149ed 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/QueryJobConfiguration.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/QueryJobConfiguration.java @@ -61,7 +61,7 @@ public enum Priority { private final String query; private final TableId destinationTable; - private final Map tableDefinitions; + private final Map tableDefinitions; private final List userDefinedFunctions; private final CreateDisposition createDisposition; private final WriteDisposition writeDisposition; @@ -77,7 +77,7 @@ public static final class Builder private String query; private TableId destinationTable; - private Map tableDefinitions; + private Map tableDefinitions; private List userDefinedFunctions; private CreateDisposition createDisposition; private WriteDisposition writeDisposition; @@ -127,7 +127,7 @@ private Builder(com.google.api.services.bigquery.model.JobConfiguration configur } if (queryConfigurationPb.getTableDefinitions() != null) { tableDefinitions = Maps.transformValues(queryConfigurationPb.getTableDefinitions(), - ExternalTableType.FROM_EXTERNAL_DATA_FUNCTION); + ExternalTableDefinition.FROM_EXTERNAL_DATA_FUNCTION); } if (queryConfigurationPb.getUserDefinedFunctionResources() != null) { userDefinedFunctions = Lists.transform( @@ -167,7 +167,7 @@ public Builder destinationTable(TableId destinationTable) { * sources. By defining these properties, the data sources can be queried as if they were * standard BigQuery tables. */ - public Builder tableDefinitions(Map tableDefinitions) { + public Builder tableDefinitions(Map tableDefinitions) { this.tableDefinitions = tableDefinitions != null ? Maps.newHashMap(tableDefinitions) : null; return this; } @@ -179,7 +179,7 @@ public Builder tableDefinitions(Map tableDefinitions) * @param tableName name of the table * @param tableDefinition external data configuration for the table used by this query */ - public Builder addTableDefinition(String tableName, ExternalTableType tableDefinition) { + public Builder addTableDefinition(String tableName, ExternalTableDefinition tableDefinition) { if (this.tableDefinitions == null) { this.tableDefinitions = Maps.newHashMap(); } @@ -383,7 +383,7 @@ public String query() { * sources. By defining these properties, the data sources can be queried as if they were * standard BigQuery tables. */ - public Map tableDefinitions() { + public Map tableDefinitions() { return tableDefinitions; } @@ -497,8 +497,8 @@ com.google.api.services.bigquery.model.JobConfiguration toPb() { queryConfigurationPb.setPriority(priority.toString()); } if (tableDefinitions != null) { - queryConfigurationPb.setTableDefinitions( - Maps.transformValues(tableDefinitions, ExternalTableType.TO_EXTERNAL_DATA_FUNCTION)); + queryConfigurationPb.setTableDefinitions(Maps.transformValues(tableDefinitions, + ExternalTableDefinition.TO_EXTERNAL_DATA_FUNCTION)); } if (useQueryCache != null) { queryConfigurationPb.setUseQueryCache(useQueryCache); 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 124d78a7b70d..7e99e2850bdd 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 DefaultTableType} to create simple BigQuery table. - * Use {@link ViewType} to create a BigQuery view. Use {@link ExternalTableType} to create a - * BigQuery a table backed by external data. + * 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. * * @see Managing Tables */ @@ -64,7 +64,7 @@ public Table apply(TableInfo tableInfo) { private final Long creationTime; private final Long expirationTime; private final Long lastModifiedTime; - private final BaseTableType type; + private final BaseTableDefinition definition; /** * Builder for tables. @@ -80,7 +80,7 @@ public static class Builder { private Long creationTime; private Long expirationTime; private Long lastModifiedTime; - private BaseTableType type; + private BaseTableDefinition definition; private Builder() {} @@ -94,7 +94,7 @@ private Builder(TableInfo tableInfo) { this.creationTime = tableInfo.creationTime; this.expirationTime = tableInfo.expirationTime; this.lastModifiedTime = tableInfo.lastModifiedTime; - this.type = tableInfo.type; + this.definition = tableInfo.definition; } private Builder(Table tablePb) { @@ -109,7 +109,7 @@ private Builder(Table tablePb) { this.etag = tablePb.getEtag(); this.id = tablePb.getId(); this.selfLink = tablePb.getSelfLink(); - this.type = BaseTableType.fromPb(tablePb); + this.definition = BaseTableDefinition.fromPb(tablePb); } Builder creationTime(Long creationTime) { @@ -171,10 +171,10 @@ public Builder tableId(TableId tableId) { } /** - * Sets the table type. + * Sets the table definition. */ - public Builder type(BaseTableType type) { - this.type = checkNotNull(type); + public Builder definition(BaseTableDefinition definition) { + this.definition = checkNotNull(definition); return this; } @@ -196,7 +196,7 @@ private TableInfo(Builder builder) { this.creationTime = builder.creationTime; this.expirationTime = builder.expirationTime; this.lastModifiedTime = builder.lastModifiedTime; - this.type = builder.type; + this.definition = builder.definition; } /** @@ -265,11 +265,11 @@ public Long lastModifiedTime() { } /** - * Returns the table type. + * Returns the table definition. */ @SuppressWarnings("unchecked") - public T type() { - return (T) type; + public T definition() { + return (T) definition; } /** @@ -290,7 +290,7 @@ ToStringHelper toStringHelper() { .add("expirationTime", expirationTime) .add("creationTime", creationTime) .add("lastModifiedTime", lastModifiedTime) - .add("type", type); + .add("definition", definition); } @Override @@ -309,17 +309,17 @@ public boolean equals(Object obj) { } /** - * Returns a builder for a {@code TableInfo} object given table identity and type. + * Returns a builder for a {@code TableInfo} object given table identity and definition. */ - public static Builder builder(TableId tableId, BaseTableType type) { - return new Builder().tableId(tableId).type(type); + public static Builder builder(TableId tableId, BaseTableDefinition definition) { + return new Builder().tableId(tableId).definition(definition); } /** - * Returns a {@code TableInfo} object given table identity and type. + * Returns a {@code TableInfo} object given table identity and definition. */ - public static TableInfo of(TableId tableId, BaseTableType type) { - return builder(tableId, type).build(); + public static TableInfo of(TableId tableId, BaseTableDefinition definition) { + return builder(tableId, definition).build(); } TableInfo setProjectId(String projectId) { @@ -327,7 +327,7 @@ TableInfo setProjectId(String projectId) { } Table toPb() { - Table tablePb = type.toPb(); + Table tablePb = definition.toPb(); tablePb.setTableReference(tableId.toPb()); if (lastModifiedTime != null) { tablePb.setLastModifiedTime(BigInteger.valueOf(lastModifiedTime)); diff --git a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ViewType.java b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ViewDefinition.java similarity index 84% rename from gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ViewType.java rename to gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ViewDefinition.java index af85f5005fbb..1358dc9eaecd 100644 --- a/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ViewType.java +++ b/gcloud-java-bigquery/src/main/java/com/google/gcloud/bigquery/ViewDefinition.java @@ -19,7 +19,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.api.services.bigquery.model.Table; -import com.google.api.services.bigquery.model.ViewDefinition; import com.google.common.base.MoreObjects.ToStringHelper; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; @@ -33,14 +32,14 @@ * * @see Views */ -public final class ViewType extends BaseTableType { +public final class ViewDefinition extends BaseTableDefinition { private static final long serialVersionUID = -8789311196910794545L; private final String query; private final List userDefinedFunctions; - public static final class Builder extends BaseTableType.Builder { + public static final class Builder extends BaseTableDefinition.Builder { private String query; private List userDefinedFunctions; @@ -49,15 +48,15 @@ private Builder() { super(Type.VIEW); } - private Builder(ViewType viewType) { - super(viewType); - this.query = viewType.query; - this.userDefinedFunctions = viewType.userDefinedFunctions; + private Builder(ViewDefinition viewDefinition) { + super(viewDefinition); + this.query = viewDefinition.query; + this.userDefinedFunctions = viewDefinition.userDefinedFunctions; } private Builder(Table tablePb) { super(tablePb); - ViewDefinition viewPb = tablePb.getView(); + com.google.api.services.bigquery.model.ViewDefinition viewPb = tablePb.getView(); if (viewPb != null) { this.query = viewPb.getQuery(); if (viewPb.getUserDefinedFunctionResources() != null) { @@ -98,15 +97,15 @@ public Builder userDefinedFunctions(UserDefinedFunction... userDefinedFunctions) } /** - * Creates a {@code ViewType} object. + * Creates a {@code ViewDefinition} object. */ @Override - public ViewType build() { - return new ViewType(this); + public ViewDefinition build() { + return new ViewDefinition(this); } } - private ViewType(Builder builder) { + private ViewDefinition(Builder builder) { super(builder); this.query = builder.query; this.userDefinedFunctions = builder.userDefinedFunctions; @@ -147,7 +146,7 @@ ToStringHelper toStringHelper() { @Override public boolean equals(Object obj) { - return obj instanceof ViewType && baseEquals((ViewType) obj); + return obj instanceof ViewDefinition && baseEquals((ViewDefinition) obj); } @Override @@ -158,7 +157,8 @@ public int hashCode() { @Override Table toPb() { Table tablePb = super.toPb(); - ViewDefinition viewDefinition = new ViewDefinition().setQuery(query); + com.google.api.services.bigquery.model.ViewDefinition viewDefinition = + new com.google.api.services.bigquery.model.ViewDefinition().setQuery(query); if (userDefinedFunctions != null) { viewDefinition.setUserDefinedFunctionResources(Lists.transform(userDefinedFunctions, UserDefinedFunction.TO_PB_FUNCTION)); @@ -201,7 +201,7 @@ public static Builder builder(String query, UserDefinedFunction... functions) { * * @param query the query used to generate the table */ - public static ViewType of(String query) { + public static ViewDefinition of(String query) { return builder(query).build(); } @@ -211,7 +211,7 @@ public static ViewType of(String query) { * @param query the query used to generate the table * @param functions user-defined functions that can be used by the query */ - public static ViewType of(String query, List functions) { + public static ViewDefinition of(String query, List functions) { return builder(query, functions).build(); } @@ -221,12 +221,12 @@ public static ViewType of(String query, List functions) { * @param query the query used to generate the table * @param functions user-defined functions that can be used by the query */ - public static ViewType of(String query, UserDefinedFunction... functions) { + public static ViewDefinition of(String query, UserDefinedFunction... functions) { return builder(query, functions).build(); } @SuppressWarnings("unchecked") - static ViewType fromPb(Table tablePb) { + static ViewDefinition fromPb(Table tablePb) { return new Builder(tablePb).build(); } } 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 f3fb07ea284c..c0cfb279cbcf 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, 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"); 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 9357f3c4b6a4..c0aa518a3270 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,7 +104,7 @@ public class BigQueryImplTest { .description("FieldDescription3") .build(); private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA1, FIELD_SCHEMA2, FIELD_SCHEMA3); - private static final DefaultTableType TABLE_TYPE = DefaultTableType.of(TABLE_SCHEMA); + 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 TableInfo TABLE_INFO_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 bd01d0435fa3..43020c282bbd 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,10 +44,11 @@ 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 DefaultTableType TABLE_TYPE = DefaultTableType.of(Schema.of(FIELD)); - private static final ViewType VIEW_TYPE = ViewType.of("QUERY"); - private static final ExternalTableType EXTERNAL_TABLE_TYPE = - ExternalTableType.of(ImmutableList.of("URI"), Schema.of(), FormatOptions.csv()); + private static final DefaultTableDefinition TABLE_TYPE = + DefaultTableDefinition.of(Schema.of(FIELD)); + private static final ViewDefinition VIEW_TYPE = ViewDefinition.of("QUERY"); + private static final ExternalTableDefinition EXTERNAL_TABLE_TYPE = + ExternalTableDefinition.of(ImmutableList.of("URI"), Schema.of(), FormatOptions.csv()); private static final Iterable TABLE_INFO_RESULTS = ImmutableList.of( TableInfo.builder(TableId.of("dataset", "table1"), TABLE_TYPE).build(), TableInfo.builder(TableId.of("dataset", "table2"), VIEW_TYPE).build(), diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DefaultTableTypeTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DefaultTableDefinitionTest.java similarity index 58% rename from gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DefaultTableTypeTest.java rename to gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DefaultTableDefinitionTest.java index 184cd8b74691..d595d7bb4a6c 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DefaultTableTypeTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/DefaultTableDefinitionTest.java @@ -19,11 +19,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import com.google.gcloud.bigquery.DefaultTableType.StreamingBuffer; +import com.google.gcloud.bigquery.DefaultTableDefinition.StreamingBuffer; import org.junit.Test; -public class DefaultTableTypeTest { +public class DefaultTableDefinitionTest { private static final Field FIELD_SCHEMA1 = Field.builder("StringField", Field.Type.string()) @@ -45,52 +45,56 @@ public class DefaultTableTypeTest { 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 DefaultTableType DEFAULT_TABLE_TYPE = DefaultTableType.builder() - .location(LOCATION) - .numBytes(NUM_BYTES) - .numRows(NUM_ROWS) - .streamingBuffer(STREAMING_BUFFER) - .schema(TABLE_SCHEMA) - .build(); - + private static final DefaultTableDefinition DEFAULT_TABLE_DEFINITION = + DefaultTableDefinition.builder() + .location(LOCATION) + .numBytes(NUM_BYTES) + .numRows(NUM_ROWS) + .streamingBuffer(STREAMING_BUFFER) + .schema(TABLE_SCHEMA) + .build(); @Test public void testToBuilder() { - compareDefaultTableType(DEFAULT_TABLE_TYPE, DEFAULT_TABLE_TYPE.toBuilder().build()); - DefaultTableType tableType = DEFAULT_TABLE_TYPE.toBuilder() + compareDefaultTableDefinition(DEFAULT_TABLE_DEFINITION, + DEFAULT_TABLE_DEFINITION.toBuilder().build()); + DefaultTableDefinition tableDefinition = DEFAULT_TABLE_DEFINITION.toBuilder() .location("EU") .build(); - assertEquals("EU", tableType.location()); - tableType = tableType.toBuilder() + assertEquals("EU", tableDefinition.location()); + tableDefinition = tableDefinition.toBuilder() .location(LOCATION) .build(); - compareDefaultTableType(DEFAULT_TABLE_TYPE, tableType); + compareDefaultTableDefinition(DEFAULT_TABLE_DEFINITION, tableDefinition); } @Test public void testToBuilderIncomplete() { - DefaultTableType tableType = DefaultTableType.of(TABLE_SCHEMA); - assertEquals(tableType, tableType.toBuilder().build()); + DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA); + assertEquals(tableDefinition, tableDefinition.toBuilder().build()); } @Test public void testBuilder() { - assertEquals(BaseTableType.Type.TABLE, DEFAULT_TABLE_TYPE.type()); - assertEquals(TABLE_SCHEMA, DEFAULT_TABLE_TYPE.schema()); - assertEquals(LOCATION, DEFAULT_TABLE_TYPE.location()); - assertEquals(NUM_BYTES, DEFAULT_TABLE_TYPE.numBytes()); - assertEquals(NUM_ROWS, DEFAULT_TABLE_TYPE.numRows()); - assertEquals(STREAMING_BUFFER, DEFAULT_TABLE_TYPE.streamingBuffer()); + 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()); } @Test public void testToAndFromPb() { - assertTrue(BaseTableType.fromPb(DEFAULT_TABLE_TYPE.toPb()) instanceof DefaultTableType); - compareDefaultTableType(DEFAULT_TABLE_TYPE, - BaseTableType.fromPb(DEFAULT_TABLE_TYPE.toPb())); + assertTrue( + BaseTableDefinition.fromPb(DEFAULT_TABLE_DEFINITION.toPb()) + instanceof DefaultTableDefinition); + compareDefaultTableDefinition(DEFAULT_TABLE_DEFINITION, + BaseTableDefinition.fromPb(DEFAULT_TABLE_DEFINITION.toPb())); } - private void compareDefaultTableType(DefaultTableType expected, DefaultTableType value) { + private void compareDefaultTableDefinition(DefaultTableDefinition expected, + DefaultTableDefinition 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/ExternalTableTypeTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ExternalTableDefinitionTest.java similarity index 58% rename from gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ExternalTableTypeTest.java rename to gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ExternalTableDefinitionTest.java index 57e7ab18cb26..8a821bf32d4e 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ExternalTableTypeTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ExternalTableDefinitionTest.java @@ -24,7 +24,7 @@ import java.util.List; -public class ExternalTableTypeTest { +public class ExternalTableDefinitionTest { private static final List SOURCE_URIS = ImmutableList.of("uri1", "uri2"); private static final Field FIELD_SCHEMA1 = @@ -47,8 +47,8 @@ public class ExternalTableTypeTest { 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 ExternalTableType EXTERNAL_TABLE_TYPE = - ExternalTableType.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS) + private static final ExternalTableDefinition EXTERNAL_TABLE_DEFINITION = + ExternalTableDefinition.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS) .compression(COMPRESSION) .ignoreUnknownValues(IGNORE_UNKNOWN_VALUES) .maxBadRecords(MAX_BAD_RECORDS) @@ -56,43 +56,47 @@ public class ExternalTableTypeTest { @Test public void testToBuilder() { - compareExternalTableType(EXTERNAL_TABLE_TYPE, EXTERNAL_TABLE_TYPE.toBuilder().build()); - ExternalTableType externalTableType = EXTERNAL_TABLE_TYPE.toBuilder().compression("NONE").build(); - assertEquals("NONE", externalTableType.compression()); - externalTableType = externalTableType.toBuilder() + compareExternalTableDefinition(EXTERNAL_TABLE_DEFINITION, + EXTERNAL_TABLE_DEFINITION.toBuilder().build()); + ExternalTableDefinition externalTableDefinition = + EXTERNAL_TABLE_DEFINITION.toBuilder().compression("NONE").build(); + assertEquals("NONE", externalTableDefinition.compression()); + externalTableDefinition = externalTableDefinition.toBuilder() .compression(COMPRESSION) .build(); - compareExternalTableType(EXTERNAL_TABLE_TYPE, externalTableType); + compareExternalTableDefinition(EXTERNAL_TABLE_DEFINITION, externalTableDefinition); } @Test public void testToBuilderIncomplete() { - ExternalTableType externalTableType = - ExternalTableType.of(SOURCE_URIS, TABLE_SCHEMA, FormatOptions.json()); - assertEquals(externalTableType, externalTableType.toBuilder().build()); + ExternalTableDefinition externalTableDefinition = + ExternalTableDefinition.of(SOURCE_URIS, TABLE_SCHEMA, FormatOptions.json()); + assertEquals(externalTableDefinition, externalTableDefinition.toBuilder().build()); } @Test public void testBuilder() { - assertEquals(BaseTableType.Type.EXTERNAL, EXTERNAL_TABLE_TYPE.type()); - assertEquals(COMPRESSION, EXTERNAL_TABLE_TYPE.compression()); - assertEquals(CSV_OPTIONS, EXTERNAL_TABLE_TYPE.formatOptions()); - assertEquals(IGNORE_UNKNOWN_VALUES, EXTERNAL_TABLE_TYPE.ignoreUnknownValues()); - assertEquals(MAX_BAD_RECORDS, EXTERNAL_TABLE_TYPE.maxBadRecords()); - assertEquals(TABLE_SCHEMA, EXTERNAL_TABLE_TYPE.schema()); - assertEquals(SOURCE_URIS, EXTERNAL_TABLE_TYPE.sourceUris()); + assertEquals(BaseTableDefinition.Type.EXTERNAL, EXTERNAL_TABLE_DEFINITION.type()); + assertEquals(COMPRESSION, EXTERNAL_TABLE_DEFINITION.compression()); + assertEquals(CSV_OPTIONS, EXTERNAL_TABLE_DEFINITION.formatOptions()); + assertEquals(IGNORE_UNKNOWN_VALUES, EXTERNAL_TABLE_DEFINITION.ignoreUnknownValues()); + assertEquals(MAX_BAD_RECORDS, EXTERNAL_TABLE_DEFINITION.maxBadRecords()); + assertEquals(TABLE_SCHEMA, EXTERNAL_TABLE_DEFINITION.schema()); + assertEquals(SOURCE_URIS, EXTERNAL_TABLE_DEFINITION.sourceUris()); } @Test public void testToAndFromPb() { - compareExternalTableType(EXTERNAL_TABLE_TYPE, - ExternalTableType.fromPb(EXTERNAL_TABLE_TYPE.toPb())); - ExternalTableType externalTableType = - ExternalTableType.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS).build(); - compareExternalTableType(externalTableType, ExternalTableType.fromPb(externalTableType.toPb())); + compareExternalTableDefinition(EXTERNAL_TABLE_DEFINITION, + ExternalTableDefinition.fromPb(EXTERNAL_TABLE_DEFINITION.toPb())); + ExternalTableDefinition externalTableDefinition = + ExternalTableDefinition.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS).build(); + compareExternalTableDefinition(externalTableDefinition, + ExternalTableDefinition.fromPb(externalTableDefinition.toPb())); } - private void compareExternalTableType(ExternalTableType expected, ExternalTableType value) { + private void compareExternalTableDefinition(ExternalTableDefinition expected, + ExternalTableDefinition value) { assertEquals(expected, value); assertEquals(expected.compression(), value.compression()); assertEquals(expected.formatOptions(), value.formatOptions()); 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 7b58303cadbb..20aaba7dd293 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); - DefaultTableType tableType = DefaultTableType.of(TABLE_SCHEMA); - TableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, tableType)); + DefaultTableDefinition tableDefinition = DefaultTableDefinition.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.type() instanceof DefaultTableType); + assertTrue(remoteTableInfo.definition() instanceof DefaultTableDefinition); assertEquals(createdTableInfo.tableId(), remoteTableInfo.tableId()); - assertEquals(BaseTableType.Type.TABLE, remoteTableInfo.type().type()); - assertEquals(TABLE_SCHEMA, remoteTableInfo.type().schema()); + assertEquals(BaseTableDefinition.Type.TABLE, remoteTableInfo.definition().type()); + assertEquals(TABLE_SCHEMA, remoteTableInfo.definition().schema()); assertNotNull(remoteTableInfo.creationTime()); assertNotNull(remoteTableInfo.lastModifiedTime()); - assertNotNull(remoteTableInfo.type().numBytes()); - assertNotNull(remoteTableInfo.type().numRows()); + assertNotNull(remoteTableInfo.definition().numBytes()); + assertNotNull(remoteTableInfo.definition().numRows()); assertTrue(bigquery.delete(DATASET, tableName)); } @@ -279,22 +279,22 @@ public void testCreateAndGetTable() { public void testCreateAndGetTableWithSelectedField() { String tableName = "test_create_and_get_selected_fields_table"; TableId tableId = TableId.of(DATASET, tableName); - DefaultTableType tableType = DefaultTableType.of(TABLE_SCHEMA); - TableInfo createdTableInfo = bigquery.create(TableInfo.of(tableId, tableType)); + DefaultTableDefinition tableDefinition = DefaultTableDefinition.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.type() instanceof DefaultTableType); + assertTrue(remoteTableInfo.definition() instanceof DefaultTableDefinition); assertEquals(createdTableInfo.tableId(), remoteTableInfo.tableId()); - assertEquals(BaseTableType.Type.TABLE, remoteTableInfo.type().type()); + assertEquals(BaseTableDefinition.Type.TABLE, remoteTableInfo.definition().type()); assertNotNull(remoteTableInfo.creationTime()); - assertNull(remoteTableInfo.type().schema()); + assertNull(remoteTableInfo.definition().schema()); assertNull(remoteTableInfo.lastModifiedTime()); - assertNull(remoteTableInfo.type().numBytes()); - assertNull(remoteTableInfo.type().numRows()); + assertNull(remoteTableInfo.definition().numBytes()); + assertNull(remoteTableInfo.definition().numRows()); assertTrue(bigquery.delete(DATASET, tableName)); } @@ -302,18 +302,18 @@ public void testCreateAndGetTableWithSelectedField() { public void testCreateExternalTable() throws InterruptedException { String tableName = "test_create_external_table"; TableId tableId = TableId.of(DATASET, tableName); - ExternalTableType externalTableType = ExternalTableType.of( + ExternalTableDefinition externalTableDefinition = ExternalTableDefinition.of( "gs://" + BUCKET + "/" + JSON_LOAD_FILE, TABLE_SCHEMA, FormatOptions.json()); - TableInfo tableInfo = TableInfo.of(tableId, externalTableType); + TableInfo tableInfo = TableInfo.of(tableId, externalTableDefinition); TableInfo createdTableInfo = bigquery.create(tableInfo); assertNotNull(createdTableInfo); assertEquals(DATASET, createdTableInfo.tableId().dataset()); assertEquals(tableName, createdTableInfo.tableId().table()); TableInfo remoteTableInfo = bigquery.getTable(DATASET, tableName); assertNotNull(remoteTableInfo); - assertTrue(remoteTableInfo.type() instanceof ExternalTableType); + assertTrue(remoteTableInfo.definition() instanceof ExternalTableDefinition); assertEquals(createdTableInfo.tableId(), remoteTableInfo.tableId()); - assertEquals(TABLE_SCHEMA, remoteTableInfo.type().schema()); + assertEquals(TABLE_SCHEMA, remoteTableInfo.definition().schema()); QueryRequest request = QueryRequest.builder( "SELECT TimestampField, StringField, IntegerField, BooleanField FROM " + DATASET + "." + tableName) @@ -352,9 +352,10 @@ public void testCreateExternalTable() throws InterruptedException { public void testCreateViewTable() throws InterruptedException { String tableName = "test_create_view_table"; TableId tableId = TableId.of(DATASET, tableName); - ViewType viewType = ViewType.of("SELECT TimestampField, StringField, BooleanField FROM " - + DATASET + "." + TABLE_ID.table()); - TableInfo tableInfo = TableInfo.of(tableId, viewType); + ViewDefinition viewDefinition = + ViewDefinition.of("SELECT TimestampField, StringField, BooleanField FROM " + DATASET + "." + + TABLE_ID.table()); + TableInfo tableInfo = TableInfo.of(tableId, viewDefinition); TableInfo createdTableInfo = bigquery.create(tableInfo); assertNotNull(createdTableInfo); assertEquals(DATASET, createdTableInfo.tableId().dataset()); @@ -362,7 +363,7 @@ public void testCreateViewTable() throws InterruptedException { TableInfo remoteTableInfo = bigquery.getTable(DATASET, tableName); assertNotNull(remoteTableInfo); assertEquals(createdTableInfo.tableId(), remoteTableInfo.tableId()); - assertTrue(remoteTableInfo.type() instanceof ViewType); + assertTrue(remoteTableInfo.definition() instanceof ViewDefinition); Schema expectedSchema = Schema.builder() .addField( Field.builder("TimestampField", Field.Type.timestamp()) @@ -377,7 +378,7 @@ public void testCreateViewTable() throws InterruptedException { .mode(Field.Mode.NULLABLE) .build()) .build(); - assertEquals(expectedSchema, remoteTableInfo.type().schema()); + assertEquals(expectedSchema, remoteTableInfo.definition().schema()); QueryRequest request = QueryRequest.builder("SELECT * FROM " + tableName) .defaultDataset(DatasetId.of(DATASET)) .maxWaitTime(60000L) @@ -408,8 +409,8 @@ public void testCreateViewTable() throws InterruptedException { @Test public void testListTables() { String tableName = "test_list_tables"; - DefaultTableType tableType = DefaultTableType.of(TABLE_SCHEMA); - TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableType); + DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA); + TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition); TableInfo createdTableInfo = bigquery.create(tableInfo); assertNotNull(createdTableInfo); Page tables = bigquery.listTables(DATASET); @@ -427,15 +428,15 @@ public void testListTables() { @Test public void testUpdateTable() { String tableName = "test_update_table"; - DefaultTableType tableType = DefaultTableType.of(TABLE_SCHEMA); - TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableType); + DefaultTableDefinition tableDefinition = DefaultTableDefinition.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("newDescription").build()); assertEquals(DATASET, updatedTableInfo.tableId().dataset()); assertEquals(tableName, updatedTableInfo.tableId().table()); - assertEquals(TABLE_SCHEMA, updatedTableInfo.type().schema()); + assertEquals(TABLE_SCHEMA, updatedTableInfo.definition().schema()); assertEquals("newDescription", updatedTableInfo.description()); assertTrue(bigquery.delete(DATASET, tableName)); } @@ -443,28 +444,27 @@ public void testUpdateTable() { @Test public void testUpdateTableWithSelectedFields() { String tableName = "test_update_with_selected_fields_table"; - DefaultTableType tableType = DefaultTableType.of(TABLE_SCHEMA); - TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableType); + DefaultTableDefinition tableDefinition = DefaultTableDefinition.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.type() instanceof DefaultTableType); + assertTrue(updatedTableInfo.definition() instanceof DefaultTableDefinition); assertEquals(DATASET, updatedTableInfo.tableId().dataset()); assertEquals(tableName, updatedTableInfo.tableId().table()); assertEquals("newDescr", updatedTableInfo.description()); - assertNull(updatedTableInfo.type().schema()); + assertNull(updatedTableInfo.definition().schema()); assertNull(updatedTableInfo.lastModifiedTime()); - assertNull(updatedTableInfo.type().numBytes()); - assertNull(updatedTableInfo.type().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"), - DefaultTableType.of(SIMPLE_SCHEMA)); + DefaultTableDefinition.of(SIMPLE_SCHEMA)); try { bigquery.update(tableInfo); fail("BigQueryException was expected"); @@ -484,8 +484,8 @@ public void testDeleteNonExistingTable() { @Test public void testInsertAll() { String tableName = "test_insert_all_table"; - DefaultTableType tableType = DefaultTableType.of(TABLE_SCHEMA); - TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableType); + DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA); + TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition); assertNotNull(bigquery.create(tableInfo)); InsertAllRequest request = InsertAllRequest.builder(tableInfo.tableId()) .addRow(ImmutableMap.of( @@ -516,8 +516,8 @@ public void testInsertAll() { @Test public void testInsertAllWithSuffix() throws InterruptedException { String tableName = "test_insert_all_with_suffix_table"; - DefaultTableType tableType = DefaultTableType.of(TABLE_SCHEMA); - TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableType); + DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA); + TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition); assertNotNull(bigquery.create(tableInfo)); InsertAllRequest request = InsertAllRequest.builder(tableInfo.tableId()) .addRow(ImmutableMap.of( @@ -557,8 +557,8 @@ public void testInsertAllWithSuffix() throws InterruptedException { @Test public void testInsertAllWithErrors() { String tableName = "test_insert_all_with_errors_table"; - DefaultTableType tableType = DefaultTableType.of(TABLE_SCHEMA); - TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableType); + DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA); + TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition); assertNotNull(bigquery.create(tableInfo)); InsertAllRequest request = InsertAllRequest.builder(tableInfo.tableId()) .addRow(ImmutableMap.of( @@ -689,8 +689,8 @@ 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); - DefaultTableType tableType = DefaultTableType.of(TABLE_SCHEMA); - TableInfo tableInfo = TableInfo.of(sourceTable, tableType); + DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA); + TableInfo tableInfo = TableInfo.of(sourceTable, tableDefinition); TableInfo createdTableInfo = bigquery.create(tableInfo); assertNotNull(createdTableInfo); assertEquals(DATASET, createdTableInfo.tableId().dataset()); @@ -722,8 +722,8 @@ 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); - DefaultTableType tableType = DefaultTableType.of(TABLE_SCHEMA); - TableInfo tableInfo = TableInfo.of(sourceTable, tableType); + DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA); + TableInfo tableInfo = TableInfo.of(sourceTable, tableDefinition); TableInfo createdTableInfo = bigquery.create(tableInfo); assertNotNull(createdTableInfo); assertEquals(DATASET, createdTableInfo.tableId().dataset()); @@ -762,8 +762,8 @@ 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); - DefaultTableType tableType = DefaultTableType.of(TABLE_SCHEMA); - TableInfo tableInfo = TableInfo.of(sourceTable, tableType); + DefaultTableDefinition tableDefinition = DefaultTableDefinition.of(TABLE_SCHEMA); + TableInfo tableInfo = TableInfo.of(sourceTable, tableDefinition); TableInfo createdTableInfo = bigquery.create(tableInfo); assertNotNull(createdTableInfo); assertEquals(DATASET, createdTableInfo.tableId().dataset()); @@ -780,7 +780,7 @@ public void testCopyJob() throws InterruptedException { assertNotNull(remoteTableInfo); assertEquals(destinationTable.dataset(), remoteTableInfo.tableId().dataset()); assertEquals(destinationTableName, remoteTableInfo.tableId().table()); - assertEquals(TABLE_SCHEMA, remoteTableInfo.type().schema()); + assertEquals(TABLE_SCHEMA, remoteTableInfo.definition().schema()); assertTrue(bigquery.delete(DATASET, sourceTableName)); assertTrue(bigquery.delete(DATASET, destinationTableName)); } 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 7a47a269dc1a..acfba8b6d0f6 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,7 +43,7 @@ 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 BaseTableType TABLE_TYPE = DefaultTableType.of(TABLE_SCHEMA); + 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 boolean SKIP_INVALID_ROWS = true; private static final boolean IGNORE_UNKNOWN_VALUES = false; diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/JobInfoTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/JobInfoTest.java index b4e7a4f1434b..260088470aff 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/JobInfoTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/JobInfoTest.java @@ -118,8 +118,8 @@ public class JobInfoTest { private static final Integer MAX_BAD_RECORDS = 42; private static final Boolean IGNORE_UNKNOWN_VALUES = true; private static final CsvOptions CSV_OPTIONS = CsvOptions.builder().build(); - private static final ExternalTableType TABLE_CONFIGURATION = - ExternalTableType.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS) + private static final ExternalTableDefinition TABLE_CONFIGURATION = + ExternalTableDefinition.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS) .compression(COMPRESSION) .ignoreUnknownValues(IGNORE_UNKNOWN_VALUES) .maxBadRecords(MAX_BAD_RECORDS) @@ -135,7 +135,7 @@ public class JobInfoTest { .schema(TABLE_SCHEMA) .build(); private static final String QUERY = "BigQuery SQL"; - private static final Map TABLE_DEFINITIONS = + private static final Map TABLE_DEFINITIONS = ImmutableMap.of("tableName", TABLE_CONFIGURATION); private static final QueryJobConfiguration.Priority PRIORITY = QueryJobConfiguration.Priority.BATCH; diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/QueryJobConfigurationTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/QueryJobConfigurationTest.java index fd2b9b9bae2f..1ef270ee69cf 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/QueryJobConfigurationTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/QueryJobConfigurationTest.java @@ -58,13 +58,13 @@ public class QueryJobConfigurationTest { 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 ExternalTableType TABLE_CONFIGURATION = - ExternalTableType.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS) + private static final ExternalTableDefinition TABLE_CONFIGURATION = + ExternalTableDefinition.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS) .compression(COMPRESSION) .ignoreUnknownValues(IGNORE_UNKNOWN_VALUES) .maxBadRecords(MAX_BAD_RECORDS) .build(); - private static final Map TABLE_DEFINITIONS = + private static final Map TABLE_DEFINITIONS = ImmutableMap.of("tableName", TABLE_CONFIGURATION); private static final CreateDisposition CREATE_DISPOSITION = CreateDisposition.CREATE_IF_NEEDED; private static final WriteDisposition WRITE_DISPOSITION = WriteDisposition.WRITE_APPEND; 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 6f2ca3f4cbe6..12f7c184087a 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.DefaultTableType.StreamingBuffer; +import com.google.gcloud.bigquery.DefaultTableDefinition.StreamingBuffer; import org.junit.Test; @@ -99,8 +99,8 @@ 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 ExternalTableType EXTERNAL_TABLE_TYPE = - ExternalTableType.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS) + private static final ExternalTableDefinition EXTERNAL_TABLE_TYPE = + ExternalTableDefinition.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS) .ignoreUnknownValues(true) .maxBadRecords(42) .build(); @@ -108,7 +108,7 @@ public class SerializationTest { new UserDefinedFunction.InlineFunction("inline"); private static final UserDefinedFunction URI_FUNCTION = new UserDefinedFunction.UriFunction("URI"); - private static final BaseTableType TABLE_TYPE = DefaultTableType.builder() + private static final BaseTableDefinition TABLE_TYPE = DefaultTableDefinition.builder() .schema(TABLE_SCHEMA) .location(LOCATION) .streamingBuffer(STREAMING_BUFFER) @@ -119,7 +119,7 @@ public class SerializationTest { .etag(ETAG) .id(ID) .build(); - private static final BaseTableType VIEW_TYPE = ViewType.of("QUERY"); + private static final BaseTableDefinition VIEW_TYPE = ViewDefinition.of("QUERY"); private static final TableInfo VIEW_INFO = TableInfo.builder(TABLE_ID, VIEW_TYPE) .creationTime(CREATION_TIME) .description(DESCRIPTION) 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 0df5a9d2c012..615d401ae1fb 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 DefaultTableType.StreamingBuffer STREAMING_BUFFER = - new DefaultTableType.StreamingBuffer(1L, 2L, 3L); - private static final DefaultTableType DEFAULT_TABLE_TYPE = DefaultTableType.builder() + private static final DefaultTableDefinition.StreamingBuffer STREAMING_BUFFER = + new DefaultTableDefinition.StreamingBuffer(1L, 2L, 3L); + private static final DefaultTableDefinition DEFAULT_TABLE_TYPE = DefaultTableDefinition.builder() .location(LOCATION) .numBytes(NUM_BYTES) .numRows(NUM_ROWS) @@ -70,8 +70,8 @@ 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 ExternalTableType EXTERNAL_TABLE_TYPE = - ExternalTableType.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS) + private static final ExternalTableDefinition EXTERNAL_TABLE_TYPE = + ExternalTableDefinition.builder(SOURCE_URIS, TABLE_SCHEMA, CSV_OPTIONS) .compression(COMPRESSION) .ignoreUnknownValues(IGNORE_UNKNOWN_VALUES) .maxBadRecords(MAX_BAD_RECORDS) @@ -80,8 +80,8 @@ public class TableInfoTest { private static final String VIEW_QUERY = "VIEW QUERY"; private static final List USER_DEFINED_FUNCTIONS = ImmutableList.of(UserDefinedFunction.inline("Function"), UserDefinedFunction.fromUri("URI")); - private static final ViewType VIEW_TYPE = - ViewType.builder(VIEW_QUERY, USER_DEFINED_FUNCTIONS).build(); + 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) .creationTime(CREATION_TIME) @@ -150,10 +150,10 @@ 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.type()); + assertEquals(DEFAULT_TABLE_TYPE, TABLE_INFO.definition()); assertEquals(SELF_LINK, TABLE_INFO.selfLink()); assertEquals(TABLE_ID, VIEW_INFO.tableId()); - assertEquals(VIEW_TYPE, VIEW_INFO.type()); + assertEquals(VIEW_TYPE, VIEW_INFO.definition()); assertEquals(CREATION_TIME, VIEW_INFO.creationTime()); assertEquals(DESCRIPTION, VIEW_INFO.description()); assertEquals(ETAG, VIEW_INFO.etag()); @@ -161,7 +161,7 @@ public void testBuilder() { assertEquals(FRIENDLY_NAME, VIEW_INFO.friendlyName()); assertEquals(ID, VIEW_INFO.id()); assertEquals(LAST_MODIFIED_TIME, VIEW_INFO.lastModifiedTime()); - assertEquals(VIEW_TYPE, VIEW_INFO.type()); + assertEquals(VIEW_TYPE, VIEW_INFO.definition()); assertEquals(SELF_LINK, VIEW_INFO.selfLink()); assertEquals(TABLE_ID, EXTERNAL_TABLE_INFO.tableId()); assertEquals(CREATION_TIME, EXTERNAL_TABLE_INFO.creationTime()); @@ -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.type()); + assertEquals(EXTERNAL_TABLE_TYPE, EXTERNAL_TABLE_INFO.definition()); assertEquals(SELF_LINK, EXTERNAL_TABLE_INFO.selfLink()); } @@ -192,7 +192,7 @@ public void testSetProjectId() { private void compareTableInfo(TableInfo expected, TableInfo value) { assertEquals(expected, value); assertEquals(expected.tableId(), value.tableId()); - assertEquals(expected.type(), value.type()); + assertEquals(expected.definition(), value.definition()); assertEquals(expected.creationTime(), value.creationTime()); assertEquals(expected.description(), value.description()); assertEquals(expected.etag(), value.etag()); @@ -201,7 +201,7 @@ private void compareTableInfo(TableInfo expected, TableInfo value) { assertEquals(expected.id(), value.id()); assertEquals(expected.lastModifiedTime(), value.lastModifiedTime()); assertEquals(expected.selfLink(), value.selfLink()); - assertEquals(expected.type(), value.type()); + assertEquals(expected.definition(), value.definition()); assertEquals(expected.hashCode(), value.hashCode()); } } 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 4c03cb0ee77a..48bdde5867fb 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,7 +55,7 @@ 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 BaseTableType TABLE_TYPE = DefaultTableType.of(Schema.of(FIELD)); + 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 List ROWS_TO_INSERT = ImmutableList.of( RowToInsert.of("id1", ImmutableMap.of("key", "val1")), diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ViewTypeTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ViewDefinitionTest.java similarity index 58% rename from gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ViewTypeTest.java rename to gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ViewDefinitionTest.java index 83a2b011582c..26e65d3a5d46 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ViewTypeTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/ViewDefinitionTest.java @@ -25,47 +25,47 @@ import java.util.List; -public class ViewTypeTest { +public class ViewDefinitionTest { private static final String VIEW_QUERY = "VIEW QUERY"; private static final List USER_DEFINED_FUNCTIONS = ImmutableList.of(UserDefinedFunction.inline("Function"), UserDefinedFunction.fromUri("URI")); - private static final ViewType VIEW_TYPE = - ViewType.builder(VIEW_QUERY, USER_DEFINED_FUNCTIONS).build(); + private static final ViewDefinition VIEW_DEFINITION = + ViewDefinition.builder(VIEW_QUERY, USER_DEFINED_FUNCTIONS).build(); @Test public void testToBuilder() { - compareViewType(VIEW_TYPE, VIEW_TYPE.toBuilder().build()); - ViewType viewType = VIEW_TYPE.toBuilder() + compareViewDefinition(VIEW_DEFINITION, VIEW_DEFINITION.toBuilder().build()); + ViewDefinition viewDefinition = VIEW_DEFINITION.toBuilder() .query("NEW QUERY") .build(); - assertEquals("NEW QUERY", viewType.query()); - viewType = viewType.toBuilder() + assertEquals("NEW QUERY", viewDefinition.query()); + viewDefinition = viewDefinition.toBuilder() .query(VIEW_QUERY) .build(); - compareViewType(VIEW_TYPE, viewType); + compareViewDefinition(VIEW_DEFINITION, viewDefinition); } @Test public void testToBuilderIncomplete() { - BaseTableType tableType = ViewType.of(VIEW_QUERY); - assertEquals(tableType, tableType.toBuilder().build()); + BaseTableDefinition viewDefinition = ViewDefinition.of(VIEW_QUERY); + assertEquals(viewDefinition, viewDefinition.toBuilder().build()); } @Test public void testBuilder() { - assertEquals(VIEW_QUERY, VIEW_TYPE.query()); - assertEquals(BaseTableType.Type.VIEW, VIEW_TYPE.type()); - assertEquals(USER_DEFINED_FUNCTIONS, VIEW_TYPE.userDefinedFunctions()); + assertEquals(VIEW_QUERY, VIEW_DEFINITION.query()); + assertEquals(BaseTableDefinition.Type.VIEW, VIEW_DEFINITION.type()); + assertEquals(USER_DEFINED_FUNCTIONS, VIEW_DEFINITION.userDefinedFunctions()); } @Test public void testToAndFromPb() { - assertTrue(BaseTableType.fromPb(VIEW_TYPE.toPb()) instanceof ViewType); - compareViewType(VIEW_TYPE, BaseTableType.fromPb(VIEW_TYPE.toPb())); + assertTrue(BaseTableDefinition.fromPb(VIEW_DEFINITION.toPb()) instanceof ViewDefinition); + compareViewDefinition(VIEW_DEFINITION, BaseTableDefinition.fromPb(VIEW_DEFINITION.toPb())); } - private void compareViewType(ViewType expected, ViewType value) { + private void compareViewDefinition(ViewDefinition expected, ViewDefinition value) { assertEquals(expected, value); assertEquals(expected.query(), value.query()); assertEquals(expected.userDefinedFunctions(), value.userDefinedFunctions()); diff --git a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/WriteChannelConfigurationTest.java b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/WriteChannelConfigurationTest.java index 17fa8446d097..dfde4795dacd 100644 --- a/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/WriteChannelConfigurationTest.java +++ b/gcloud-java-bigquery/src/test/java/com/google/gcloud/bigquery/WriteChannelConfigurationTest.java @@ -47,15 +47,16 @@ public class WriteChannelConfigurationTest { .description("FieldDescription") .build(); private static final Schema TABLE_SCHEMA = Schema.of(FIELD_SCHEMA); - private static final WriteChannelConfiguration LOAD_CONFIGURATION = WriteChannelConfiguration.builder(TABLE_ID) - .createDisposition(CREATE_DISPOSITION) - .writeDisposition(WRITE_DISPOSITION) - .formatOptions(CSV_OPTIONS) - .ignoreUnknownValues(IGNORE_UNKNOWN_VALUES) - .maxBadRecords(MAX_BAD_RECORDS) - .projectionFields(PROJECTION_FIELDS) - .schema(TABLE_SCHEMA) - .build(); + private static final WriteChannelConfiguration LOAD_CONFIGURATION = + WriteChannelConfiguration.builder(TABLE_ID) + .createDisposition(CREATE_DISPOSITION) + .writeDisposition(WRITE_DISPOSITION) + .formatOptions(CSV_OPTIONS) + .ignoreUnknownValues(IGNORE_UNKNOWN_VALUES) + .maxBadRecords(MAX_BAD_RECORDS) + .projectionFields(PROJECTION_FIELDS) + .schema(TABLE_SCHEMA) + .build(); @Test public void testToBuilder() { @@ -106,7 +107,8 @@ public void testToPbAndFromPb() { compareLoadConfiguration(configuration, WriteChannelConfiguration.fromPb(configuration.toPb())); } - private void compareLoadConfiguration(WriteChannelConfiguration expected, WriteChannelConfiguration value) { + private void compareLoadConfiguration(WriteChannelConfiguration expected, + WriteChannelConfiguration value) { assertEquals(expected, value); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); 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 8dc72b5b30a9..9a9f1e42eb07 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 @@ -18,15 +18,14 @@ import com.google.common.collect.ImmutableMap; import com.google.gcloud.WriteChannel; -import com.google.gcloud.bigquery.DefaultTableType; -import com.google.gcloud.bigquery.ExternalTableType; -import com.google.gcloud.bigquery.TableInfo; import com.google.gcloud.bigquery.BigQuery; import com.google.gcloud.bigquery.BigQueryError; import com.google.gcloud.bigquery.BigQueryOptions; 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.ExternalTableDefinition; import com.google.gcloud.bigquery.ExtractJobConfiguration; import com.google.gcloud.bigquery.Field; import com.google.gcloud.bigquery.FieldValue; @@ -34,13 +33,14 @@ import com.google.gcloud.bigquery.JobId; import com.google.gcloud.bigquery.JobInfo; import com.google.gcloud.bigquery.JobStatus; -import com.google.gcloud.bigquery.ViewType; -import com.google.gcloud.bigquery.WriteChannelConfiguration; import com.google.gcloud.bigquery.LoadJobConfiguration; import com.google.gcloud.bigquery.QueryRequest; import com.google.gcloud.bigquery.QueryResponse; import com.google.gcloud.bigquery.Schema; import com.google.gcloud.bigquery.TableId; +import com.google.gcloud.bigquery.TableInfo; +import com.google.gcloud.bigquery.ViewDefinition; +import com.google.gcloud.bigquery.WriteChannelConfiguration; import com.google.gcloud.spi.BigQueryRpc.Tuple; import java.nio.channels.FileChannel; @@ -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 of type - * {@link DefaultTableType}). + * {@link DefaultTableDefinition}). * * @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, DefaultTableType.of(parseSchema(args, 2, args.length))); + return TableInfo.of(tableId, DefaultTableDefinition.of(parseSchema(args, 2, args.length))); } throw new IllegalArgumentException("Missing required arguments."); } @@ -460,7 +460,7 @@ protected String params() { /** * This class demonstrates how to create a BigQuery External Table (i.e. a table of type - * {@link ExternalTableType}). + * {@link ExternalTableDefinition}). * * @see Tables: insert * @@ -472,10 +472,10 @@ TableInfo parse(String... args) throws Exception { String dataset = args[0]; String table = args[1]; TableId tableId = TableId.of(dataset, table); - ExternalTableType externalTableType = - ExternalTableType.of(args[args.length - 1], + ExternalTableDefinition externalTableDefinition = + ExternalTableDefinition.of(args[args.length - 1], parseSchema(args, 3, args.length - 1), FormatOptions.of(args[2])); - return TableInfo.of(tableId, externalTableType); + return TableInfo.of(tableId, externalTableDefinition); } throw new IllegalArgumentException("Missing required arguments."); } @@ -488,7 +488,7 @@ protected String params() { /** * This class demonstrates how to create a BigQuery View Table (i.e. a table of type - * {@link ViewType}). + * {@link ViewDefinition}). * * @see Tables: insert * @@ -502,7 +502,7 @@ TableInfo parse(String... args) throws Exception { String table = args[1]; String query = args[2]; TableId tableId = TableId.of(dataset, table); - return TableInfo.of(tableId, ViewType.of(query)); + return TableInfo.of(tableId, ViewDefinition.of(query)); } else if (args.length < 3) { message = "Missing required dataset id, table id or query."; } else {