Pagination - issue with QueryBuilder.raw when using token function

275 views
Skip to first unread message

Julien Sebrien

unread,
Mar 12, 2015, 4:00:12 AM3/12/15
to java-dri...@lists.datastax.com
Hello, I would like to perform pagination queries using the token function.
Here is some example data to illustrate the issue:

CREATE TABLE IF NOT EXISTS my_users (
id uuid PRIMARY KEY,
email varchar
);

INSERT INTO my_users (id, email)
VALUES(f75fabef-1bcf-11e4-a07d-c761ccb0bd09, 
);

INSERT INTO my_users (id, email)
VALUES(f75d61f0-1bcf-11e4-a07d-c761ccb0bd09, 
);

INSERT INTO my_users (id, email)
VALUES(f75fabec-1bcf-11e4-a07d-c761ccb0bd09, 
);


Here is the java code I'm using to perform to use pagination with Datastax java driver:

public static void main(String[] args){
try (Session session = new Cluster.Builder().withoutJMXReporting().addContactPoints("localhost")
.withPort(9042).build().connect();){
String fromId="f75fabef-1bcf-11e4-a07d-c761ccb0bd09";
int limit=2;
Select select = QueryBuilder.select("id","email").from("my_users").limit(limit);
RegularStatement query = select.where(QueryBuilder.gt(
QueryBuilder.token("id"), 
QueryBuilder.raw(StringHelper.buildStringNoSep("token(",fromId,")"))
));
List<Row> results = session.execute(query).all();
System.out.println("results="+results);
} catch (Exception e) {
e.printStackTrace();
}
System.exit(0);
}

This throws the following exception:

java.lang.IllegalArgumentException: Value 0 of type class com.datastax.driver.core.querybuilder.Utils$RawString does not correspond to any CQL3 type
at com.datastax.driver.core.querybuilder.Utils.convert(Utils.java:84)
at com.datastax.driver.core.querybuilder.BuiltStatement.getValues(BuiltStatement.java:172)
at com.datastax.driver.core.querybuilder.BuiltStatement$ForwardingStatement.getValues(BuiltStatement.java:341)
at com.datastax.driver.core.querybuilder.Select$Where.getValues(Select.java:188)
at com.datastax.driver.core.SessionManager.makeRequestMessage(SessionManager.java:488)
at com.datastax.driver.core.SessionManager.makeRequestMessage(SessionManager.java:457)
at com.datastax.driver.core.SessionManager.executeAsync(SessionManager.java:119)
at com.datastax.driver.core.AbstractSession.execute(AbstractSession.java:52)
at TestClass.main(UserConfImpl.java:155)

I'm using Datastax Java Driver 2.1.4, with cassandra-all 2.1.1 jar, connected to a Cassandra 2.1.0 database.

Is there a working way to perform such queries?

Thanks!

Julien

Olivier Michallat

unread,
Mar 12, 2015, 8:28:05 AM3/12/15
to java-dri...@lists.datastax.com
Hi Julien,

This is a bug, I've just created JAVA-688 to track it.

In this specific case you have a workaround by using a function call:

        Select select = QueryBuilder.select("id","email").from("my_users").limit(2);
        RegularStatement query = select.where(QueryBuilder.gt(
            QueryBuilder.token("id"),
            QueryBuilder.fcall("token", fromId)
        ));


--

Olivier Michallat

Driver & tools engineer, DataStax


To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.

Julien Sebrien

unread,
Mar 12, 2015, 10:24:51 AM3/12/15
to java-dri...@lists.datastax.com
Thanks for the workaround, it works great!

Julien
Reply all
Reply to author
Forward
0 new messages