Jan Kuipers
Jan Kuipers

Reputation: 67

Paging through Cassandra using QueryBuilder

The DataStax documentation says that to page through all data, the following CQL query is useful:

SELECT * FROM test WHERE token(k) > token(42);

Is it possible to build this query using the QueryBuilder? It provides a token method, but that seems to work only on column names, not on values.

Ideally, the value (in the example: 42) is of type Object, just like in the eq/gte/lte functions.

Upvotes: 1

Views: 1338

Answers (2)

good man
good man

Reputation: 1

QueryBuilder.fcall("token", value) ;

can solve the problem!

Upvotes: 0

phact
phact

Reputation: 7305

Try using automatic paging with the .fetchSize method. It uses token under the hood:

Automatic paging is introduced Cassandra 2.0. Automatic paging allows the developer to iterate on an entire ResultSet without having to care about its size: some extra rows are fetched as the client code iterate over the results while the old ones are dropped. The amount of rows that must be retrieved can be parameterized at query time. In the Java Driver this will looks like:

Statement stmt = new SimpleStatement("SELECT * FROM images");
stmt.setFetchSize(100);
ResultSet rs = session.execute(stmt);

Source: http://www.datastax.com/dev/blog/client-side-improvements-in-cassandra-2-0

Upvotes: 1

Related Questions