我一直在关注CQL 3.0数据建模文档 http://www.datastax.com/documentation/cql/3.0/webhelp/cql/ddl/ddl_anatomy_table_c.html#concept_ds_qqw_1dy_zj它描述了带有标签的歌曲列系列,创建如下:
CREATE TABLE songs (
id uuid PRIMARY KEY,
title text,
tags set<text>
);
我想获取具有特定标签的所有歌曲的列表,因此我需要添加适当的索引。
我可以创建一个索引title
列很容易,但是如果我尝试索引tags
列是一个集合,如下所示:
CREATE INDEX ON songs ( tags );
我从 DataStax Java 驱动程序 1.0.4 收到以下错误:
Exception in thread "main" com.datastax.driver.core.exceptions.InvalidQueryException: Indexes on collections are no yet supported
at com.datastax.driver.core.exceptions.InvalidQueryException.copy(InvalidQueryException.java:35)
at com.datastax.driver.core.ResultSetFuture.extractCauseFromExecutionException(ResultSetFuture.java:269)
根据 JIRA 问题,这似乎可能在 Cassandra (2.1) 的更高版本中得到修复卡桑德拉-4511 https://issues.apache.org/jira/browse/CASSANDRA-4511。不过,我目前正在使用 Apache Cassandra 1.2.11,并且还不想升级。根据问题卡桑德拉-5615 https://issues.apache.org/jira/browse/CASSANDRA-5615不过,在 Cassandra 1.2.6 中is支持自定义索引关于收藏。
问题是,唯一文档 http://www.datastax.com/documentation/cql/3.1/webhelp/cql/cql_reference/create_index_r.html可用状态:
Cassandra 支持创建自定义索引,该索引仅供内部使用,超出了本文档的范围。
But, it does建议使用以下语法:
CREATE CUSTOM INDEX ON songs ( tags ) USING 'class_name';
是什么class_name
此 CQL 语句中指定了哪些内容?
有没有更好的方法来索引标签,以便我可以查询songs具有特定标签的歌曲列表的表?