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 | arrayConfiguration options. | 
| ↳ apiEndpoint | stringThe hostname with optional port to use in place of the default service endpoint. Example:  | 
| ↳ projectId | stringThe project ID from the Google Developer's Console. | 
| ↳ authCache | CacheItemPoolInterfaceA cache for storing access tokens. Defaults to a simple in memory implementation. | 
| ↳ authCacheOptions | arrayCache configuration options. | 
| ↳ authHttpHandler | callableA handler used to deliver Psr7 requests specifically for authentication. | 
| ↳ credentialsFetcher | FetchAuthTokenInterfaceA credentials fetcher instance. | 
| ↳ httpHandler | callableA handler used to deliver Psr7 requests. Only valid for requests sent over REST. | 
| ↳ keyFile | arrayThe contents of the service account credentials .json file retrieved from the Google Developer's Console. Ex:  | 
| ↳ keyFilePath | stringThe full path to your service account credentials .json file retrieved from the Google Developers Console. | 
| ↳ requestTimeout | floatSeconds to wait before timing out the request. Defaults to  | 
| ↳ retries | intNumber of retries for a failed request. Defaults to  | 
| ↳ scopes | arrayScopes to be used for the request. | 
| ↳ quotaProject | stringSpecifies a user project to bill for access charges associated with the request. | 
| ↳ returnInt64AsObject | boolIf true, 64 bit integers will be returned as a Google\Cloud\Core\Int64 object for 32 bit platform compatibility. Defaults to false. | 
| ↳ location | stringIf 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). | 
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 | stringA BigQuery SQL query. | ||||||
| options | arrayConfiguration options. | ||||||
| ↳ configuration | arrayJob 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 | stringA BigQuery SQL query. | ||||||
| options | arrayConfiguration options. | ||||||
| ↳ configuration | arrayJob configuration. Please see the API documentation for the available options. 
 | ||||||
| Returns | |
|---|---|
| Type | Description | 
| QueryJobConfiguration | |
runQuery
See also:
| Parameters | |
|---|---|
| Name | Description | 
| query | QueryJobConfigurationA BigQuery SQL query configuration. | 
| options | arrayConfiguration options. | 
| ↳ maxResults | intThe 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 | intZero-based index of the starting row. | 
| ↳ timeoutMs | intHow 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 | intThe number of times to poll the Job status, until the job is complete. By default, will poll indefinitely. | 
| ↳ returnRawResults | boolReturns 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 | booleanOptional. Output timestamp as usec int64. Default is false. | 
| Returns | |
|---|---|
| Type | Description | 
| QueryResults | |
startQuery
See also:
| Parameters | |
|---|---|
| Name | Description | 
| query | QueryJobConfigurationA 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 | stringThe id of the already run or running job to request. | 
| options | arrayConfiguration options. | 
| ↳ location | stringThe 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 | arrayConfiguration options. | 
| ↳ allUsers | boolWhether to display jobs owned by all users in the project. Defaults to  | 
| ↳ maxResults | intMaximum number of results to return per page. | 
| ↳ resultLimit | intLimit the number of results returned in total. Defaults to  | 
| ↳ pageToken | stringA previously-returned page token used to resume the loading of results from a specific point. | 
| ↳ stateFilter | stringFilter for job state. Maybe be either  | 
| ↳ maxCreationTime | intMilliseconds since the POSIX epoch. If set, only jobs created before or at this timestamp are returned. | 
| ↳ minCreationTime | intMilliseconds since the POSIX epoch. If set, only jobs created after or at this timestamp are returned. | 
| ↳ parentJobId | stringIf 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 | stringThe id of the dataset to request. | 
| projectId | string|nullThe id of the project. Defaults to current project id. | 
| Returns | |
|---|---|
| Type | Description | 
| Dataset | |
datasets
See also:
| Parameters | |
|---|---|
| Name | Description | 
| options | arrayConfiguration options. | 
| ↳ all | boolWhether to list all datasets, including hidden ones. Defaults to  | 
| ↳ maxResults | intMaximum number of results to return per page. | 
| ↳ resultLimit | intLimit the number of results returned in total. Defaults to  | 
| ↳ pageToken | stringA previously-returned page token used to resume the loading of results from a specific point. | 
| ↳ filter | stringAn expression for filtering the results of the request by label. The syntax is "labels. 
 | 
