Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Paginating

smarsching edited this page · 2 revisions
Clone this wiki locally

Sample column family setup

cqlsh:astyanaxunittests> describe columnfamily paginate1;

CREATE TABLE paginate1 (
  key int,
  column1 int,
  value int,
  PRIMARY KEY (key, column1)
) WITH COMPACT STORAGE AND
  bloom_filter_fp_chance=0.010000 AND
  caching='KEYS_ONLY' AND
  comment='' AND
  dclocal_read_repair_chance=0.000000 AND
  gc_grace_seconds=864000 AND
  read_repair_chance=0.100000 AND
  replicate_on_write='true' AND
  populate_io_cache_on_flush='false' AND
  compaction={'class': 'SizeTieredCompactionStrategy'} AND
  compression={'sstable_compression': 'SnappyCompressor'};

cqlsh:astyanaxunittests> select * from paginate1;

 key | column1 | value
-----+---------+-------
   1 |       0 |     1
   1 |       1 |     1
   1 |       2 |     1
   1 |       3 |     1
   1 |       4 |     1
   1 |       5 |     1
   1 |       6 |     1
   1 |       7 |     1
   1 |       8 |     1
   1 |       9 |     1

cqlsh:astyanaxunittests> 

Insert some data

           Keyspace ks = ....;

       MutationBatch m = ks.prepareMutationBatch();
       for (int i=0; i<=9; i++) {
           m.withRow(CF, 1).putColumn(i, 1);
       }
       m.execute();

Read with pagination turned on

 RowQuery<Integer, Integer> query  = ks.prepareQuery(CF)
                           .getRow(1)                    
                                       .withColumnRange(0, 9, false, 4)
                                       .autoPaginate(true);                                            

OperationResult<ColumnList<Integer>> result;

while (!(result = query.execute()).getResult().isEmpty()) {
        System.out.println("\nNEXT PAGE \n");
    for (Column<Integer> col : result.getResult()) {
       System.out.println(col.getName() + " " + col.getIntegerValue());
        }
  }

Reverse Pagination

 RowQuery<Integer, Integer> query  = ks.prepareQuery(CF)
                           .getRow(1)                    
                                       .withColumnRange(9, 0, true, 4)
                                       .autoPaginate(true);                                            

OperationResult<ColumnList<Integer>> result;

while (!(result = query.execute()).getResult().isEmpty()) {
        System.out.println("\nNEXT PAGE \n");
    for (Column<Integer> col : result.getResult()) {
       System.out.println(col.getName() + " " + col.getIntegerValue());
        }
  }
Something went wrong with that request. Please try again.