Skip to content

Commit

Permalink
feat(bigquery): support job deletion (#3935)
Browse files Browse the repository at this point in the history
* feat(bigquery): support job deletion
  • Loading branch information
shollyman committed Jun 14, 2021
1 parent 2220787 commit 363ba03
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
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

0 comments on commit 363ba03

Please sign in to comment.