cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/2] git commit: Fix 2ndary index queries with DESC clustering order
Date Wed, 21 May 2014 09:36:28 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 7abd76e45 -> 94f25ce15


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.1
Commit: 20e058b2bd0ae452966afa7f548bd305e2f742c4
Parents: 786396e
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Wed May 21 11:29:42 2014 +0200
Committer: Sylvain Lebresne <sylvain@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);


Mime
View raw message