Repository: cassandra
Updated Branches:
  refs/heads/trunk dfda97cbf -> e2df76e02


Fix 2i lookup on collection cell names w/ some clustering columns

Patch by Tyler Hobbs; reviewed by Aleksey Yeschenko for CASSANDRA-8073


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

Branch: refs/heads/trunk
Commit: f54cd98d26b3fcc1dc15ef7b5645b5cc5f69d416
Parents: f16507d
Author: Tyler Hobbs <tylerho...@apache.org>
Authored: Wed Oct 15 12:10:39 2014 -0500
Committer: Tyler Hobbs <tylerho...@apache.org>
Committed: Wed Oct 15 12:10:39 2014 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 ++
 .../cassandra/db/filter/ExtendedFilter.java     | 26 +++++++++++++++++---
 .../CompositesIndexOnCollectionKey.java         |  2 +-
 .../cassandra/cql3/ContainsRelationTest.java    | 25 +++++++++++++++++++
 4 files changed, 50 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f54cd98d/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 0ae7af9..4da1e56 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
 2.1.1
+ * Fix exception when querying secondary index on set items or map keys
+   when some clustering columns are specified (CASSANDRA-8073)
  * Send proper error response when there is an error during native
    protocol message decode (CASSANDRA-8118)
  * Gossip should ignore generation numbers too far in the future 
(CASSANDRA-8113)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f54cd98d/src/java/org/apache/cassandra/db/filter/ExtendedFilter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/filter/ExtendedFilter.java 
b/src/java/org/apache/cassandra/db/filter/ExtendedFilter.java
index 4f27a51..e945d2b 100644
--- a/src/java/org/apache/cassandra/db/filter/ExtendedFilter.java
+++ b/src/java/org/apache/cassandra/db/filter/ExtendedFilter.java
@@ -20,10 +20,7 @@ package org.apache.cassandra.db.filter;
 import java.nio.ByteBuffer;
 import java.util.*;
 
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterators;
-import org.apache.cassandra.db.marshal.CollectionType;
-import org.apache.cassandra.utils.ByteBufferUtil;
+import com.google.common.base.Objects;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -33,6 +30,7 @@ import org.apache.cassandra.db.*;
 import org.apache.cassandra.db.composites.CellName;
 import org.apache.cassandra.db.composites.Composite;
 import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.cassandra.db.marshal.CollectionType;
 import org.apache.cassandra.db.marshal.CompositeType;
 
 /**
@@ -151,6 +149,17 @@ public abstract class ExtendedFilter
         }
     }
 
+    public String toString()
+    {
+        return Objects.toStringHelper(this)
+                      .add("dataRange", dataRange)
+                      .add("maxResults", maxResults)
+                      .add("currentLimit", currentLimit)
+                      .add("timestamp", timestamp)
+                      .add("countCQL3Rows", countCQL3Rows)
+                      .toString();
+    }
+
     public static class WithClauses extends ExtendedFilter
     {
         private final List<IndexExpression> clause;
@@ -395,6 +404,15 @@ public abstract class ExtendedFilter
             }
             throw new AssertionError();
         }
+
+        public String toString()
+        {
+            return Objects.toStringHelper(this)
+                          .add("dataRange", dataRange)
+                          .add("timestamp", timestamp)
+                          .add("clause", clause)
+                          .toString();
+        }
     }
 
     private static class EmptyClauseFilter extends ExtendedFilter

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f54cd98d/src/java/org/apache/cassandra/db/index/composites/CompositesIndexOnCollectionKey.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/db/index/composites/CompositesIndexOnCollectionKey.java
 
b/src/java/org/apache/cassandra/db/index/composites/CompositesIndexOnCollectionKey.java
index 2d25f8e..c252546 100644
--- 
a/src/java/org/apache/cassandra/db/index/composites/CompositesIndexOnCollectionKey.java
+++ 
b/src/java/org/apache/cassandra/db/index/composites/CompositesIndexOnCollectionKey.java
@@ -74,7 +74,7 @@ public class CompositesIndexOnCollectionKey extends 
CompositesIndex
         int count = 1 + baseCfs.metadata.clusteringColumns().size();
         CBuilder builder = getIndexComparator().builder();
         builder.add(rowKey);
-        for (int i = 0; i < count - 1; i++)
+        for (int i = 0; i < Math.min(cellName.size(), count - 1); i++)
             builder.add(cellName.get(i));
         return builder.build();
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f54cd98d/test/unit/org/apache/cassandra/cql3/ContainsRelationTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/ContainsRelationTest.java 
b/test/unit/org/apache/cassandra/cql3/ContainsRelationTest.java
index 525059d..605f3ed 100644
--- a/test/unit/org/apache/cassandra/cql3/ContainsRelationTest.java
+++ b/test/unit/org/apache/cassandra/cql3/ContainsRelationTest.java
@@ -157,4 +157,29 @@ public class ContainsRelationTest extends CQLTester
 
         assertEmpty(execute("SELECT * FROM %s WHERE k2 = ? AND v CONTAINS ? 
ALLOW FILTERING", 1, 7));
     }
+
+    // See CASSANDRA-8073
+    @Test
+    public void testIndexLookupWithClusteringPrefix() throws Throwable
+    {
+        createTable("CREATE TABLE %s (a int, b int, c int, d set<int>, PRIMARY 
KEY (a, b, c))");
+        createIndex("CREATE INDEX ON %s(d)");
+        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 0, 
set(1, 2, 3));
+        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 0, 1, 
set(3, 4, 5));
+        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 0, 
set(1, 2, 3));
+        execute("INSERT INTO %s (a, b, c, d) VALUES (?, ?, ?, ?)", 0, 1, 1, 
set(3, 4, 5));
+
+        assertRows(execute("SELECT * FROM %s WHERE a=? AND b=? AND d CONTAINS 
?", 0, 1, 3),
+            row(0, 1, 0, set(1, 2, 3)),
+            row(0, 1, 1, set(3, 4, 5))
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a=? AND b=? AND d CONTAINS 
?", 0, 1, 2),
+            row(0, 1, 0, set(1, 2, 3))
+        );
+
+        assertRows(execute("SELECT * FROM %s WHERE a=? AND b=? AND d CONTAINS 
?", 0, 1, 5),
+            row(0, 1, 1, set(3, 4, 5))
+        );
+    }
 }

Reply via email to