incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tyler Hobbs <ty...@datastax.com>
Subject Re: pycassa : composite key and UTF8Type ,DateType
Date Thu, 07 Mar 2013 16:49:00 GMT
FYI, there's a mailing list that's dedicated to pycassa:
https://groups.google.com/forum/?fromgroups#!forum/pycassa-discuss

On Thu, Mar 7, 2013 at 8:13 AM, Sloot, Hans-Peter <hans-peter.sloot@atos.net
> wrote:

> I have a tab separatd file with a number of columns.
>
> Columns 5 and 6 are the date as yyyy-mm-dd  and hh24:mi:ss
>
>
>
> I want to add rows with a composite key that consists of an UTF8Type and
> the DateType (which are fields 5 and 6).
>
>
>
> The column family is :
>
> CREATE COLUMN FAMILY traffic
>
>      WITH comparator = 'CompositeType(UTF8Type,UTF8Type)' and
> key_validation_class='CompositeType(UTF8Type,DateType)'
>
>      AND column_metadata = [ {column_name: fac, validation_class:
> UTF8Type, index_type : 0, index_name : fac_idx }]
>
>
>
> How can I insert rows with a composite key : field 0  + the combined
> fields 5 and 6 of the rows.
>
> Below a small piece of the code:
>
>
>
> b=cf.batch(queue_size=10000)
>
10000 is pretty high, I would start out with 100.


> with open (‘xxx.csv’) as csvfile:
>
>   spamreader=csv.reader(csvfile,delimiter='\t')
>
>  for row in spamreader:
>
>      b.insert(   )   ß how should the insert be done?
>
Build your key as described below and put the rest of the fields into a
dict.  Then all you need to do is b.insert(key, my_columns_dict).


> b.send()
>
>
>
> And more in general how can I cast a string to DateType?
>
pycassa can accept datetime objects for DateType fields, so just use
datetime.strptime to create a datetime object from the string:
http://docs.python.org/2/library/datetime.html#datetime.datetime.strptime

Make sure your datetime objects have a UTC timezone, though.


-- 
Tyler Hobbs
DataStax <http://datastax.com/>

Mime
View raw message