Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2aad717

Browse files
committedSep 19, 2017
BigQuery: client.extract_table use **kwargs for Python 2.7.
1 parent 2ec56fd commit 2aad717

File tree

5 files changed

+30
-16
lines changed

5 files changed

+30
-16
lines changed
 

‎bigquery/google/cloud/bigquery/client.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,8 @@ def copy_table(self, job_id, destination, *sources):
387387
"""
388388
return CopyJob(job_id, destination, sources, client=self)
389389

390-
def extract_table(
391-
self, source, *destination_uris, job_config=None, job_id=None):
392-
"""Construct a job for extracting a table into Cloud Storage files.
390+
def extract_table(self, source, *destination_uris, **kwargs):
391+
"""Start a job to extract a table into Cloud Storage files.
393392
394393
See
395394
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.extract
@@ -402,16 +401,27 @@ def extract_table(
402401
URIs of Cloud Storage file(s) into which table data is to be
403402
extracted; in format ``gs://<bucket_name>/<object_name_or_glob>``.
404403
405-
:type job_config: :class:`google.cloud.bigquery.job.ExtractJobConfig`
406-
:param job_config:
407-
(Optional) Extra configuration options for the extract job.
404+
:type kwargs: dict
405+
:param kwargs: Additional keyword arguments.
408406
409-
:type job_id: str
410-
:param job_id: (Optional) The ID of the job.
407+
:Keyword Arguments:
408+
* *job_config*
409+
(:class:`google.cloud.bigquery.job.ExtractJobConfig`) --
410+
(Optional) Extra configuration options for the extract job.
411+
* *job_id* (``str``) --
412+
Additional content
413+
(Optional) The ID of the job.
411414
412415
:rtype: :class:`google.cloud.bigquery.job.ExtractJob`
413416
:returns: a new ``ExtractJob`` instance
414417
"""
418+
job_config = None
419+
if 'job_config' in kwargs:
420+
job_config = kwargs['job_config']
421+
422+
job_id = None
423+
if 'job_id' in kwargs:
424+
job_id = kwargs['job_id']
415425
if job_id is None:
416426
job_id = str(uuid.uuid4())
417427

‎bigquery/google/cloud/bigquery/job.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,7 @@ def to_api_repr(self):
10171017
:rtype: dict
10181018
:returns: A dictionary in the format used by the BigQuery API.
10191019
"""
1020-
resource = copy.deepcopy(self._properties)
1021-
return resource
1020+
return copy.deepcopy(self._properties)
10221021

10231022
@classmethod
10241023
def from_api_repr(cls, resource):
@@ -1120,7 +1119,7 @@ def _build_resource(self):
11201119
"""Generate a resource for :meth:`begin`."""
11211120

11221121
source_ref = {
1123-
'projectId': self.source.dataset.project_id,
1122+
'projectId': self.source.dataset.project,
11241123
'datasetId': self.source.dataset.dataset_id,
11251124
'tableId': self.source.table_id,
11261125
}

‎bigquery/tests/system.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,8 @@ def _load_table_for_extract_table(
566566
blob.upload_from_file(csv_read, content_type='text/csv')
567567
self.to_delete.insert(0, blob)
568568

569-
dataset = Dataset(
570-
table.dataset.dataset_id, Config.CLIENT)
571-
retry_403(dataset.create)()
569+
dataset = retry_403(Config.CLIENT.create_dataset)(
570+
Dataset(table.dataset.dataset_id))
572571
self.to_delete.append(dataset)
573572
table = dataset.table(table.table_id)
574573
self.to_delete.insert(0, table)

‎bigquery/tests/unit/test_client.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ def test_extract_table(self):
763763

764764
def test_extract_table_generated_job_id(self):
765765
from google.cloud.bigquery.job import ExtractJob
766+
from google.cloud.bigquery.job import ExtractJobConfig
767+
from google.cloud.bigquery.job import DestinationFormat
766768

767769
PROJECT = 'PROJECT'
768770
JOB = 'job_name'
@@ -782,6 +784,7 @@ def test_extract_table_generated_job_id(self):
782784
'tableId': SOURCE,
783785
},
784786
'destinationUris': [DESTINATION],
787+
'destinationFormat': 'NEWLINE_DELIMITED_JSON',
785788
},
786789
},
787790
}
@@ -791,8 +794,11 @@ def test_extract_table_generated_job_id(self):
791794
conn = client._connection = _Connection(RESOURCE)
792795
dataset = client.dataset(DATASET)
793796
source = dataset.table(SOURCE)
797+
job_config = ExtractJobConfig()
798+
job_config.destination_format = (
799+
DestinationFormat.NEWLINE_DELIMITED_JSON)
794800

795-
job = client.extract_table(source, DESTINATION)
801+
job = client.extract_table(source, DESTINATION, job_config=job_config)
796802

797803
# Check that extract_table actually starts the job.
798804
self.assertEqual(len(conn._requested), 1)

‎bigquery/tests/unit/test_job.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ def _verifyResourceProperties(self, job, resource):
12201220
self.assertEqual(job.destination_uris, config['destinationUris'])
12211221

12221222
table_ref = config['sourceTable']
1223-
self.assertEqual(job.source.dataset.project_id, table_ref['projectId'])
1223+
self.assertEqual(job.source.dataset.project, table_ref['projectId'])
12241224
self.assertEqual(job.source.dataset.dataset_id, table_ref['datasetId'])
12251225
self.assertEqual(job.source.table_id, table_ref['tableId'])
12261226

0 commit comments

Comments
 (0)
Please sign in to comment.