Skip to content

Commit 4bcaaf5

Browse files
committed
Add job factory: 'Client.extract_table_to_storage'.
1 parent 0feb8f3 commit 4bcaaf5

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

gcloud/bigquery/client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from gcloud.bigquery.connection import Connection
2020
from gcloud.bigquery.dataset import Dataset
2121
from gcloud.bigquery.job import CopyJob
22+
from gcloud.bigquery.job import ExtractTableToStorageJob
2223
from gcloud.bigquery.job import LoadTableFromStorageJob
2324

2425

@@ -133,3 +134,22 @@ def copy_table(self, name, destination, *sources):
133134
:returns: a new ``CopyJob`` instance
134135
"""
135136
return CopyJob(name, destination, sources, client=self)
137+
138+
def extract_table_to_storage(self, name, source, *destination_uris):
139+
"""Construct a job for copying one or more tables into another table.
140+
141+
:type name: string
142+
:param name: Name of the job.
143+
144+
:type source: :class:`gcloud.bigquery.table.Table`
145+
:param source: table to be extracted.
146+
147+
:type destination_uris: sequence of string
148+
:param destination_uris: URIs of CloudStorage file(s) into which
149+
table data is to be extracted.
150+
151+
:rtype: :class:`gcloud.bigquery.job.ExtractTableToStorageJob`
152+
:returns: a new ``ExtractTableToStorageJob`` instance
153+
"""
154+
return ExtractTableToStorageJob(name, source, destination_uris,
155+
client=self)

gcloud/bigquery/test_client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,25 @@ def test_copy_table(self):
167167
self.assertEqual(list(job.sources), [source])
168168
self.assertTrue(job.destination is destination)
169169

170+
def test_extract_table_to_storage(self):
171+
from gcloud.bigquery.job import ExtractTableToStorageJob
172+
PROJECT = 'PROJECT'
173+
JOB = 'job_name'
174+
DATASET = 'dataset_name'
175+
SOURCE = 'source_table'
176+
DESTINATION = 'gs://bucket_name/object_name'
177+
creds = _Credentials()
178+
http = object()
179+
client = self._makeOne(project=PROJECT, credentials=creds, http=http)
180+
dataset = client.dataset(DATASET)
181+
source = dataset.table(SOURCE)
182+
job = client.extract_table_to_storage(JOB, source, DESTINATION)
183+
self.assertTrue(isinstance(job, ExtractTableToStorageJob))
184+
self.assertTrue(job._client is client)
185+
self.assertEqual(job.name, JOB)
186+
self.assertEqual(job.source, source)
187+
self.assertEqual(list(job.destination_uris), [DESTINATION])
188+
170189

171190
class _Credentials(object):
172191

0 commit comments

Comments
 (0)