Skip to content
Browse files

Tests for get_range by token, minor fixes

  • Loading branch information...
1 parent 9ff9bdb commit 02cac9f42367e3c083ecfa866a00c05c0b81ec27 @thobbs thobbs committed
Showing with 25 additions and 5 deletions.
  1. +6 −5 pycassa/columnfamily.py
  2. +19 −0 tests/test_columnfamily.py
View
11 pycassa/columnfamily.py
@@ -890,11 +890,12 @@ def get_range(self, start="", finish="", columns=None, column_start="",
of keys is not feasible.
In place of `start` and `finish`, you may use `start_token` and
- `end_token` or a combination of `start` and `end_token`. In this
+ `finish_token` or a combination of `start` and `finish_token`. In this
case, you are specifying a token range to fetch instead of a key
range. This can be useful for fetching all data owned
by a node or for parallelizing a full data set scan. Otherwise,
- you should typically just use `start` and `finish`.
+ you should typically just use `start` and `finish`. Both `start_token`
+ and `finish_token` must be specified as hex-encoded strings.
The `row_count` parameter limits the total number of rows that may be
returned. If left as ``None``, the number of rows that may be returned
@@ -938,12 +939,12 @@ def get_range(self, start="", finish="", columns=None, column_start="",
if start_token is not None:
kr_args['start_token'] = start_token
- else:
+ kr_args['end_token'] = "" if finish_token is None else finish_token
+ elif finish_token is not None:
kr_args['start_key'] = self._pack_key(start)
-
- if finish_token is not None:
kr_args['end_token'] = finish_token
else:
+ kr_args['start_key'] = self._pack_key(start)
kr_args['end_key'] = self._pack_key(finish)
if buffer_size is None:
View
19 tests/test_columnfamily.py
@@ -245,6 +245,25 @@ def test_get_range_batching(self):
cf.truncate()
+ @requireOPP
+ def test_get_range_tokens(self):
+ cf.truncate()
+ columns = {'c': 'v'}
+ for i in range(100, 201):
+ cf.insert('key%d' % i, columns)
+
+ results = list(cf.get_range(start_token="key100".encode('hex'), finish_token="key200".encode('hex')))
+ assert_equal(100, len(results))
+
+ results = list(cf.get_range(start_token="key100".encode('hex'), finish_token="key200".encode('hex'), buffer_size=10))
+ assert_equal(100, len(results))
+
+ results = list(cf.get_range(start_token="key100".encode('hex'), buffer_size=10))
+ assert_equal(100, len(results))
+
+ results = list(cf.get_range(finish_token="key201".encode('hex'), buffer_size=10))
+ assert_equal(101, len(results))
+
def insert_insert_get_indexed_slices(self):
indexed_cf = ColumnFamily(pool, 'Indexed1')

0 comments on commit 02cac9f

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