@@ -46,17 +46,24 @@ type Job struct {
46
46
// For jobs whose location is other than "US" or "EU", set Client.Location or use
47
47
// JobFromIDLocation.
48
48
func (c * Client ) JobFromID (ctx context.Context , id string ) (* Job , error ) {
49
- return c .JobFromIDLocation (ctx , id , c .Location )
49
+ return c .JobFromProject (ctx , c . projectID , id , c .Location )
50
50
}
51
51
52
52
// JobFromIDLocation creates a Job which refers to an existing BigQuery job. The job
53
53
// need not have been created by this package (for example, it may have
54
54
// been created in the BigQuery console), but it must exist in the specified location.
55
55
func (c * Client ) JobFromIDLocation (ctx context.Context , id , location string ) (j * Job , err error ) {
56
- ctx = trace .StartSpan (ctx , "cloud.google.com/go/bigquery.JobFromIDLocation" )
56
+ return c .JobFromProject (ctx , c .projectID , id , location )
57
+ }
58
+
59
+ // JobFromProject creates a Job which refers to an existing BigQuery job. The job
60
+ // need not have been created by this package, nor does it need to reside within the same
61
+ // project or location as the instantiated client.
62
+ func (c * Client ) JobFromProject (ctx context.Context , projectID , jobID , location string ) (j * Job , err error ) {
63
+ ctx = trace .StartSpan (ctx , "cloud.google.com/go/bigquery.JobFromProject" )
57
64
defer func () { trace .EndSpan (ctx , err ) }()
58
65
59
- bqjob , err := c .getJobInternal (ctx , id , location , "configuration" , "jobReference" , "status" , "statistics" )
66
+ bqjob , err := c .getJobInternal (ctx , jobID , location , projectID , "configuration" , "jobReference" , "status" , "statistics" )
60
67
if err != nil {
61
68
return nil , err
62
69
}
@@ -799,9 +806,13 @@ func convertListedJob(j *bq.JobListJobs, c *Client) (*Job, error) {
799
806
return bqToJob2 (j .JobReference , j .Configuration , j .Status , j .Statistics , j .UserEmail , c )
800
807
}
801
808
802
- func (c * Client ) getJobInternal (ctx context.Context , jobID , location string , fields ... googleapi.Field ) (* bq.Job , error ) {
809
+ func (c * Client ) getJobInternal (ctx context.Context , jobID , location , projectID string , fields ... googleapi.Field ) (* bq.Job , error ) {
803
810
var job * bq.Job
804
- call := c .bqs .Jobs .Get (c .projectID , jobID ).Context (ctx )
811
+ proj := projectID
812
+ if proj == "" {
813
+ proj = c .projectID
814
+ }
815
+ call := c .bqs .Jobs .Get (proj , jobID ).Context (ctx )
805
816
if location != "" {
806
817
call = call .Location (location )
807
818
}
0 commit comments