BigQuery Client - Class BigQueryClient (1.31.1) (original) (raw)

BigQuery Client - Class BigQueryClient (1.31.1)

Stay organized with collections Save and categorize content based on your preferences.

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 theGoogle Cloud BigQuery Docs.

Example:

use Google\Cloud\BigQuery\BigQueryClient;

$bigQuery = new BigQueryClient();

Namespace

Google \ Cloud \ BigQuery

Methods

__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: foobar.com or foobar.com:1234.
↳ projectId string The project ID from the Google Developer's Console.
↳ authCache 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 FetchAuthTokenInterface A credentials fetcher instance.
↳ httpHandler callable A handler used to deliver Psr7 requests. Only valid for requests sent over REST.
↳ keyFile array The contents of the service account credentials .json file retrieved from the Google Developer's Console. Ex: json_decode(file_get_contents($path), true).
↳ keyFilePath string The full path to your service account credentials .json file retrieved from the Google Developers Console.
↳ requestTimeout float Seconds to wait before timing out the request. Defaults to 0 with REST and 60 with gRPC.
↳ retries int Number of retries for a failed request. Defaults to 3.
↳ 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).

query

Returns a BigQuery job configuration.

The job configuration is passed to eitherBigQueryClient::runQuery() orBigQueryClient::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 thequery job configurationexcept for configuration.query.useLegacySql, which defaults to falsein this client.

Example:

    'SELECT commit FROM `bigquery-public-data.github_repos.commits` LIMIT 100'
);
// Set create disposition using fluent setters. <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>q</mi><mi>u</mi><mi>e</mi><mi>r</mi><mi>y</mi><mi>J</mi><mi>o</mi><mi>b</mi><mi>C</mi><mi>o</mi><mi>n</mi><mi>f</mi><mi>i</mi><mi>g</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">queryJobConfig = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">q</span><span class="mord mathnormal">u</span><span class="mord mathnormal" style="margin-right:0.03588em;">ery</span><span class="mord mathnormal" style="margin-right:0.09618em;">J</span><span class="mord mathnormal">o</span><span class="mord mathnormal">b</span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>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. <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>q</mi><mi>u</mi><mi>e</mi><mi>r</mi><mi>y</mi><mi>J</mi><mi>o</mi><mi>b</mi><mi>C</mi><mi>o</mi><mi>n</mi><mi>f</mi><mi>i</mi><mi>g</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">queryJobConfig = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">q</span><span class="mord mathnormal">u</span><span class="mord mathnormal" style="margin-right:0.03588em;">ery</span><span class="mord mathnormal" style="margin-right:0.09618em;">J</span><span class="mord mathnormal">o</span><span class="mord mathnormal">b</span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>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. <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>q</mi><mi>u</mi><mi>e</mi><mi>r</mi><mi>y</mi><mi>J</mi><mi>o</mi><mi>b</mi><mi>C</mi><mi>o</mi><mi>n</mi><mi>f</mi><mi>i</mi><mi>g</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">queryJobConfig = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">q</span><span class="mord mathnormal">u</span><span class="mord mathnormal" style="margin-right:0.03588em;">ery</span><span class="mord mathnormal" style="margin-right:0.09618em;">J</span><span class="mord mathnormal">o</span><span class="mord mathnormal">b</span><span class="mord mathnormal" style="margin-right:0.07153em;">C</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>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.
↳ configuration array .query Query job configuration. Please see the documentation for the available options.
Returns
Type Description
QueryJobConfiguration

queryConfig

Returns a BigQuery job configuration.

The job configuration is passed to eitherBigQueryClient::runQuery() orBigQueryClient::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 thequery job configurationexcept for configuration.query.useLegacySql, which defaults to falsein this client.

As this method is an alias, please seeBigQueryClient::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.
↳ configuration array .query Query job configuration. Please see the documentation for the available options.
Returns
Type Description
QueryJobConfiguration

runQuery

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 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.
Returns
Type Description
QueryResults

startQuery

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:

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

Parameters
Name Description
options array Configuration options.
↳ allUsers bool Whether to display jobs owned by all users in the project. Defaults to false.
↳ maxResults int Maximum number of results to return per page.
↳ resultLimit int Limit the number of results returned in total. Defaults to 0 (return all results).
↳ 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 done, pending, or running.
↳ 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:

