offset in a cassandra query

3,273 views
Skip to first unread message

Hafiz Mujadid

unread,
Aug 4, 2015, 7:15:07 AM8/4/15
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi users!

How can i skip first n rows by passing offset in cql query as we can pass offset and limit in Sql.

thanks

Alexandre Dutra

unread,
Aug 4, 2015, 7:55:01 AM8/4/15
to java-dri...@lists.datastax.com
Hello Hafiz,

There is no way with CQL to pass an arbitrary offset to a query. See this topic on this mailing list for more details.

You can, however, page your results: see the driver's documentation.

Thanks,

Alexandre

To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.
--
Alexandre Dutra
Driver & Tools Engineer @ DataStax

Steve S

unread,
Aug 4, 2015, 8:59:45 AM8/4/15
to java-dri...@lists.datastax.com
I created a helper class to provide a offset function, it build on top of Cassandra's paging state. The worse case is that skip rows one by one. 


Hope this can help you a little 

Steve

Hafiz Mujadid

unread,
Aug 4, 2015, 10:01:45 AM8/4/15
to java-dri...@lists.datastax.com
thanks all
Regards: HAFIZ MUJADID

Hafiz Mujadid

unread,
Aug 10, 2015, 4:14:32 AM8/10/15
to java-dri...@lists.datastax.com
Hi Steve!

I tried to use your class from here https://gist.github.com/stevesun21/df3fa5141bd01a4f83fc

compiler is reporting that "setPagingState is not a member of com.datastax.driver.core.Statement"
is it because of new version of cassandra driver ?

how can i fix it?

thanks
--
Regards: HAFIZ MUJADID

Steve S

unread,
Aug 10, 2015, 9:20:55 AM8/10/15
to java-dri...@lists.datastax.com
Hi,

I compiled it with 2.1.6. which version you are using? I can try to fix it.

Cheers,

Steve

Hafiz Mujadid

unread,
Aug 10, 2015, 9:28:18 AM8/10/15
to java-dri...@lists.datastax.com
using following maven dependency
<dependency>
<groupId>com.datastax.spark</groupId>
<artifactId>spark-cassandra-connector-java_2.10</artifactId>
<version>1.4.0-M1</version>
</dependency>

Alexandre Dutra

unread,
Aug 11, 2015, 4:43:48 AM8/11/15
to java-dri...@lists.datastax.com
Hi Hafiz,

The dependency you're using is transitively pulling driver version 2.1.5.

Paging state is available from 2.0.10 and 2.1.6, so to compile Steve's helper class you need to manually override the driver version in your pom, e.g.

<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>2.1.7.1</version>
</dependency>

(Please note: I did not test if this version remains compatible with spark connector 1.4.0-M1)

Hope that helps,

Alexandre
Reply all
Reply to author
Forward
0 new messages