Query total result size?

25 views
Skip to first unread message

st...@heliossoftware.com

unread,
Nov 23, 2017, 11:28:09 AM11/23/17
to DataStax Java Driver for Apache Cassandra User Mailing List
For queries that return a large result set, is it possible to obtain the total query result size if the size is larger than the page fetch size?

Example:

Page Fetch Size is 5,000.
Table has 100,000 rows
My query will produce a result set of 5,678 entries.

If I call getAvailableWithoutFetching, that will return 5,000, but I want to know the total of 5,678.

Is it possible to obtain the total potential result count of 5,678, but not the results themselves?  In other words, I would like to obtain the 5,678 total from the ResultSet without calling all(), or without incurring a separate count(*) query or without prefetching other results.

Thanks!
-Steve

Kevin Gallardo

unread,
Nov 27, 2017, 11:20:30 AM11/27/17
to java-dri...@lists.datastax.com
Hello Steve, 

You would need to disable paging to be able to do that. It is not generally recommended to disable paging but if you are certain that your results will stay a constant size and that this size can be held in memory then this would be a solution. That way the driver would get the whole result set at once and calling getAvailableWithoutFetching() would return the total size.

To disable paging you need to call setFetchSize(Integer.MAX_VALUE) on either the Statement or the QueryOptions set on your Cluster.

Other than that there isn't much the driver is aware of to be able to know in advance the total size of the results, only the server would know it with a count(*). Without a count(*) even the server itself is not aware of the total size of the results until it reached the end/finished paging.

Thanks.

--
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.



--
Kévin Gallardo.
Software Developer in Drivers and Tools Team,
DataStax.

Steve Munini

unread,
Nov 27, 2017, 11:42:33 AM11/27/17
to java-dri...@lists.datastax.com
Thank you very much Kevin for your response.

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



--
Kévin Gallardo.
Software Developer in Drivers and Tools Team,
DataStax.

--
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-us...@lists.datastax.com.
--
Steve Munini 
CEO & CTO
978-590-4493
heliossoftware.com


Reply all
Reply to author
Forward
0 new messages