How to set a timeout for a BigQuery API request in Java

Sometimes, when we conduct a survey for a BigQuery job, our query ends with a SocketTimeoutException . You can see the code throwing the exception below.

 this.bigquery.jobs().get(projectNumber, jobId).execute(); 

And here is the error message we receive.

 ... Caused by: java.net.SocketTimeoutException: Timeout while fetching URL: https://www.googleapis.com/bigquery/v2/projects/######/jobs/###### ... 

My question is is there a way to extend the timeout. And does anyone know what the default timeout is?

+7
java google-app-engine google-bigquery
source share
2 answers

You can wrap the credential object in an HTTP initializer that disables (or extends) timeouts. That is, when you have this:

 Credential credential = ... Bigquery bigquery = new Bigquery(HTTP_TRANSPORT, JSON_FACTORY, credential); 

you could do

 final Credential credential = ... HttpRequestInitializer initializer = new HttpRequestInitializer() { public void initialize(HttpRequest request) { credential.initialize(request); request.connectTimeout = request.readTimeout = 0; } } Bigquery bigquery = new Bigquery(HTTP_TRANSPORT, JSON_FACTORY, initializer); 

See this for the javadoc BigQuery object, this for an example of creating a BigQuery object and this for overloading the HttpRequestInitializer.

+7
source share

If this is a request , only if you want to set a timeout in the request body:

query_config = { 'timeoutMs': 1000,

set ms timeouts on whatever you like, given the reason;)

Hope documentation help here

Edit

To get the results of the query, even if it did not complete the Call jobs.getQueryResults timeout taken from the site, you must specify the start line, and this also requires a timeout that behaves the same as times.query timeout to wait. if the task is not yet completed.

+1
source share

All Articles