Reference documentation and code samples for the BigQuery Client class Job.
Jobs are objects that manage asynchronous tasks such as running queries, loading data, and exporting data.
Namespace
Google \ Cloud \ BigQueryMethods
__construct
Parameters | |
---|---|
Name | Description |
connection | Google\Cloud\BigQuery\Connection\ConnectionInterface Represents a connection to BigQuery. |
id | string The job's ID. |
projectId | string The project's ID. |
mapper | Google\Cloud\BigQuery\ValueMapper Maps values between PHP and BigQuery. |
info | array [optional] The job's metadata. |
location | string|null [optional] A default geographic location, used when no job metadata exists. |
exists
Check whether or not the job exists.
Example:
echo $job->exists();
Returns | |
---|---|
Type | Description |
bool |
cancel
Requests that a job be cancelled. You will need to poll the job to ensure the cancel request successfully goes through.
Please note that by default the library will not attempt to retry this call on your behalf.
Example:
$job->cancel(); $isComplete = $job->isComplete(); while (!$isComplete) { sleep(1); // let's wait for a moment... $job->reload(); $isComplete = $job->isComplete(); } echo 'Job successfully cancelled.';
Parameter | |
---|---|
Name | Description |
options | array [optional] Configuration options. |
queryResults
Retrieves the results of a query job.
Please note this method will trigger an initial network request, but further polling may be necessary in order to access the full query results. Polling for completion can be initiated by iterating on the returned Google\Cloud\BigQuery\QueryResults, or by calling either Google\Cloud\BigQuery\QueryResults::rows() or Google\Cloud\BigQuery\QueryResults::waitUntilComplete().
Example:
$queryResults = $job->queryResults();
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. |
↳ initialTimeoutMs | int How long, in milliseconds, to wait for query results to become available before timing out. Defaults to |
↳ 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. Please note that this option is used when iterating on the returned class, and will not block immediately upon calling of this method. |
Returns | |
---|---|
Type | Description |
Google\Cloud\BigQuery\QueryResults |
waitUntilComplete
Blocks until the job is complete.
Example:
$job->waitUntilComplete();
Parameters | |
---|---|
Name | Description |
options | array Configuration options. |
↳ maxRetries | int The number of times to poll the Job status, until the job is complete. By default, will poll indefinitely. |
isComplete
Checks the job's completeness. Useful in combination with Job::reload() to poll for job status.
Example:
$isComplete = $job->isComplete(); while (!$isComplete) { sleep(1); // let's wait for a moment... $job->reload(); $isComplete = $job->isComplete(); } echo 'Query complete!';
Parameter | |
---|---|
Name | Description |
options | array [optional] Configuration options. |
Returns | |
---|---|
Type | Description |
bool |
info
Retrieves the job's details. If no job data is cached a network request will be made to retrieve it.
Example:
$info = $job->info(); echo $info['statistics']['startTime'];
Parameter | |
---|---|
Name | Description |
options | array [optional] Configuration options. |
Returns | |
---|---|
Type | Description |
array |
reload
Triggers a network request to reload the job's details.
Example:
echo $job->isComplete(); // false sleep(1); // let's wait for a moment... $job->reload(); // execute a network request echo $job->isComplete(); // true
Parameter | |
---|---|
Name | Description |
options | array [optional] Configuration options. |
Returns | |
---|---|
Type | Description |
array |
id
Retrieves the job's ID.
Example:
echo $job->id();
Returns | |
---|---|
Type | Description |
string |
identity
Retrieves the job's identity.
An identity provides a description of a nested resource.
Example:
echo $job->identity()['projectId'];
Returns | |
---|---|
Type | Description |
array |
Constants
MAX_RETRIES
Value: PHP_INT_MAX