2010-07-13 57 views
10

嘿, 我使用生成UUID的卡桑德拉在Python

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

创建一个卡桑德拉TimeUUID,但得到错误

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

它不与

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

要么。

什么是最好的方式来创建一个有效的TimeUUID与CompareWith =“TimeUUIDType”标志一起使用?

感谢,
亨里克

回答

4

您必须确保您的列族架构接受UUID作为关键字。您的代码将作为创建一个列族的工作(使用卡桑德拉-CLI):

create column family MyColumnFamily 
    with column_type = 'Standard' 
    and comparator = 'AsciiType' 
    and default_validation_class = 'BytesType' 
    and key_validation_class = 'TimeUUIDType'; 

将值添加到这个CF:

import pycassa 
pool = pycassa.ConnectionPool('Keyspace1') 
cf = pycassa.ColumnFamily(pool, 'MyColumnFamily') 
cf.insert(uuid.uuid1(), {'column1': 'val1'}) 
9

看起来你正在使用的UUID作为行键,而不是列名。

的“compare_with:TimeUUIDType”属性指定列名称将被使用TimeUUIDType进行比较,即它tells Cassandra how to sort the columns for slicing operations

你有没有考虑使用任何高级别蟒蛇的客户?例如。 Tradedgy,Lazy Boy,TelephusPycassa

+0

我应该提到,我USIG pycassa,但似乎我必须自己创建timeuuids。 – 2010-07-13 18:47:57

+0

同样的错误。也许这是与pycassa – 2010-07-13 18:55:14

+1

再次感谢问题。并为您的ICQ消息:) – 2010-07-13 19:54:39