diff options
author | Wouter Bolsterlee <uws@xs4all.nl> | 2013-06-07 23:40:09 +0200 |
---|---|---|
committer | Wouter Bolsterlee <uws@xs4all.nl> | 2013-06-07 23:42:08 +0200 |
commit | 2fb7f8e4cffe0f8854f2945d3cdc114aeebff2d0 (patch) | |
tree | 9a84f34d62b96b8d4ddcc47813323d573cc89946 | |
parent | 2835e418ca7a7f8ae631fc21fa845708551033e5 (diff) | |
download | happybase-filter.tar.gz |
Support filter instances directly in Table.scan()filter
-rw-r--r-- | happybase/table.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/happybase/table.py b/happybase/table.py index bb32ce6..77756b1 100644 --- a/happybase/table.py +++ b/happybase/table.py @@ -10,6 +10,7 @@ from struct import Struct from .hbase.ttypes import TScan from .util import thrift_type_to_dict, str_increment from .batch import Batch +from .filter import _FilterNode logger = logging.getLogger(__name__) @@ -204,8 +205,8 @@ class Table(object): return map(make_cell, cells) def scan(self, row_start=None, row_stop=None, row_prefix=None, - columns=None, filter=None, timestamp=None, - include_timestamp=False, batch_size=1000, limit=None): + columns=None, timestamp=None, include_timestamp=False, + batch_size=1000, limit=None, filter=None): """Create a scanner for data in the table. This method returns an iterable that can be used for looping over the @@ -230,9 +231,6 @@ class Table(object): The `columns`, `timestamp` and `include_timestamp` arguments behave exactly the same as for :py:meth:`row`. - The `filter` argument may be a filter string that will be applied at - the server by the region servers. - If `limit` is given, at most `limit` results will be returned. The `batch_size` argument specifies how many results should be @@ -240,6 +238,12 @@ class Table(object): this to a low value (or even 1) if your data is large, since a low batch size results in added round-trips to the server. + The `filter` argument may be a filter string that will be + applied at the server by the region servers. If you need more + than a static filter string literal, use the helpers in the + :py:mod:`happybase.filter` module to construct filter strings + programmatically. + **Compatibility note:** The `filter` argument is only available when using HBase 0.92 (or up). In HBase 0.90 compatibility mode, specifying a `filter` raises an exception. @@ -274,6 +278,14 @@ class Table(object): if row_start is None: row_start = '' + if filter is not None: + if isinstance(filter, _FilterNode): + filter = str(filter) + + if not isinstance(filter, str): + raise TypeError( + "'filter' must be a filter instance or a (byte) string") + if self.connection.compat == '0.90': # The scannerOpenWithScan() Thrift function is not # available, so work around it as much as possible with the |