在 Python 中为 Cassandra 生成 UUID

发布于 2024-09-09 15:55:36 字数 442 浏览 4 评论 0原文

呵呵, 我正在使用

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

为 Cassandra 创建 TimeUUID,但收到错误

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

It does'不能与

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

任何一个一起工作。

创建与 CompareWith="TimeUUIDType" 标志一起使用的有效 TimeUUID 的最佳方法是什么?

谢谢,
亨里克

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薯片软お妹 2024-09-16 15:55:36

看起来您正在使用 uuid 作为行键而不是列名。

'compare_with: TimeUUIDType' 属性指定将使用 TimeUUIDType 来比较列名,即 告诉 Cassandra 如何对列进行排序以进行切片操作

您是否考虑过使用任何高级 Python 客户端?例如 Tradedgy懒惰男孩TelephusPycassa

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

隱形的亼 2024-09-16 15:55:36

您必须确保您的列族架构接受 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'})

You must ensure your column family schema accepts UUID as key. Your code will work with a column family created as (using cassandra-cli):

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

To add values to this CF:

import pycassa
pool = pycassa.ConnectionPool('Keyspace1')
cf = pycassa.ColumnFamily(pool, 'MyColumnFamily')
cf.insert(uuid.uuid1(), {'column1': 'val1'})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文