cql3 - Cassandra CQL query check multiple values -


how can check if non-primary key field's value either 'a' or 'b' cassandra cql query? (i'm using cassandra 2.0.1)

here's table definition:

create table my_table (   my_field text,   my_field2 text,   primary key (my_field) ); 

i tried:

1> select * my_table my_field2 in ('a', 'b');  2> select * my_table my_field2 = 'a' or my_field = 'b' ; 

the first 1 failed messeage:

bad request: in predicates on non-primary-key columns (my_field2) not yet supported 

the second 1 failed because cassandra cql doesn't support or keyword

i couldn't simple query working (with pretty straight forward way). i'm pretty frustrated dealing cql queries in general. because cassandra not mature enough , has poor support queries, or me must change way of thinking?

this intentional functionality of cassandra. cannot query using clause on columns not

  • the partition key
  • part of composite key

this because data partitioned around ring of cassandra nodes. want avoid having ask entire ring return answer query. ideally want able retrieve data single node in ring

generally in cassandra want structure table match queries opposed relational normalization. have few options deal this.

1) write data multiple tables support various queries. in case may want create second table as

create table my_table (   my_field2 text,   my_field text,   primary key (my_field2) ); 

then first query return correctly

2) create table composite key as

create table my_table (   my_field text,   my_field2 text,   primary key (my_field, my_field2) ); 

with method, if not specify query value my_field need append query qualifier tell cassandra want query entire ring

select * my_table my_field2 in ('a', 'b') allow filtering; 

-edit-

you cannot use secondary index search multiple values. per cql documentation

http://www.datastax.com/documentation/cql/3.0/webhelp/cql/ddl/ddl_primary_index_c.html

"an index data structure allows fast, efficient lookup of data matching given condition."

so, must give 1 , 1 value.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -