Skip to content

Commit c0fd747

Browse files
committed
Merge pull request #1327 from dhermes/bigtable-add-filter-to-row-ctor
Adding filter to Bigtable Row constructor.
2 parents 7422824 + 2991175 commit c0fd747

File tree

6 files changed

+33
-9
lines changed

6 files changed

+33
-9
lines changed

gcloud/bigtable/_helpers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@
1919
"""
2020

2121

22+
import platform
23+
2224
from grpc.beta import implementations
2325

2426

2527
# See https://gist.github.com/dhermes/bbc5b7be1932bfffae77
2628
# for appropriate values on other systems.
27-
# NOTE: Even this path is Unix specific.
28-
SSL_CERT_FILE = '/etc/ssl/certs/ca-certificates.crt'
29+
_PLAT_SYS = platform.system()
30+
SSL_CERT_FILE = None
31+
if _PLAT_SYS == 'Linux':
32+
SSL_CERT_FILE = '/etc/ssl/certs/ca-certificates.crt'
33+
elif _PLAT_SYS == 'Darwin': # pragma: NO COVER
34+
SSL_CERT_FILE = '/usr/local/etc/openssl/cert.pem'
2935

3036

3137
class MetadataTransformer(object):

gcloud/bigtable/column_family.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _timedelta_to_duration_pb(timedelta_val):
3535
:type timedelta_val: :class:`datetime.timedelta`
3636
:param timedelta_val: A timedelta object.
3737
38-
:rtype: :class:`duration_pb2.Duration`
38+
:rtype: :class:`.duration_pb2.Duration`
3939
:returns: A duration object equivalent to the time delta.
4040
"""
4141
seconds_decimal = _total_seconds(timedelta_val)
@@ -144,7 +144,7 @@ class GCRuleUnion(GarbageCollectionRule):
144144
"""Union of garbage collection rules.
145145
146146
:type rules: list
147-
:param rules: List of :class:`GarbageCollectionRule`,
147+
:param rules: List of :class:`GarbageCollectionRule`.
148148
"""
149149

150150
def __init__(self, rules):

gcloud/bigtable/row.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,20 @@ class Row(object):
2828
2929
:type table: :class:`Table <gcloud.bigtable.table.Table>`
3030
:param table: The table that owns the row.
31+
32+
:type filter_: :class:`RowFilter`
33+
:param filter_: (Optional) Filter to be used for conditional mutations.
34+
If a filter is set, then the :class:`Row` will accumulate
35+
mutations for either a :data:`True` or :data:`False` state.
36+
When :meth:`commit`-ed, the mutations for the :data:`True`
37+
state will be applied if the filter matches any cells in
38+
the row, otherwise the :data:`False` state will be.
3139
"""
3240

33-
def __init__(self, row_key, table):
41+
def __init__(self, row_key, table, filter_=None):
3442
self._row_key = _to_bytes(row_key)
3543
self._table = table
44+
self._filter = filter_
3645

3746

3847
class RowFilter(object):

gcloud/bigtable/table.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Table(object):
4444
* :meth:`create` the table
4545
* :meth:`rename` the table
4646
* :meth:`delete` the table
47+
* :meth:`list_column_families` in the table
4748
4849
:type table_id: str
4950
:param table_id: The ID of the table.
@@ -90,16 +91,20 @@ def column_family(self, column_family_id, gc_rule=None):
9091
"""
9192
return ColumnFamily(column_family_id, self, gc_rule=gc_rule)
9293

93-
def row(self, row_key):
94+
def row(self, row_key, filter_=None):
9495
"""Factory to create a row associated with this table.
9596
9697
:type row_key: bytes
9798
:param row_key: The key for the row being created.
9899
100+
:type filter_: :class:`.RowFilter`
101+
:param filter_: (Optional) Filter to be used for conditional mutations.
102+
See :class:`.Row` for more details.
103+
99104
:rtype: :class:`.Row`
100105
:returns: A row owned by this table.
101106
"""
102-
return Row(row_key, self)
107+
return Row(row_key, self, filter_=filter_)
103108

104109
def __eq__(self, other):
105110
if not isinstance(other, self.__class__):

gcloud/bigtable/test_row.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ def _makeOne(self, *args, **kwargs):
2828
def test_constructor(self):
2929
row_key = b'row_key'
3030
table = object()
31+
filter_ = object()
3132

32-
row = self._makeOne(row_key, table)
33+
row = self._makeOne(row_key, table, filter_=filter_)
3334
self.assertEqual(row._row_key, row_key)
3435
self.assertTrue(row._table is table)
36+
self.assertTrue(row._filter is filter_)
3537

3638
def test_constructor_with_unicode(self):
3739
row_key = u'row_key'

gcloud/bigtable/test_table.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ def test_row_factory(self):
6262
table_id = 'table-id'
6363
table = self._makeOne(table_id, None)
6464
row_key = b'row_key'
65-
row = table.row(row_key)
65+
filter_ = object()
66+
row = table.row(row_key, filter_=filter_)
6667

6768
self.assertTrue(isinstance(row, Row))
6869
self.assertEqual(row._row_key, row_key)
6970
self.assertEqual(row._table, table)
71+
self.assertEqual(row._filter, filter_)
7072

7173
def test___eq__(self):
7274
table_id = 'table_id'

0 commit comments

Comments
 (0)