bigquery_api_service
Table of Contents
Properties
- $client : mixed
- Client instance for handling requests.
- $instance : mixed
- Singleton instance of the class.
Methods
- __construct() : mixed
- Constructs an instance of the class and initializes the BigQuery client.
- createDataset() : Dataset
- Creates a new dataset with the specified identifier and options.
- createTable() : Table
- Creates a table in a specified dataset in BigQuery.
- get_client() : BigQueryClient
- Retrieves the BigQuery client instance.
- get_dataset() : mixed
- Fetches the specified dataset.
- get_datasets() : ItemIterator
- Retrieves a list of datasets based on the provided options.
- get_table() : null|Table
- Retrieves a specific table from a dataset in BigQuery.
- get_tables() : ItemIterator
- Retrieves the list of tables from the specified dataset.
- instance() : self
- Provides a singleton instance of the class.
- load() : mixed
- Loads a dataset table with data from a specified file.
- merge() : null|Job
- Executes a merge operation between two tables in BigQuery.
- prepare_table() : null|Table
- Prepares a table in the specified dataset on BigQuery by ensuring the dataset and table exist, and updates the table structure if necessary.
- test() : array<string|int, mixed>
- Retrieves information about datasets and their respective tables.
- load_data() : Job
- Loads data into a BigQuery table.
- update_table_structure() : bool
- Updates the table structure based on the provided schema in the options.
Properties
$client
Client instance for handling requests.
protected
mixed
$client
$instance
Singleton instance of the class.
protected
static mixed
$instance
Methods
__construct()
Constructs an instance of the class and initializes the BigQuery client.
public
__construct() : mixed
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.
Tags
createDataset()
Creates a new dataset with the specified identifier and options.
public
static createDataset(string $id[, array<string|int, mixed> $options = [] ]) : Dataset
Parameters
- $id : string
-
the unique identifier for the dataset to be created
- $options : array<string|int, mixed> = []
-
optional parameters for configuring the dataset creation
Tags
Return values
Dataset —the newly created dataset instance
createTable()
Creates a table in a specified dataset in BigQuery.
public
createTable(string $datasetid, string $tableid[, array<string|int, mixed> $options = [] ]) : Table
Parameters
- $datasetid : string
-
ID of the dataset
- $tableid : string
-
ID of the table to be created
- $options : array<string|int, mixed> = []
-
Additional options for table creation
Tags
Return values
Table —The created table object
get_client()
Retrieves the BigQuery client instance.
public
get_client() : BigQueryClient
Tags
Return values
BigQueryClient —The BigQuery client instance
get_dataset()
Fetches the specified dataset.
public
get_dataset(string $id[, null|string $projectId = null ]) : mixed
Parameters
- $id : string
-
the identifier of the dataset to be fetched
- $projectId : null|string = null
-
optional project identifier for scoping the dataset
Return values
mixed —the dataset object if found
get_datasets()
Retrieves a list of datasets based on the provided options.
public
get_datasets([array<string|int, mixed> $options = [] ]) : ItemIterator
Parameters
- $options : array<string|int, mixed> = []
-
optional parameters to customize the retrieval of datasets
Return values
ItemIterator —a list of datasets
get_table()
Retrieves a specific table from a dataset in BigQuery.
public
get_table(string $datasetid, string $tableid) : null|Table
Parameters
- $datasetid : string
-
ID of the dataset
- $tableid : string
-
ID of the table
Return values
null|Table —The table object if it exists, or null if an error occurs
get_tables()
Retrieves the list of tables from the specified dataset.
public
get_tables(string $datasetid[, array<string|int, mixed> $options = [] ]) : ItemIterator
Parameters
- $datasetid : string
-
the identifier of the dataset from which tables need to be retrieved
- $options : array<string|int, mixed> = []
-
optional parameters to customize the retrieval of tables
Return values
ItemIterator —an array of tables if found, or null if an error occurs
instance()
Provides a singleton instance of the class.
public
static instance() : self
Return values
self —the shared instance of the class
load()
Loads a dataset table with data from a specified file.
public
load(array<string|int, mixed> $params) : mixed
Parameters
- $params : array<string|int, mixed>
-
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 values
mixed —Result of the data loading operation
merge()
Executes a merge operation between two tables in BigQuery.
public
merge(string $origintable, string $destinationtable[, string $write_disposition = 'WRITE_TRUNCATE' ]) : null|Job
Parameters
- $origintable : string
-
The name of the source table
- $destinationtable : string
-
The name of the target table
- $write_disposition : string = 'WRITE_TRUNCATE'
-
The write disposition mode (default is 'WRITE_TRUNCATE')
Return values
null|Job —The job object resulting from the merge operation or null on failure
prepare_table()
Prepares a table in the specified dataset on BigQuery by ensuring the dataset and table exist, and updates the table structure if necessary.
public
prepare_table(string $datasetid, string $tableid, array<string|int, mixed> $options) : null|Table
Parameters
- $datasetid : string
-
ID of the dataset
- $tableid : string
-
ID of the table
- $options : array<string|int, mixed>
-
Additional options for table creation or structure update
Tags
Return values
null|Table —The prepared table or null if an error occurs
test()
Retrieves information about datasets and their respective tables.
public
test() : array<string|int, mixed>
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 values
array<string|int, mixed> —an associative array containing datasets and their tables, including metadata such as dataset ID, table IDs, paths, and creation times
load_data()
Loads data into a BigQuery table.
protected
load_data(string $datasetid, string $tableid, resource|string $data[, bool $has_header = false ][, string $format = 'CSV' ][, string $write_disposition = 'WRITE_TRUNCATE' ]) : Job
Parameters
- $datasetid : string
-
The ID of the dataset
- $tableid : string
-
The ID of the table within the dataset
- $data : resource|string
-
The data to be loaded, can be a resource or a string
- $has_header : bool = false
-
Whether the data has a header row to skip (default is false)
- $format : string = 'CSV'
-
The format of the source data (default is 'CSV')
- $write_disposition : string = 'WRITE_TRUNCATE'
-
The write disposition for the job, e.g., 'WRITE_TRUNCATE' (default is 'WRITE_TRUNCATE')
Return values
Job —The BigQuery job representing the load operation
update_table_structure()
Updates the table structure based on the provided schema in the options.
protected
update_table_structure(Table $table, array<string|int, mixed> $options) : bool
Parameters
- $table : Table
-
The table instance to update
- $options : array<string|int, mixed>
-
The options for the update, including the new schema definition with 'fields'
Return values
bool —Returns true if the table structure was updated, false otherwise