【问题标题】:cassandra cqlengine map column index on keycassandra cqlengine 在键上映射列索引
【发布时间】:2016-02-19 06:37:58
【问题描述】:

使用 Cassandra python 驱动映射器 cqlengine,在创建带有地图集合的模型时,似乎只能在地图值上创建索引

class Foo(Model):
    id = columns.UUID(partition_key=True)
    time_id = columns.UUID(primary_key=True, clustering_order='DESC')
    bar = columns.Map(columns.Ascii(), columns.Double(), index=True)

会生成一个类似的表格

cqlsh:baz> DESCRIBE foo;
    CREATE TABLE bar.asset_metric (
        id uuid,
        time_id timeuuid,
        bar map<ascii, double>,
        PRIMARY KEY (id, time_id)
    ) WITH CLUSTERING ORDER BY (time_id DESC)
CREATE INDEX index_foo_bar ON baz.foo (values(bar));

如何让 cqlengine 改为在映射键上创建索引?

【问题讨论】:

    标签: python cassandra cqlengine


    【解决方案1】:

    理查德, 目前 cqlengine 不支持索引映射键。如果您有兴趣,创建运行的 cql 索引查询的代码位于此处。

    https://github.com/datastax/python-driver/blob/master/cassandra/cqlengine/management.py#L197-L201

    这是将要执行的 cql 语句。 它会形成一个查询。

    在 keyspace.model_name_here ("map_name_here") 上创建索引 index_name_here。

    默认情况下,这将索引值。有一种方法可以使用 KEYS 前缀使用纯 cql 索引地图的键。

    该查询看起来像这样 CREATE INDEX index_name_here ON keyspace.model_name_here(KEYS(map_name_here));

    您可以在此博客文章中阅读有关集合索引的更多信息。 http://www.datastax.com/dev/blog/cql-in-2-1

    不幸的是,cqlengine 还不支持该功能。您将不得不进入基本驱动程序并直接使用 cql 来创建该类型的索引。

    【讨论】:

    • 看起来我们需要的是列类处理其index_column_name,以便可以正确处理映射情况下的专业化,即值/键/条目等。当我查看github.com/datastax/python-driver/blob/master/cassandra/… 并认为那是生成创建索引字符串的地方时,我试图自己解决这个问题时陷入了困境。
    猜你喜欢
    • 1970-01-01
    • 2021-02-06
    • 2012-11-20
    • 1970-01-01
    • 2011-06-08
    • 2017-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多