Fix 2ndary index queries with DESC clustering order

patch by slebresne; reviewed by thobbs for CASSANDRA-6950
This commit is contained in:
Sylvain Lebresne 2014-05-21 11:29:42 +02:00
parent 786396eaf0
commit 20e058b2bd
2 changed files with 21 additions and 1 deletions

View File

@ -46,6 +46,7 @@
* reduce garbage on codec flag deserialization (CASSANDRA-7244)
* Proper null handle for IF with map element access (CASSANDRA-7155)
* Improve compaction visibility (CASSANDRA-7242)
* Fix 2ndary index queries with DESC clustering order (CASSANDRA-6950)
Merged from 1.2:
* Add Cloudstack snitch (CASSANDRA-7147)
* Update system.peers correctly when relocating tokens (CASSANDRA-7126)

View File

@ -927,7 +927,14 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
throw new InvalidRequestException(String.format("Unsupported null value for indexed column %s", name));
if (value.remaining() > 0xFFFF)
throw new InvalidRequestException("Index expression values may not be larger than 64K");
expressions.add(new IndexExpression(name.name.key, slice.getIndexOperator(b), value));
IndexOperator op = slice.getIndexOperator(b);
// If the underlying comparator for name is reversed, we need to reverse the IndexOperator: user operation
// always refer to the "forward" sorting even if the clustering order is reversed, but the 2ndary code does
// use the underlying comparator as is.
if (name.type instanceof ReversedType)
op = reverse(op);
expressions.add(new IndexExpression(name.name.key, op, value));
}
}
}
@ -949,6 +956,18 @@ public class SelectStatement implements CQLStatement, MeasurableForPreparedCache
return expressions;
}
private static IndexOperator reverse(IndexOperator op)
{
switch (op)
{
case LT: return IndexOperator.GT;
case LTE: return IndexOperator.GTE;
case GT: return IndexOperator.LT;
case GTE: return IndexOperator.LTE;
default: return op;
}
}
private ResultSet process(List<Row> rows, List<ByteBuffer> variables, int limit, long now) throws InvalidRequestException
{
Selection.ResultSetBuilder result = selection.resultSetBuilder(now);