Search code examples
cassandracassandra-cli

Cassandra table structure suggestion and way of query


I am trying to create a following hierarchy: UserId as rowKey, Hourly time series as columns and inside each hourly column I want to have a user specific information such as hourly activity.

{
   UserId:long
   {
      Timestamp:datetime{
         pageview: integer,
         clicks:integer
      }
   }

I've read that it is possible to achieve it using supercolumns but at the same time it was mentioned that supercolumns are outdated right now. If it is true, any alternatives I can use?

Could you please provide me CQL / Java thrift example how should I create and insert such type of structure in Cassandra?

Thanks!


Solution

  • You can user composite primary key for this, I add a table creation CQL query for the table. And you can use counter column for clicks.

    CREATE TABLE user_click_by_hour(
    userid long,
    time_stamp timestamp,
    clicks int,
    pageview int,
    PRIMARY KEY(userid,time_stamp)
    

    )