Fix CQL3 composite partition key error

patch by slebresne; reviewed by jbellis for CASSANDRA-5240


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/03b4c279
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/03b4c279
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/03b4c279

Branch: refs/heads/trunk
Commit: 03b4c2794c4c0f5e11ec9a24b52b523d8746fbb5
Parents: 686f516
Author: Sylvain Lebresne <sylv...@datastax.com>
Authored: Wed Feb 20 17:49:41 2013 +0100
Committer: Sylvain Lebresne <sylv...@datastax.com>
Committed: Wed Feb 20 17:49:41 2013 +0100

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../cassandra/cql3/statements/SelectStatement.java |    9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/03b4c279/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 0489968..f684747 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -28,6 +28,7 @@
  * cli: Add JMX authentication support (CASSANDRA-5080)
  * Fix forceFlush behavior (CASSANDRA-5241)
  * cqlsh: Add username autocompletion (CASSANDRA-5231)
+ * Fix CQL3 composite partition key error (CASSANDRA-5240)
 
 
 1.2.1

http://git-wip-us.apache.org/repos/asf/cassandra/blob/03b4c279/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 4491394..4badb8e 100644
--- a/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/SelectStatement.java
@@ -357,7 +357,7 @@ public class SelectStatement implements CQLStatement
 
     private ByteBuffer getKeyBound(Bound b, List<ByteBuffer> variables) throws 
InvalidRequestException
     {
-        return buildBound(b, cfDef.keys.values(), keyRestrictions, isReversed, 
cfDef.getKeyNameBuilder(), variables);
+        return buildBound(b, cfDef.keys.values(), keyRestrictions, false, 
cfDef.getKeyNameBuilder(), variables);
     }
 
     private Token getTokenBound(Bound b, List<ByteBuffer> variables, 
IPartitioner<?> p) throws InvalidRequestException
@@ -521,7 +521,12 @@ public class SelectStatement implements CQLStatement
             }
         }
         // Means no relation at all or everything was an equal
-        return (bound == Bound.END) ? builder.buildAsEndOfRange() : 
builder.build();
+        // Note: if the builder is "full", there is no need to use the 
end-of-component bit. For columns selection,
+        // it would be harmless to do it. However, we use this method got the 
partition key too. And when a query
+        // with 2ndary index is done, and with the the partition provided with 
an EQ, we'll end up here, and in that
+        // case using the eoc would be bad, since for the random partitioner 
we have no guarantee that
+        // builder.buildAsEndOfRange() will sort after builder.build() (see 
#5240).
+        return (bound == Bound.END && builder.remainingCount() > 0) ? 
builder.buildAsEndOfRange() : builder.build();
     }
 
     private ByteBuffer getRequestedBound(Bound b, List<ByteBuffer> variables) 
throws InvalidRequestException

Reply via email to