在Python中为Cassandra生成UUID
题
嘿, 我正在使用
cf.insert(uuid.uuid1().bytes_le, {'column1': 'val1'})
(pycassa)
为Cassandra创建TimeUID,但收到错误
InvalidRequestException:
InvalidRequestException(why='UUIDs must be exactly 16 bytes')
.
它不适用于
uuid.uuid1()
uuid.uuid1().bytes
str(uuid.uuid1())
.
也是如此。
创建有效TimeUID以与CompareWith=“timeuuidtype”标志一起使用的最佳方法是什么?
谢谢,
henrik
解决方案
必须确保您的列族架构接受UUID作为键。您的代码将使用创建的列族(使用Cassandra-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'})
. 其他提示
看起来您使用的是uuid作为行键而不是列名称。
' compare_with:timeuudtype '属性指定将使用timeuuidtype将列名进行比较,即它告诉cassandra如何对切片操作进行分类列
不隶属于 StackOverflow