Reference documentation and code samples for the BigQuery Client class BigQueryClient.
Google Cloud BigQuery allows you to create, manage, share and query data.
Find more information at the Google Cloud BigQuery Docs.
Example:
use Google\Cloud\BigQuery\BigQueryClient;
$bigQuery = new BigQueryClient();
Namespace
Google \ Cloud \ BigQueryMethods
__construct
Create a BigQuery client.
| Parameters | |
|---|---|
| Name | Description |
config |
array
Configuration options. |
↳ apiEndpoint |
string
The hostname with optional port to use in place of the default service endpoint. Example: |
↳ projectId |
string
The project ID from the Google Developer's Console. |
↳ authCache |
Psr\Cache\CacheItemPoolInterface
A cache for storing access tokens. Defaults to a simple in memory implementation. |
↳ authCacheOptions |
array
Cache configuration options. |
↳ authHttpHandler |
callable
A handler used to deliver Psr7 requests specifically for authentication. |
↳ credentialsFetcher |
Google\Auth\FetchAuthTokenInterface
A credentials fetcher instance. |
↳ httpHandler |
callable
A handler used to deliver Psr7 requests. Only valid for requests sent over REST. |
↳ keyFile |
array
[DEPRECATED] This option is being deprecated because of a potential security risk. This option does not validate the credential configuration. The security risk occurs when a credential configuration is accepted from a source that is not under your control and used without validation on your side. If you know that you will be loading credential configurations of a specific type, it is recommended to create the credentials directly and configure them using the |
↳ keyFilePath |
string
[DEPRECATED] This option is being deprecated because of a potential security risk. This option does not validate the credential configuration. The security risk occurs when a credential configuration is accepted from a source that is not under your control and used without validation on your side. If you know that you will be loading credential configurations of a specific type, it is recommended to create the credentials directly and configure them using the |
↳ requestTimeout |
float
Seconds to wait before timing out the request. Defaults to |
↳ retries |
int
Number of retries for a failed request. Defaults to |
↳ scopes |
array
Scopes to be used for the request. |
↳ quotaProject |
string
Specifies a user project to bill for access charges associated with the request. |
↳ returnInt64AsObject |
bool
If true, 64 bit integers will be returned as a Google\Cloud\Core\Int64 object for 32 bit platform compatibility. Defaults to false. |
↳ location |
string
If provided, determines the default geographic location used when creating datasets and managing jobs. Please note: This is only required for jobs started outside of the US and EU regions. Also, if location metadata has already been fetched over the network it will take precedent over this setting (by calling Table::reload(), for example). |
↳ logger |
false|Psr\Log\LoggerInterface
A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the 'GOOGLE_SDK_PHP_LOGGING' environment flag |
query
Returns a BigQuery job configuration.
The job configuration is passed to either BigQueryClient::runQuery() or BigQueryClient::startQuery(). A configuration can be built using fluent setters or by providing a full set of options at once.
Unless otherwise specified, all configuration options will default based on the
query job configuration
except for configuration.query.useLegacySql, which defaults to false
in this client.
Example:
$queryJobConfig = $bigQuery->query(
'SELECT commit FROM `bigquery-public-data.github_repos.commits` LIMIT 100'
);
// Set create disposition using fluent setters.
$queryJobConfig = $bigQuery->query(
'SELECT commit FROM `bigquery-public-data.github_repos.commits` LIMIT 100'
)->createDisposition('CREATE_NEVER');
// This is equivalent to the above example, using array configuration
// instead of fluent setters.
$queryJobConfig = $bigQuery->query(
'SELECT commit FROM `bigquery-public-data.github_repos.commits` LIMIT 100',
[
'configuration' => [
'query' => [
'createDisposition' => 'CREATE_NEVER'
]
]
]
);
// Set a region to run the job in.
$queryJobConfig = $bigQuery->query(
'SELECT name FROM `my_project.users_dataset.users` LIMIT 100'
)->location('asia-northeast1');
| Parameters | |||||||
|---|---|---|---|---|---|---|---|
| Name | Description | ||||||
query |
string
A BigQuery SQL query. |
||||||
options |
array
Configuration options. |
||||||
↳ configuration |
array
Job configuration. Please see the API documentation for the available options.
|
||||||
| Returns | |
|---|---|
| Type | Description |
QueryJobConfiguration |
|
queryConfig
Returns a BigQuery job configuration.
The job configuration is passed to either BigQueryClient::runQuery() or BigQueryClient::startQuery(). A configuration can be built using fluent setters or by providing a full set of options at once.
Unless otherwise specified, all configuration options will default based on the
query job configuration
except for configuration.query.useLegacySql, which defaults to false
in this client.
As this method is an alias, please see BigQueryClient::query() for usage examples.
| Parameters | |||||||
|---|---|---|---|---|---|---|---|
| Name | Description | ||||||
query |
string
A BigQuery SQL query. |
||||||
options |
array
Configuration options. |
||||||
↳ configuration |
array
Job configuration. Please see the API documentation for the available options.
|
||||||
| Returns | |
|---|---|
| Type | Description |
QueryJobConfiguration |
|
runQuery
See also:
| Parameters | |
|---|---|
| Name | Description |
query |
QueryJobConfiguration
A BigQuery SQL query configuration. |
options |
array
Configuration options. |
↳ maxResults |
int
The maximum number of rows to return per page of results. Setting this flag to a small value such as 1000 and then paging through results might improve reliability when the query result set is large. |
↳ 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. Default is false. |
↳ formatOptions.useInt64Timestamp |
boolean
Optional. Output timestamp as usec int64. Default is false. |
| Returns | |
|---|---|
| Type | Description |
QueryResults |
|
startQuery
See also:
| Parameters | |
|---|---|
| Name | Description |
query |
QueryJobConfiguration
A BigQuery SQL query configuration. |
options |
array
[optional] Configuration options. |
| Returns | |
|---|---|
| Type | Description |
Job |
|
job
Lazily instantiates a job.
There are no network requests made at this point. To see the operations that can be performed on a job please see Job.
Example:
$job = $bigQuery->job('myJobId');
| Parameters | |
|---|---|
| Name | Description |
id |
string
The id of the already run or running job to request. |
options |
array
Configuration options. |
↳ location |
string
The geographic location of the job. Required for jobs started outside of the US and EU regions. Defaults to a location specified in the client configuration. |
| Returns | |
|---|---|
| Type | Description |
Job |
|
jobs
See also:
| Parameters | |
|---|---|
| Name | Description |
options |
array
Configuration options. |
↳ allUsers |
bool
Whether to display jobs owned by all users in the project. Defaults to |
↳ maxResults |
int
Maximum number of results to return per page. |
↳ resultLimit |
int
Limit the number of results returned in total. Defaults to |
↳ pageToken |
string
A previously-returned page token used to resume the loading of results from a specific point. |
↳ stateFilter |
string
Filter for job state. Maybe be either |
↳ maxCreationTime |
int
Milliseconds since the POSIX epoch. If set, only jobs created before or at this timestamp are returned. |
↳ minCreationTime |
int
Milliseconds since the POSIX epoch. If set, only jobs created after or at this timestamp are returned. |
↳ parentJobId |
string
If set, show only child jobs of the specified parent. Otherwise, show all top-level jobs. |
| Returns | |
|---|---|
| Type | Description |
Google\Cloud\Core\Iterator\ItemIterator<Job> |
|
dataset
Lazily instantiates a dataset.
There are no network requests made at this point. To see the operations that can be performed on a dataset please see Dataset.
If the dataset is owned by a different project than the project used to authenticate the client, provide the project ID as the second argument.
Example:
$dataset = $bigQuery->dataset('myDatasetId');
// Reference a dataset from other project.
$dataset = $bigQuery->dataset('samples', 'bigquery-public-data');
| Parameters | |
|---|---|
| Name | Description |
id |
string
The id of the dataset to request. |
projectId |
string|null
The id of the project. Defaults to current project id. |
| Returns | |
|---|---|
| Type | Description |
Dataset |
|
datasets
See also:
| Parameters | |
|---|---|
| Name | Description |
options |
array
|