BigQuery Client - Class QueryResults (1.31.1)

Reference documentation and code samples for the BigQuery Client class QueryResults.

QueryResults represent the result of a BigQuery SQL query. Read more at the Query Response API Documentation

This class should be not instantiated directly, but as a result of calling BigQueryClient::runQuery() or Job::queryResults().

Namespace

Google \ Cloud \ BigQuery

Methods

__construct

Parameters
Name Description
connection Connection\ConnectionInterface

Represents a connection to BigQuery. This object is created by BigQueryClient, and should not be instantiated outside of this client.

jobId string

The job's ID.

projectId string

The project's ID.

info array

The query result's metadata.

mapper ValueMapper

Maps values between PHP and BigQuery.

job Job

The job from which the query results originated.

queryResultsOptions array

Default options to be used for calls to get query results.

rows

Retrieves the rows associated with the query and merges them together with the table's schema.

Refer to the table below for a guide on how BigQuery types are mapped as they come back from the API.

PHP Type BigQuery Data Type
\DateTimeInterface DATETIME
Bytes BYTES
Date DATE
Google\Cloud\Core\Int64 INTEGER
Time TIME
Timestamp TIMESTAMP
Associative Array RECORD
Non-Associative Array RECORD (Repeated)
float FLOAT
int INTEGER
string STRING
bool BOOLEAN

Example:

$rows = $queryResults->rows();

foreach ($rows as $row) {
    echo $row['name'] . PHP_EOL;
}
Parameters
Name Description
options array

Configuration options. Please note, these options will inherit the values set by either BigQueryClient::runQuery() or Job::queryResults().

↳ maxResults int

Maximum number of results to read per page.

↳ startIndex int

Zero-based index of the starting row.

↳ timeoutMs int

How long, in milliseconds, each API call will wait for query results to become available before timing out. Depending on whether the $maxRetries has been exceeded, the results will be polled again after the timeout has been reached. Defaults to 10000 milliseconds (10 seconds).

↳ maxRetries int

The number of times to poll the Job status, until the job is complete. By default, will poll indefinitely.

↳ returnRawResults bool

Returns the raw data types returned from BigQuery without converting their values into native PHP types or the custom type classes supported by this library.

Returns
Type Description
Google\Cloud\Core\Iterator\ItemIterator

waitUntilComplete

Blocks until the query is complete.

Example:

$queryResults->waitUntilComplete();
Parameters
Name Description
options array

Configuration options. Please note, these options will inherit the values set by either BigQueryClient::runQuery() or Job::queryResults().

↳ maxResults int

Maximum number of results to read per page.

↳ startIndex int

Zero-based index of the starting row.

↳ timeoutMs int

How long, in milliseconds, each API call will wait for query results to become available before timing out. Depending on whether the $maxRetries has been exceeded, the results will be polled again after the timeout has been reached. Defaults to 10000 milliseconds (10 seconds).

↳ maxRetries int

The number of times to poll the Job status, until the job is complete. By default, will poll indefinitely.

info

Returns
Type Description
array

reload

Parameters
Name Description
options array

Configuration options.

↳ maxResults int

Maximum number of results to read per page.

↳ startIndex int

Zero-based index of the starting row.

↳ timeoutMs int

How long to wait for the query to complete, in milliseconds. Defaults to 10000 milliseconds (10 seconds).

Returns
Type Description
array

identity

Retrieves the query result's identity.

An identity provides a description of a nested resource.

Example:

echo $queryResults->identity()['projectId'];
Returns
Type Description
array

isComplete

Checks the job's completeness.

Useful in combination with QueryResults::reload() to poll for query status.

Example:

$isComplete = $queryResults->isComplete();

while (!$isComplete) {
    sleep(1); // let's wait for a moment...
    $queryResults->reload();
    $isComplete = $queryResults->isComplete();
}

echo 'Query complete!';
Returns
Type Description
bool

job

Returns a reference to the job.

The Job instance is used to fetch the query results. This is especially useful when attempting to access job statistics after calling BigQueryClient::runQuery().

Example:

$job = $queryResults->job();
Returns
Type Description
Job

getIterator

Returns
Type Description
Google\Cloud\Core\Iterator\ItemIterator