Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate UUID for Cassandra in Python

Heh, I'm using

cf.insert(uuid.uuid1().bytes_le, {'column1': 'val1'}) (pycassa)

to create a TimeUUID for Cassandra, but getting the error

InvalidRequestException: 
InvalidRequestException(why='UUIDs must be exactly 16 bytes')

It doesn't work with

uuid.uuid1()
uuid.uuid1().bytes
str(uuid.uuid1())

either.

What's the best way to create a valid TimeUUID to use with the CompareWith="TimeUUIDType" flag?

Thanks,
Henrik

like image 217
Henrik P. Hessel Avatar asked Jul 13 '10 18:07

Henrik P. Hessel


1 Answers

Looks like you are using the uuid as the row key and not the column name.

The 'compare_with: TimeUUIDType' attribute specifies that the column names will be compared with using the TimeUUIDType, i.e it tells Cassandra how to sort the columns for slicing operations

Have you considered using any of the high level python clients? E.g. Tradedgy, Lazy Boy, Telephus or Pycassa

like image 118
Schildmeijer Avatar answered Oct 05 '22 00:10

Schildmeijer