You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Paul Loy <ke...@gmail.com> on 2012/10/22 03:28:03 UTC

find smallest counter

I have a set of categories. In these categories I want to add groups of
users. If a user does not specify the group they want to join in a
category, I want to add them to the least subscribed group.

So the groups are a super column with CategoryId as key, GroupId as
superColumnName and then columns for the group members.

Then I was planning on having some counters so I could keep track of the
group sizes. I figured I'd have a counter column for the groups. The key
being the CategoryId, then counter columns named by the GroupId. But I
can't figure out how to grab just the smallest group.

Many thanks in advance,

Paul.

-- 
---------------------------------------------
Paul Loy
paul@keteracel.com
http://uk.linkedin.com/in/paulloy

Re: find smallest counter

Posted by aaron morton <aa...@thelastpickle.com>.
> So the groups are a super column with CategoryId as key, GroupId as superColumnName and then columns for the group members.
If this is a new project please consider not using Super Columns. They have some limitations http://wiki.apache.org/cassandra/CassandraLimitations and are often slower than a model that only uses Standard CF's 

> But I can't figure out how to grab just the smallest group.
You cannot do that in a single statement / request. Cassandra does not support ordering by column value (outside of secondary indexes) nor does it support aggregate operations. 

You will need to iterate the columns and find the smallest value. 

Cheers

-----------------
Aaron Morton
Freelance Developer
@aaronmorton
http://www.thelastpickle.com

On 22/10/2012, at 2:28 PM, Paul Loy <ke...@gmail.com> wrote:

> I have a set of categories. In these categories I want to add groups of users. If a user does not specify the group they want to join in a category, I want to add them to the least subscribed group.
> 
> So the groups are a super column with CategoryId as key, GroupId as superColumnName and then columns for the group members.
> 
> Then I was planning on having some counters so I could keep track of the group sizes. I figured I'd have a counter column for the groups. The key being the CategoryId, then counter columns named by the GroupId. But I can't figure out how to grab just the smallest group.
> 
> Many thanks in advance,
> 
> Paul.
> 
> -- 
> ---------------------------------------------
> Paul Loy
> paul@keteracel.com
> http://uk.linkedin.com/in/paulloy