Permalink
Browse files

Fix xget paging for non-string comparators

column_start and column_finish were being packed twice,
which broke when the comparator had a non-idempotent pack
method.

Fixes #139
  • Loading branch information...
1 parent e39acda commit 50e668beb1f504b8ac115322c12f4ad0dca8b6ed @thobbs thobbs committed May 4, 2012
Showing with 17 additions and 10 deletions.
  1. +5 −4 pycassa/columnfamily.py
  2. +12 −6 tests/test_autopacking.py
@@ -376,19 +376,19 @@ def _column_parent(self, super_column=None):
super_column=self._pack_name(super_column, is_supercol_name=True))
def _slice_predicate(self, columns, column_start, column_finish,
- column_reversed, column_count, super_column=None):
+ column_reversed, column_count, super_column=None, pack=True):
is_supercol_name = self.super and super_column is None
if columns is not None:
packed_cols = []
for col in columns:
packed_cols.append(self._pack_name(col, is_supercol_name=is_supercol_name))
return SlicePredicate(column_names=packed_cols)
else:
- if column_start != '':
+ if column_start != '' and pack:
column_start = self._pack_name(column_start,
is_supercol_name=is_supercol_name,
slice_start=(not column_reversed))
- if column_finish != '':
+ if column_finish != '' and pack:
column_finish = self._pack_name(column_finish,
is_supercol_name=is_supercol_name,
slice_start=column_reversed)
@@ -521,6 +521,7 @@ def xget(self, key, column_start="", column_finish="", column_reversed=False,
last_name = self._pack_name(column_start)
if column_finish != "":
finish = self._pack_name(column_finish)
+
while True:
if column_count is not None:
if i == 0 and column_count <= buffer_size:
@@ -529,7 +530,7 @@ def xget(self, key, column_start="", column_finish="", column_reversed=False,
buffer_size = min(column_count - count + 1, buffer_size)
sp = self._slice_predicate(None, last_name, finish,
- column_reversed, buffer_size, None)
+ column_reversed, buffer_size, None, pack=False)
list_cosc = self.pool.execute('get_slice', packed_key, cp, sp, rcl)
if not list_cosc:
@@ -70,9 +70,9 @@ def tearDown(self):
cf.remove(key)
def make_group(self, cf, cols):
- diction = { cols[0]: VALS[0],
- cols[1]: VALS[1],
- cols[2]: VALS[2]}
+ diction = OrderedDict([(cols[0], VALS[0]),
+ (cols[1], VALS[1]),
+ (cols[2], VALS[2])])
return { 'cf': cf, 'cols': cols, 'dict': diction}
def test_standard_column_family(self):
@@ -140,6 +140,9 @@ def test_standard_column_family(self):
assert_equal(cf.get_count(KEYS[0]), 3)
+ # Test xget paging
+ assert_equal(list(cf.xget(KEYS[0], buffer_size=2)), gdict.items())
+
# Test removing rows
cf.remove(KEYS[0], columns=gcols[:1])
assert_equal(cf.get_count(KEYS[0]), 2)
@@ -233,9 +236,9 @@ def tearDown(self):
cf.remove(key)
def make_super_group(self, cf, cols):
- diction = { cols[0]: {'bytes': VALS[0]},
- cols[1]: {'bytes': VALS[1]},
- cols[2]: {'bytes': VALS[2]}}
+ diction = OrderedDict([(cols[0], {'bytes': VALS[0]}),
+ (cols[1], {'bytes': VALS[1]}),
+ (cols[2], {'bytes': VALS[2]})])
return { 'cf': cf, 'cols': cols, 'dict': diction}
def test_super_column_families(self):
@@ -297,6 +300,9 @@ def test_super_column_families(self):
assert_equal(cf.get(KEYS[0], column_start=gcols[0], column_finish=gcols[0]),
{gcols[0]: {'bytes': VALS[0]}})
+ # test xget paging
+ assert_equal(list(cf.xget(KEYS[0], buffer_size=2)), gdict.items())
+
assert_equal(cf.get_count(KEYS[0]), 3)
# Test removing rows

0 comments on commit 50e668b

Please sign in to comment.