Skip to content

Commit 16dba9d

Browse files
committed
Add 'Client.copy_table' factory.
1 parent 3ef5ed1 commit 16dba9d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

gcloud/bigquery/client.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from gcloud.client import JSONClient
1919
from gcloud.bigquery.connection import Connection
2020
from gcloud.bigquery.dataset import Dataset
21+
from gcloud.bigquery.job import CopyJob
2122
from gcloud.bigquery.job import LoadTableFromStorageJob
2223

2324

@@ -115,3 +116,20 @@ def load_table_from_storage(self, name, destination, *source_uris):
115116
"""
116117
return LoadTableFromStorageJob(name, destination, source_uris,
117118
client=self)
119+
120+
def copy_table(self, name, destination, *sources):
121+
"""Construct a job for copying one or more tables into another table.
122+
123+
:type name: string
124+
:param name: Name of the job.
125+
126+
:type destination: :class:`gcloud.bigquery.table.Table`
127+
:param destination: Table into which data is to be copied.
128+
129+
:type sources: sequence of :class:`gcloud.bigquery.table.Table`
130+
:param sources: tables to be copied.
131+
132+
:rtype: :class:`gcloud.bigquery.job.CopyJob`
133+
:returns: a new ``CopyJob`` instance
134+
"""
135+
return CopyJob(name, destination, sources, client=self)

gcloud/bigquery/test_client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,26 @@ def test_load_table_from_storage(self):
147147
self.assertEqual(list(job.source_uris), [SOURCE_URI])
148148
self.assertTrue(job.destination is destination)
149149

150+
def test_copy_table(self):
151+
from gcloud.bigquery.job import CopyJob
152+
PROJECT = 'PROJECT'
153+
JOB = 'job_name'
154+
DATASET = 'dataset_name'
155+
SOURCE = 'source_table'
156+
DESTINATION = 'destination_table'
157+
creds = _Credentials()
158+
http = object()
159+
client = self._makeOne(project=PROJECT, credentials=creds, http=http)
160+
dataset = client.dataset(DATASET)
161+
source = dataset.table(SOURCE)
162+
destination = dataset.table(DESTINATION)
163+
job = client.copy_table(JOB, destination, source)
164+
self.assertTrue(isinstance(job, CopyJob))
165+
self.assertTrue(job._client is client)
166+
self.assertEqual(job.name, JOB)
167+
self.assertEqual(list(job.sources), [source])
168+
self.assertTrue(job.destination is destination)
169+
150170

151171
class _Credentials(object):
152172

0 commit comments

Comments
 (0)