incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Theo Hultberg <t...@iconara.net>
Subject Re: How to paginate through all columns in a row?
Date Fri, 28 Feb 2014 06:39:21 GMT
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.Lu@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
>
>
>

Mime
View raw message