Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用CQL 3.0在集合上创建自定义索引_Java_Cassandra_Cql3_Datastax Java Driver - Fatal编程技术网

Java 使用CQL 3.0在集合上创建自定义索引

Java 使用CQL 3.0在集合上创建自定义索引,java,cassandra,cql3,datastax-java-driver,Java,Cassandra,Cql3,Datastax Java Driver,我一直在看CQL 3.0,它描述了一系列带有标签的歌曲,创建如下: CREATE TABLE songs ( id uuid PRIMARY KEY, title text, tags set<text> ); CREATE INDEX ON songs ( tags ); 我从DataStax Java驱动程序1.0.4中得到以下错误: Exception in thread "main" com.datastax.driver.core.excepti

我一直在看CQL 3.0,它描述了一系列带有标签的歌曲,创建如下:

CREATE TABLE songs (
    id uuid PRIMARY KEY,
    title text,
    tags set<text>
);
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)中修复。但是,我目前正在使用ApacheCassandra1.2.11,不想升级。但根据问题,在Cassandra 1.2.6中支持集合上的自定义索引

问题是,唯一可用的状态是:

Cassandra支持创建自定义索引,该索引仅供内部使用,超出了本文档的范围

但是,它确实建议使用以下语法:

CREATE CUSTOM INDEX ON songs ( tags ) USING 'class_name';
此CQL语句中指定的
类名称是什么


是否有更好的方法对标签进行索引,以便我可以查询歌曲表中具有特定标签的歌曲列表?

在我看来,您尝试这样做的方式并不是在Cassandra中对其进行建模的最佳方法。您基于查询而不是数据构建模型。如果您需要根据标签查找歌曲,那么可以为其制作另一个表并复制数据。类似于

CREATE TABLE tagged_songs (
  tag varchar,
  song_id uuid,
  song_title varchar,
  ... anything else you might need with your songs here ...
  PRIMARY KEY ((tag), song_id)
);
《卡桑德拉》的前提是存储成本低廉。复制数据以满足您的查询。写入速度很快,通常可以将相同的数据写入3、4、10次

您还需要将歌曲标题和任何其他需要的信息存储在此表中。您不想在阅读时获取大量ID并尝试加入其中。这不是关系数据库

当有人标记一首歌曲时,您可能希望将该标记作为当前歌曲插入到集合中,并将其添加到tagged_songs表中。查询带有标记X的所有歌曲基本上是O(1)