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

Adding remaining Bigtable regex row filters. #1300

Merged
merged 1 commit into from
Dec 17, 2015
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
60 changes: 60 additions & 0 deletions gcloud/bigtable/row.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,63 @@ def to_pb(self):
:returns: The converted current object.
"""
return data_pb2.RowFilter(family_name_regex_filter=self.regex)


class ColumnQualifierRegexFilter(_RegexFilter):
"""Row filter for a column qualifier regular expression.

The ``regex`` must be valid RE2 patterns. See Google's
`RE2 reference`_ for the accepted syntax.

.. _RE2 reference: https://github.com/google/re2/wiki/Syntax

.. note::

Special care need be used with the expression used. Since
each of these properties can contain arbitrary bytes, the ``\\C``
escape sequence must be used if a true wildcard is desired. The ``.``
character will not match the new line character ``\\n``, which may be
present in a binary value.

:type regex: bytes
:param regex: A regular expression (RE2) to match cells from column that
match this regex (irrespective of column family).
"""

def to_pb(self):
"""Converts the row filter to a protobuf.

:rtype: :class:`.data_pb2.RowFilter`
:returns: The converted current object.
"""
return data_pb2.RowFilter(column_qualifier_regex_filter=self.regex)


class ValueRegexFilter(_RegexFilter):
"""Row filter for a value regular expression.

The ``regex`` must be valid RE2 patterns. See Google's
`RE2 reference`_ for the accepted syntax.

.. _RE2 reference: https://github.com/google/re2/wiki/Syntax

.. note::

Special care need be used with the expression used. Since
each of these properties can contain arbitrary bytes, the ``\\C``
escape sequence must be used if a true wildcard is desired. The ``.``
character will not match the new line character ``\\n``, which may be
present in a binary value.

:type regex: bytes
:param regex: A regular expression (RE2) to match cells with values that
match this regex.
"""

def to_pb(self):
"""Converts the row filter to a protobuf.

:rtype: :class:`.data_pb2.RowFilter`
:returns: The converted current object.
"""
return data_pb2.RowFilter(value_regex_filter=self.regex)
38 changes: 38 additions & 0 deletions gcloud/bigtable/test_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,41 @@ def test_to_pb(self):
pb_val = row_filter.to_pb()
expected_pb = data_pb2.RowFilter(family_name_regex_filter=regex)
self.assertEqual(pb_val, expected_pb)


class TestColumnQualifierRegexFilter(unittest2.TestCase):

def _getTargetClass(self):
from gcloud.bigtable.row import ColumnQualifierRegexFilter
return ColumnQualifierRegexFilter

def _makeOne(self, *args, **kwargs):
return self._getTargetClass()(*args, **kwargs)

def test_to_pb(self):
from gcloud.bigtable._generated import bigtable_data_pb2 as data_pb2

regex = b'column-regex'
row_filter = self._makeOne(regex)
pb_val = row_filter.to_pb()
expected_pb = data_pb2.RowFilter(column_qualifier_regex_filter=regex)
self.assertEqual(pb_val, expected_pb)


class TestValueRegexFilter(unittest2.TestCase):

def _getTargetClass(self):
from gcloud.bigtable.row import ValueRegexFilter
return ValueRegexFilter

def _makeOne(self, *args, **kwargs):
return self._getTargetClass()(*args, **kwargs)

def test_to_pb(self):
from gcloud.bigtable._generated import bigtable_data_pb2 as data_pb2

regex = b'value-regex'
row_filter = self._makeOne(regex)
pb_val = row_filter.to_pb()
expected_pb = data_pb2.RowFilter(value_regex_filter=regex)
self.assertEqual(pb_val, expected_pb)