Skip to content

Commit

Permalink
Merging some upstream changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Jan 20, 2016
1 parent 3c5b059 commit 4286446
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 38 deletions.
18 changes: 18 additions & 0 deletions gcloud_bigtable/_non_upstream_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,21 @@ def _total_seconds(offset):
return _total_seconds_backport(offset)
else:
return offset.total_seconds()


def _pb_timestamp_to_datetime(timestamp):
"""Convert a Timestamp protobuf to a datetime object.
:type timestamp: :class:`google.protobuf.timestamp_pb2.Timestamp`
:param timestamp: A Google returned timestamp protobuf.
:rtype: :class:`datetime.datetime`
:returns: A UTC datetime object converted from a protobuf timestamp.
"""
return (
EPOCH +
datetime.timedelta(
seconds=timestamp.seconds,
microseconds=(timestamp.nanos / 1000.0),
)
)
27 changes: 4 additions & 23 deletions gcloud_bigtable/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""User friendly container for Google Cloud Bigtable Cluster."""


import datetime
import re

from google.longrunning import operations_pb2
Expand All @@ -25,7 +24,7 @@
bigtable_cluster_service_messages_pb2 as messages_pb2)
from gcloud_bigtable._generated import (
bigtable_table_service_messages_pb2 as table_messages_pb2)
from gcloud_bigtable._non_upstream_helpers import EPOCH as _EPOCH
from gcloud_bigtable._non_upstream_helpers import _pb_timestamp_to_datetime
from gcloud_bigtable.table import Table


Expand Down Expand Up @@ -93,24 +92,6 @@ def _prepare_create_request(cluster):
)


def _pb_timestamp_to_datetime(timestamp):
"""Convert a Timestamp protobuf to a datetime object.
:type timestamp: :class:`google.protobuf.timestamp_pb2.Timestamp`
:param timestamp: A Google returned timestamp protobuf.
:rtype: :class:`datetime.datetime`
:returns: A UTC datetime object converted from a protobuf timestamp.
"""
return (
_EPOCH +
datetime.timedelta(
seconds=timestamp.seconds,
microseconds=(timestamp.nanos / 1000.0),
)
)


def _parse_pb_any_to_native(any_val, expected_type=None):
"""Convert a serialized "google.protobuf.Any" value to actual type.
Expand Down Expand Up @@ -214,7 +195,7 @@ def finished(self):
operation_name = ('operations/' + self._cluster.name +
'/operations/%d' % (self.op_id,))
request_pb = operations_pb2.GetOperationRequest(name=operation_name)
# We expect a :class:`google.longrunning.operations_pb2.Operation`
# We expect a `google.longrunning.operations_pb2.Operation`.
operation_pb = self._cluster._client._operations_stub.GetOperation(
request_pb, self._cluster._client.timeout_seconds)

Expand Down Expand Up @@ -395,7 +376,7 @@ def create(self):
create operation.
"""
request_pb = _prepare_create_request(self)
# We expect an :class:`google.longrunning.operations_pb2.Operation`
# We expect a `google.longrunning.operations_pb2.Operation`.
cluster_pb = self._client._cluster_stub.CreateCluster(
request_pb, self._client.timeout_seconds)

Expand Down Expand Up @@ -489,7 +470,7 @@ def undelete(self):
undelete operation.
"""
request_pb = messages_pb2.UndeleteClusterRequest(name=self.name)
# We expect a :class:`google.longrunning.operations_pb2.Operation`
# We expect a `google.longrunning.operations_pb2.Operation`.
operation_pb2 = self._client._cluster_stub.UndeleteCluster(
request_pb, self._client.timeout_seconds)

