BigQuery Client - Class QueryResults (1.27.0)

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 Google\Cloud\BigQuery\BigQueryClient::runQuery() or Google\Cloud\BigQuery\Job::queryResults().

Namespace

Google \ Cloud \ BigQuery

Methods

__construct

Parameters
NameDescription
connection Google\Cloud\BigQuery\Connection\ConnectionInterface

Represents a connection to BigQuery.

jobId string

The job's ID.

projectId string

The project's ID.

info array

The query result's metadata.

mapper Google\Cloud\BigQuery\ValueMapper

Maps values between PHP and BigQuery.

job Google\Cloud\BigQuery\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 TypeBigQuery Data Type
\DateTimeInterfaceDATETIME
Google\Cloud\BigQuery\BytesBYTES
Google\Cloud\BigQuery\DateDATE
Google\Cloud\Core\Int64INTEGER
Google\Cloud\BigQuery\TimeTIME
Google\Cloud\BigQuery\TimestampTIMESTAMP
Associative ArrayRECORD
Non-Associative ArrayRECORD (Repeated)
floatFLOAT
intINTEGER
stringSTRING
boolBOOLEAN

Example:

$rows = $queryResults->rows();

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

Configuration options. Please note, these options will inherit the values set by either Google\Cloud\BigQuery\BigQueryClient::runQuery() or Google\Cloud\BigQuery\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
TypeDescription
Google\Cloud\Core\Iterator\ItemIterator

waitUntilComplete

Blocks until the query is complete.

Example:

$queryResults->waitUntilComplete();
Parameters
NameDescription
options array

Configuration options. Please note, these options will inherit the values set by either Google\Cloud\BigQuery\BigQueryClient::runQuery() or Google\Cloud\BigQuery\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

Retrieves the cached query details.

Example:

$info = $queryResults->info();
echo $info['totalBytesProcessed'];
Returns
TypeDescription
array

reload

Triggers a network request to reload the query's details.

Example:

$queryResults->reload();
Parameters
NameDescription
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
TypeDescription
array

identity

Retrieves the query result's identity.

An identity provides a description of a nested resource.

Example:

echo $queryResults->identity()['projectId'];
Returns
TypeDescription
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
TypeDescription
bool

job

Returns a reference to the Job instance 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
TypeDescription
Google\Cloud\BigQuery\Job

getIterator

Returns
TypeDescription
Google\Cloud\Core\Iterator\ItemIterator