cassandra - Get count of followers for each user -


i have following table. possible count of followers each user single cql select?

create table user_follows ( name text, follows_name text, primary key (name,follows_name) );  name    | follows_name ---------+--------------  indrani |      aravind  indrani |        jorge  indrani |      lalitha  indrani |        vijay    vijay |      aravind    vijay |        david    vijay |         mark   filmon |        david   filmon |        jorge   filmon |      kishore   filmon |      lalitha   filmon |         mark   filmon |        vijay    david |      aravind    david |         mark 

i have following query returning count single user

select count(follows_name) user_follows name='indrani'; 

i'm afraid not supported. thing can issue count(*) query every partition.

if don't know partitions use per partition limit 1 retrieve first record (and hence partition key) each partition (data inside partition ordered cluster key):

select name user_follows per partition limit 1; 

this requires cassandra 3.6 , later.

thinking more it, however, single count query (with where restricting partition) produce scan of partition, because that's how c* count records. if issue query of partitions you'll scan dataset, , kill cluster.

if don't need precise create counter table same partition key , increment/decrement counter each user:

create table user_follows_counts (     name text primary key,      followers counter, ); 

now you'd want without scanning dataset, more efficient query:

select * user_follows_counts; 

check documentation on counters further information.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -