cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From DuyHai Doan <doanduy...@gmail.com>
Subject Re: Having Counters in a Collection, like a map<int, counter>?
Date Wed, 09 Nov 2016 14:10:39 GMT
"they require knowing the key in advance in order to look up the counters"

--> Wrong

Imagine your table

partition_key uuid,
first_map map<int, counter>,
second_map map<int, counter>

With my proposed data model:

SELECT first_map FROM table would translate to

SELECT map_key, count FROM my_counters_map WHERE partition_key = xxx AND
map_name = 'first_map';



On Wed, Nov 9, 2016 at 1:52 PM, Ali Akhtar <ali.rac200@gmail.com> wrote:

> The only issue with the last 2 solutions is, they require knowing the key
> in advance in order to look up the counters.
>
> The keys however are dynamic in my case.
>
> On Wed, Nov 9, 2016 at 5:47 PM, DuyHai Doan <doanduyhai@gmail.com> wrote:
>
>> "Is there a way to do this in c* which doesn't require creating 1 table
>> per type of map<int, counter> that i need?"
>>
>> You're lucky, it's possible with some tricks
>>
>>
>> CREATE TABLE my_counters_map (
>>      partition_key id uuid,
>>      map_name text,
>>      map_key int,
>>      count counter,
>>      PRIMARY KEY ((id), map_name, map_key)
>> );
>>
>> This table can be seen as:
>>
>> Map <partition_key, SortedMap<map_name, SortddMap<map_key, counter>>>
>>
>> The couple (map_key, counter) simulates your map
>>
>> The clustering column map_name allows you to have multiple maps of
>> counters for a single partition_key
>>
>>
>>
>> On Wed, Nov 9, 2016 at 1:32 PM, Vladimir Yudovin <vladyu@winguzone.com>
>> wrote:
>>
>>> Unfortunately it's impossible nor to use counters inside collections
>>> neither mix them with other non-counter columns :
>>>
>>> CREATE TABLE cnt (id int PRIMARY KEY , cntmap MAP<int,counter>);
>>> InvalidRequest: Error from server: code=2200 [Invalid query]
>>> message="Counters are not allowed inside collections: map<int, counter>"
>>>
>>> CREATE TABLE cnt (id int PRIMARY KEY , cnt1 counter, txt text);
>>> InvalidRequest: Error from server: code=2200 [Invalid query]
>>> message="Cannot mix counter and non counter columns in the same table"
>>>
>>>
>>> >Is there a way to do this in c* which doesn't require creating 1 table
>>> per type of map<int, counter> that i need?
>>> But you don't need to create separate table per each counter, just use
>>> one row per counter:
>>>
>>> CREATE TABLE cnt (id int PRIMARY KEY , value counter);
>>>
>>> Best regards, Vladimir Yudovin,
>>>
>>> *Winguzone <https://winguzone.com?from=list> - Hosted Cloud
>>> CassandraLaunch your cluster in minutes.*
>>>
>>>
>>> ---- On Wed, 09 Nov 2016 07:17:53 -0500*Ali Akhtar
>>> <ali.rac200@gmail.com <ali.rac200@gmail.com>>* wrote ----
>>>
>>> I have a use-case where I need to have a dynamic number of counters.
>>>
>>> The easiest way to do this would be to have a map<int, counter> where
>>> the int is the key, and the counter is the value which is incremented /
>>> decremented. E.g if something related to 5 happened, then i'd get the
>>> counter for 5 and increment / decrement it.
>>>
>>> I also need to have multiple map<int, counter>s of this type, where each
>>> int is a key referring to something different.
>>>
>>> Is there a way to do this in c* which doesn't require creating 1 table
>>> per type of map<int, counter> that i need?
>>>
>>>
>>>
>>
>

Mime
View raw message