Skip to content

Commit

Permalink
Add parent_job parameter to client.list_jobs()
Browse files Browse the repository at this point in the history
  • Loading branch information
plamut committed Sep 13, 2019
1 parent 971b0ad commit b0f261a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bigquery/google/cloud/bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ def cancel_job(self, job_id, project=None, location=None, retry=DEFAULT_RETRY):
def list_jobs(
self,
project=None,
parent_job=None,
max_results=None,
page_token=None,
all_users=None,
Expand All @@ -1233,6 +1234,11 @@ def list_jobs(
project (str, optional):
Project ID to use for retreiving datasets. Defaults
to the client's project.
parent_job (Optional[Union[ \
:class:`~google.cloud.bigquery.job._AsyncJob`, \
str, \
]]):
If set, retrieve only child jobs of the specified parent.
max_results (int, optional):
Maximum number of jobs to return.
page_token (str, optional):
Expand Down Expand Up @@ -1265,6 +1271,9 @@ def list_jobs(
google.api_core.page_iterator.Iterator:
Iterable of job instances.
"""
if isinstance(parent_job, job._AsyncJob):
parent_job = parent_job.job_id

extra_params = {
"allUsers": all_users,
"stateFilter": state_filter,
Expand All @@ -1275,6 +1284,7 @@ def list_jobs(
google.cloud._helpers._millis_from_datetime(max_creation_time)
),
"projection": "full",
"parentJobId": parent_job,
}

extra_params = {
Expand Down
18 changes: 18 additions & 0 deletions bigquery/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2952,6 +2952,24 @@ def test_list_jobs_w_time_filter(self):
},
)

def test_list_jobs_w_parent_job_filter(self):
from google.cloud.bigquery import job

creds = _make_credentials()
client = self._make_one(self.PROJECT, creds)
conn = client._connection = make_connection({}, {})

parent_job_args = ["parent-job-123", job._AsyncJob("parent-job-123", client)]

for parent_job in parent_job_args:
list(client.list_jobs(parent_job=parent_job))
conn.api_request.assert_called_once_with(
method="GET",
path="/projects/%s/jobs" % self.PROJECT,
query_params={"projection": "full", "parentJobId": "parent-job-123"},
)
conn.api_request.reset_mock()

def test_load_table_from_uri(self):
from google.cloud.bigquery.job import LoadJob

Expand Down

0 comments on commit b0f261a

Please sign in to comment.