Unfortunately, there is no way to do this easily with just one column family in Kassandra. The problem is that you want cassandra to sort based on two different things: datetime1 and datetime2.
The obvious structure for this would be for your columns to be Composite composite types (TimeUUID, TimeUUID, Integer). In this case, they will be sorted by datetime1, then datetime2, then an integer.
But you will always receive orders based on datetime1, not datetime2 (although if two records have the same datetime1, then they will only order these records based on datetime2).
A possible workaround would be to have two families of columns with duplicate data (or even two rows for each logical row). One line where data is inserted (datetime1: datetime2: integer), and the other where it is inserted (datetime2: datetime1: integer). You can then perform a multi-segment operation on these two lines and combine the data before passing it to the caller:
final MultigetSliceQuery<String, Composite, String> query = HFactory.createMultigetSliceQuery(keyspace, StringSerializer.get(), CompositeSerializer.get(), StringSerializer.get()); query.setColumnFamily("myColumnFamily"); startQuery.setKeys("myRow.arrangedByDateTime1", "myRow.arrangedByDateTime2"); startQuery.setRange(new Composite(startTime), new Composite(endTime), false, Integer.MAX_VALUE); final QueryResult<Rows<String,Composite,String>> queryResult = query.execute(); final Rows<String,Composite,String> rows = queryResult.get();
source share