【问题标题】:Generate UUID for Cassandra in Python在 Python 中为 Cassandra 生成 UUID
【发布时间】:2011-03-15 11:49:30
【问题描述】:

嘿嘿, 我正在使用

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

为 Cassandra 创建 TimeUUID,但出现错误

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

不适合

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

要么。

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

谢谢,
亨里克

【问题讨论】:

    标签: python cassandra uuid pycassa


    【解决方案1】:

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

    'compare_with: TimeUUIDType' 属性指定列名将与使用 TimeUUIDType 进行比较,即 tells Cassandra how to sort the columns for slicing operations

    您是否考虑过使用任何高级 python 客户端?例如。 TradedgyLazy BoyTelephusPycassa

    【讨论】:

    • 我应该提到我正在使用 pycassa,但似乎我必须自己创建 timeuuid。
    • 我不明白这是如何回答这个问题的。我也遇到了同样的问题,能不能详细点?
    • 你知道键名和列名的区别吗?
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2019-04-01
      • 2015-04-02
      • 2019-02-03
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 2021-12-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多