class bigquery_api_service

Properties

static protected $instance

Singleton instance of the class.

protected mixed $client

Client instance for handling requests.

Methods

__construct()

Constructs an instance of the class and initializes the BigQuery client.

instance()

Provides a singleton instance of the class.

ItemIterator
get_datasets(array $options = [])

Retrieves a list of datasets based on the provided options.

mixed
get_dataset(string $id, null|string $projectId = null)

Fetches the specified dataset.

static Dataset
createDataset(string $id, array $options = [])

Creates a new dataset with the specified identifier and options.

ItemIterator
get_tables(string $datasetid, array $options = [])

Retrieves the list of tables from the specified dataset.

null|Table
get_table(string $datasetid, string $tableid)

Retrieves a specific table from a dataset in BigQuery.

Table
createTable(string $datasetid, string $tableid, array $options = [])

Creates a table in a specified dataset in BigQuery.

BigQueryClient
get_client()

Retrieves the BigQuery client instance.

null|Table
prepare_table(string $datasetid, string $tableid, array $options)

Prepares a table in the specified dataset on BigQuery by ensuring the dataset and table exist, and updates the table structure if necessary.

mixed
load(array $params)

Loads a dataset table with data from a specified file.

array
test()

Retrieves information about datasets and their respective tables.

null|Job
merge(string $origintable, string $destinationtable, string $write_disposition = 'WRITE_TRUNCATE')

Executes a merge operation between two tables in BigQuery.

bool
update_table_structure(Table $table, array $options)

Updates the table structure based on the provided schema in the options.

Job
load_data(string $datasetid, string $tableid, resource|string $data, bool $has_header = false, string $format = 'CSV', string $write_disposition = 'WRITE_TRUNCATE')

Loads data into a BigQuery table.

Details

at line 52
__construct()

Constructs an instance of the class and initializes the BigQuery client.

Retrieves the configuration for Google BigQuery credentials, validates and processes the credentials, and initializes the BigQueryClient using the provided options. If the credentials are missing, invalid, or improperly formatted, an exception is thrown.

Exceptions

Exception

at line 84
static bigquery_api_service instance()

Provides a singleton instance of the class.

Return Value

bigquery_api_service

the shared instance of the class

at line 102
ItemIterator get_datasets(array $options = [])

Retrieves a list of datasets based on the provided options.

Parameters

array $options

optional parameters to customize the retrieval of datasets

Return Value

ItemIterator

a list of datasets

at line 115
mixed get_dataset(string $id, null|string $projectId = null)

Fetches the specified dataset.

Parameters

string $id

the identifier of the dataset to be fetched

null|string $projectId

optional project identifier for scoping the dataset

Return Value

mixed

the dataset object if found

at line 130
static Dataset createDataset(string $id, array $options = [])

Creates a new dataset with the specified identifier and options.

Parameters

string $id

the unique identifier for the dataset to be created

array $options

optional parameters for configuring the dataset creation

Return Value

Dataset

the newly created dataset instance

Exceptions

Exception

at line 151
ItemIterator get_tables(string $datasetid, array $options = [])

Retrieves the list of tables from the specified dataset.

Parameters

string $datasetid

the identifier of the dataset from which tables need to be retrieved

array $options

optional parameters to customize the retrieval of tables

Return Value

ItemIterator

an array of tables if found, or null if an error occurs

at line 170
null|Table get_table(string $datasetid, string $tableid)

Retrieves a specific table from a dataset in BigQuery.

Parameters

string $datasetid

ID of the dataset

string $tableid

ID of the table

Return Value

null|Table

The table object if it exists, or null if an error occurs

at line 198
Table createTable(string $datasetid, string $tableid, array $options = [])

Creates a table in a specified dataset in BigQuery.

Parameters

string $datasetid

ID of the dataset

string $tableid

ID of the table to be created

array $options

Additional options for table creation

Return Value

Table

The created table object

Exceptions

Exception

at line 218
BigQueryClient get_client()

Retrieves the BigQuery client instance.

Return Value

BigQueryClient

The BigQuery client instance

Exceptions

Exception

at line 240
null|Table prepare_table(string $datasetid, string $tableid, array $options)

Prepares a table in the specified dataset on BigQuery by ensuring the dataset and table exist, and updates the table structure if necessary.

Parameters

string $datasetid

ID of the dataset

string $tableid

ID of the table

array $options

Additional options for table creation or structure update

Return Value

null|Table

The prepared table or null if an error occurs

Exceptions

Exception

at line 268
mixed load(array $params)

Loads a dataset table with data from a specified file.

Parameters

array $params

Associative array containing the following keys:

  • datasetid: string, ID of the dataset
  • tableid: string, ID of the table
  • filePath: string, Path to the source file
  • has_header: bool, Optional, whether the source file has headers (default: false)
  • format: string, Format of the data file
  • write_disposition: string, Optional, write mode for the table (default: 'WRITE_TRUNCATE')

Return Value

mixed

Result of the data loading operation

at line 291
array test()

Retrieves information about datasets and their respective tables.

Each dataset includes details such as its ID and a list of associated tables. For each table, information such as ID, path, and creation time is provided.

Return Value

array

an associative array containing datasets and their tables, including metadata such as dataset ID, table IDs, paths, and creation times

at line 332
null|Job merge(string $origintable, string $destinationtable, string $write_disposition = 'WRITE_TRUNCATE')

Executes a merge operation between two tables in BigQuery.

Parameters

string $origintable

The name of the source table

string $destinationtable

The name of the target table

string $write_disposition

The write disposition mode (default is 'WRITE_TRUNCATE')

Return Value

null|Job

The job object resulting from the merge operation or null on failure

at line 354
protected bool update_table_structure(Table $table, array $options)

Updates the table structure based on the provided schema in the options.

Parameters

Table $table

The table instance to update

array $options

The options for the update, including the new schema definition with 'fields'

Return Value

bool

Returns true if the table structure was updated, false otherwise

at line 403
protected Job load_data(string $datasetid, string $tableid, resource|string $data, bool $has_header = false, string $format = 'CSV', string $write_disposition = 'WRITE_TRUNCATE')

Loads data into a BigQuery table.

Parameters

string $datasetid

The ID of the dataset

string $tableid

The ID of the table within the dataset

resource|string $data

The data to be loaded, can be a resource or a string

bool $has_header

Whether the data has a header row to skip (default is false)

string $format

The format of the source data (default is 'CSV')

string $write_disposition

The write disposition for the job, e.g., 'WRITE_TRUNCATE' (default is 'WRITE_TRUNCATE')

Return Value

Job

The BigQuery job representing the load operation