Delete a scheduled query

Delete the configuration for a scheduled query, stopping any future runs.

Code sample

Go

Before trying this sample, follow the Go setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Go API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

import (
	"context"
	"fmt"

	datatransfer "cloud.google.com/go/bigquery/datatransfer/apiv1"
	"cloud.google.com/go/bigquery/datatransfer/apiv1/datatransferpb"
)

// deleteScheduledQuery delete a scheduled query based on
// the config ID, stopping any future runs.
// transferConfigID follows the format:
//
//	`projects/{project_id}/locations/{location_id}/transferConfigs/{config_id}`
//	or `projects/{project_id}/transferConfigs/{config_id}`
func deleteScheduledQuery(transferConfigID string) error {
	// transferConfigID := "projects/{project_id}/transferConfigs/{config_id}"
	ctx := context.Background()
	dtc, err := datatransfer.NewClient(ctx)
	if err != nil {
		return fmt.Errorf("datatransfer.NewClient: %w", err)
	}
	defer dtc.Close()

	req := &datatransferpb.DeleteTransferConfigRequest{
		Name: transferConfigID,
	}
	err = dtc.DeleteTransferConfig(ctx, req)
	if err != nil {
		return fmt.Errorf("dtc.DeleteTransferConfig: %w", err)
	}

	return nil
}

Java

Before trying this sample, follow the Java setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Java API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

import com.google.api.gax.rpc.ApiException;
import com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient;
import com.google.cloud.bigquery.datatransfer.v1.DeleteTransferConfigRequest;
import java.io.IOException;

// Sample to delete a scheduled query
public class DeleteScheduledQuery {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    // i.e projects/{project_id}/transferConfigs/{config_id}` or
    // `projects/{project_id}/locations/{location_id}/transferConfigs/{config_id}`
    String name = "MY_CONFIG_ID";
    deleteScheduledQuery(name);
  }

  public static void deleteScheduledQuery(String name) throws IOException {
    try (DataTransferServiceClient dataTransferServiceClient = DataTransferServiceClient.create()) {
      DeleteTransferConfigRequest request =
          DeleteTransferConfigRequest.newBuilder().setName(name).build();
      dataTransferServiceClient.deleteTransferConfig(request);
      System.out.print("Scheduled query deleted successfully.\n");
    } catch (ApiException ex) {
      System.out.print("Scheduled query was not deleted." + ex.toString());
    }
  }
}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.