public final class QueryRequest extends Object implements Serializable
QueryResponse.getJobId()
. If
the query does not complete within the provided QueryRequest.Builder.setMaxWaitTime(Long)
, the
response returned by BigQuery.query(QueryRequest)
will have
QueryResponse.jobCompleted()
set to false
and QueryResponse.getResult()
set to null
. To obtain query results you can use
BigQuery.getQueryResults(JobId, BigQuery.QueryResultsOption...)
until
QueryResponse.jobCompleted()
returns true
.
Example usage of a query request:
// Substitute "field", "table" and "dataset" with real field, table and dataset identifiers
QueryRequest request = QueryRequest.newBuilder("SELECT field FROM table")
.setDefaultDataset(DatasetId.of("dataset"))
.setMaxWaitTime(60000L)
.setPageSize(1000L)
.build();
QueryResponse response = bigquery.query(request);
while (!response.jobCompleted()) {
Thread.sleep(1000);
response = bigquery.getQueryResults(response.getJobId());
}
List<BigQueryError> executionErrors = response.getExecutionErrors();
// look for errors in executionErrors
QueryResult result = response.getResult();
Iterator<List<FieldValue>> rowIterator = result.iterateAll();
while(rowIterator.hasNext()) {
List<FieldValue> row = rowIterator.next();
// do something with row
}
Modifier and Type | Class and Description |
---|---|
static class |
QueryRequest.Builder |
Modifier and Type | Method and Description |
---|---|
static QueryRequest.Builder |
builder(String query)
Deprecated.
|
DatasetId |
defaultDataset()
Deprecated.
|
Boolean |
dryRun()
Returns whether the query has to be dry run or not.
|
boolean |
equals(Object obj) |
DatasetId |
getDefaultDataset()
Returns the default dataset to assume for any unqualified table names in the query.
|
Long |
getMaxWaitTime()
Returns how long to wait for the query to complete, in milliseconds, before the request times
out and returns.
|
Map<String,QueryParameterValue> |
getNamedParameters()
Returns the named query parameters to use for the query.
|
Long |
getPageSize()
Returns the maximum number of rows of data to return per page of results.
|
List<QueryParameterValue> |
getPositionalParameters()
Returns the positional query parameters to use for the query.
|
String |
getQuery()
Sets the BigQuery query to be executed.
|
int |
hashCode() |
Long |
maxWaitTime()
Deprecated.
|
static QueryRequest.Builder |
newBuilder(String query)
Creates a builder for a
QueryRequest given the BigQuery SQL query to be executed. |
static QueryRequest |
of(String query)
Creates a
QueryRequest object given the BigQuery SQL query to be executed. |
Long |
pageSize()
Deprecated.
|
String |
query()
Deprecated.
|
QueryRequest.Builder |
toBuilder()
Returns a builder for the
QueryRequest object. |
String |
toString() |
Boolean |
useLegacySql()
Returns whether to use BigQuery's legacy SQL dialect for this query.
|
Boolean |
useQueryCache()
Returns whether to look for the result in the query cache.
|
@Deprecated public String query()
public String getQuery()
public List<QueryParameterValue> getPositionalParameters()
public Map<String,QueryParameterValue> getNamedParameters()
@Deprecated public Long pageSize()
public Long getPageSize()
@Deprecated public DatasetId defaultDataset()
public DatasetId getDefaultDataset()
@Deprecated public Long maxWaitTime()
QueryResponse.jobCompleted()
set to false
. You can call
BigQuery.getQueryResults(JobId, BigQuery.QueryResultsOption...)
to wait for the query
to complete and read the results. If not set, a wait time of 10000 milliseconds (10 seconds)
is used.public Long getMaxWaitTime()
QueryResponse.jobCompleted()
set to false
. You can call
BigQuery.getQueryResults(JobId, BigQuery.QueryResultsOption...)
to wait for the query
to complete and read the results. If not set, a wait time of 10000 milliseconds (10 seconds)
is used.public Boolean dryRun()
public Boolean useQueryCache()
public Boolean useLegacySql()
false
,
the query will use BigQuery's
Standard SQL. If not set, legacy SQL dialect is used. This property is experimental and
might be subject to change.public QueryRequest.Builder toBuilder()
QueryRequest
object.@Deprecated public static QueryRequest.Builder builder(String query)
QueryRequest
given the BigQuery SQL query to be executed.public static QueryRequest.Builder newBuilder(String query)
QueryRequest
given the BigQuery SQL query to be executed.public static QueryRequest of(String query)
QueryRequest
object given the BigQuery SQL query to be executed.Copyright © 2017 Google. All rights reserved.