Skip to content

Commit

Permalink
Revert "Allow batch_size=None in Table.scan() to avoid filter incompa…
Browse files Browse the repository at this point in the history
…tibilities"

This reverts commit 8481d31, since it
is not a correct fix. See issue #56.
  • Loading branch information
wbolster committed Feb 25, 2014
1 parent 91e0f8a commit da109ab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 33 deletions.
5 changes: 0 additions & 5 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ Release date: *not yet released*
Python 2.6 a separate ```ordereddict``` pacakge has to be installed from PyPI.
(`issue #39 <https://github.com/wbolster/happybase/issues/39>`_)

* Allow `None` as a valid value for the `batch_size` argument to
:py:meth:`Table.scan`, since HBase does not support specifying a batch size
when some scanner filters are used. (`issue #54
<https://github.com/wbolster/happybase/issues/54>`_).


HappyBase 0.7
-------------
Expand Down
31 changes: 11 additions & 20 deletions happybase/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,6 @@ def scan(self, row_start=None, row_stop=None, row_prefix=None,
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.
.. warning::
Not all HBase filters can be used in combination with a batch
size. Explicitly specify `None` for the `batch_size` argument
in those cases to override the default value. Failure to do
so can result in hard to debug errors (not HappyBase's
fault), such as a non-responsive connection. The HBase logs
may contain more useful information in these situations.
**Compatibility notes:**
* The `filter` argument is only available when using HBase 0.92
Expand All @@ -289,11 +280,11 @@ def scan(self, row_start=None, row_stop=None, row_prefix=None,
:return: generator yielding the rows matching the scan
:rtype: iterable of `(row_key, row_data)` tuples
"""
if batch_size is not None and batch_size < 1:
raise ValueError("'batch_size' must be >= 1 (or None)")
if batch_size < 1:
raise ValueError("'batch_size' must be >= 1")

if limit is not None and limit < 1:
raise ValueError("'limit' must be >= 1 (or None)")
raise ValueError("'limit' must be >= 1")

if sorted_columns and self.connection.compat < '0.96':
raise NotImplementedError(
Expand Down Expand Up @@ -358,16 +349,16 @@ def scan(self, row_start=None, row_stop=None, row_prefix=None,
n_returned = n_fetched = 0
try:
while True:
if batch_size is None:
how_many = 1
else:
if limit is None:
how_many = batch_size
else:
how_many = min(batch_size, limit - n_returned)

if limit is not None:
how_many = min(how_many, limit - n_returned)

items = self.connection.client.scannerGetList(
scan_id, how_many)
if how_many == 1:
items = self.connection.client.scannerGet(scan_id)
else:
items = self.connection.client.scannerGetList(
scan_id, how_many)

n_fetched += len(items)

Expand Down
9 changes: 1 addition & 8 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def test_scan():
list(table.scan(row_prefix='foobar', row_start='xyz'))

with assert_raises(ValueError):
list(table.scan(batch_size=0))
list(table.scan(batch_size=None))

if connection.compat == '0.90':
with assert_raises(NotImplementedError):
Expand Down Expand Up @@ -446,13 +446,6 @@ def test_scan_sorting():
row.items())


def test_scan_filter_and_batch_size():
# See issue #54
filter = "SingleColumnValueFilter ('cf1', 'qual1', =, 'binary:val1')"
for k, v in table.scan(filter=filter, batch_size=None):
print v


def test_delete():
row_key = 'row-test-delete'
data = {'cf1:col1': 'v1',
Expand Down

0 comments on commit da109ab

Please sign in to comment.