and clause in cql cassandra -


i have created table schema

create table iplocation (     "idiplocation" uuid,     "fromip" bigint,     "toip" bigint,     "idcity" uuid,     "idcountry" uuid,     "idprovince" uuid,     "isactive" boolean,     primary key ("idiplocation", "fromip", "toip") )  

and inserted records in it! want fetch record this

select * iplocation "toip" <= 3065377522 , "fromip" >= 3065377522 allow filtering; 

but giving me error of

a column of clustering key can restricted if preceding 1 restricted equal relation. need restrict fromip before restrict toip. 

but if want just

select * iplocation "toip" <= 3065377522 allow filtering; 

it still says

 column of clustering key can restricted if preceding    1 restricted equal relation. need restrict    fromip before restrict toip. 

i cant figureout whats problem?

your misusing partition key concept. in case partition key idiplocation cassandra use key know in partition data write or read. in select statement have provide partition key. can filter data within specified partition provide fromip, toip.

you have 4 solutions : 1) chose better partition key : can example use followinf partition key clause : primary key ("toip"). in case guess solution won't work because want query data idiplocation too.

2) denormalize : add new table same data structure différent partition key : create table backup_advertyze.iplocation ( "idiplocation" uuid, "fromip" bigint, "toip" bigint, "idcity" uuid, "idcountry" uuid, "idprovince" uuid, "isactive" boolean, primary key ("idiplocation", "fromip", "toip") ); create table backup_advertyze.iplocationbytoip ( "idiplocation" uuid, "fromip" bigint, "toip" bigint, "idcity" uuid, "idcountry" uuid, "idprovince" uuid, "isactive" boolean, primary key ("toip", "fromip") );

with structure can run query select * iplocationbytoip "toip" <= 3065377522 , "fromip" >= 3065377522. solution have maintain doubles in 2 tables

3) use materialized view : same concept 2) have maintain data in 1 table instead of 2 : `create table backup_advertyze.iplocation ( "idiplocation" uuid, "fromip" bigint, "toip" bigint, "idcity" uuid, "idcountry" uuid, "idprovince" uuid, "isactive" boolean, primary key ("idiplocation", "fromip", "toip") );

create materialized view backup_advertyze.iplocationbytoip select * backup_advertyze.iplocation idiplocation not null , fromip not null , toip not null primary key (toip, fromip, idiplocation);`

4) simple solution don't recommend due query performences issues use secondary indexes :

create index iplocationfromindex on backup_advertyze.iplocation(fromip);

you can run query select * iplocation "toip" <= 3065377522 , "fromip" >= 3065377522 allow filtering;.

hope can you.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -