Skip to content

Commit 363ba03

Browse files
authored
feat(bigquery): support job deletion (#3935)
* feat(bigquery): support job deletion
1 parent 2220787 commit 363ba03

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

Diff for: bigquery/integration_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -2582,6 +2582,29 @@ func TestIntegration_ListJobs(t *testing.T) {
25822582
}
25832583
}
25842584

2585+
func TestIntegration_DeleteJob(t *testing.T) {
2586+
if client == nil {
2587+
t.Skip("Integration tests skipped")
2588+
}
2589+
ctx := context.Background()
2590+
2591+
q := client.Query("SELECT 17 as foo")
2592+
q.Location = "us-east1"
2593+
2594+
job, err := q.Run(ctx)
2595+
if err != nil {
2596+
t.Fatalf("job Run failure: %v", err)
2597+
}
2598+
_, err = job.Wait(ctx)
2599+
if err != nil {
2600+
t.Fatalf("job completion failure: %v", err)
2601+
}
2602+
2603+
if err := job.Delete(ctx); err != nil {
2604+
t.Fatalf("job.Delete failed: %v", err)
2605+
}
2606+
}
2607+
25852608
const tokyo = "asia-northeast1"
25862609

25872610
func TestIntegration_Location(t *testing.T) {

Diff for: bigquery/job.go

+17
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,23 @@ func (j *Job) Cancel(ctx context.Context) error {
233233
})
234234
}
235235

236+
// Delete deletes the job.
237+
func (j *Job) Delete(ctx context.Context) (err error) {
238+
ctx = trace.StartSpan(ctx, "cloud.google.com/go/bigquery.Job.Delete")
239+
defer func() { trace.EndSpan(ctx, err) }()
240+
241+
call := j.c.bqs.Jobs.Delete(j.projectID, j.jobID).Context(ctx)
242+
if j.location != "" {
243+
call = call.Location(j.location)
244+
}
245+
setClientHeader(call.Header())
246+
247+
return runWithRetry(ctx, func() (err error) {
248+
err = call.Do()
249+
return err
250+
})
251+
}
252+
236253
// Wait blocks until the job or the context is done. It returns the final status
237254
// of the job.
238255
// If an error occurs while retrieving the status, Wait returns that error. But

0 commit comments

Comments
 (0)