Getting Paged Results with Datastax Java Cassandra driver version 4.15.0

36 views Asked by At

Hello I am confused on using querying through Datastax Java driver and not being able to get past the limit of only 2,100 results returned. In the documentation and countless references online I see the following code example

for (Row row : rs) {
    if (rs.getAvailableWithoutFetching() == 100 && !rs.isFullyFetched())
        rs.fetchMoreResults(); // this is asynchronous
    // Process the row ...
    System.out.println(row);
}

where rs.fetchMoreResults() is available as a method on the ResultSet, in version 4.15.0 , i can see getAvailableWithoutFetching() and is rs.fullyFetched() which seems to always return true despite my query expecting to return many thousands of results and there is no fethMoreResults() method available on this driver version, every time I can only get 2,100 results. This is my code

SimpleStatement st = new SimpleStatementBuilder("SELECT * FROM " + StreamDataTables.VAR_SNAPSHOT).build();
        ResultSet rs = session.execute(st); //CqlSession being used
        Iterator<Row> iterator = rs.iterator();
        int rowCount = 0;
        while (iterator.hasNext()) {
            Row currentRow = iterator.next();
            rowCount++;
            System.out.println("fully fetched " + rs.isFullyFetched());
            
        }
        System.out.println("Results returned : " + rowCount);

Every time the row count is 2,701 despite more records in the table, and the only way i could try to get that is to cast the ResultSet to a DefaultAsyncResultSet which is the instance returned and the class has methods like hasNextPage() etc. which is what I am expecting, but throws a class cast exception saying something like app module not loaded.

So how in the world do I figure out how to get all the results which is way more than 2,100 returned in my query! its driving me nuts.

0

There are 0 answers