Skip to content
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

fix: allow partial streaming_buffer statistics #37

Merged
merged 6 commits into from Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions google/cloud/bigquery/table.py
Expand Up @@ -1139,12 +1139,17 @@ class StreamingBuffer(object):
"""

def __init__(self, resource):
self.estimated_bytes = int(resource["estimatedBytes"])
self.estimated_rows = int(resource["estimatedRows"])
# time is in milliseconds since the epoch.
self.oldest_entry_time = google.cloud._helpers._datetime_from_microseconds(
1000.0 * int(resource["oldestEntryTime"])
)
self.estimated_bytes = None
if "estimatedBytes" in resource:
self.estimated_bytes = int(resource["estimatedBytes"])
self.estimated_rows = None
if "estimatedRows" in resource:
self.estimated_rows = int(resource["estimatedRows"])
self.oldest_entry_time = None
if "oldestEntryTime" in resource:
self.oldest_entry_time = google.cloud._helpers._datetime_from_microseconds(
1000.0 * int(resource["oldestEntryTime"])
)


class Row(object):
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_table.py
Expand Up @@ -855,6 +855,21 @@ def test_from_api_repr_w_properties(self):
table = klass.from_api_repr(RESOURCE)
self._verifyResourceProperties(table, RESOURCE)

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

RESOURCE = self._make_resource()
self.OLDEST_TIME = datetime.datetime(2015, 8, 1, 23, 59, 59, tzinfo=UTC)
RESOURCE["streamingBuffer"] = {"oldestEntryTime": _millis(self.OLDEST_TIME)}
klass = self._get_target_class()
table = klass.from_api_repr(RESOURCE)
self.assertIsNotNone(table.streaming_buffer)
self.assertIsNone(table.streaming_buffer.estimated_rows)
self.assertIsNone(table.streaming_buffer.estimated_bytes)
self.assertEqual(table.streaming_buffer.oldest_entry_time, self.OLDEST_TIME)

def test_from_api_with_encryption(self):
self._setUpConstants()
RESOURCE = {
Expand Down