开发者

How to Search Value in Cassandra like 'WHERE' in SQL?

Hello fellow developers,i a bit stuck in querying in cassandra,im trying to google how to add restriction/conditioning in cassandra and got some example,so i create method like this,i using Hector for client 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;

is the method right? is the 'WHERE' like method is indexedSlicesQuery.addEqualsExpression(columnName, value);?

any body can help me? i still try this out,because i got some error like this :

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.开发者_如何学Pythonjava: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)

iam sorry for my newbie question and my bad english..thanks..:D

UPDATE

OK,After Googling and googling,i found a solutions based on this Link, this technic is to create index_type when create some column family,like this (based on that link):

[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}];

after create that indexed column family,you can query llike ordinray sql in cassandra-cli..and i would try that in hector..thanks for your attention..:D


You need to add an index to the column that you want to run the WHERE clause on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