【问题标题】:How to define frozen columns in Cassandra using cqlengine?如何使用 cqlengine 在 Cassandra 中定义冻结列?
【发布时间】:2019-06-01 16:07:21
【问题描述】:

我正在尝试在 Cassandra 中创建一个冻结列表,以便我可以将该列用作主键,如果我手动运行查询,我可以这样做,

some_field frozen <list<int>>

但我很难弄清楚如何在 Python 中使用 cqlengine,

some_field = columns.List(columns.Integer(), primary_key=True)

如何使用 cqlengine 完成同样的事情?

编辑:最终代码 sn-p 看起来像这样,

from cassandra.cqlengine import columns
from cassandra.cqlengine.models import Model

class MyModel(Model):
    __table_name__ = 'my_table'
    __options__ = {'compaction': {'class': 'DateTieredCompactionStrategy',
                              'base_time_seconds': 3600,
                              'max_sstable_age_days': 1}}

    keys = columns.Set(columns.Integer(), primary_key=True)
    columns.BaseCollectionColumn._freeze_db_type(keys)
    time_stamp = columns.DateTime(primary_key=True, clustering_order="DESC")
    ...

【问题讨论】:

    标签: python cassandra cqlengine


    【解决方案1】:

    作为I see in the source code,您需要在创建集合类型的实例后调用函数_freeze_db_type - 这会将类型更改为frozen&lt;...&gt;

    【讨论】:

    • 是的,成功了,作为参考,我在问题上添加了最终代码,
    猜你喜欢
    • 1970-01-01
    • 2013-07-20
    • 2021-02-06
    • 1970-01-01
    • 2014-04-13
    • 1970-01-01
    • 1970-01-01
    • 2019-04-11
    • 2019-01-13
    相关资源
    最近更新 更多