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 {@see} or {@see}.
Methods
__construct
Parameters | |
---|---|
Name | Description |
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 Type | BigQuery Data Type |
---|---|
\DateTimeInterface | DATETIME |
{@see} | BYTES |
{@see} | DATE |
{@see} | INTEGER |
{@see} | TIME |
{@see} | 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 {@see} or {@see}. |
↳ 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 |
↳ 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 {@see} or {@see}. |
↳ 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 |
↳ 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 | |
---|---|
Type | Description |
array |
reload
Triggers a network request to reload the query's details.
Example:
$queryResults->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 |
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 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 | |
---|---|
Type | Description |
array |
getIterator
Returns | |
---|---|
Type | Description |
Google\Cloud\Core\Iterator\ItemIterator |