You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Shuge Lee <sh...@gmail.com> on 2010/04/06 10:49:16 UTC

how to store list data in Apache Cassndra ?

Dear firends:

how to store list data in Apache Cassndra ?

For example:

user['lee'] = {
    'name': 'lee',
    'age'; '21',
    'girls': ['java', 'actionscript', 'python'],
}

Notice key `gils`

I using pycassa (a python lib of cassandra)

import pycassa
client = pycassa.connect()
cf = pycassa.ColumnFamily(client, 'mygame', 'user')

key = '1234567890'
value = {
    'name': 'Lee Li',
    'age'; '21',
    'girls': ['java', 'actionscript', 'python'],
}

cf.insert(key, value)


Oops, get error while save a `value` like above.

So, how to store list data in Apache Cassndra ?


Thanks for reply.




-- 
Shuge Lee | Lee Li

Re: how to store list data in Apache Cassndra ?

Posted by Tatu Saloranta <ts...@gmail.com>.
On Tue, Apr 6, 2010 at 8:06 AM, Shuge Lee <sh...@gmail.com> wrote:
>>     'girls': pickle.dumps(['java', 'actionscript', 'python'])
>
> I think this is a really bad idea, I can't do any search if using Pickle.

Just to be sure: are you thinking of traditional queries, lookups by
values (find entries that have certain element in a list value)?
If so, you may be in trouble anyway: you can only do efficient queries
by primary entry key, not by values (Cassandra at least can do range
queries on keys, but still).

-+ Tatu +-

Re: how to store list data in Apache Cassndra ?

Posted by Shuge Lee <sh...@gmail.com>.
>     'girls': pickle.dumps(['java', 'actionscript', 'python'])

I think this is a really bad idea, I can't do any search if using Pickle.

> use a SuperColumnFamily
sounds nice :)

I'm try handle it with following:

 value = {
    'name': 'Lee Li',
    'age'; '21',
    'girls': {
        'java': '',
        'actionscript': '',
        'python': '',
        ),
 }

2010/4/6 David Strauss <da...@fourkitchens.com>

