You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2014/05/21 11:31:31 UTC
git commit: Fix 2ndary index queries with DESC clustering order
Repository: cassandra
Updated Branches:
refs/heads/cassandra-2.0 786396eaf -> 20e058b2b
Fix 2ndary index queries with DESC clustering order
patch by slebresne; reviewed by thobbs for CASSANDRA-6950
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/20e058b2
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/20e058b2
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/20e058b2
Branch: refs/heads/cassandra-2.0
Commit: 20e058b2bd0ae452966afa7f548bd305e2f742c4
Parents: 786396e
Author: Sylvain Lebresne <sy...@datastax.com>
Authored: Wed May 21 11:29:42 2014 +0200
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Wed May 21 11:29:42 2014 +0200
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../cql3/statements/SelectStatement.java | 21 +++++++++++++++++++-
2 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/20e058b2/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index df3741e..bd0031e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -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)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/20e058b2/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
index 2468eb9..6b4309f 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -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);