Expand Down
14 changes: 9 additions & 5 deletions gcloud_bigtable/column_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _timedelta_to_duration_pb(timedelta_val):
:type timedelta_val: :class:`datetime.timedelta`
:param timedelta_val: A timedelta object.
:rtype: :class:`.duration_pb2.Duration`
:rtype: :class:`google.protobuf.duration_pb2.Duration`
:returns: A duration object equivalent to the time delta.
"""
seconds_decimal = _total_seconds(timedelta_val)
Expand All @@ -59,7 +59,7 @@ def _duration_pb_to_timedelta(duration_pb):
The Python timedelta has a granularity of microseconds while
the protobuf duration type has a duration of nanoseconds.
:type duration_pb: :class:`.duration_pb2.Duration`
:type duration_pb: :class:`google.protobuf.duration_pb2.Duration`
:param duration_pb: A protobuf duration object.
:rtype: :class:`datetime.timedelta`
Expand Down Expand Up @@ -259,7 +259,9 @@ def create(self):
column_family=column_family,
)
client = self._table._cluster._client
# We expect a `.data_pb2.ColumnFamily`
# We expect a `.data_pb2.ColumnFamily`. We ignore it since the only
# data it contains are the GC rule and the column family ID already
# stored on this instance.
client._table_stub.CreateColumnFamily(request_pb,
client.timeout_seconds)

Expand All @@ -276,15 +278,17 @@ def update(self):
request_kwargs['gc_rule'] = self.gc_rule.to_pb()
request_pb = data_pb2.ColumnFamily(**request_kwargs)
client = self._table._cluster._client
# We expect a `.data_pb2.ColumnFamily`
# We expect a `.data_pb2.ColumnFamily`. We ignore it since the only
# data it contains are the GC rule and the column family ID already
# stored on this instance.
client._table_stub.UpdateColumnFamily(request_pb,
client.timeout_seconds)

def delete(self):
"""Delete this column family."""
request_pb = messages_pb2.DeleteColumnFamilyRequest(name=self.name)
client = self._table._cluster._client
# We expect a `._generated.empty_pb2.Empty`
# We expect a `google.protobuf.empty_pb2.Empty`
client._table_stub.DeleteColumnFamily(request_pb,
client.timeout_seconds)

Expand Down
11 changes: 6 additions & 5 deletions gcloud_bigtable/happybase/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from gcloud_bigtable.table import Table as _LowLevelTable


# Constants reproduced here for compatibility, though values are
# all null.
# Constants reproduced here for HappyBase compatibility, though values
# are all null.
COMPAT_MODES = None
THRIFT_TRANSPORTS = None
THRIFT_PROTOCOLS = None
Expand Down Expand Up @@ -149,14 +149,15 @@ class Connection(object):
:param timeout: (Optional) The socket timeout in milliseconds.
:type autoconnect: bool
:param autoconnect: Whether the connection should be :meth:`open`-ed
during construction.
:param autoconnect: (Optional) Whether the connection should be
:meth:`open`-ed during construction.
:type table_prefix: str
:param table_prefix: (Optional) Prefix used to construct table names.
:type table_prefix_separator: str
:param table_prefix_separator: Separator used with ``table_prefix``.
:param table_prefix_separator: (Optional) Separator used with
``table_prefix``. Defaults to ``_``.
:type compat: :data:`NoneType <types.NoneType>`
:param compat: Unused parameter. Provided for compatibility with
Expand Down
4 changes: 2 additions & 2 deletions gcloud_bigtable/row.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ def _get_mutations(self, state=None):
:raises: :class:`ValueError <exceptions.ValueError>`
"""
if state is None:
if self.filter is not None:
if self._filter is not None:
raise ValueError('A filter is set on the current row, but no '
'state given for the mutation')
return self._pb_mutations
else:
if self.filter is None:
if self._filter is None:
raise ValueError('No filter was set on the current row, but a '
'state was given for the mutation')
if state:
Expand Down
7 changes: 4 additions & 3 deletions gcloud_bigtable/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,10 @@ def delete(self):
def list_column_families(self):
"""List the column families owned by this table.
:rtype: dictionary with string as keys and
:class:`.column_family.ColumnFamily` as values
:returns: List of column families attached to this table.
:rtype: dict
:returns: Dictionary of column families attached to this table. Keys
are strings (column family names) and values are
:class:`.column_family.ColumnFamily` instances.
:raises: :class:`ValueError <exceptions.ValueError>` if the column
family name from the response does not agree with the computed
name from the column family ID.
Expand Down

0 comments on commit 4286446

Please sign in to comment.