I have stored the data in the ComparatorType.BYTESTYPE in the Cassandra database. Now I want to retrieve data in the stored order.
I used the following code in Hector to get data, but the query results seems not sorted.
Keyspace keyspace = HFactory.createKeyspace("ClusterName", cluster);
Map<String, String> resultMap = new HashMap<String, String>();
SliceQuery<String, String, String> query = HFactory.createSliceQuery(keyspace, StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
query.setColumnFamily("ColumnFamilyName").setKey("RowKey")
.setRange("", "", false, Integer.MAX_VALUE);
QueryResult<ColumnSlice<String, String>> result = query.execute();
for (HColumn<String, String> column : result.get().getColumns()) {
resultMap.put(column.getName(), column.getValue());
}
what am I missing?? Do I have to use RangeSliceQueries and OrderedRows??
Thanks in advance.
It all depends on the comparator you have set for the column names. If it is BytesType (cassandra's default) as well, then it won't be the order you expect.
if you want alphabetical order you should define your table with something like that in the cassandra-cli:
create column family ColumnFamilyName with comparator = UTF8Type;
or you are still in time maybe to do
update column family ColumnFamilyName with comparator = UTF8Type;