Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6D000200BB7 for ; Wed, 9 Nov 2016 13:49:17 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 6B85A160AFD; Wed, 9 Nov 2016 12:49:17 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8EE8D160AEE for ; Wed, 9 Nov 2016 13:49:16 +0100 (CET) Received: (qmail 57731 invoked by uid 500); 9 Nov 2016 12:49:15 -0000 Mailing-List: contact user-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cassandra.apache.org Delivered-To: mailing list user@cassandra.apache.org Received: (qmail 57721 invoked by uid 99); 9 Nov 2016 12:49:15 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 Nov 2016 12:49:15 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id A5BB218819F for ; Wed, 9 Nov 2016 12:49:14 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.379 X-Spam-Level: *** X-Spam-Status: No, score=3.379 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_REPLY=1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id e8cvQBqCGBbV for ; Wed, 9 Nov 2016 12:49:12 +0000 (UTC) Received: from mail-ua0-f174.google.com (mail-ua0-f174.google.com [209.85.217.174]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id A69A15FE36 for ; Wed, 9 Nov 2016 12:49:12 +0000 (UTC) Received: by mail-ua0-f174.google.com with SMTP id 12so172587117uas.2 for ; Wed, 09 Nov 2016 04:49:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=NZW7wianEkF5T6xYfZ5pDJxsDTwau7FE2ZVejPf4Eeg=; b=OoiRKYuG1jMqRjiiOTSdaZ90BxmZcDXM0q3Eh7eRrUdJ7ulbl5+anIvtT4WdbQeBpI nsLZtdXILSlBTghwkcXHcO7wZTItNog+Eu1nTY8EJ0X0+nwtHX/bgN/HL+gXOThvDI+9 PRU6jn+h5Dq/EYGuOyKZqRBNfoZua0+2dY0MhnsuQVw4Zvp2A8GV9x4gPhgJk9gXXZ// ct+PqV5Idu8hH12grU7qRvKg0QPhmHCtT0r16uECmpe02OyEW+5b1iYik5u48gdh+NV+ V+gxbgXjCHlkl62V7LAQUjmTQMDOnCrjX5LEUa1UtlFFMPPhZnRMxcHsQeR4kWGMHPci 3zgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=NZW7wianEkF5T6xYfZ5pDJxsDTwau7FE2ZVejPf4Eeg=; b=gc/BTM2QDiZcWXIMmeH75p2BFCM8DxUhz9o8ZxD+u0M47vv3pr5XtKPIfBmlqfUeyv 7Ot9DQMGyHZ2cl/pga2bXFsqpNIFdbODbV+QgOcyvfTU3Wc/kiKjkEdHhqLerJrWLz21 RDyhibdVtYYTqgZAr/Nl1uCSpt9BvbKY95JfGOEN0s4hF2LKiw+I6c2TnI9S/mpoH8fu IUevJhFC1Z79QAsLPbrwRKKdMY5NnWy5HG9sT1wSbrlm03Bp+Ui0P1ftb9biLkC1dc74 iezBvsRTVzZww3UgWLgOSEql2IJ3ySUFtbe00ZJAlolnZOBnPklTlmVZZdP5B3MNxLrX MUcg== X-Gm-Message-State: ABUngvdLwRq092XW8o910oRpGc/wf1Kj5TuzzDajzrQcz2UT1sh6eeHmdxxGmk8/kbA0Iw883ldjmNin9HmcHw== X-Received: by 10.159.54.239 with SMTP id p102mr1006822uap.67.1478695681925; Wed, 09 Nov 2016 04:48:01 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.149.137 with HTTP; Wed, 9 Nov 2016 04:47:41 -0800 (PST) In-Reply-To: <158491383ea.af8a1984134902.3977439974496170996@winguzone.com> References: <158491383ea.af8a1984134902.3977439974496170996@winguzone.com> From: DuyHai Doan Date: Wed, 9 Nov 2016 13:47:41 +0100 Message-ID: Subject: Re: Having Counters in a Collection, like a map? To: user@cassandra.apache.org Content-Type: multipart/alternative; boundary=94eb2c04cbbada2ac10540ddaa5a archived-at: Wed, 09 Nov 2016 12:49:17 -0000 --94eb2c04cbbada2ac10540ddaa5a Content-Type: text/plain; charset=UTF-8 "Is there a way to do this in c* which doesn't require creating 1 table per type of map 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 >> 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 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); > InvalidRequest: Error from server: code=2200 [Invalid query] > message="Counters are not allowed inside collections: map" > > 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 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 - Hosted Cloud > CassandraLaunch your cluster in minutes.* > > > ---- On Wed, 09 Nov 2016 07:17:53 -0500*Ali Akhtar >* 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 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 maps 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 that i need? > > > --94eb2c04cbbada2ac10540ddaa5a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
"Is there a way to d= o 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_counter= s_map (
=C2=A0 =C2=A0 =C2= =A0partition_key id uuid,
=C2=A0 =C2=A0 =C2=A0map_name text,
=C2=A0 =C2=A0 =C2=A0map_key int,
=C2=A0 =C2=A0 =C2=A0count counter,
=C2=A0 =C2=A0 =C2=A0PRIMARY KEY ((id), map_nam= e,=C2=A0map_key)
)= ;

<= span style=3D"font-size:12.8px">This table can be seen as:

Map <partition_key, SortedMap<map_name, SortddMap<ma= p_key, counter>>>

The couple (map_ke= y, 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@wing= uzone.com> wrote:
<= div>
Unfortunately it's impossible nor to use counters inside col= lections neither mix them with other non-counter columns :
CREATE TABLE cnt (id int PRIMARY KEY , cntmap MAP<int,count= er>);
InvalidRequest: Error from server: code=3D2200 [Invalid que= ry] message=3D"Counters are not allowed inside collections: map<int= , counter>"

CREATE TABLE cnt (i= d int PRIMARY KEY , cnt1 counter, txt text);
InvalidRequest: Error f= rom server: code=3D2200 [Invalid query] message=3D"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, counte= r> that i need?
But you don't need to create se= parate table per each counter, just use one row per counter:
=
CREATE TABLE cnt (id int PRIMARY KEY , value counter);

Best regards, Vla= dimir Yudovin,
Winguzone - Hosted Cloud Cassandra
Launch your= cluster in minutes.


<= div>---- On Wed, 09 Nov 2016 07:17:53 -0500Ali Akhtar <ali.rac200@gmail.com> wrote ----

I have a use-case where I need to have a dynam= ic number of counters.

The easiest way to do t= his would be to have a map<int, counter> where the int is the key, an= d the counter is the value which is incremented / decremented. E.g if somet= hing related to 5 happened, then i'd get the counter for 5 and incremen= t / decrement it.

I also need to have multiple= map<int, counter>s of this type, where each int is a key referring t= o something different.

Is there a way to do th= is in c* which doesn't require creating 1 table per type of map<int,= counter> that i need?


--94eb2c04cbbada2ac10540ddaa5a--