Search code examples
pythongetcassandrauuidpycassa

how to get the data using pycassa with uuid key


I inserted the data like this.

import pycassa, datetime
cf.insert(pycassa.util.convert_time_to_uuid(datetime.datetime.now()),{str(i): 'val'})

......

data

dbed33be-cc9e-11e1-8080-808080808080 OrderedDict([('column1', 'val1')])

How to get the data with uuid key?

I tried to get the data like this.

cf.get("UUID('dbed33be-cc9e-11e1-8080-808080808080')")
cf.get("dbed33be-cc9e-11e1-8080-808080808080")
cf.get(UUID('dbed33be-cc9e-11e1-8080-808080808080'))

But, I didn't get.


Solution

  • You were really close to the solution, but yet so far away..


    pycassa.util.convert_time_to_uuid will return a value of type uuid.UUID, to generate one from a string (as you've tried) you will need to use either of the below methods:

    UUID('{12345678-1234-5678-1234-567812345678}')
    
    UUID('12345678123456781234567812345678')
    
    UUID('urn:uuid:12345678-1234-5678-1234-567812345678')
    

    cf.get(UUID('{dbed33be-cc9e-11e1-8080-808080808080}')) # example
    

    Read more about UUID under the following link: