Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bigquery): support job deletion #3935

Merged
merged 4 commits into from Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions bigquery/integration_test.go
Expand Up @@ -2582,6 +2582,29 @@ func TestIntegration_ListJobs(t *testing.T) {
}
}

func TestIntegration_DeleteJob(t *testing.T) {
if client == nil {
t.Skip("Integration tests skipped")
}
ctx := context.Background()

q := client.Query("SELECT 17 as foo")
q.Location = "us-east1"

job, err := q.Run(ctx)
if err != nil {
t.Fatalf("job Run failure: %v", err)
}
_, err = job.Wait(ctx)
if err != nil {
t.Fatalf("job completion failure: %v", err)
}

if err := job.Delete(ctx); err != nil {
t.Fatalf("job.Delete failed: %v", err)
}
}

const tokyo = "asia-northeast1"

func TestIntegration_Location(t *testing.T) {
Expand Down
17 changes: 17 additions & 0 deletions bigquery/job.go
Expand Up @@ -233,6 +233,23 @@ func (j *Job) Cancel(ctx context.Context) error {
})
}

// Delete deletes the job.
func (j *Job) Delete(ctx context.Context) (err error) {
ctx = trace.StartSpan(ctx, "cloud.google.com/go/bigquery.Job.Delete")
defer func() { trace.EndSpan(ctx, err) }()

call := j.c.bqs.Jobs.Delete(j.projectID, j.jobID).Context(ctx)
if j.location != "" {
call = call.Location(j.location)
}
setClientHeader(call.Header())

return runWithRetry(ctx, func() (err error) {
err = call.Do()
return err
})
}

// Wait blocks until the job or the context is done. It returns the final status
// of the job.
// If an error occurs while retrieving the status, Wait returns that error. But
Expand Down