Search code examples
javacassandradoublehector

Retrieve (negative) double values from Cassandra using Hector gives wrong results


I want to store double values (as column names) using Hector. As far as I understand it, I have to use the LONGTYPE comparator in conjunction with a DoubleSerializer. I have created a columnFamily with ComparatorType.LONGTYPE as comparator and ComparatorType.UTF8TYPE as validator. I insert data into my column family like this:

Mutator<String> m = HFactory.createMutator(_keyspace, _ss);
m.addInsertion(rowKey, cf, HFactory.createColumn(colKey, "", _ds, _ss));

where rowKey is a String, colKey is a double, _ds a DoubleSerializer and _ss a StringSerializer. Everything seems to work for positive double values. However, when I want to do range queries with negative start and/or finish parameters, things get odd. This is the code I use to query:

SliceQuery<String, Double, String> q = 
          HFactory.createSliceQuery(ks, _ss, _ds, _ss);
q.setRange(START, FINISH., false, 500);

When START and FINISH are positive, everything is ok.

When START is negative and FINISH positive, it will return the correct positive values, but only those negative values that are actually smaller then START.

When both are negative and START is smaller (as it should be !?) then FINISH, it will throw an

InvalidRequestException(why:range finish must come after start in the order of traversal).

When both are negative, but START is bigger then FINISH (i.e. less negative), it will return the correct results, but in the wrong order (the least negative, i.e. biggest, first).

Can anyone comment on that? Am I doing something wrong or is there maybe a bug in hector somewhere?

Edit: Unfortunately, the DoubleType has been removed in a previous version of hector. I forgot to mention that the version Im using is 1.1-0.


Solution

  • Since there seemed to be no way to "solve" this issue, I have implemented Double and Float format for hector. It has been pulled into the masterbranch and is therefore available in current snapshot . I assume it will make its way into the next release as well.