Skip to content

Commit b0f261a

Browse files
committed
Add parent_job parameter to client.list_jobs()
1 parent 971b0ad commit b0f261a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

bigquery/google/cloud/bigquery/client.py

+10
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,7 @@ def cancel_job(self, job_id, project=None, location=None, retry=DEFAULT_RETRY):
12161216
def list_jobs(
12171217
self,
12181218
project=None,
1219+
parent_job=None,
12191220
max_results=None,
12201221
page_token=None,
12211222
all_users=None,
@@ -1233,6 +1234,11 @@ def list_jobs(
12331234
project (str, optional):
12341235
Project ID to use for retreiving datasets. Defaults
12351236
to the client's project.
1237+
parent_job (Optional[Union[ \
1238+
:class:`~google.cloud.bigquery.job._AsyncJob`, \
1239+
str, \
1240+
]]):
1241+
If set, retrieve only child jobs of the specified parent.
12361242
max_results (int, optional):
12371243
Maximum number of jobs to return.
12381244
page_token (str, optional):
@@ -1265,6 +1271,9 @@ def list_jobs(
12651271
google.api_core.page_iterator.Iterator:
12661272
Iterable of job instances.
12671273
"""
1274+
if isinstance(parent_job, job._AsyncJob):
1275+
parent_job = parent_job.job_id
1276+
12681277
extra_params = {
12691278
"allUsers": all_users,
12701279
"stateFilter": state_filter,
@@ -1275,6 +1284,7 @@ def list_jobs(
12751284
google.cloud._helpers._millis_from_datetime(max_creation_time)
12761285
),
12771286
"projection": "full",
1287+
"parentJobId": parent_job,
12781288
}
12791289

12801290
extra_params = {

bigquery/tests/unit/test_client.py

+18
Original file line numberDiff line numberDiff line change
@@ -2952,6 +2952,24 @@ def test_list_jobs_w_time_filter(self):
29522952
},
29532953
)
29542954

2955+
def test_list_jobs_w_parent_job_filter(self):
2956+
from google.cloud.bigquery import job
2957+
2958+
creds = _make_credentials()
2959+
client = self._make_one(self.PROJECT, creds)
2960+
conn = client._connection = make_connection({}, {})
2961+
2962+
parent_job_args = ["parent-job-123", job._AsyncJob("parent-job-123", client)]
2963+
2964+
for parent_job in parent_job_args:
2965+
list(client.list_jobs(parent_job=parent_job))
2966+
conn.api_request.assert_called_once_with(
2967+
method="GET",
2968+
path="/projects/%s/jobs" % self.PROJECT,
2969+
query_params={"projection": "full", "parentJobId": "parent-job-123"},
2970+
)
2971+
conn.api_request.reset_mock()
2972+
29552973
def test_load_table_from_uri(self):
29562974
from google.cloud.bigquery.job import LoadJob
29572975

0 commit comments

Comments
 (0)