diff --git a/google-cloud-bigquery/clirr-ignored-differences.xml b/google-cloud-bigquery/clirr-ignored-differences.xml
index 9ef680c66..37e349413 100644
--- a/google-cloud-bigquery/clirr-ignored-differences.xml
+++ b/google-cloud-bigquery/clirr-ignored-differences.xml
@@ -14,6 +14,13 @@
com.google.api.services.bigquery.model.GetQueryResultsResponse getQueryResultsWithRowLimit(java.lang.String, java.lang.String, java.lang.String, java.lang.Integer)
getQueryResultsWithRowLimit is just used by ConnectionImpl at the moment so it should be fine to update the signature instead of writing an overloaded method
+
+ 7006
+ com/google/cloud/bigquery/BigQueryOptions*
+ *getBigQueryRpcV2(*)
+ com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc
+ getBigQueryRpcV2 is protected and is only used within the BigQuery package
+
7013
com/google/cloud/bigquery/ExternalTableDefinition*
diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryBaseService.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryBaseService.java
index aefb4329b..976015873 100644
--- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryBaseService.java
+++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryBaseService.java
@@ -31,6 +31,7 @@ protected BigQueryBaseService(ServiceOptions options) {
.abortOn(RuntimeException.class)
.retryOn(java.net.ConnectException.class) // retry on Connection Exception
.retryOn(java.net.UnknownHostException.class) // retry on UnknownHostException
+ .retryOn(java.net.SocketException.class) // retry on SocketException
.addInterceptors(EXCEPTION_HANDLER_INTERCEPTOR)
.build();
}
diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java
index 23cb001ac..3db8c88f7 100644
--- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java
+++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryImpl.java
@@ -15,7 +15,6 @@
*/
package com.google.cloud.bigquery;
-import static com.google.cloud.RetryHelper.runWithRetries;
import static com.google.cloud.bigquery.PolicyHelper.convertFromApiPolicy;
import static com.google.cloud.bigquery.PolicyHelper.convertToApiPolicy;
import static com.google.common.base.Preconditions.checkArgument;
@@ -37,13 +36,13 @@
import com.google.cloud.PageImpl;
import com.google.cloud.PageImpl.NextPageFetcher;
import com.google.cloud.Policy;
-import com.google.cloud.RetryHelper;
-import com.google.cloud.RetryHelper.RetryHelperException;
import com.google.cloud.RetryOption;
import com.google.cloud.Tuple;
+import com.google.cloud.bigquery.BigQueryRetryHelper.BigQueryRetryHelperException;
import com.google.cloud.bigquery.InsertAllRequest.RowToInsert;
import com.google.cloud.bigquery.QueryJobConfiguration.JobCreationMode;
import com.google.cloud.bigquery.spi.v2.BigQueryRpc;
+import com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Strings;
@@ -53,6 +52,7 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -242,7 +242,11 @@ public Page getNextPage() {
}
}
- private final BigQueryRpc bigQueryRpc;
+ private final HttpBigQueryRpc bigQueryRpc;
+
+ private static final BigQueryRetryConfig EMPTY_RETRY_CONFIG =
+ BigQueryRetryConfig.newBuilder().build();
+
private static final BigQueryRetryConfig DEFAULT_RETRY_CONFIG =
BigQueryRetryConfig.newBuilder()
.retryOnMessage(BigQueryErrorMessages.RATE_LIMIT_EXCEEDED_MSG)
@@ -268,17 +272,18 @@ public Dataset create(DatasetInfo datasetInfo, DatasetOption... options) {
try {
return Dataset.fromPb(
this,
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Dataset call() {
- return bigQueryRpc.create(datasetPb, optionsMap);
+ public com.google.api.services.bigquery.model.Dataset call() throws IOException {
+ return bigQueryRpc.createSkipExceptionTranslation(datasetPb, optionsMap);
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock()));
- } catch (RetryHelper.RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG));
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -297,17 +302,18 @@ public Table create(TableInfo tableInfo, TableOption... options) {
try {
return Table.fromPb(
this,
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Table call() {
- return bigQueryRpc.create(tablePb, optionsMap);
+ public com.google.api.services.bigquery.model.Table call() throws IOException {
+ return bigQueryRpc.createSkipExceptionTranslation(tablePb, optionsMap);
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock()));
- } catch (RetryHelper.RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG));
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -335,17 +341,18 @@ public Routine create(RoutineInfo routineInfo, RoutineOption... options) {
try {
return Routine.fromPb(
this,
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Routine call() {
- return bigQueryRpc.create(routinePb, optionsMap);
+ public com.google.api.services.bigquery.model.Routine call() throws IOException {
+ return bigQueryRpc.createSkipExceptionTranslation(routinePb, optionsMap);
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock()));
- } catch (RetryHelper.RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG));
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -397,7 +404,7 @@ Job create(JobInfo jobInfo, Supplier idProvider, JobOption... options) {
BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Job call() {
+ public com.google.api.services.bigquery.model.Job call() throws IOException {
if (idRandom) {
// re-generate a new random job with the same jobInfo when jobId is not
// provided by the user
@@ -406,11 +413,11 @@ public com.google.api.services.bigquery.model.Job call() {
com.google.api.services.bigquery.model.Job newJobPb =
recreatedJobInfo.setProjectId(getOptions().getProjectId()).toPb();
finalJobId[0] = recreatedJobInfo.getJobId();
- return bigQueryRpc.create(newJobPb, optionsMap);
+ return bigQueryRpc.createSkipExceptionTranslation(newJobPb, optionsMap);
} else {
com.google.api.services.bigquery.model.Job jobPb =
jobInfo.setProjectId(getOptions().getProjectId()).toPb();
- return bigQueryRpc.create(jobPb, optionsMap);
+ return bigQueryRpc.createSkipExceptionTranslation(jobPb, optionsMap);
}
}
},
@@ -423,7 +430,7 @@ public com.google.api.services.bigquery.model.Job call() {
getBigQueryRetryConfig(optionsMap) != null
? getBigQueryRetryConfig(optionsMap)
: DEFAULT_RETRY_CONFIG));
- } catch (BigQueryRetryHelper.BigQueryRetryHelperException e) {
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
} catch (BigQueryException e) {
@@ -490,22 +497,26 @@ public Dataset getDataset(final DatasetId datasetId, DatasetOption... options) {
final Map optionsMap = optionMap(options);
try {
com.google.api.services.bigquery.model.Dataset answer =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Dataset call() {
- return bigQueryRpc.getDataset(
+ public com.google.api.services.bigquery.model.Dataset call() throws IOException {
+ return bigQueryRpc.getDatasetSkipExceptionTranslation(
completeDatasetId.getProject(), completeDatasetId.getDataset(), optionsMap);
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock());
- if (getOptions().getThrowNotFound() && answer == null) {
- throw new BigQueryException(HTTP_NOT_FOUND, "Dataset not found");
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG);
+ return Dataset.fromPb(this, answer);
+ } catch (BigQueryRetryHelperException e) {
+ if (isRetryErrorCodeHttpNotFound(e)) {
+ if (getOptions().getThrowNotFound()) {
+ throw new BigQueryException(HTTP_NOT_FOUND, "Dataset not found");
+ }
+ return null;
}
- return answer == null ? null : Dataset.fromPb(this, answer);
- } catch (RetryHelper.RetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -526,18 +537,21 @@ private static Page listDatasets(
final Map optionsMap) {
try {
Tuple> result =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable<
Tuple>>() {
@Override
public Tuple>
- call() {
- return serviceOptions.getBigQueryRpcV2().listDatasets(projectId, optionsMap);
+ call() throws IOException {
+ return serviceOptions
+ .getBigQueryRpcV2()
+ .listDatasetsSkipExceptionTranslation(projectId, optionsMap);
}
},
serviceOptions.getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- serviceOptions.getClock());
+ serviceOptions.getClock(),
+ EMPTY_RETRY_CONFIG);
String cursor = result.x();
return new PageImpl<>(
new DatasetPageFetcher(projectId, serviceOptions, cursor, optionsMap),
@@ -550,7 +564,7 @@ public Dataset apply(com.google.api.services.bigquery.model.Dataset dataset) {
return Dataset.fromPb(serviceOptions.getService(), dataset);
}
}));
- } catch (RetryHelper.RetryHelperException e) {
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -565,18 +579,22 @@ public boolean delete(DatasetId datasetId, DatasetDeleteOption... options) {
final DatasetId completeDatasetId = datasetId.setProjectId(getOptions().getProjectId());
final Map optionsMap = optionMap(options);
try {
- return runWithRetries(
+ return BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public Boolean call() {
- return bigQueryRpc.deleteDataset(
+ public Boolean call() throws IOException {
+ return bigQueryRpc.deleteDatasetSkipExceptionTranslation(
completeDatasetId.getProject(), completeDatasetId.getDataset(), optionsMap);
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock());
- } catch (RetryHelper.RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG);
+ } catch (BigQueryRetryHelperException e) {
+ if (isRetryErrorCodeHttpNotFound(e)) {
+ return false;
+ }
throw BigQueryException.translateAndThrow(e);
}
}
@@ -594,11 +612,11 @@ public boolean delete(TableId tableId) {
? getOptions().getProjectId()
: tableId.getProject());
try {
- return runWithRetries(
+ return BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public Boolean call() {
- return bigQueryRpc.deleteTable(
+ public Boolean call() throws IOException {
+ return bigQueryRpc.deleteTableSkipExceptionTranslation(
completeTableId.getProject(),
completeTableId.getDataset(),
completeTableId.getTable());
@@ -606,8 +624,12 @@ public Boolean call() {
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock());
- } catch (RetryHelper.RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG);
+ } catch (BigQueryRetryHelperException e) {
+ if (isRetryErrorCodeHttpNotFound(e)) {
+ return false;
+ }
throw BigQueryException.translateAndThrow(e);
}
}
@@ -620,11 +642,11 @@ public boolean delete(ModelId modelId) {
? getOptions().getProjectId()
: modelId.getProject());
try {
- return runWithRetries(
+ return BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public Boolean call() {
- return bigQueryRpc.deleteModel(
+ public Boolean call() throws IOException {
+ return bigQueryRpc.deleteModelSkipExceptionTranslation(
completeModelId.getProject(),
completeModelId.getDataset(),
completeModelId.getModel());
@@ -632,8 +654,12 @@ public Boolean call() {
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock());
- } catch (RetryHelper.RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG);
+ } catch (BigQueryRetryHelperException e) {
+ if (isRetryErrorCodeHttpNotFound(e)) {
+ return false;
+ }
throw BigQueryException.translateAndThrow(e);
}
}
@@ -646,11 +672,11 @@ public boolean delete(RoutineId routineId) {
? getOptions().getProjectId()
: routineId.getProject());
try {
- return runWithRetries(
+ return BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public Boolean call() {
- return bigQueryRpc.deleteRoutine(
+ public Boolean call() throws IOException {
+ return bigQueryRpc.deleteRoutineSkipExceptionTranslation(
completeRoutineId.getProject(),
completeRoutineId.getDataset(),
completeRoutineId.getRoutine());
@@ -658,8 +684,12 @@ public Boolean call() {
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock());
- } catch (RetryHelper.RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG);
+ } catch (BigQueryRetryHelperException e) {
+ if (isRetryErrorCodeHttpNotFound(e)) {
+ return false;
+ }
throw BigQueryException.translateAndThrow(e);
}
}
@@ -672,18 +702,19 @@ public boolean delete(JobId jobId) {
? getOptions().getProjectId()
: jobId.getProject());
try {
- return runWithRetries(
+ return BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public Boolean call() {
- return bigQueryRpc.deleteJob(
+ public Boolean call() throws IOException {
+ return bigQueryRpc.deleteJobSkipExceptionTranslation(
completeJobId.getProject(), completeJobId.getJob(), completeJobId.getLocation());
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock());
- } catch (RetryHelper.RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG);
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -696,17 +727,18 @@ public Dataset update(DatasetInfo datasetInfo, DatasetOption... options) {
try {
return Dataset.fromPb(
this,
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Dataset call() {
- return bigQueryRpc.patch(datasetPb, optionsMap);
+ public com.google.api.services.bigquery.model.Dataset call() throws IOException {
+ return bigQueryRpc.patchSkipExceptionTranslation(datasetPb, optionsMap);
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock()));
- } catch (RetryHelper.RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG));
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -725,17 +757,18 @@ public Table update(TableInfo tableInfo, TableOption... options) {
try {
return Table.fromPb(
this,
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Table call() {
- return bigQueryRpc.patch(tablePb, optionsMap);
+ public com.google.api.services.bigquery.model.Table call() throws IOException {
+ return bigQueryRpc.patchSkipExceptionTranslation(tablePb, optionsMap);
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock()));
- } catch (RetryHelper.RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG));
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -753,17 +786,18 @@ public Model update(ModelInfo modelInfo, ModelOption... options) {
try {
return Model.fromPb(
this,
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Model call() {
- return bigQueryRpc.patch(modelPb, optionsMap);
+ public com.google.api.services.bigquery.model.Model call() throws IOException {
+ return bigQueryRpc.patchSkipExceptionTranslation(modelPb, optionsMap);
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock()));
- } catch (RetryHelper.RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG));
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -781,17 +815,18 @@ public Routine update(RoutineInfo routineInfo, RoutineOption... options) {
try {
return Routine.fromPb(
this,
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Routine call() {
- return bigQueryRpc.update(routinePb, optionsMap);
+ public com.google.api.services.bigquery.model.Routine call() throws IOException {
+ return bigQueryRpc.updateSkipExceptionTranslation(routinePb, optionsMap);
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock()));
- } catch (RetryHelper.RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG));
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -813,11 +848,11 @@ public Table getTable(TableId tableId, TableOption... options) {
final Map optionsMap = optionMap(options);
try {
com.google.api.services.bigquery.model.Table answer =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Table call() {
- return bigQueryRpc.getTable(
+ public com.google.api.services.bigquery.model.Table call() throws IOException {
+ return bigQueryRpc.getTableSkipExceptionTranslation(
completeTableId.getProject(),
completeTableId.getDataset(),
completeTableId.getTable(),
@@ -826,12 +861,16 @@ public com.google.api.services.bigquery.model.Table call() {
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock());
- if (getOptions().getThrowNotFound() && answer == null) {
- throw new BigQueryException(HTTP_NOT_FOUND, "Table not found");
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG);
+ return Table.fromPb(this, answer);
+ } catch (BigQueryRetryHelperException e) {
+ if (isRetryErrorCodeHttpNotFound(e)) {
+ if (getOptions().getThrowNotFound()) {
+ throw new BigQueryException(HTTP_NOT_FOUND, "Table not found");
+ }
+ return null;
}
- return answer == null ? null : Table.fromPb(this, answer);
- } catch (RetryHelper.RetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -851,11 +890,11 @@ public Model getModel(ModelId modelId, ModelOption... options) {
final Map optionsMap = optionMap(options);
try {
com.google.api.services.bigquery.model.Model answer =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Model call() {
- return bigQueryRpc.getModel(
+ public com.google.api.services.bigquery.model.Model call() throws IOException {
+ return bigQueryRpc.getModelSkipExceptionTranslation(
completeModelId.getProject(),
completeModelId.getDataset(),
completeModelId.getModel(),
@@ -864,12 +903,16 @@ public com.google.api.services.bigquery.model.Model call() {
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock());
- if (getOptions().getThrowNotFound() && answer == null) {
- throw new BigQueryException(HTTP_NOT_FOUND, "Model not found");
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG);
+ return Model.fromPb(this, answer);
+ } catch (BigQueryRetryHelperException e) {
+ if (isRetryErrorCodeHttpNotFound(e)) {
+ if (getOptions().getThrowNotFound()) {
+ throw new BigQueryException(HTTP_NOT_FOUND, "Model not found");
+ }
+ return null;
}
- return answer == null ? null : Model.fromPb(this, answer);
- } catch (RetryHelper.RetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -889,11 +932,11 @@ public Routine getRoutine(RoutineId routineId, RoutineOption... options) {
final Map optionsMap = optionMap(options);
try {
com.google.api.services.bigquery.model.Routine answer =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Routine call() {
- return bigQueryRpc.getRoutine(
+ public com.google.api.services.bigquery.model.Routine call() throws IOException {
+ return bigQueryRpc.getRoutineSkipExceptionTranslation(
completeRoutineId.getProject(),
completeRoutineId.getDataset(),
completeRoutineId.getRoutine(),
@@ -902,12 +945,16 @@ public com.google.api.services.bigquery.model.Routine call() {
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock());
- if (getOptions().getThrowNotFound() && answer == null) {
- throw new BigQueryException(HTTP_NOT_FOUND, "Routine not found");
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG);
+ return Routine.fromPb(this, answer);
+ } catch (BigQueryRetryHelperException e) {
+ if (isRetryErrorCodeHttpNotFound(e)) {
+ if (getOptions().getThrowNotFound()) {
+ throw new BigQueryException(HTTP_NOT_FOUND, "Routine not found");
+ }
+ return null;
}
- return answer == null ? null : Routine.fromPb(this, answer);
- } catch (RetryHelper.RetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -978,20 +1025,22 @@ private static Page listTables(
final Map optionsMap) {
try {
Tuple> result =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable<
Tuple>>() {
@Override
- public Tuple>
- call() {
+ public Tuple> call()
+ throws IOException {
return serviceOptions
.getBigQueryRpcV2()
- .listTables(datasetId.getProject(), datasetId.getDataset(), optionsMap);
+ .listTablesSkipExceptionTranslation(
+ datasetId.getProject(), datasetId.getDataset(), optionsMap);
}
},
serviceOptions.getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- serviceOptions.getClock());
+ serviceOptions.getClock(),
+ EMPTY_RETRY_CONFIG);
String cursor = result.x();
Iterable tables =
Iterables.transform(
@@ -1004,7 +1053,7 @@ public Table apply(com.google.api.services.bigquery.model.Table table) {
});
return new PageImpl<>(
new TablePageFetcher(datasetId, serviceOptions, cursor, optionsMap), cursor, tables);
- } catch (RetryHelper.RetryHelperException e) {
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -1015,20 +1064,22 @@ private static Page listModels(
final Map optionsMap) {
try {
Tuple> result =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable<
Tuple>>() {
@Override
- public Tuple>
- call() {
+ public Tuple> call()
+ throws IOException {
return serviceOptions
.getBigQueryRpcV2()
- .listModels(datasetId.getProject(), datasetId.getDataset(), optionsMap);
+ .listModelsSkipExceptionTranslation(
+ datasetId.getProject(), datasetId.getDataset(), optionsMap);
}
},
serviceOptions.getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- serviceOptions.getClock());
+ serviceOptions.getClock(),
+ EMPTY_RETRY_CONFIG);
String cursor = result.x();
Iterable models =
Iterables.transform(
@@ -1041,7 +1092,7 @@ public Model apply(com.google.api.services.bigquery.model.Model model) {
});
return new PageImpl<>(
new ModelPageFetcher(datasetId, serviceOptions, cursor, optionsMap), cursor, models);
- } catch (RetryHelper.RetryHelperException e) {
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -1052,20 +1103,22 @@ private static Page listRoutines(
final Map optionsMap) {
try {
Tuple> result =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable<
Tuple>>() {
@Override
public Tuple>
- call() {
+ call() throws IOException {
return serviceOptions
.getBigQueryRpcV2()
- .listRoutines(datasetId.getProject(), datasetId.getDataset(), optionsMap);
+ .listRoutinesSkipExceptionTranslation(
+ datasetId.getProject(), datasetId.getDataset(), optionsMap);
}
},
serviceOptions.getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- serviceOptions.getClock());
+ serviceOptions.getClock(),
+ EMPTY_RETRY_CONFIG);
String cursor = result.x();
Iterable routines =
Iterables.transform(
@@ -1078,7 +1131,7 @@ public Routine apply(com.google.api.services.bigquery.model.Routine routinePb) {
});
return new PageImpl<>(
new RoutinePageFetcher(datasetId, serviceOptions, cursor, optionsMap), cursor, routines);
- } catch (RetryHelper.RetryHelperException e) {
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -1120,21 +1173,23 @@ public Rows apply(RowToInsert rowToInsert) {
// allowing retries only if all row insertIds are set (used for deduplication)
try {
responsePb =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
public TableDataInsertAllResponse call() throws Exception {
- return bigQueryRpc.insertAll(
+ return bigQueryRpc.insertAllSkipExceptionTranslation(
tableId.getProject(), tableId.getDataset(), tableId.getTable(), requestPb);
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock());
- } catch (RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG);
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
} else {
+ // Use insertAll that translate the exception as we are not retrying.
responsePb =
bigQueryRpc.insertAll(
tableId.getProject(), tableId.getDataset(), tableId.getTable(), requestPb);
@@ -1183,13 +1238,13 @@ private static Tuple extends Page, Long> listTableData(
? serviceOptions.getProjectId()
: tableId.getProject());
TableDataList result =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public TableDataList call() {
+ public TableDataList call() throws IOException {
return serviceOptions
.getBigQueryRpcV2()
- .listTableData(
+ .listTableDataSkipExceptionTranslation(
completeTableId.getProject(),
completeTableId.getDataset(),
completeTableId.getTable(),
@@ -1198,7 +1253,8 @@ public TableDataList call() {
},
serviceOptions.getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- serviceOptions.getClock());
+ serviceOptions.getClock(),
+ EMPTY_RETRY_CONFIG);
String cursor = result.getPageToken();
Map pageOptionMap =
Strings.isNullOrEmpty(cursor) ? optionsMap : optionMap(TableDataListOption.startIndex(0));
@@ -1208,7 +1264,7 @@ public TableDataList call() {
cursor,
transformTableData(result.getRows(), schema, serviceOptions.getUseInt64Timestamps())),
result.getTotalRows());
- } catch (RetryHelper.RetryHelperException e) {
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -1245,11 +1301,11 @@ public Job getJob(JobId jobId, JobOption... options) {
: jobId.getLocation());
try {
com.google.api.services.bigquery.model.Job answer =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Job call() {
- return bigQueryRpc.getJob(
+ public com.google.api.services.bigquery.model.Job call() throws IOException {
+ return bigQueryRpc.getJobSkipExceptionTranslation(
completeJobId.getProject(),
completeJobId.getJob(),
completeJobId.getLocation(),
@@ -1258,12 +1314,16 @@ public com.google.api.services.bigquery.model.Job call() {
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock());
- if (getOptions().getThrowNotFound() && answer == null) {
- throw new BigQueryException(HTTP_NOT_FOUND, "Job not found");
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG);
+ return Job.fromPb(this, answer);
+ } catch (BigQueryRetryHelperException e) {
+ if (isRetryErrorCodeHttpNotFound(e)) {
+ if (getOptions().getThrowNotFound()) {
+ throw new BigQueryException(HTTP_NOT_FOUND, "Job not found");
+ }
+ return null;
}
- return answer == null ? null : Job.fromPb(this, answer);
- } catch (RetryHelper.RetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -1275,30 +1335,36 @@ public Page listJobs(JobListOption... options) {
private static Page listJobs(
final BigQueryOptions serviceOptions, final Map optionsMap) {
- Tuple> result =
- runWithRetries(
- new Callable>>() {
- @Override
- public Tuple> call() {
- return serviceOptions
- .getBigQueryRpcV2()
- .listJobs(serviceOptions.getProjectId(), optionsMap);
- }
- },
- serviceOptions.getRetrySettings(),
- BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- serviceOptions.getClock());
- String cursor = result.x();
- Iterable jobs =
- Iterables.transform(
- result.y(),
- new Function() {
- @Override
- public Job apply(com.google.api.services.bigquery.model.Job job) {
- return Job.fromPb(serviceOptions.getService(), job);
- }
- });
- return new PageImpl<>(new JobPageFetcher(serviceOptions, cursor, optionsMap), cursor, jobs);
+ try {
+ Tuple> result =
+ BigQueryRetryHelper.runWithRetries(
+ new Callable>>() {
+ @Override
+ public Tuple> call()
+ throws IOException {
+ return serviceOptions
+ .getBigQueryRpcV2()
+ .listJobsSkipExceptionTranslation(serviceOptions.getProjectId(), optionsMap);
+ }
+ },
+ serviceOptions.getRetrySettings(),
+ BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
+ serviceOptions.getClock(),
+ EMPTY_RETRY_CONFIG);
+ String cursor = result.x();
+ Iterable jobs =
+ Iterables.transform(
+ result.y(),
+ new Function() {
+ @Override
+ public Job apply(com.google.api.services.bigquery.model.Job job) {
+ return Job.fromPb(serviceOptions.getService(), job);
+ }
+ });
+ return new PageImpl<>(new JobPageFetcher(serviceOptions, cursor, optionsMap), cursor, jobs);
+ } catch (BigQueryRetryHelperException e) {
+ throw BigQueryException.translateAndThrow(e);
+ }
}
@Override
@@ -1316,18 +1382,22 @@ public boolean cancel(JobId jobId) {
? getOptions().getLocation()
: jobId.getLocation());
try {
- return runWithRetries(
+ return BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public Boolean call() {
- return bigQueryRpc.cancel(
+ public Boolean call() throws IOException {
+ return bigQueryRpc.cancelSkipExceptionTranslation(
completeJobId.getProject(), completeJobId.getJob(), completeJobId.getLocation());
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock());
- } catch (RetryHelper.RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG);
+ } catch (BigQueryRetryHelperException e) {
+ if (isRetryErrorCodeHttpNotFound(e)) {
+ return false;
+ }
throw BigQueryException.translateAndThrow(e);
}
}
@@ -1370,8 +1440,9 @@ private TableResult queryRpc(
BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.QueryResponse call() {
- return bigQueryRpc.queryRpc(projectId, content);
+ public com.google.api.services.bigquery.model.QueryResponse call()
+ throws IOException {
+ return bigQueryRpc.queryRpcSkipExceptionTranslation(projectId, content);
}
},
getOptions().getRetrySettings(),
@@ -1498,10 +1569,10 @@ private static QueryResponse getQueryResults(
BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public GetQueryResultsResponse call() {
+ public GetQueryResultsResponse call() throws IOException {
return serviceOptions
.getBigQueryRpcV2()
- .getQueryResults(
+ .getQueryResultsSkipExceptionTranslation(
completeJobId.getProject(),
completeJobId.getJob(),
completeJobId.getLocation(),
@@ -1528,7 +1599,7 @@ public GetQueryResultsResponse call() {
.setTotalRows(results.getTotalRows() == null ? 0 : results.getTotalRows().longValue())
.setErrors(errors.build())
.build();
- } catch (BigQueryRetryHelper.BigQueryRetryHelperException e) {
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -1558,17 +1629,19 @@ public Policy getIamPolicy(TableId tableId, IAMOption... options) {
try {
final Map optionsMap = optionMap(options);
return convertFromApiPolicy(
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Policy call() {
- return bigQueryRpc.getIamPolicy(completeTableId.getIAMResourceName(), optionsMap);
+ public com.google.api.services.bigquery.model.Policy call() throws IOException {
+ return bigQueryRpc.getIamPolicySkipExceptionTranslation(
+ completeTableId.getIAMResourceName(), optionsMap);
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock()));
- } catch (RetryHelper.RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG));
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -1583,18 +1656,19 @@ public Policy setIamPolicy(TableId tableId, final Policy policy, IAMOption... op
try {
final Map optionsMap = optionMap(options);
return convertFromApiPolicy(
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Policy call() {
- return bigQueryRpc.setIamPolicy(
+ public com.google.api.services.bigquery.model.Policy call() throws IOException {
+ return bigQueryRpc.setIamPolicySkipExceptionTranslation(
completeTableId.getIAMResourceName(), convertToApiPolicy(policy), optionsMap);
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock()));
- } catch (RetryHelperException e) {
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG));
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -1610,21 +1684,23 @@ public List testIamPermissions(
try {
final Map optionsMap = optionMap(options);
com.google.api.services.bigquery.model.TestIamPermissionsResponse response =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.TestIamPermissionsResponse call() {
- return bigQueryRpc.testIamPermissions(
+ public com.google.api.services.bigquery.model.TestIamPermissionsResponse call()
+ throws IOException {
+ return bigQueryRpc.testIamPermissionsSkipExceptionTranslation(
completeTableId.getIAMResourceName(), permissions, optionsMap);
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock());
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG);
return response.getPermissions() == null
? ImmutableList.of()
: ImmutableList.copyOf(response.getPermissions());
- } catch (RetryHelperException e) {
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -1647,4 +1723,13 @@ static BigQueryRetryConfig getBigQueryRetryConfig(Map opt
static RetryOption[] getRetryOptions(Map options) {
return (RetryOption[]) options.getOrDefault(BigQueryRpc.Option.RETRY_OPTIONS, null);
}
+
+ private static boolean isRetryErrorCodeHttpNotFound(BigQueryRetryHelperException e) {
+ if (e.getCause() instanceof BigQueryException) {
+ if (((BigQueryException) e.getCause()).getCode() == HTTP_NOT_FOUND) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java
index 465cc8305..ca34a2d2d 100644
--- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java
+++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java
@@ -21,7 +21,6 @@
import com.google.cloud.ServiceRpc;
import com.google.cloud.TransportOptions;
import com.google.cloud.bigquery.spi.BigQueryRpcFactory;
-import com.google.cloud.bigquery.spi.v2.BigQueryRpc;
import com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc;
import com.google.cloud.http.HttpTransportOptions;
import com.google.common.annotations.VisibleForTesting;
@@ -132,8 +131,8 @@ protected Set getScopes() {
return SCOPES;
}
- protected BigQueryRpc getBigQueryRpcV2() {
- return (BigQueryRpc) getRpc();
+ protected HttpBigQueryRpc getBigQueryRpcV2() {
+ return (HttpBigQueryRpc) getRpc();
}
public String getLocation() {
diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryRetryHelper.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryRetryHelper.java
index 405a2371e..d315241a3 100644
--- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryRetryHelper.java
+++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryRetryHelper.java
@@ -25,6 +25,7 @@
import com.google.api.gax.retrying.RetryingFuture;
import com.google.api.gax.retrying.TimedRetryAlgorithm;
import com.google.cloud.RetryHelper;
+import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
@@ -52,6 +53,11 @@ public static V runWithRetries(
algorithm,
bigQueryRetryConfig);
} catch (Exception e) {
+ // Checks for IOException and translate it into BigQueryException. The BigQueryException
+ // constructor parses the IOException and translate it into internal code.
+ if (e.getCause() instanceof IOException) {
+ throw new BigQueryRetryHelperException(new BigQueryException((IOException) e.getCause()));
+ }
throw new BigQueryRetryHelperException(e.getCause());
}
}
diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ConnectionImpl.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ConnectionImpl.java
index 5ad9fe284..d524cedfc 100644
--- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ConnectionImpl.java
+++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/ConnectionImpl.java
@@ -16,7 +16,6 @@
package com.google.cloud.bigquery;
-import static com.google.cloud.RetryHelper.runWithRetries;
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
import com.google.api.core.BetaApi;
@@ -28,8 +27,8 @@
import com.google.api.services.bigquery.model.QueryRequest;
import com.google.api.services.bigquery.model.TableDataList;
import com.google.api.services.bigquery.model.TableRow;
-import com.google.cloud.RetryHelper;
import com.google.cloud.Tuple;
+import com.google.cloud.bigquery.BigQueryRetryHelper.BigQueryRetryHelperException;
import com.google.cloud.bigquery.JobStatistics.QueryStatistics;
import com.google.cloud.bigquery.JobStatistics.SessionInfo;
import com.google.cloud.bigquery.spi.v2.BigQueryRpc;
@@ -102,6 +101,8 @@ class ConnectionImpl implements Connection {
bufferFvl; // initialized lazily iff we end up using the tabledata.list end point
private BlockingQueue
bufferRow; // initialized lazily iff we end up using Read API
+ private static final BigQueryRetryConfig EMPTY_RETRY_CONFIG =
+ BigQueryRetryConfig.newBuilder().build();
ConnectionImpl(
ConnectionSettings connectionSettings,
@@ -466,12 +467,15 @@ private BigQueryResult queryRpc(
try {
results =
BigQueryRetryHelper.runWithRetries(
- () -> bigQueryRpc.queryRpc(projectId, queryRequest),
+ () ->
+ bigQueryOptions
+ .getBigQueryRpcV2()
+ .queryRpcSkipExceptionTranslation(projectId, queryRequest),
bigQueryOptions.getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
bigQueryOptions.getClock(),
retryConfig);
- } catch (BigQueryRetryHelper.BigQueryRetryHelperException e) {
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
@@ -914,21 +918,30 @@ private Job getQueryJobRpc(JobId jobId) {
com.google.api.services.bigquery.model.Job jobPb;
try {
jobPb =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
() ->
- bigQueryRpc.getQueryJob(
- completeJobId.getProject(),
- completeJobId.getJob(),
- completeJobId.getLocation()),
+ bigQueryOptions
+ .getBigQueryRpcV2()
+ .getQueryJobSkipExceptionTranslation(
+ completeJobId.getProject(),
+ completeJobId.getJob(),
+ completeJobId.getLocation()),
bigQueryOptions.getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- bigQueryOptions.getClock());
- if (bigQueryOptions.getThrowNotFound() && jobPb == null) {
- throw new BigQueryException(HTTP_NOT_FOUND, "Query job not found");
+ bigQueryOptions.getClock(),
+ EMPTY_RETRY_CONFIG);
+ } catch (BigQueryRetryHelperException e) {
+ if (e.getCause() instanceof BigQueryException) {
+ if (((BigQueryException) e.getCause()).getCode() == HTTP_NOT_FOUND) {
+ if (bigQueryOptions.getThrowNotFound()) {
+ throw new BigQueryException(HTTP_NOT_FOUND, "Query job not found");
+ }
+ return null;
+ }
}
- } catch (RetryHelper.RetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
+ // getQueryJobSkipExceptionTranslation will never return null so this is safe.
return Job.fromPb(bigQueryOptions.getService(), jobPb);
}
@@ -948,11 +961,11 @@ TableDataList tableDataListRpc(TableId destinationTable, String pageToken) {
? bigQueryOptions.getProjectId()
: destinationTable.getProject());
TableDataList results =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
() ->
bigQueryOptions
.getBigQueryRpcV2()
- .listTableDataWithRowLimit(
+ .listTableDataWithRowLimitSkipExceptionTranslation(
completeTableId.getProject(),
completeTableId.getDataset(),
completeTableId.getTable(),
@@ -960,10 +973,11 @@ TableDataList tableDataListRpc(TableId destinationTable, String pageToken) {
pageToken),
bigQueryOptions.getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- bigQueryOptions.getClock());
+ bigQueryOptions.getClock(),
+ EMPTY_RETRY_CONFIG);
return results;
- } catch (RetryHelper.RetryHelperException e) {
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -1177,12 +1191,14 @@ GetQueryResultsResponse getQueryResultsFirstPage(JobId jobId) {
results =
BigQueryRetryHelper.runWithRetries(
() ->
- bigQueryRpc.getQueryResultsWithRowLimit(
- completeJobId.getProject(),
- completeJobId.getJob(),
- completeJobId.getLocation(),
- connectionSettings.getMaxResultPerPage(),
- timeoutMs),
+ bigQueryOptions
+ .getBigQueryRpcV2()
+ .getQueryResultsWithRowLimitSkipExceptionTranslation(
+ completeJobId.getProject(),
+ completeJobId.getJob(),
+ completeJobId.getLocation(),
+ connectionSettings.getMaxResultPerPage(),
+ timeoutMs),
bigQueryOptions.getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
bigQueryOptions.getClock(),
@@ -1197,7 +1213,7 @@ GetQueryResultsResponse getQueryResultsFirstPage(JobId jobId) {
// with the case where there is a HTTP error
throw new BigQueryException(bigQueryErrors);
}
- } catch (BigQueryRetryHelper.BigQueryRetryHelperException e) {
+ } catch (BigQueryRetryHelperException e) {
logger.log(Level.WARNING, "\n Error occurred while calling getQueryResultsWithRowLimit", e);
throw BigQueryException.translateAndThrow(e);
}
@@ -1442,7 +1458,10 @@ com.google.api.services.bigquery.model.Job createQueryJob(
try {
queryJob =
BigQueryRetryHelper.runWithRetries(
- () -> bigQueryRpc.createJobForQuery(jobPb),
+ () ->
+ bigQueryOptions
+ .getBigQueryRpcV2()
+ .createJobForQuerySkipExceptionTranslation(jobPb),
bigQueryOptions.getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
bigQueryOptions.getClock(),
@@ -1482,7 +1501,10 @@ com.google.api.services.bigquery.model.Job createDryRunJob(String sql) {
try {
dryRunJob =
BigQueryRetryHelper.runWithRetries(
- () -> bigQueryRpc.createJobForQuery(jobPb),
+ () ->
+ bigQueryOptions
+ .getBigQueryRpcV2()
+ .createJobForQuerySkipExceptionTranslation(jobPb),
bigQueryOptions.getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
bigQueryOptions.getClock(),
diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableDataWriteChannel.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableDataWriteChannel.java
index 0f9632aea..aabd87d47 100644
--- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableDataWriteChannel.java
+++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/TableDataWriteChannel.java
@@ -16,12 +16,11 @@
package com.google.cloud.bigquery;
-import static com.google.cloud.RetryHelper.runWithRetries;
-
import com.google.cloud.BaseWriteChannel;
import com.google.cloud.RestorableState;
-import com.google.cloud.RetryHelper;
import com.google.cloud.WriteChannel;
+import com.google.cloud.bigquery.BigQueryRetryHelper.BigQueryRetryHelperException;
+import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
@@ -34,6 +33,9 @@
public class TableDataWriteChannel
extends BaseWriteChannel {
+ private static final BigQueryRetryConfig EMPTY_RETRY_CONFIG =
+ BigQueryRetryConfig.newBuilder().build();
+
private Job job;
TableDataWriteChannel(
@@ -50,20 +52,22 @@ public class TableDataWriteChannel
protected void flushBuffer(final int length, final boolean last) {
try {
com.google.api.services.bigquery.model.Job jobPb =
- runWithRetries(
+ BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public com.google.api.services.bigquery.model.Job call() {
+ public com.google.api.services.bigquery.model.Job call() throws IOException {
return getOptions()
.getBigQueryRpcV2()
- .write(getUploadId(), getBuffer(), 0, getPosition(), length, last);
+ .writeSkipExceptionTranslation(
+ getUploadId(), getBuffer(), 0, getPosition(), length, last);
}
},
getOptions().getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- getOptions().getClock());
+ getOptions().getClock(),
+ EMPTY_RETRY_CONFIG);
job = jobPb != null ? Job.fromPb(getOptions().getService(), jobPb) : null;
- } catch (RetryHelper.RetryHelperException e) {
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
@@ -78,13 +82,13 @@ private static String open(
final JobId jobId,
final WriteChannelConfiguration writeChannelConfiguration) {
try {
- return runWithRetries(
+ return BigQueryRetryHelper.runWithRetries(
new Callable() {
@Override
- public String call() {
+ public String call() throws IOException {
return options
.getBigQueryRpcV2()
- .open(
+ .openSkipExceptionTranslation(
new com.google.api.services.bigquery.model.Job()
.setConfiguration(writeChannelConfiguration.toPb())
.setJobReference(jobId.toPb()));
@@ -92,8 +96,9 @@ public String call() {
},
options.getRetrySettings(),
BigQueryBaseService.BIGQUERY_EXCEPTION_HANDLER,
- options.getClock());
- } catch (RetryHelper.RetryHelperException e) {
+ options.getClock(),
+ EMPTY_RETRY_CONFIG);
+ } catch (BigQueryRetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
}
}
diff --git a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java
index 3946f83f5..14a14fdb9 100644
--- a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java
+++ b/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java
@@ -129,20 +129,7 @@ private void validateRPC() throws BigQueryException, IOException {
@Override
public Dataset getDataset(String projectId, String datasetId, Map