I want to count the total number of columns for a Cassandra row using Hector client. Currently I am doing this with a CountQuery
, but it seems really slow to me. Also for a row, with just 60k columns it's taking nearly 2 seconds. My code currently looks like this:
QueryResult<Integer> qr = HFactory.createCountQuery(ksp, se, se).
setColumnFamily("ColumnFamily1").
setKey("RowKey").
setRange(null, null, 1000000000).execute();
PS: I have to set the range to such a high number, otherwise it only counts me max. to the number I've provided in the range.
Any ideas how I can improve this?
Counting columns in Cassandra is inherently slow. Cassandra has to iterate over the whole row in order to return the count.
You probably want to denormalize the count. You could use a counter column which you update every time you insert.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With