On Wed, Sep 19, 2012 at 2:00 PM, Roshni Rajagopal
<roshni_rajago...@hotmail.com> wrote:
> Hi,
>
> There was a conversation on this some time earlier, and to continue it
>
> Suppose I want to associate a user to  an item, and I want to also store 3
> commonly used attributes without needing to go to an entity item column
> family , I have 2 options :-
>
> A) use composite columns
> UserId1 : {
>  <itemid1>:<Name> = Betty Crocker,
>  <itemid1>:<Descr> = Cake
> <itemid1>:<Qty> = 5
>  <itemid2>:<Name> = Nutella,
>  <itemid2>:<Descr> = Choc spread
> <itemid2>:<Qty> = 15
> }
>
> B) use a json with the data
> UserId1 : {
>  <itemid1> = {name: Betty Crocker,descr: Cake, Qty: 5},
>  <itemid2> ={name: Nutella,descr: Choc spread, Qty: 15}
> }

> How does approach B work in CQL

The "way" CQL3 (the precision is because basically CQL2 doesn't have any good
solution for this problem) handle this is basically by using composite columns,
i.e. it uses solution A). However, the whole point is that the syntax is, we
think, much more friendly that if you were to use composites yourself in say
thrift.

More concretely, you'd handle your 'shopping cart' example with the following
table:
  CREATE TABLE shopping_cart (
      userId uuid,
      itemId uuid,
      name text,
      descr text,
      qty int,
      PRIMARY KEY (userId, itemId)
  )

The way this will be layout internally is pretty much exactly the layout you've
described for A).

> Can we read/write a JSON easily in CQL?

There is no specific support of JSON by CQL (or any of the Cassandra data model
for that matter). You can insert JSON string obviously, but Cassandra won't use
it in any way (and so you'd have to read the string and extract whatever
field you're interested client side). Obviously, using the "CQL" way described
above is the preferred way.

--
Sylvain

Reply via email to