FluentCassandra selecting timestamp range with CQL

425 Views Asked by At

I have a method in my DAL that selects objects with CQL query. I'm trying to pass time interval as follows:

//FilterStartTime, FilterEndTime are of type DateTime, stored in config
// converting DateTime to unix timestamp
var start = (FilterStartTime - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds;
var end = (FilterEndTime - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds;
// UploadedOn is of type timestamp
var selectQuery2 = "SELECT * FROM MyColumnFamily WHERE DocumentKey=" + key
                            + " AND UploadedOn>=" + start
                            + " AND UploadedOn<=" + end;
//"SELECT * FROM MyColumnFamily WHERE DocumentKey=000001 AND UploadedOn>=1341093600 AND UploadedOn<=1343599200"

Database contains record that is in specified range. Above query returns 0 elements though. CQL usage is not a requirement, so i might have been used API, but there is no Fetch method anymore (http://stackoverflow.com/questions/5325035/fluentcassandra-range-selection-problem), and i still want to know what's wrong with my query.

1

There are 1 best solutions below

0
On BEST ANSWER

Changed seconds to milliseconds in conversion, recreated database and everything worked.

var start = (FilterStartTime - new DateTime(1970, 1, 1).ToLocalTime()).TotalMilliseconds;
var end = (FilterEndTime - new DateTime(1970, 1, 1).ToLocalTime()).TotalMilliseconds;

Still interested how to do same request in API (use SlicePredicateQuery?).