| Returns | |
|---|---|
| Type | Description | 
| Google\Cloud\Core\Iterator\ItemIterator<Dataset> | |
createDataset
See also:
| Parameters | |
|---|---|
| Name | Description | 
| id | stringThe id of the dataset to create. | 
| options | arrayConfiguration options. | 
| ↳ metadata | arrayThe available options for metadata are outlined at the Dataset Resource API docs | 
| Returns | |
|---|---|
| Type | Description | 
| Dataset | |
runJob
See also:
| Parameters | |
|---|---|
| Name | Description | 
| config | JobConfigurationInterfaceThe job configuration. | 
| options | arrayConfiguration options. | 
| ↳ maxRetries | intThe number of times to retry, checking if the job has completed. Defaults to  | 
| Returns | |
|---|---|
| Type | Description | 
| Job | |
startJob
See also:
| Parameters | |
|---|---|
| Name | Description | 
| config | JobConfigurationInterfaceThe job configuration. | 
| options | array[optional] Configuration options. | 
| Returns | |
|---|---|
| Type | Description | 
| Job | |
bytes
Create a Bytes object.
Example:
$bytes = $bigQuery->bytes('hello world'); | Parameter | |
|---|---|
| Name | Description | 
| value | string|resource|Psr\Http\Message\StreamInterfaceThe bytes value. | 
| Returns | |
|---|---|
| Type | Description | 
| Bytes | |
date
Create a Date object.
Example:
$date = $bigQuery->date(new \DateTime('1995-02-04')); | Parameter | |
|---|---|
| Name | Description | 
| value | DateTimeInterfaceThe date value. | 
| Returns | |
|---|---|
| Type | Description | 
| Date | |
int64
Create an Int64 object. This can be used to work with 64 bit integers as a string value while on a 32 bit platform.
Example:
$int64 = $bigQuery->int64('9223372036854775807'); | Parameter | |
|---|---|
| Name | Description | 
| value | stringThe 64 bit integer value in string format. | 
| Returns | |
|---|---|
| Type | Description | 
| Google\Cloud\Core\Int64 | |
time
Create a Time object.
Example:
$time = $bigQuery->time(new \DateTime('12:15:00.482172')); | Parameter | |
|---|---|
| Name | Description | 
| value | DateTimeInterfaceThe time value. | 
| Returns | |
|---|---|
| Type | Description | 
| Time | |
timestamp
Create a Timestamp object.
Example:
$timestamp = $bigQuery->timestamp(new \DateTime('2003-02-05 11:15:02.421827Z')); | Parameter | |
|---|---|
| Name | Description | 
| value | DateTimeInterfaceThe timestamp value. | 
| Returns | |
|---|---|
| Type | Description | 
| Timestamp | |
numeric
Create a Numeric object.
Numeric represents a value with a data type of Numeric.
It supports a fixed 38 decimal digits of precision and 9 decimal digits of scale, and values are in the range of -99999999999999999999999999999.999999999 to 99999999999999999999999999999.999999999.
Example:
$numeric = $bigQuery->numeric('99999999999999999999999999999999999999.999999999'); | Parameter | |
|---|---|
| Name | Description | 
| value | string|int|floatThe Numeric value. | 
| Returns | |
|---|---|
| Type | Description | 
| numeric | |
bigNumeric
Create a BigNumeric object.
Numeric represents a value with a data type of BIGNUMERIC.
It supports 76.76 (the 77th digit is partial) decimal digits of precision and 38 decimal digits of scale. Values are in the range of -5.7896044618658097711785492504343953926634992332820282019728792003956564819968E+38 to 5.7896044618658097711785492504343953926634992332820282019728792003956564819967E+38.
Example:
$bigNumeric = $bigQuery->bigNumeric('999999999999999999999999999999999999999999999.99999999999999'); | Parameter | |
|---|---|
| Name | Description | 
| value | string|int|floatThe Numeric value. | 
| Returns | |
|---|---|
| Type | Description | 
| BigNumeric | |
geography
Create a Geography object.
Example:
$geography = $bigQuery->geography('POINT(10 20)'); | Parameter | |
|---|---|
| Name | Description | 
| value | stringThe geography data in WKT format. | 
| Returns | |
|---|---|
| Type | Description | 
| Geography | |
json
Create a BigQuery Json object.
Json represents a value with a data type of JSON
Example:
use Google\Cloud\BigQuery\BigQueryClient; $bigQuery = new BigQueryClient(); $json = $bigQuery->json('{"key":"value"}'); | Parameter | |
|---|---|
| Name | Description | 
| value | string|nullThe JSON string value. | 
| Returns | |
|---|---|
| Type | Description | 
| Json | |
getServiceAccount
Get a service account for the KMS integration.
Example:
$serviceAccount = $bigQuery->getServiceAccount(); | Parameter | |
|---|---|
| Name | Description | 
| options | array[optional] Configuration options. | 
| Returns | |
|---|---|
| Type | Description | 
| string | |
copy
See also:
| Parameters | |||||||
|---|---|---|---|---|---|---|---|
| Name | Description | ||||||
| options | arrayConfiguration options. | ||||||
| ↳ configuration | arrayJob configuration. Please see the API documentation for the available options. 
 | ||||||
| Returns | |
|---|---|
| Type | Description | 
| CopyJobConfiguration | |
extract
See also:
| Parameters | |||||||
|---|---|---|---|---|---|---|---|
| Name | Description | ||||||
| options | arrayConfiguration options. | ||||||
| ↳ configuration | arrayJob configuration. Please see the API documentation for the available options. 
 | ||||||
| Returns | |
|---|---|
| Type | Description | 
| ExtractJobConfiguration | |
load
See also:
| Parameters | |||||||
|---|---|---|---|---|---|---|---|
| Name | Description | ||||||
| options | arrayConfiguration options. | ||||||
| ↳ configuration | arrayJob configuration. Please see the API documentation for the available options. 
 | ||||||
| Returns | |
|---|---|
| Type | Description | 
| LoadJobConfiguration | |
Constants
VERSION
Value: '1.33.1'MAX_DELAY_MICROSECONDS
Value: 32000000SCOPE
Value: 'https://www.googleapis.com/auth/bigquery'INSERT_SCOPE
Value: 'https://www.googleapis.com/auth/bigquery.insertdata'