I wanna run a query like this on a table:
SELECT count(*) FROM mytable WHERE token(_id) >= -9220405531215751472 AND token(_id) < -9215701564955960000 AND state=true ALLOW FILTERING;
I read range of tokens by metadata.getTokenMap()
and then tokenMap.getTokenRanges()
. But it gives me start and end token as Token Object (e.g. Murmur3Token(9187337865070158013)
)! How I can convert it to long or String to use in query:
CqlSession session = builder.build();
Metadata metadata = session.getMetadata();
if (metadata.getTokenMap().isPresent()) {
TokenMap tokenMap = metadata.getTokenMap().get();
for(TokenRange range : tokenMap.getTokenRanges()) {
System.out.println(range.getStart()); // output Murmur3Token(9187337865070158013)
}
}
I found how I can convert it! It must be converted to Murmur3Token
explicitly and call getValue
method.
long start,end;
String sql;
for(TokenRange range : tokenMap.getTokenRanges()) {
start = ((Murmur3Token) range.getStart()).getValue();
end = ((Murmur3Token) range.getEnd()).getValue();
sql = "SELECT count(*) FROM mytable WHERE token(_id) >= "+start+" AND token(_id) < "+end+" AND state=true ALLOW FILTERING;";
System.out.println(i +":" + sql);
}