3

trying to write a query which will paginate through all rows in a column family using astyanax client and RowSliceQuery.

keyspace.prepareQuery(COLUMN_FAMILY).getKeyRange(null, null, null, null, 100);

Done this successfully using hector where 1st call is done with null start and end keys. After retrieving 1st page I use last key from the result to make query for second page and etc. This is code for 1st page using hector.

HFactory.createRangeSlicesQuery(keyspace,
LongSerializer.get(), new CompositeSerializer(),
BytesArraySerializer.get())
.setColumnFamily(COLUMN_FAMILY)
.setRange(null, null, false, 100).setRowCount(100);

Now when I am trying to do this with astyanax I am getting errors about null and non-null keys and tokens. Not sure what tokens do in this query. Also I am able to use allRows(), but would like to do this using key range query as it gives me more flexibility.

Does anybody have an example of key range query using astyanax? I cannot find an example neither in "getting started" documentation or anywhere else on the net.

Thanks! Anton

2 Answers2

0

What you are referring to is the getRowRange method:

keyspace.prepareQuery(CF_STANDARD1)
  .getRowRange(startKey, endKey, startToken, endToken, count)

Note however that this works only when the ByteOrderedPartitioner is used. Since by default Cassandra uses the Murmur3Partitioner, this will usually not work. Using an index to do this instead is recommended. Astyanax also provides the reverse index search recipe which takes advantage of a second column family which stores your keys as columns to allow efficient range searches on the original data.

Martin Serrano
  • 3,727
  • 1
  • 35
  • 48
-1

Check this sample code. I hope this code will help you in doing the paging.

IndexQuery<String, String> query = keyspace
   .prepareQuery(CF_STANDARD1).searchWithIndex()
   .setRowLimit(10).autoPaginateRows(true).addExpression()
   .whereColumn("Index2").equals().value(42);

Best,

abhi
  • 4,762
  • 4
  • 29
  • 49