gpt4 book ai didi

nosql - 按 Cassandra 中的 map 值查询

转载 作者:行者123 更新时间:2023-12-01 23:59:57 24 4
gpt4 key购买 nike

假设我有这样的列族:

CREATE TABLE test(
id text,
meta map <text, text>,
PRIMARY KEY (key)
);

然后我将一些数据放入我的 map ,例如:{'username' : 'ivan'}

我想通过 meta 映射中的元素查询我的测试列族。像这样:

SELECT * FROM test WHERE meta['username'] = 'ivan';

根据 Cassandra documentation这应该是可能的:

As its name implies, a map maps one thing to another. A map is a name and a pair of typed values. Using the map type, you can store timestamp-related information in user profiles. Each element of the map is internally stored as one Cassandra column that you can modify, replace, delete, and query.

但是我在网上找不到任何这样的例子,这真的可能吗?

谢谢,伊万

最佳答案

您需要添加二级索引以通过键或值查询 map :

CREATE INDEX meta_idx ON test (ENTRIES(meta));
SELECT * FROM test WHERE meta['username'] = 'ivan';

另见:

https://docs.datastax.com/en/cql/3.3/cql/cql_using/useIndexColl.html

关于nosql - 按 Cassandra 中的 map 值查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22016115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com