如何在Cassandra中搜索值,如SQL中的'WHERE'?

时间:2011-05-30 08:40:38

标签: cassandra

你好开发人员,我有点卡在查询cassandra,我试图谷歌如何在cassandra中添加限制/条件并得到一些例子,所以我创建这样的方法,我使用Hector为客户端API:

    IndexedSlicesQuery<String,String,String> indexedSlicesQuery=new IndexedSlicesQuery<String, String, String>(keyspace, serializer, serializer, serializers);
    indexedSlicesQuery.addEqualsExpression(columnName, value);
    indexedSlicesQuery.setReturnKeysOnly();
    indexedSlicesQuery.setColumnFamily(COLUMNFAMILY);
    indexedSlicesQuery.setStartKey("");
    QueryResult<OrderedRows<String,String,String>> result=indexedSlicesQuery.execute();

    return result;

方法对吗? 是'WHERE'的方法是indexedSlicesQuery.addEqualsExpression(columnName, value);

任何人都可以帮助我吗? 我仍然尝试这个,因为我有这样的错误:

1296 [main] INFO me.prettyprint.cassandra.hector.TimingLogger - start[1306744089788] time[158] tag[READ.fail_]
Exception in thread "main" me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:No indexed columns present in index clause with operator EQ)
        at me.prettyprint.cassandra.service.ExceptionsTranslatorImpl.translate(ExceptionsTranslatorImpl.java:42)
        at me.prettyprint.cassandra.service.KeyspaceServiceImpl$12.execute(KeyspaceServiceImpl.java:513)
        at me.prettyprint.cassandra.service.KeyspaceServiceImpl$12.execute(KeyspaceServiceImpl.java:495)
        at me.prettyprint.cassandra.service.Operation.executeAndSetResult(Operation.java:101)
        at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:221)
        at me.prettyprint.cassandra.service.KeyspaceServiceImpl.operateWithFailover(KeyspaceServiceImpl.java:129)
        at me.prettyprint.cassandra.service.KeyspaceServiceImpl.getIndexedSlices(KeyspaceServiceImpl.java:517)
        at me.prettyprint.cassandra.model.IndexedSlicesQuery$1.doInKeyspace(IndexedSlicesQuery.java:140)
        at me.prettyprint.cassandra.model.IndexedSlicesQuery$1.doInKeyspace(IndexedSlicesQuery.java:131)
        at me.prettyprint.cassandra.model.KeyspaceOperationCallback.doInKeyspaceAndMeasure(KeyspaceOperationCallback.java:20)
        at me.prettyprint.cassandra.model.ExecutingKeyspace.doExecute(ExecutingKeyspace.java:85)
        at me.prettyprint.cassandra.model.IndexedSlicesQuery.execute(IndexedSlicesQuery.java:130)
对不起我的新手问题和我的英语不好......谢谢......:D

更新

好的,经过谷歌搜索和谷歌搜索,我发现了一个基于这个Link的解决方案,这个技术是在创建一些列族时创建index_type,像这样(基于该链接):

[default@demo] create column family users with comparator=UTF8Type
... and column_metadata=[{column_name: full_name, validation_class: UTF8Type},
... {column_name: state, validation_class: UTF8Type},
... {column_name: birth_date, validation_class: LongType, index_type: KEYS}];

在创建索引列族之后,你可以在cassandra-cli中查询llike ordinray sql ...我会在hector中尝试..感谢你的注意..:D

1 个答案:

答案 0 :(得分:2)

您需要向要在其上运行WHERE子句的列添加索引。