Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package com.google.cloud.bigquery;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.api.services.bigquery.model.DatasetReference;
import java.io.Serializable;
Expand All @@ -41,18 +42,19 @@ public String getDataset() {
}

private DatasetId(String project, String dataset) {
checkArgument(!isNullOrEmpty(dataset), "Provided dataset is null or empty");
this.project = project;
this.dataset = dataset;
}

/** Creates a dataset identity given project's and dataset's user-defined ids. */
public static DatasetId of(String project, String dataset) {
return new DatasetId(checkNotNull(project), checkNotNull(dataset));
return new DatasetId(project, dataset);
}

/** Creates a dataset identity given only its user-defined id. */
public static DatasetId of(String dataset) {
return new DatasetId(null, checkNotNull(dataset));
return new DatasetId(null, dataset);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.google.cloud.bigquery;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.api.services.bigquery.model.ExternalDataConfiguration;
import com.google.api.services.bigquery.model.Table;
import com.google.auto.value.AutoValue;
Expand Down Expand Up @@ -295,6 +298,7 @@ public static Builder newBuilder(List<String> sourceUris, Schema schema, FormatO
* Source Format</a>
*/
public static Builder newBuilder(String sourceUri, Schema schema, FormatOptions format) {
checkArgument(!isNullOrEmpty(sourceUri), "Provided sourceUri is null or empty");
return newBuilder(ImmutableList.of(sourceUri), schema, format);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package com.google.cloud.bigquery;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.api.services.bigquery.model.JobConfigurationExtract;
import com.google.common.base.MoreObjects.ToStringHelper;
Expand Down Expand Up @@ -265,7 +267,8 @@ com.google.api.services.bigquery.model.JobConfiguration toPb() {
* URI.
*/
public static Builder newBuilder(TableId sourceTable, String destinationUri) {
return newBuilder(sourceTable, ImmutableList.of(checkNotNull(destinationUri)));
checkArgument(!isNullOrEmpty(destinationUri), "Provided destinationUri is null or empty");
return newBuilder(sourceTable, ImmutableList.of(destinationUri));
}

/**
Expand Down Expand Up @@ -296,6 +299,7 @@ public static ExtractJobConfiguration of(TableId sourceTable, List<String> desti
*/
public static ExtractJobConfiguration of(
TableId sourceTable, String destinationUri, String format) {
checkArgument(!isNullOrEmpty(format), "Provided format is null or empty");
return newBuilder(sourceTable, destinationUri).setFormat(format).build();
}

Expand All @@ -305,6 +309,7 @@ public static ExtractJobConfiguration of(
*/
public static ExtractJobConfiguration of(
TableId sourceTable, List<String> destinationUris, String format) {
checkArgument(!isNullOrEmpty(format), "Provided format is null or empty");
return newBuilder(sourceTable, destinationUris).setFormat(format).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package com.google.cloud.bigquery;

import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.api.client.util.Data;
import com.google.api.services.bigquery.model.TableFieldSchema;
Expand Down Expand Up @@ -262,11 +264,13 @@ public boolean equals(Object obj) {

/** Returns a Field object with given name and type. */
public static Field of(String name, LegacySQLTypeName type, Field... subFields) {
checkArgument(!isNullOrEmpty(name), "Provided name is null or empty");
return newBuilder(name, type, subFields).build();
}

/** Returns a Field object with given name and type. */
public static Field of(String name, LegacySQLTypeName type, FieldList subFields) {
checkArgument(!isNullOrEmpty(name), "Provided name is null or empty");
return newBuilder(name, type, subFields).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package com.google.cloud.bigquery;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.common.base.MoreObjects;
import java.io.Serializable;
Expand Down Expand Up @@ -116,7 +117,8 @@ public static FormatOptions orc() {

/** Default options for the provided format. */
public static FormatOptions of(String format) {
if (checkNotNull(format).equals(CSV)) {
checkArgument(!isNullOrEmpty(format), "Provided format is null or empty");
if (format.equals(CSV)) {
return csv();
} else if (format.equals(DATASTORE_BACKUP)) {
return datastoreBackup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package com.google.cloud.bigquery;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.api.services.bigquery.model.JobReference;
import com.google.auto.value.AutoValue;
Expand Down Expand Up @@ -84,12 +85,15 @@ public Builder setRandomJob() {

/** Creates a job identity given project's and job's user-defined id. */
public static JobId of(String project, String job) {
return newBuilder().setProject(checkNotNull(project)).setJob(checkNotNull(job)).build();
checkArgument(!isNullOrEmpty(project), "Provided project is null or empty");
checkArgument(!isNullOrEmpty(job), "Provided job is null or empty");
return newBuilder().setProject(project).setJob(job).build();
}

/** Creates a job identity given only its user-defined id. */
public static JobId of(String job) {
return newBuilder().setJob(checkNotNull(job)).build();
checkArgument(!isNullOrEmpty(job), "Provided job is null or empty");
return newBuilder().setJob(job).build();
}

/** Creates a job identity with autogenerated id and no project specified. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

package com.google.cloud.bigquery;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.api.services.bigquery.model.ModelReference;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import java.io.Serializable;
import java.util.Objects;

Expand Down Expand Up @@ -62,19 +61,21 @@ public String getModel() {
}

private ModelId(String project, String dataset, String model) {
checkArgument(!isNullOrEmpty(dataset), "Provided dataset is null or empty");
checkArgument(!isNullOrEmpty(model), "Provided model is null or empty");
this.project = project;
this.dataset = dataset;
this.model = model;
}

/** Creates a model identity given project, dataset, and model identifiers. * */
public static ModelId of(String project, String dataset, String model) {
return new ModelId(checkNotNull(project), checkNotNull(dataset), checkNotNull(model));
return new ModelId(project, dataset, model);
}

/** Creates a model identity given dataset and model identifiers. * */
public static ModelId of(String dataset, String model) {
return new ModelId(null, checkNotNull(dataset), checkNotNull(model));
return new ModelId(null, dataset, model);
}

@Override
Expand All @@ -93,8 +94,7 @@ public String toString() {
}

ModelId setProjectId(String projectId) {
Preconditions.checkArgument(
!Strings.isNullOrEmpty(projectId), "Provided projectId is null or empty");
checkArgument(!isNullOrEmpty(projectId), "Provided projectId is null or empty");
return ModelId.of(projectId, getDataset(), getModel());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.api.services.bigquery.model.JobConfigurationQuery;
import com.google.api.services.bigquery.model.QueryParameter;
Expand All @@ -26,7 +27,6 @@
import com.google.cloud.bigquery.JobInfo.WriteDisposition;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
Expand Down Expand Up @@ -796,8 +796,7 @@ public int hashCode() {
@Override
QueryJobConfiguration setProjectId(String projectId) {
Builder builder = toBuilder();
if (getDestinationTable() != null
&& Strings.isNullOrEmpty(getDestinationTable().getProject())) {
if (getDestinationTable() != null && isNullOrEmpty(getDestinationTable().getProject())) {
builder.setDestinationTable(getDestinationTable().setProjectId(projectId));
}
if (getDefaultDataset() != null) {
Expand Down Expand Up @@ -886,6 +885,7 @@ com.google.api.services.bigquery.model.JobConfiguration toPb() {

/** Creates a builder for a BigQuery Query Job given the query to be run. */
public static Builder newBuilder(String query) {
checkArgument(!isNullOrEmpty(query), "Provided query is null or empty");
return new Builder().setQuery(query);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

package com.google.cloud.bigquery;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.api.services.bigquery.model.RoutineReference;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import java.io.Serializable;
import java.util.Objects;

Expand Down Expand Up @@ -63,19 +62,21 @@ public String getRoutine() {
}

private RoutineId(String project, String dataset, String routine) {
checkArgument(!isNullOrEmpty(dataset), "Provided dataset is null or empty");
checkArgument(!isNullOrEmpty(routine), "Provided routine is null or empty");
this.project = project;
this.dataset = dataset;
this.routine = routine;
}

/** Creates a routine identity given project, dataset, and routine identifiers. * */
public static RoutineId of(String project, String dataset, String routine) {
return new RoutineId(checkNotNull(project), checkNotNull(dataset), checkNotNull(routine));
return new RoutineId(project, dataset, routine);
}

/** Creates a routine identity given dataset and routine identifiers. * */
public static RoutineId of(String dataset, String routine) {
return new RoutineId(null, checkNotNull(dataset), checkNotNull(routine));
return new RoutineId(null, dataset, routine);
}

@Override
Expand All @@ -95,8 +96,7 @@ public String toString() {
}

RoutineId setProjectId(String projectId) {
Preconditions.checkArgument(
!Strings.isNullOrEmpty(projectId), "Provided projectId is null or empty");
checkArgument(!isNullOrEmpty(projectId), "Provided projectId is null or empty");
return RoutineId.of(projectId, getDataset(), getRoutine());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

package com.google.cloud.bigquery;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Strings.isNullOrEmpty;

import com.google.api.services.bigquery.model.TableReference;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import java.io.Serializable;
import java.util.Objects;

Expand Down Expand Up @@ -64,19 +64,21 @@ public String getTable() {
}

private TableId(String project, String dataset, String table) {
checkArgument(!isNullOrEmpty(dataset), "Provided dataset is null or empty");
checkArgument(!isNullOrEmpty(table), "Provided table is null or empty");
this.project = project;
this.dataset = dataset;
this.table = table;
}

/** Creates a table identity given project's, dataset's and table's user-defined ids. */
public static TableId of(String project, String dataset, String table) {
return new TableId(checkNotNull(project), checkNotNull(dataset), checkNotNull(table));
return new TableId(checkNotNull(project), dataset, table);
}

/** Creates a table identity given dataset's and table's user-defined ids. */
public static TableId of(String dataset, String table) {
return new TableId(null, checkNotNull(dataset), checkNotNull(table));
return new TableId(null, dataset, table);
}

@Override
Expand All @@ -95,8 +97,7 @@ public String toString() {
}

TableId setProjectId(String projectId) {
Preconditions.checkArgument(
!Strings.isNullOrEmpty(projectId), "Provided projectId is null or empty");
checkArgument(!isNullOrEmpty(projectId), "Provided projectId is null or empty");
return TableId.of(projectId, getDataset(), getTable());
}

Expand Down