Thanks a lot for your help.

I use composite column, so I have to change a little bit.
I need to use CompositeRangeBuilder.greaterThan(Object) and 
lessThenEquals(Object) to ‘get next page’,
since the API document says little about these APIs,  can I use the String 
object that represents the last column as the argument of the 
greaterThan(Object)?

Thanks again

Boying

From: Theo Hultberg [mailto:t...@iconara.net]
Sent: 2014年2月28日 14:39
To: user@cassandra.apache.org
Subject: Re: How to paginate through all columns in a row?

You can page yourself using the withColumnRange method (see the slice query 
example on the page you linked to). What you do is that you save the last 
column you got from the previous query, and you set that as the start of the 
range you pass to withColumnRange. You don't need to set an end of a range, but 
you want to set a max size.

This code is just a quick rewrite from the page you linked to and I haven't 
checked that it worked, but it should give you an idea of where to start

ColumnList<String> result;
int pageSize = 100;
String offset = Character.toString('\0');
while (true) {
  result = keyspace.prepareQuery(CF_STANDARD1)
   .getKey(rowKey)
   .withColumnRange(new 
RangeBuilder().setStart(offset).setMaxSize(pageSize).build())
   .execute().getResult();
  while (result.hasNext()) {
    Column<String> col = result.next();
    // do something with your column here, then save
    // the last column to use as the offset when loading the next page
    offset = col.getStringValue();
} while (result.size() == pageSize);

I'm using a string with a null byte as the first offset because that should 
sort before all strings, but there might be a better way of doing. If you have 
non-string columns or composite columns the exact way to do this is a bit 
different but I hope this shows you the general idea.

T#


On Thu, Feb 27, 2014 at 11:36 AM, Lu, Boying 
<boying...@emc.com<mailto:boying...@emc.com>> wrote:
Hi, All,

I’m using Netflix/Astyanax as a java cassandra client to access Cassandra DB.

I need to paginate through all columns in a row and I found the document at 
https://github.com/Netflix/astyanax/wiki/Reading-Data
about how to do that.

But my requirement is a little different.  I don’t want to do paginate in ‘one 
querying session’,
i.e. I don’t want to hold the returned ‘RowQuery’ object to get next page.

Is there any way that I can keep a ‘marker’ for next page, so by using the 
marker,
I can tell the Cassandra DB that where to start query.
e.g.  the query result has three ‘pages’,
Can I build the query by giving a marker pointed to the ‘page 2’ and Cassandra 
will return the second page of the query?

Thanks a lot.

Boying


Reply via email to