0

I have a Cassandra table as below:

create table experience.userstats (stream varchar, user varchar, computer varchar, experience varchar, amount int, primary key (experience, stream, user, computer);

I am using Apache storm bolts to create these records in Cassandra from a queue spout.

I want to generate aggregate statistics and display the counter for different experiences for a given stream as a pie chart. For example, 30% satisfied, 40% mixed and 30% unsatisfied experience.

Since I cannot update counters online, I am using a Clock spout (timer) to read this data and generate counters into a new table. But Cassandra does not support group by clauses and hence I have to read thrice to get the counter for each experience as below.

select count(*) from experience.userstats where experience='satisfied' and stream='xyz';

select count(*) from experience.userstats where experience='unsatisfied' and stream='xyz';

select count(*) from experience.userstats where experience='mixed' and stream='xyz';

The problem with this approach is that I have to execute three queries on database to get the counters for the 3 types of experience and experience could be modified in the mean-time making these counters inconsistent.

Is there a way I can execute above three select statements in a single batch? Or could you please suggest an alternative design approach?

2 Answers2

0

you can use

IN

relation operator like this,

SELECT count(*) FROM userstats WHERE experience IN('mixed','unsatisfied','satisfied) AND stream = 'xyz' ;

Albin Mathew
  • 604
  • 9
  • 19
  • That would give the count for all experiences. I need count for each experience. –  Jun 20 '16 at 15:27
0

Executing count(*) will give you timeouts easy. Why don't you use counter field and just increment it when insert happens? This way you will just query for one value. Distributed counters are improved in 2.1 and later and they work great.

Matija Gobec
  • 850
  • 6
  • 12
  • Thanks for the tip. I will avoid count(*) but I need counters by experience so might have to create new tables to maintain this counter. –  Jun 29 '16 at 05:38