-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding creationTime and expirationTime properties to TableListItem #7684
Changes from 2 commits
3b3220b
db05b8f
7618e9c
865d693
46d8d6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -906,6 +906,42 @@ def __init__(self, resource): | |
|
||
self._properties = resource | ||
|
||
@property | ||
def created(self): | ||
"""Union[datetime.datetime, None]: Datetime at which the table was | ||
created (:data:`None` until set from the server). | ||
""" | ||
creation_time = self._properties.get("creationTime") | ||
if creation_time is not None: | ||
# creation_time will be in milliseconds. | ||
return google.cloud._helpers._datetime_from_microseconds( | ||
1000.0 * float(creation_time) | ||
) | ||
|
||
@property | ||
def expires(self): | ||
"""Union[datetime.datetime, None]: Datetime at which the table will be | ||
deleted. | ||
|
||
Raises: | ||
ValueError: For invalid value types. | ||
""" | ||
expiration_time = self._properties.get("expirationTime") | ||
if expiration_time is not None: | ||
# expiration_time will be in milliseconds. | ||
return google.cloud._helpers._datetime_from_microseconds( | ||
1000.0 * float(expiration_time) | ||
) | ||
|
||
@expires.setter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TableListItem is read-only, so a setter is not needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the setter. |
||
def expires(self, value): | ||
if not isinstance(value, datetime.datetime) and value is not None: | ||
raise ValueError("Pass a datetime, or None") | ||
value_ms = google.cloud._helpers._millis_from_datetime(value) | ||
self._properties["tableReference"]["expirationTime"] = _helpers._str_or_none( | ||
value_ms | ||
) | ||
|
||
@property | ||
def project(self): | ||
"""str: Project bound to the table.""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1115,11 +1115,20 @@ def _get_target_class(): | |
def _make_one(self, *args, **kw): | ||
return self._get_target_class()(*args, **kw) | ||
|
||
def _setUpConstants(self): | ||
import datetime | ||
from google.cloud._helpers import UTC | ||
|
||
self.WHEN_TS = 1437767599.006 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made change to .125 as recommended. |
||
self.WHEN = datetime.datetime.utcfromtimestamp(self.WHEN_TS).replace(tzinfo=UTC) | ||
|
||
def test_ctor(self): | ||
self._setUpConstants() | ||
project = "test-project" | ||
dataset_id = "test_dataset" | ||
table_id = "coffee_table" | ||
resource = { | ||
"creationTime": self.WHEN_TS * 1000, | ||
"kind": "bigquery#table", | ||
"id": "{}:{}.{}".format(project, dataset_id, table_id), | ||
"tableReference": { | ||
|
@@ -1138,6 +1147,17 @@ def test_ctor(self): | |
} | ||
|
||
table = self._make_one(resource) | ||
|
||
if "creationTime" in resource: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the If statements for creation an expiration, added asserts on expected value. |
||
self.assertEqual(table.created, self.WHEN) | ||
else: | ||
self.assertIsNone(table.created) | ||
|
||
if "expirationTime" in resource: | ||
self.assertEqual(table.expires, self.EXP_TIME) | ||
else: | ||
self.assertIsNone(table.expires) | ||
|
||
self.assertEqual(table.project, project) | ||
self.assertEqual(table.dataset_id, dataset_id) | ||
self.assertEqual(table.table_id, table_id) | ||
|
@@ -1154,6 +1174,7 @@ def test_ctor(self): | |
self.assertEqual(table.time_partitioning.field, "mycolumn") | ||
self.assertEqual(table.labels["some-stuff"], "this-is-a-label") | ||
self.assertIsNone(table.view_use_legacy_sql) | ||
self.assertIsNone(table.expires) | ||
|
||
with warnings.catch_warnings(record=True) as warned: | ||
self.assertEqual(table.partitioning_type, "DAY") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Raises
section can be removed when the setter is removed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the raises comment since setter was removed!