Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
removes table.create()
  • Loading branch information
alixhami committed Sep 22, 2017
commit 9a8fb888fdd7034754069ff4fcfb946b394d45f7
2 changes: 1 addition & 1 deletion bigquery/google/cloud/bigquery/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def create_dataset(self, dataset):
return Dataset.from_api_repr(api_response)

def create_table(self, table):
"""API call: create the table via a PUT request
"""API call: create a table via a PUT request

See
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/insert
Expand Down
18 changes: 0 additions & 18 deletions bigquery/google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,24 +596,6 @@ def _build_resource(self):

return resource

def create(self, client=None):
"""API call: create the table via a PUT request

See
https://cloud.google.com/bigquery/docs/reference/rest/v2/tables/insert

:type client: :class:`~google.cloud.bigquery.client.Client` or
``NoneType``
:param client: the client to use. If not passed, falls back to the
``client`` stored on the current dataset.
"""
client = self._require_client(client)
path = '/projects/%s/datasets/%s/tables' % (
self._project, self._dataset_id)
api_response = client._connection.api_request(
method='POST', path=path, data=self._build_resource())
self._set_properties(api_response)

def exists(self, client=None):
"""API call: test for the existence of the table via a GET request

Expand Down
6 changes: 3 additions & 3 deletions bigquery/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ def test_create_table(self):
self.assertFalse(table.exists())

got = retry_403(Config.CLIENT.create_table)(table)

self.to_delete.insert(0, got)

self.assertTrue(got.exists())
self.assertEqual(got.table_id, table_id)

Expand Down Expand Up @@ -237,8 +237,8 @@ def test_list_dataset_tables(self):
age = bigquery.SchemaField('age', 'INTEGER', mode='REQUIRED')
for table_name in tables_to_create:
table = Table(dataset.table(table_name),
schema=[full_name, age],
client=Config.CLIENT)
schema=[full_name, age],
client=Config.CLIENT)
created_table = Config.CLIENT.create_table(table)
self.to_delete.insert(0, created_table)

Expand Down
1 change: 0 additions & 1 deletion bigquery/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ def test_create_table_w_schema(self):
{'name': 'full_name', 'type': 'STRING', 'mode': 'REQUIRED'},
{'name': 'age', 'type': 'INTEGER', 'mode': 'REQUIRED'}]
},

}
schema = [
SchemaField('full_name', 'STRING', mode='REQUIRED'),
Expand Down
214 changes: 0 additions & 214 deletions bigquery/tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,135 +465,6 @@ def test_from_api_repr_w_properties(self):
self.assertIs(table._client, client)
self._verifyResourceProperties(table, RESOURCE)

def test_create_new_day_partitioned_table(self):
PATH = 'projects/%s/datasets/%s/tables' % (self.PROJECT, self.DS_ID)
RESOURCE = self._makeResource()
conn = _Connection(RESOURCE)
client = _Client(project=self.PROJECT, connection=conn)
dataset = DatasetReference(self.PROJECT, self.DS_ID)
table_ref = dataset.table(self.TABLE_NAME)
table = self._make_one(table_ref, client=client)
table.partitioning_type = 'DAY'
table.create()

self.assertEqual(len(conn._requested), 1)
req = conn._requested[0]
self.assertEqual(req['method'], 'POST')
self.assertEqual(req['path'], '/%s' % PATH)
SENT = {
'tableReference': {
'projectId': self.PROJECT,
'datasetId': self.DS_ID,
'tableId': self.TABLE_NAME},
'timePartitioning': {'type': 'DAY'},
}
self.assertEqual(req['data'], SENT)
self._verifyResourceProperties(table, RESOURCE)

def test_create_w_bound_client(self):
from google.cloud.bigquery.table import SchemaField

PATH = 'projects/%s/datasets/%s/tables' % (self.PROJECT, self.DS_ID)
RESOURCE = self._makeResource()
conn = _Connection(RESOURCE)
client = _Client(project=self.PROJECT, connection=conn)
dataset = DatasetReference(self.PROJECT, self.DS_ID)
table_ref = dataset.table(self.TABLE_NAME)
full_name = SchemaField('full_name', 'STRING', mode='REQUIRED')
age = SchemaField('age', 'INTEGER', mode='REQUIRED')
table = self._make_one(table_ref, schema=[full_name, age],
client=client)

table.create()

self.assertEqual(len(conn._requested), 1)
req = conn._requested[0]
self.assertEqual(req['method'], 'POST')
self.assertEqual(req['path'], '/%s' % PATH)
SENT = {
'tableReference': {
'projectId': self.PROJECT,
'datasetId': self.DS_ID,
'tableId': self.TABLE_NAME},
'schema': {'fields': [
{'name': 'full_name', 'type': 'STRING', 'mode': 'REQUIRED'},
{'name': 'age', 'type': 'INTEGER', 'mode': 'REQUIRED'}]},
}
self.assertEqual(req['data'], SENT)
self._verifyResourceProperties(table, RESOURCE)

def test_create_w_partition_no_expire(self):
from google.cloud.bigquery.table import SchemaField

PATH = 'projects/%s/datasets/%s/tables' % (self.PROJECT, self.DS_ID)
RESOURCE = self._makeResource()
conn = _Connection(RESOURCE)
client = _Client(project=self.PROJECT, connection=conn)
dataset = DatasetReference(self.PROJECT, self.DS_ID)
table_ref = dataset.table(self.TABLE_NAME)
full_name = SchemaField('full_name', 'STRING', mode='REQUIRED')
age = SchemaField('age', 'INTEGER', mode='REQUIRED')
table = self._make_one(table_ref, schema=[full_name, age],
client=client)

self.assertIsNone(table.partitioning_type)
table.partitioning_type = "DAY"
self.assertEqual(table.partitioning_type, "DAY")
table.create()

self.assertEqual(len(conn._requested), 1)
req = conn._requested[0]
self.assertEqual(req['method'], 'POST')
self.assertEqual(req['path'], '/%s' % PATH)
SENT = {
'tableReference': {
'projectId': self.PROJECT,
'datasetId': self.DS_ID,
'tableId': self.TABLE_NAME},
'timePartitioning': {'type': 'DAY'},
'schema': {'fields': [
{'name': 'full_name', 'type': 'STRING', 'mode': 'REQUIRED'},
{'name': 'age', 'type': 'INTEGER', 'mode': 'REQUIRED'}]},
}
self.assertEqual(req['data'], SENT)
self._verifyResourceProperties(table, RESOURCE)

def test_create_w_partition_and_expire(self):
from google.cloud.bigquery.table import SchemaField

PATH = 'projects/%s/datasets/%s/tables' % (self.PROJECT, self.DS_ID)
RESOURCE = self._makeResource()
conn = _Connection(RESOURCE)
client = _Client(project=self.PROJECT, connection=conn)
dataset = DatasetReference(self.PROJECT, self.DS_ID)
table_ref = dataset.table(self.TABLE_NAME)
full_name = SchemaField('full_name', 'STRING', mode='REQUIRED')
age = SchemaField('age', 'INTEGER', mode='REQUIRED')
table = self._make_one(table_ref, schema=[full_name, age],
client=client)
self.assertIsNone(table.partition_expiration)
table.partition_expiration = 100
self.assertEqual(table.partitioning_type, "DAY")
self.assertEqual(table.partition_expiration, 100)
table.create()

self.assertEqual(len(conn._requested), 1)
req = conn._requested[0]
self.assertEqual(req['method'], 'POST')
self.assertEqual(req['path'], '/%s' % PATH)
SENT = {
'tableReference': {
'projectId': self.PROJECT,
'datasetId': self.DS_ID,
'tableId': self.TABLE_NAME},
'timePartitioning': {'type': 'DAY', 'expirationMs': 100},
'schema': {'fields': [
{'name': 'full_name', 'type': 'STRING', 'mode': 'REQUIRED'},
{'name': 'age', 'type': 'INTEGER', 'mode': 'REQUIRED'}]},
}
self.assertEqual(req['data'], SENT)
self._verifyResourceProperties(table, RESOURCE)

def test_partition_type_setter_bad_type(self):
from google.cloud.bigquery.table import SchemaField

Expand Down Expand Up @@ -741,91 +612,6 @@ def test_list_partitions(self):
client=client)
self.assertEqual(table.list_partitions(), [20160804, 20160805])

def test_create_w_alternate_client(self):
import datetime
from google.cloud._helpers import UTC
from google.cloud._helpers import _millis

PATH = 'projects/%s/datasets/%s/tables' % (self.PROJECT, self.DS_ID)
DESCRIPTION = 'DESCRIPTION'
TITLE = 'TITLE'
QUERY = 'select fullname, age from person_ages'
RESOURCE = self._makeResource()
RESOURCE['description'] = DESCRIPTION
RESOURCE['friendlyName'] = TITLE
self.EXP_TIME = datetime.datetime(2015, 8, 1, 23, 59, 59,
tzinfo=UTC)
RESOURCE['expirationTime'] = _millis(self.EXP_TIME)
RESOURCE['view'] = {}
RESOURCE['view']['query'] = QUERY
RESOURCE['type'] = 'VIEW'
conn1 = _Connection()
client1 = _Client(project=self.PROJECT, connection=conn1)
conn2 = _Connection(RESOURCE)
client2 = _Client(project=self.PROJECT, connection=conn2)
dataset = DatasetReference(self.PROJECT, self.DS_ID)
table_ref = dataset.table(self.TABLE_NAME)
table = self._make_one(table_ref, client=client1)
table.friendly_name = TITLE
table.description = DESCRIPTION
table.view_query = QUERY

table.create(client=client2)

self.assertEqual(len(conn1._requested), 0)
self.assertEqual(len(conn2._requested), 1)
req = conn2._requested[0]
self.assertEqual(req['method'], 'POST')
self.assertEqual(req['path'], '/%s' % PATH)
SENT = {
'tableReference': {
'projectId': self.PROJECT,
'datasetId': self.DS_ID,
'tableId': self.TABLE_NAME},
'description': DESCRIPTION,
'friendlyName': TITLE,
'view': {'query': QUERY},
}
self.assertEqual(req['data'], SENT)
self._verifyResourceProperties(table, RESOURCE)

def test_create_w_missing_output_properties(self):
# In the wild, the resource returned from 'dataset.create' sometimes
# lacks 'creationTime' / 'lastModifiedTime'
from google.cloud.bigquery.table import SchemaField

PATH = 'projects/%s/datasets/%s/tables' % (self.PROJECT, self.DS_ID)
RESOURCE = self._makeResource()
del RESOURCE['creationTime']
del RESOURCE['lastModifiedTime']
self.WHEN = None
conn = _Connection(RESOURCE)
client = _Client(project=self.PROJECT, connection=conn)
dataset = DatasetReference(self.PROJECT, self.DS_ID)
table_ref = dataset.table(self.TABLE_NAME)
full_name = SchemaField('full_name', 'STRING', mode='REQUIRED')
age = SchemaField('age', 'INTEGER', mode='REQUIRED')
table = self._make_one(table_ref, schema=[full_name, age],
client=client)

table.create()

self.assertEqual(len(conn._requested), 1)
req = conn._requested[0]
self.assertEqual(req['method'], 'POST')
self.assertEqual(req['path'], '/%s' % PATH)
SENT = {
'tableReference': {
'projectId': self.PROJECT,
'datasetId': self.DS_ID,
'tableId': self.TABLE_NAME},
'schema': {'fields': [
{'name': 'full_name', 'type': 'STRING', 'mode': 'REQUIRED'},
{'name': 'age', 'type': 'INTEGER', 'mode': 'REQUIRED'}]},
}
self.assertEqual(req['data'], SENT)
self._verifyResourceProperties(table, RESOURCE)

def test_exists_miss_w_bound_client(self):
PATH = 'projects/%s/datasets/%s/tables/%s' % (
self.PROJECT, self.DS_ID, self.TABLE_NAME)
Expand Down