Missing rows from following snippet

8 views
Skip to first unread message

Mani Maran

unread,
Apr 26, 2017, 10:37:10 AM4/26/17
to java-dri...@lists.datastax.com
Hi Guys,

   Can you please help me with finding the missing rows?
   I am sending a snippet of java code.

   I am missing 20 or 30 rows when I set fetch size 100.
   I am missing 100s or rows when I set fetch size of 1000.

   Can someone solve the puzzle for me?
    I appreciate your help.

Cluster cluster = clusterBuilder.build();
 Session session = cluster.connect(keyspace);

 Statement stmt = new SimpleStatement("SELECT * FROM " + table);
 stmt.setFetchSize(100);
 ResultSet rs = session.execute(stmt);
 Iterator<Row> iter = rs.iterator();

 while (!rs.isFullyFetched()) {
 rs.fetchMoreResults();
 Row row = iter.next();
 if (row != null)
 {
 StringBuilder line = new StringBuilder();
 for (Definition key : row.getColumnDefinitions().asList())
 {
 String val = myGetValue(key, row);
 line.append(val);
 line.append(",");
 }
 line.deleteCharAt(line.length()-1);
 System.out.println(line.toString());
 }
 }
 session.close();
 cluster.close();

--
Thanks!

Mani Maran

The starting point of success is to develop an outstanding attitude, an unstoppable belief, and crystal clarity on what you want.” Mani Maran

Voytek Jarnot

unread,
Apr 26, 2017, 11:05:51 AM4/26/17
to java-dri...@lists.datastax.com
Very odd way of iterating over a resultset.

Change your while to while(iter.hasNext()) and remove rs.fetchMoreResults() entirely and that should start you down the path.

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-user+unsubscribe@lists.datastax.com.

Mani Maran

unread,
Apr 26, 2017, 11:33:44 AM4/26/17
to java-dri...@lists.datastax.com
You are amazing! Thank you so much!!

Have a nice day!!!

Sent from my iPhone
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.
Reply all
Reply to author
Forward
0 new messages