Return-Path: X-Original-To: apmail-cassandra-user-archive@www.apache.org Delivered-To: apmail-cassandra-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D999A7B3D for ; Sun, 4 Dec 2011 02:16:42 +0000 (UTC) Received: (qmail 49088 invoked by uid 500); 4 Dec 2011 02:16:37 -0000 Delivered-To: apmail-cassandra-user-archive@cassandra.apache.org Received: (qmail 49054 invoked by uid 500); 4 Dec 2011 02:16:37 -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 49018 invoked by uid 99); 4 Dec 2011 02:16:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Dec 2011 02:16:37 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of yulinyen@gmail.com designates 74.125.83.44 as permitted sender) Received: from [74.125.83.44] (HELO mail-ee0-f44.google.com) (74.125.83.44) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 04 Dec 2011 02:16:30 +0000 Received: by eeuu47 with SMTP id u47so733113eeu.31 for ; Sat, 03 Dec 2011 18:16:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=+L84m0YImONTXviP30ienZiL8RgTK+iheHXKvvPonNo=; b=XaoJoAXZqxJU+nIj7Ghvee/eGKG8CXjRddlDdguLPTyPXNkOVwKUdbWKbEAhewSU2q NpUY7Qznrf5KgvGg/Jcd/oXZqhV0x3TK257yJX3Z7qfu3NIrN1w6wyargkgF896An9Ab 1CE3n582ii6txzB8M8S1eEAh2EZp7sqKloDaI= MIME-Version: 1.0 Received: by 10.14.14.21 with SMTP id c21mr88541eec.181.1322964970298; Sat, 03 Dec 2011 18:16:10 -0800 (PST) Received: by 10.14.19.195 with HTTP; Sat, 3 Dec 2011 18:16:10 -0800 (PST) In-Reply-To: <30291830.85883.1322560928214.JavaMail.www@wsfrf1128> References: <30291830.85883.1322560928214.JavaMail.www@wsfrf1128> Date: Sun, 4 Dec 2011 10:16:10 +0800 Message-ID: Subject: Re: Cassandra DataModeling recommendations From: Boris Yen To: user@cassandra.apache.org, pcohen@cegetel.net Content-Type: multipart/alternative; boundary=0016e659fe9c1ade0a04b33ac9a9 X-Virus-Checked: Checked by ClamAV on apache.org --0016e659fe9c1ade0a04b33ac9a9 Content-Type: text/plain; charset=ISO-8859-1 Not sure I understand your use case, but I think you could use a composite column instead of composite key. For example, UserID:{ TimeUUID1:CartID1, TimeUUID2:CartID2, TimeUUID3:CartID3, } This way, you could do a slice query on the time if you do not need all the carts, and you could also get all the carts in one query. For expired carts, maybe you could attach TTL to each column that has time constraint, let the database remove the data for you. On Tue, Nov 29, 2011 at 6:02 PM, wrote: > Hi all, > In order to evaluate NoSQL solutions and to gain knowledge, I am currently > working on a kind of prototype. > Here is a brief overview of the scope: > > I would like to manage user carts. Lets keep things simple: > A user can have up to n (lets say 3 for example) carts. Each cart will > contain metadata and among them an expiration date and a blob containing > stuff (xml in fact but I really don't care of the content). > > A user can save, retrieve or delete his carts. Additionally, a dedicated > batch process would remove carts who are expired. > > Basically I was thinking of two ways to model the data: > 1- A ColumnFamily with the userid as a key and having several SuperColumns > each one describing a Cart and its content. > This has the advantage that I can get all the Carts in a single get or can > do some slice queries to get only some Carts. The problem is that I cannot > if I am right create a secondary index on the expired date column inside > each Cart. > 2- A ColumnFamily with a composite key like userid::cartId containing the > expiration date column and the blob. I can in that case create an index to > perform a query on the expiration timestamp. The drawback is that if I want > to get all the Carts I need to create either a secondary ColumnFamily > listing the carts associated to a userid or use a kind of > OrderPreservingPartitionner if I want to perform a Key-Range Query. > > I made some tests and I had some problems > First I was unable to perform queries in the case 2 like: > get Carts where timestamp < xxxxxxx; The (ugly, really!) workaround was to > create a fake column always set to true and the query that worked was: > get Carts where dummy=true and timestamp < xxxxxxx; But I really dislike > this solution and I am almost sure this is not the right way to go. > > I tried something different like creating a dedicated timestamp > columnfamily associating a key based on a timestamp and columns related to > user and carts. In that case if I want outdated entries I could perform a > range query on keys of this columnfamily. But again in that case I need an > OrderPreservingPartionner and I fear that using a timestamp as a key would > lead to a bad repartition scheme among the nodes. If I fit to the second > proposal (with Standard Columns), columns could be directly the key like > userId::cartId and there is no logic in the removal process. If I fit to > first solution solution, I need to have some logic to analyze the column > key or value to get userid + cartid. > Another point, if I use this column family I have to manage "updates". If > for example I replace Cart2 of user1, I need to remove the corresponding > entry and add a new one. This is honestly probably not the hardest part. > > I have the feeling that having a userId based ColumnFamily with > SuperColumns inside and a dedicated timestamp table is the best choice. In > fact I think that basically my requests will be: > - Give me all the carts of a userId > - Remove all the expired carts: which is probably in fact 2 requests: Find > all carts whose expiry date is before a given date. Delete the found stuff. > > I am fairly new to NoSQL and especially to Cassandra so I would like to > get any advice on: > 1- Is Cassandra suited to this kind of storage ? I would say yes > 2- What is the right way to model the data and the related constraints. > > If my description is unclear or anyone does need more details, do not > hesitate to ask > Thanks in advance for any help or advice > > Regards > > Pascal > --0016e659fe9c1ade0a04b33ac9a9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Not sure I understand your use case, but I think you could use a composite = column instead of composite key.

For example,=A0

UserID:{
=A0 =A0 TimeUUID1:CartID1,
= =A0 =A0=A0TimeUUID2:CartID2,
=A0 =A0=A0TimeUUID3:CartID3,
}

This w= ay, you could do a slice query on the time if you do not need all the carts= , and you could also get all the carts in one query.

For=A0expired carts, maybe you could attach TTL to each column that has tim= e constraint, let the database remove the data for you.

On Tue, Nov 29, 2011 at 6:02 PM, &= lt;pcohen@cegetel.net> = wrote:
Hi all,
In order to evaluate NoSQL solut= ions and to gain knowledge, I am currently working on a kind of prototype. =
Here is a brief overview of the scope:

I would like to manage user c= arts. Lets keep things simple:
A user can have up to n (lets say 3 for e= xample) carts. Each cart will contain metadata and among them an expiration= date and a blob containing stuff (xml in fact but I really don't care = of the content).

A user can save, retrieve or delete his carts. Additionally, a dedicate= d batch process would remove carts who are expired.

Basically I was = thinking of two ways to model the data:
1- A ColumnFamily with the useri= d as a key and having several SuperColumns each one describing a Cart and i= ts content.
This has the advantage that I can get all the Carts in a single get or can = do some slice queries to get only some Carts. The problem is that I cannot = if I am right create a secondary index on the expired date column inside ea= ch Cart.
2- A ColumnFamily with a composite key like userid::cartId containing the e= xpiration date column and the blob. I can in that case create an index to p= erform a query on the expiration timestamp. The drawback is that if I want = to get all the Carts I need to create either a secondary ColumnFamily listi= ng the carts associated to a userid or use a kind of OrderPreservingPartiti= onner if I want to perform a Key-Range Query.

I made some tests and I had some problems
First I was unable to perf= orm queries in the case 2 like:
get Carts where timestamp < xxxxxxx; = The (ugly, really!) workaround was to create a fake column always set to tr= ue and the query that worked was:
get Carts where dummy=3Dtrue and timestamp < xxxxxxx; But I really disli= ke this solution and I am almost sure this is not the right way to go.
<= br>I tried something different like creating a dedicated timestamp columnfa= mily associating a key based on a timestamp and columns related to user and= carts. In that case if I want outdated entries I could perform a range que= ry on keys of this columnfamily. But again in that case I need an OrderPres= ervingPartionner and I fear that using a timestamp as a key would lead to a= bad repartition scheme among the nodes. If I fit to the second proposal (w= ith Standard Columns), columns could be directly the key like userId::cartI= d and there is no logic in the removal process. If I fit to first solution = solution, I need to have some logic to analyze the column key or value to g= et userid + cartid.
Another point, if I use this column family I have to manage "updates&q= uot;. If for example I replace Cart2 of user1, I need to remove the corresp= onding entry and add a new one. This is honestly probably not the hardest p= art.

I have the feeling that having a userId based ColumnFamily with SuperCo= lumns inside and a dedicated timestamp table is the best choice. In fact I = think that basically my requests will be:
- Give me all the carts of a u= serId
- Remove all the expired carts: which is probably in fact 2 requests: Find = all carts whose expiry date is before a given date. Delete the found stuff.=

I am fairly new to NoSQL and especially to Cassandra so I would lik= e to get any advice on:
1- Is Cassandra suited to this kind of storage ? I would say yes
2- What= is the right way to model the data and the related constraints.

If = my description is unclear or anyone does need more details, do not hesitate= to ask
Thanks in advance for any help or advice

Regards

Pascal

--0016e659fe9c1ade0a04b33ac9a9--