1.39.4 (latest) 1.39.3 1.38.0 1.37.0 1.36.0 1.35.2 1.34.7 1.33.1 1.32.0 1.31.1 1.30.3 1.29.0 1.28.3 1.27.0 1.26.1 1.25.1 1.24.2 1.23.10 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](https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query#response-body)

This class should be not instantiated directly, but as a result of
calling [BigQueryClient::runQuery()](https://docs.cloud.google.com/php/docs/reference/cloud-bigquery/latest/BigQueryClient.md.txt#_Google_Cloud_BigQuery_BigQueryClient__runQuery__) or
[Job::queryResults()](https://docs.cloud.google.com/php/docs/reference/cloud-bigquery/latest/Job.md.txt#_Google_Cloud_BigQuery_Job__queryResults__).

## Namespace

Google \\ Cloud \\ BigQuery

## Implements

\\IteratorAggregate

## 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. See [documentation](https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/getQueryResults#query-parameters) for available options. |

### 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](https://docs.cloud.google.com/php/docs/reference/cloud-bigquery/latest/Bytes.md.txt) | `BYTES` |
| [Date](https://docs.cloud.google.com/php/docs/reference/cloud-bigquery/latest/Date.md.txt) | `DATE` |
| [Google\\Cloud\\Core\\Int64](https://docs.cloud.google.com/php/docs/reference/cloud-core/latest/Int64.md.txt) | `INTEGER` |
| [Time](https://docs.cloud.google.com/php/docs/reference/cloud-bigquery/latest/Time.md.txt) | `TIME` |
| [Timestamp](https://docs.cloud.google.com/php/docs/reference/cloud-bigquery/latest/Timestamp.md.txt) | `TIMESTAMP` |
| Associative Array | `RECORD` |
| Non-Associative Array | `RECORD` (Repeated) |
| `float` | `FLOAT` |
| `int` | `INTEGER` |
| `string` | `STRING` |
| `bool` | `BOOLEAN` |

Example:

```php
$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()](https://docs.cloud.google.com/php/docs/reference/cloud-bigquery/latest/BigQueryClient.md.txt#_Google_Cloud_BigQuery_BigQueryClient__runQuery__) or [Job::queryResults()](https://docs.cloud.google.com/php/docs/reference/cloud-bigquery/latest/Job.md.txt#_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. Default is false. |
| `↳ formatOptions.useInt64Timestamp` | `boolean` Optional. Output timestamp as usec int64. Default is false. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Google\Cloud\Core\Iterator\ItemIterator` |   |

### waitUntilComplete

Blocks until the query is complete.

Example:

```php
$queryResults->waitUntilComplete();
```

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `options` | `array` Configuration options. Please note, these options will inherit the values set by either [BigQueryClient::runQuery()](https://docs.cloud.google.com/php/docs/reference/cloud-bigquery/latest/BigQueryClient.md.txt#_Google_Cloud_BigQuery_BigQueryClient__runQuery__) or [Job::queryResults()](https://docs.cloud.google.com/php/docs/reference/cloud-bigquery/latest/Job.md.txt#_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. |
| `↳ formatOptions.useInt64Timestamp` | `boolean` Optional. Output timestamp as usec int64. Default is false. |

### info

See also:

- [Jobs getQueryResults API response documentation.](https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/getQueryResults#response-body)

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array` |   |

### reload

See also:

- [Jobs getQueryResults API documentation.](https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/getQueryResults)

| **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). |
| `↳ formatOptions.useInt64Timestamp` | `boolean` Optional. Output timestamp as usec int64. Default is false. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array` |   |

### identity

Retrieves the query result's identity.

An identity provides a description of a nested resource.

Example:

```php
echo $queryResults->identity()['projectId'];
```

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `array` |   |

### isComplete

Checks the job's completeness.

Useful in combination with [QueryResults::reload()](https://docs.cloud.google.com/php/docs/reference/cloud-bigquery/latest/QueryResults.md.txt#_Google_Cloud_BigQuery_QueryResults__reload__) to poll for
query status.

Example:

```php
$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](https://docs.cloud.google.com/php/docs/reference/cloud-bigquery/latest/Job.md.txt) instance is used to fetch the query results. This is
especially useful when attempting to access job statistics after calling
[BigQueryClient::runQuery()](https://docs.cloud.google.com/php/docs/reference/cloud-bigquery/latest/BigQueryClient.md.txt#_Google_Cloud_BigQuery_BigQueryClient__runQuery__).

Example:

```php
$job = $queryResults->job();
```

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Job` |   |

### getIterator

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `Google\Cloud\Core\Iterator\ItemIterator` |   |