BigQuery DataTransfer : Invalid constructor input for StartManualTransferRunsRequest

824 Views Asked by At

I am trying to trigger a Scheduled Query through a Cloud Function in GCP. I tried to follow several tutorials and examples and went through the documentation too but with the new version of the API google-cloud-bigquery-datatransfer==3.1.1 I can't find anything showing the proper procedure.

You will find below my current code :

from google.cloud import bigquery_datatransfer_v1

def triggerQuery (parent, requested_run_time):
    client = bigquery_datatransfer_v1.DataTransferServiceClient()
    project_id = '###' # Enter your projectID here
    location_id = 'europe' # Enter your locationID here
    transfer_id = '###'  # Enter your transferId here
    transfer_config = {...}
    path = f"projects/{project_id}/locations/{location_id}/transferConfigs/{transfer_id}"
    parent = client.transfer_config_path(project_id, transfer_id)
    response = client.start_manual_transfer_runs(path)
    print(response)

I tried passing to client.start_manual_transfer_runs either pathor parent but I get :

TypeError: Invalid constructor input for StartManualTransferRunsRequest: 'projects/###/locations/europe/transferConfigs/###'

I also need to specify that the Cloud Function is associated to the proper Service Account that has the rights to run queries in BigQuery.

Help would be greatly appreciated !

1

There are 1 best solutions below

0
On

You need to enter parameters of manual transfer run in dictionary format. Below code works for me:

import time
from google.cloud import bigquery_datatransfer_v1
from google.protobuf.timestamp_pb2 import Timestamp


client = bigquery_datatransfer_v1.DataTransferServiceClient()

project_id = 'your-project-id'
transfer_config_id = 'config-id-can-be-found-in-ui' 
location = 'location-of-your-transfer-config'

start_time = Timestamp(seconds=int(time.time()+20))
parent = f'projects/{project_id}/locations/{location}/transferConfigs/{transfer_config_id}'

response = client.start_manual_transfer_runs({"parent": parent, "requested_run_time": start_time})
print(response)