2

使用 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 在映射键上创建索引?

4

1 回答 1

1

Richard,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 来创建该类型的索引。

于 2016-02-18T22:37:58.437 回答