// Reference a dataset from other project. <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>d</mi><mi>a</mi><mi>t</mi><mi>a</mi><mi>s</mi><mi>e</mi><mi>t</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">dataset = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span><span class="mord mathnormal">a</span><span class="mord mathnormal">se</span><span class="mord mathnormal">t</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>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

Parameters
Name Description
options array Configuration options.
↳ all bool Whether to list all datasets, including hidden ones. Defaults to false.
↳ maxResults int Maximum number of results to return per page.
↳ resultLimit int Limit the number of results returned in total. Defaults to 0 (return all results).
↳ pageToken string A previously-returned page token used to resume the loading of results from a specific point.
↳ filter string An expression for filtering the results of the request by label. The syntax is "labels.
Returns
Type Description
Google\Cloud\Core\Iterator\ItemIterator<Dataset>

createDataset

Parameters
Name Description
id string The id of the dataset to create.
options array Configuration options.
↳ metadata array The available options for metadata are outlined at the Dataset Resource API docs
Returns
Type Description
Dataset

runJob

Parameters
Name Description
config JobConfigurationInterface The job configuration.
options array Configuration options.
↳ maxRetries int The number of times to retry, checking if the job has completed. Defaults to 100.
Returns
Type Description
Job

startJob

Parameters
Name Description
config JobConfigurationInterface The job configuration.
options array [optional] Configuration options.
Returns
Type Description
Job

bytes

Create a Bytes object.

Example:

Parameter
Name Description
value string|resource
Returns
Type Description
Bytes

date

Create a Date object.

Example:

Parameter
Name Description
value DateTimeInterface The 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:

Parameter
Name Description
value string The 64 bit integer value in string format.
Returns
Type Description
Google\Cloud\Core\Int64

time

Create a Time object.

Example:

Parameter
Name Description
value DateTimeInterface The time value.
Returns
Type Description
Time

timestamp

Create a Timestamp object.

Example:

Parameter
Name Description
value DateTimeInterface The timestamp value.
Returns
Type Description
Timestamp

numeric

Create a Numeric object.

Numeric represents a value with a data type ofNumeric.

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:

Parameter
Name Description
value string|int
Returns
Type Description
numeric

bigNumeric

Create a BigNumeric object.

Numeric represents a value with a data type ofBIGNUMERIC.

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:

Parameter
Name Description
value string|int
Returns
Type Description
BigNumeric

geography

Create a Geography object.

Example:

Parameter
Name Description
value string The geography data in WKT format.
Returns
Type Description
Geography

json

Create a BigQuery Json object.

Json represents a value with a data type ofJSON

Example:

use Google\Cloud\BigQuery\BigQueryClient;

$bigQuery = new BigQueryClient(); <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>j</mi><mi>s</mi><mi>o</mi><mi>n</mi><mo>=</mo></mrow><annotation encoding="application/x-tex">json = </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.854em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05724em;">j</span><span class="mord mathnormal">so</span><span class="mord mathnormal">n</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span></span></span></span>bigQuery->json('{"key":"value"}');
Parameter
Name Description
value string|null The JSON string value.
Returns
Type Description
Json

getServiceAccount

Get a service account for the KMS integration.

Example:

Parameter
Name Description
options array [optional] Configuration options.
Returns
Type Description
string

copy

Parameters
Name Description
options array Configuration options.
↳ configuration array Job configuration. Please see the API documentation for the available options.
↳ configuration array .copy Copy job configuration. Please see the documentation for the available options.
Returns
Type Description
CopyJobConfiguration
Parameters
Name Description
options array Configuration options.
↳ configuration array Job configuration. Please see the API documentation for the available options.
↳ configuration array .extract Extract job configuration. Please see the documentation for the available options.
Returns
Type Description
ExtractJobConfiguration

load

Parameters
Name Description
options array Configuration options.
↳ configuration array Job configuration. Please see the API documentation for the available options.
↳ configuration array .load Load job configuration. Please see the documentation for the available options.
Returns
Type Description
LoadJobConfiguration

Constants

VERSION

MAX_DELAY_MICROSECONDS

SCOPE

Value: 'https://www.googleapis.com/auth/bigquery'

INSERT_SCOPE

Value: 'https://www.googleapis.com/auth/bigquery.insertdata'