> Another option is to use a SuperColumnFamily, but that extends the depth
> of all such values to be arrays. The "name" and "age" columns would
> therefore also need to be SuperColumns -- just with a single sub-column
> each.
>
> Like many things in Cassandra, the preferred storage method depends on
> your application's access patterns. It's quite unlike the normalization
> procedure for an RDBMS, which is possible without knowing future queries.
>
> On 2010-04-06 09:12, Michael Pearson wrote:
> > Column Families are keyed attribute/value pairs, your 'girls' column
> > will need to be serialised on save, and deserialiased on load so that
> > it can treated as your intended array.  Pickle will do this for you
> > (http://docs.python.org/library/pickle.html)
> >
> > eg:
> >
> >  import pycassa
> >  import pickle
> >  client = pycassa.connect()
> >  cf = pycassa.ColumnFamily(client, 'mygame', 'user')
> >
> >  key = '1234567890'
> >  value = {
> >      'name': 'Lee Li',
> >      'age'; '21',
> >      'girls': pickle.dumps(['java', 'actionscript', 'python'])
> >  }
> >
> > cf.insert(key, value)
> >
> > hope that helps
> >
> > -michael
> >
> >
> > On Tue, Apr 6, 2010 at 6:49 PM, Shuge Lee <sh...@gmail.com> wrote:
> >> Dear firends:
> >>
> >> how to store list data in Apache Cassndra ?
> >>
> >> For example:
> >> user['lee'] = {
> >>     'name': 'lee',
> >>     'age'; '21',
> >>     'girls': ['java', 'actionscript', 'python'],
> >> }
> >> Notice key `gils`
> >>
> >> I using pycassa (a python lib of cassandra)
> >>
> >> import pycassa
> >> client = pycassa.connect()
> >> cf = pycassa.ColumnFamily(client, 'mygame', 'user')
> >>
> >> key = '1234567890'
> >> value = {
> >>     'name': 'Lee Li',
> >>
> >>     'age'; '21',
> >>     'girls': ['java', 'actionscript', 'python'],
> >> }
> >>
> >> cf.insert(key, value)
> >>
> >>
> >> Oops, get error while save a `value` like above.
> >>
> >> So, how to store list data in Apache Cassndra ?
> >>
> >>
> >> Thanks for reply.
> >>
> >>
> >>
> >>
> >> --
> >> Shuge Lee | Lee Li
> >>
>
>
> --
> David Strauss
>   | david@fourkitchens.com
> Four Kitchens
>   | http://fourkitchens.com
>   | +1 512 454 6659 [office]
>   | +1 512 870 8453 [direct]
>
>


-- 
Shuge Lee | Lee Li | 李蠡

Re: how to store list data in Apache Cassndra ?

Posted by David Strauss <da...@fourkitchens.com>.
Another option is to use a SuperColumnFamily, but that extends the depth
of all such values to be arrays. The "name" and "age" columns would
therefore also need to be SuperColumns -- just with a single sub-column
each.

Like many things in Cassandra, the preferred storage method depends on
your application's access patterns. It's quite unlike the normalization
procedure for an RDBMS, which is possible without knowing future queries.

On 2010-04-06 09:12, Michael Pearson wrote:
> Column Families are keyed attribute/value pairs, your 'girls' column
> will need to be serialised on save, and deserialiased on load so that
> it can treated as your intended array.  Pickle will do this for you
> (http://docs.python.org/library/pickle.html)
> 
> eg:
> 
>  import pycassa
>  import pickle
>  client = pycassa.connect()
>  cf = pycassa.ColumnFamily(client, 'mygame', 'user')
> 
>  key = '1234567890'
>  value = {
>      'name': 'Lee Li',
>      'age'; '21',
>      'girls': pickle.dumps(['java', 'actionscript', 'python'])
>  }
> 
> cf.insert(key, value)
> 
> hope that helps
> 
> -michael
> 
> 
> On Tue, Apr 6, 2010 at 6:49 PM, Shuge Lee <sh...@gmail.com> wrote:
>> Dear firends:
>>
>> how to store list data in Apache Cassndra ?
>>
>> For example:
>> user['lee'] = {
>>     'name': 'lee',
>>     'age'; '21',
>>     'girls': ['java', 'actionscript', 'python'],
>> }
>> Notice key `gils`
>>
>> I using pycassa (a python lib of cassandra)
>>
>> import pycassa
>> client = pycassa.connect()
>> cf = pycassa.ColumnFamily(client, 'mygame', 'user')
>>
>> key = '1234567890'
>> value = {
>>     'name': 'Lee Li',
>>
>>     'age'; '21',
>>     'girls': ['java', 'actionscript', 'python'],
>> }
>>
>> cf.insert(key, value)
>>
>>
>> Oops, get error while save a `value` like above.
>>
>> So, how to store list data in Apache Cassndra ?
>>
>>
>> Thanks for reply.
>>
>>
>>
>>
>> --
>> Shuge Lee | Lee Li
>>


-- 
David Strauss
   | david@fourkitchens.com
Four Kitchens
   | http://fourkitchens.com
   | +1 512 454 6659 [office]
   | +1 512 870 8453 [direct]


Re: how to store list data in Apache Cassndra ?

Posted by Michael Pearson <mj...@gmail.com>.
Column Families are keyed attribute/value pairs, your 'girls' column
will need to be serialised on save, and deserialiased on load so that
it can treated as your intended array.  Pickle will do this for you
(http://docs.python.org/library/pickle.html)

eg:

 import pycassa
 import pickle
 client = pycassa.connect()
 cf = pycassa.ColumnFamily(client, 'mygame', 'user')

 key = '1234567890'
 value = {
     'name': 'Lee Li',
     'age'; '21',
     'girls': pickle.dumps(['java', 'actionscript', 'python'])
 }

cf.insert(key, value)

hope that helps

-michael


On Tue, Apr 6, 2010 at 6:49 PM, Shuge Lee <sh...@gmail.com> wrote:
> Dear firends:
>
> how to store list data in Apache Cassndra ?
>
> For example:
> user['lee'] = {
>     'name': 'lee',
>     'age'; '21',
>     'girls': ['java', 'actionscript', 'python'],
> }
> Notice key `gils`
>
> I using pycassa (a python lib of cassandra)
>
> import pycassa
> client = pycassa.connect()
> cf = pycassa.ColumnFamily(client, 'mygame', 'user')
>
> key = '1234567890'
> value = {
>     'name': 'Lee Li',
>
>     'age'; '21',
>     'girls': ['java', 'actionscript', 'python'],
> }
>
> cf.insert(key, value)
>
>
> Oops, get error while save a `value` like above.
>
> So, how to store list data in Apache Cassndra ?
>
>
> Thanks for reply.
>
>
>
>
> --
> Shuge Lee | Lee Li
>