Search code examples
google-bigquerydata-transfer

BigQuery Data Transfer Services - php client library - and check, backfill the bigquery data transfer automatically?


https://cloud.google.com/bigquery/docs/reference/datatransfer/rest/

I am looking for php client library of "bigquery data transfer services", specially for how to launch the bigquery job to run or schedule a backfill of a defined bigquery data transfer services.

I could not find the php client library of "bigquery data transfer services". Maybe it is because that it is kind new.

For bigquery data services, the problems I am facing are

  1. Sometimes, it failed. The "Transfer" log will show "The transfer run has failed" status.
  2. Sometimes, the status of "Transfer" shows "The transfer run has completed successfully." But the data the scheduled transfer supposed to pull was still empty (maybe it is due to when the transfer is running the data was not available).

For both cases, usually, I would run a backfill transfer manually, which will fix the problems.

But the issue is that all the above activities, check if there are status shows failed, or if the data is missing, or run a backfill, are all done manually.

How could I do the above works about the "bigquery data transfer" automatically?

Thanks!


Solution

  • You can use the auto-generated Google API PHP Client Services library to use any Google API, such as the Google BigQuery DataTransfer service.

    A simple example

    // include your composer dependencies
    require_once 'vendor/autoload.php';
    
    $client = new Google_Client();
    $client->setApplicationName("Client_Library_Examples");
    $client->setDeveloperKey("YOUR_APP_KEY");
    
    $service = new Google_Service_BigQueryDataTransfer($client);
    // Use $service to run transfer service API calls.
    

    Adapted from the simple example given for the Google PHP API client, for BigQueryDataTransfer.