Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions gcloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ def num_bytes(self):
:rtype: integer, or ``NoneType``
:returns: the byte count (None until set from the server).
"""
return self._properties.get('numBytes')
num_bytes_as_str = self._properties.get('numBytes')
if num_bytes_as_str is not None:
return int(num_bytes_as_str)

@property
def num_rows(self):
Expand All @@ -180,7 +182,9 @@ def num_rows(self):
:rtype: integer, or ``NoneType``
:returns: the row count (None until set from the server).
"""
return self._properties.get('numRows')
num_rows_as_str = self._properties.get('numRows')
if num_rows_as_str is not None:
return int(num_rows_as_str)

@property
def self_link(self):
Expand Down Expand Up @@ -247,7 +251,7 @@ def expires(self):

@expires.setter
def expires(self, value):
"""Update atetime at which the table will be removed.
"""Update datetime at which the table will be removed.

:type value: ``datetime.datetime``, or ``NoneType``
:param value: the new expiration time, or None
Expand Down
44 changes: 44 additions & 0 deletions gcloud/bigquery/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,50 @@ def test_ctor_w_schema(self):
schema=[full_name, age])
self.assertEqual(table.schema, [full_name, age])

def test_num_bytes_getter(self):
client = _Client(self.PROJECT)
dataset = _Dataset(client)
table = self._makeOne(self.TABLE_NAME, dataset)

# Check with no value set.
self.assertEqual(table.num_bytes, None)

num_bytes = 1337
# Check with integer value set.
table._properties = {'numBytes': num_bytes}
self.assertEqual(table.num_bytes, num_bytes)

# Check with a string value set.
table._properties = {'numBytes': str(num_bytes)}
self.assertEqual(table.num_bytes, num_bytes)

# Check with invalid int value.
table._properties = {'numBytes': 'x'}
with self.assertRaises(ValueError):
getattr(table, 'num_bytes')

def test_num_rows_getter(self):
client = _Client(self.PROJECT)
dataset = _Dataset(client)
table = self._makeOne(self.TABLE_NAME, dataset)

# Check with no value set.
self.assertEqual(table.num_rows, None)

num_rows = 42
# Check with integer value set.
table._properties = {'numRows': num_rows}
self.assertEqual(table.num_rows, num_rows)

# Check with a string value set.
table._properties = {'numRows': str(num_rows)}
self.assertEqual(table.num_rows, num_rows)

# Check with invalid int value.
table._properties = {'numRows': 'x'}
with self.assertRaises(ValueError):
getattr(table, 'num_rows')

def test_schema_setter_non_list(self):
client = _Client(self.PROJECT)
dataset = _Dataset(client)
Expand Down