Skip to content
Browse files

Support filter instances directly in Table.scan()

  • Loading branch information...
1 parent 2835e41 commit 2fb7f8e4cffe0f8854f2945d3cdc114aeebff2d0 @wbolster committed Jun 7, 2013
Showing with 17 additions and 5 deletions.
  1. +17 −5 happybase/table.py
View
22 happybase/table.py
@@ -10,6 +10,7 @@
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 @@ def cells(self, row, column, versions=None, timestamp=None,
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,16 +231,19 @@ def scan(self, row_start=None, row_stop=None, row_prefix=None,
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
retrieved per batch when retrieving results from the scanner. Only set
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 @@ def scan(self, row_start=None, row_stop=None, row_prefix=None,
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

0 comments on commit 2fb7f8e

Please sign in to comment.
Something went wrong with that request. Please try again.