How to do polls in cassandra?

I am trying to find a way to do a survey on the cassandra database, but I am new to this and I do not know how to do it.

Suppose I have a user table like this

-> users -> user_name -> gender -> state 

and I want to constantly do a poll to see if a new user has been added to the table. How can i do this?

+5
source share
1 answer

A standard approach in a relational database would include executing a SELECT, ordering with some temporary code identifier, so that the newest row would be returned first, so you could see if this matches your last "last row" and define a change-in cassandra, that will not work, because without a WHERE clause, the results are ordered by a section token, which (almost certainly) is random.

So the solution is to create a table in which there is a section where users are sorted in a specific section. For instance:

 CREATE TABLE user_buckets ( bucket text, user_timestamp timeuuid, user_username text, PRIMARY KEY(bucket, user_timestamp) ) WITH CLUSTERING ORDER BY (user_timestamp DESC); 

In this case, you should write both in the users table and in the user_buckets table, and "bucket" is something reasonable (for example, date (YYYY)), where each section contains all registered users this year or date (YYYYMMDD) - where each section contains all registered users that day), and then use SELECT ... FROM user_buckets WHERE bucket = (current-bucket) AND user_timestamp> (the last timestamp you saw).

+1
source

All Articles