Update configuration metadata Stay organized with collections Save and categorize content based on your preferences.
Update transfer configuration metadata.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
Java
Before trying this sample, follow theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
importcom.google.api.gax.rpc.ApiException;importcom.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient;importcom.google.cloud.bigquery.datatransfer.v1.TransferConfig;importcom.google.cloud.bigquery.datatransfer.v1.UpdateTransferConfigRequest;importcom.google.protobuf.FieldMask;importcom.google.protobuf.util.FieldMaskUtil;importjava.io.IOException;// Sample to update transfer config.publicclassUpdateTransferConfig{publicstaticvoidmain(String[]args)throwsIOException{// TODO(developer): Replace these variables before running the sample.StringconfigId="MY_CONFIG_ID";TransferConfigtransferConfig=TransferConfig.newBuilder().setName(configId).setDisplayName("UPDATED_DISPLAY_NAME").build();FieldMaskupdateMask=FieldMaskUtil.fromString("display_name");updateTransferConfig(transferConfig,updateMask);}publicstaticvoidupdateTransferConfig(TransferConfigtransferConfig,FieldMaskupdateMask)throwsIOException{try(DataTransferServiceClientdataTransferServiceClient=DataTransferServiceClient.create()){UpdateTransferConfigRequestrequest=UpdateTransferConfigRequest.newBuilder().setTransferConfig(transferConfig).setUpdateMask(updateMask).build();TransferConfigupdateConfig=dataTransferServiceClient.updateTransferConfig(request);System.out.println("Transfer config updated successfully :"+updateConfig.getDisplayName());}catch(ApiExceptionex){System.out.print("Transfer config was not updated."+ex.toString());}}}Node.js
Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
const{DataTransferServiceClient}=require('@google-cloud/bigquery-data-transfer').v1;const{status}=require('@grpc/grpc-js');constclient=newDataTransferServiceClient();/** * Updates a transfer configuration for a BigQuery data transfer. * * This sample shows how to update properties of an existing transfer configuration, such as its display name. * An update mask is required to specify which fields to modify. * * @param {string} projectId The Google Cloud project ID, for example 'example-project-id' * @param {string} location The location of the transfer config, for example 'us-central1' * @param {string} configId The ID of the transfer config to update, for example '1234a-5678-9012b-3456c' */asyncfunctionupdateTransferConfig(projectId,location,configId){consttransferConfig={name:`projects/${projectId}/locations/${location}/transferConfigs/${configId}`,displayName:'Example Data Transfer (Update)',};constrequest={transferConfig,updateMask:{paths:['display_name'],},};try{const[response]=awaitclient.updateTransferConfig(request);console.log(`Transfer config:${response.name}`);console.log(` Updated display name:${response.displayName}`);}catch(err){if(err.code===status.NOT_FOUND){console.error(`Transfer config not found:${transferConfig.name}`);}else{console.error('An error occurred:',err);}}}Python
Before trying this sample, follow thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
fromgoogle.cloudimportbigquery_datatransferfromgoogle.protobufimportfield_mask_pb2transfer_client=bigquery_datatransfer.DataTransferServiceClient()transfer_config_name="projects/1234/locations/us/transferConfigs/abcd"new_display_name="My Transfer Config"transfer_config=bigquery_datatransfer.TransferConfig(name=transfer_config_name)transfer_config.display_name=new_display_nametransfer_config=transfer_client.update_transfer_config({"transfer_config":transfer_config,"update_mask":field_mask_pb2.FieldMask(paths=["display_name"]),})print(f"Updated config: '{transfer_config.name}'")print(f"New display name: '{transfer_config.display_name}'")What's next
To search and filter code samples for other Google Cloud products, see theGoogle Cloud sample browser.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.