You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by mi...@apache.org on 2014/06/12 20:11:45 UTC
[2/3] git commit: Handle SliceQueryFilter with empty bounds in
CompositesSearcher
Handle SliceQueryFilter with empty bounds in CompositesSearcher
patch by Mikhail Stepura; reviewed by Sylvain Lebresne for CASSANDRA-7372
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/68c92652
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/68c92652
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/68c92652
Branch: refs/heads/trunk
Commit: 68c92652aec5934c5050520f060c07a91057c3c0
Parents: fa601bd
Author: Mikhail Stepura <mi...@apache.org>
Authored: Mon Jun 9 11:40:33 2014 -0700
Committer: Mikhail Stepura <mi...@apache.org>
Committed: Thu Jun 12 11:09:38 2014 -0700
----------------------------------------------------------------------
CHANGES.txt | 2 +
.../db/index/composites/CompositesSearcher.java | 3 +-
.../cassandra/cql3/ContainsRelationTest.java | 63 ++++++++++++++++++++
3 files changed, 67 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/68c92652/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 7d277db..680c2f8 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,6 @@
2.1.0
+ * Fix exception when querying a composite-keyed table with a collection index
+ (CASSANDRA-7372)
* Use node's host id in place of counter ids (CASSANDRA-7366)
* Explicitly use Long.MAX_VALUE timestamp for counter deletions
(CASSANDRA-7346)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/68c92652/src/java/org/apache/cassandra/db/index/composites/CompositesSearcher.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/index/composites/CompositesSearcher.java b/src/java/org/apache/cassandra/db/index/composites/CompositesSearcher.java
index dbce024..5c1abc9 100644
--- a/src/java/org/apache/cassandra/db/index/composites/CompositesSearcher.java
+++ b/src/java/org/apache/cassandra/db/index/composites/CompositesSearcher.java
@@ -79,7 +79,8 @@ public class CompositesSearcher extends SecondaryIndexSearcher
if (columnFilter instanceof SliceQueryFilter)
{
SliceQueryFilter sqf = (SliceQueryFilter)columnFilter;
- prefix = index.makeIndexColumnPrefix(key, isStart ? sqf.start() : sqf.finish());
+ Composite columnName = isStart ? sqf.start() : sqf.finish();
+ prefix = columnName.isEmpty() ? index.getIndexComparator().make(key) : index.makeIndexColumnPrefix(key, columnName);
}
else
{
http://git-wip-us.apache.org/repos/asf/cassandra/blob/68c92652/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
new file mode 100644
index 0000000..7b9ef91
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/ContainsRelationTest.java
@@ -0,0 +1,63 @@
+package org.apache.cassandra.cql3;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Sets.newHashSet;
+
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class ContainsRelationTest extends CQLTester
+{
+ @Test
+ public void testSetContains() throws Throwable
+ {
+ createTable("CREATE TABLE %s (account text, id int, categories set<text>, PRIMARY KEY (account, id));");
+ execute("CREATE INDEX cat_index_set ON %s(categories);");
+ execute("INSERT INTO %s (account, id , categories) VALUES ('test', 5, {'lmn'});");
+
+ assertEmpty(execute("SELECT * FROM %s WHERE account = 'xyz' AND categories CONTAINS 'lmn';"));
+
+ assertRows(execute("SELECT * FROM %s WHERE categories CONTAINS 'lmn';"), row("test", 5, newHashSet("lmn")));
+ assertRows(execute("SELECT * FROM %s WHERE account = 'test' AND categories CONTAINS 'lmn';"), row("test", 5, newHashSet("lmn")));
+ }
+
+ @Test
+ public void testListContains() throws Throwable
+ {
+ createTable("CREATE TABLE %s (account text, id int, categories list<text>, PRIMARY KEY (account, id));");
+ execute("CREATE INDEX cat_index_list ON %s(categories);");
+ execute("INSERT INTO %s (account, id , categories) VALUES ('test', 5, ['lmn']);");
+
+ assertEmpty(execute("SELECT * FROM %s WHERE account = 'xyz' AND categories CONTAINS 'lmn';"));
+
+ assertRows(execute("SELECT * FROM %s WHERE account = 'test' AND categories CONTAINS 'lmn';"), row("test", 5, newArrayList("lmn")));
+ assertRows(execute("SELECT * FROM %s WHERE categories CONTAINS 'lmn';"), row("test", 5, newArrayList("lmn")));
+ }
+
+ @Test
+ public void testMapKeyContains() throws Throwable
+ {
+ createTable("CREATE TABLE %s (account text, id int, categories map<text,text>, PRIMARY KEY (account, id));");
+ execute("CREATE INDEX cat_index_map_key ON %s(keys(categories));");
+ execute("INSERT INTO %s (account, id , categories) VALUES ('test', 5, {'lmn':'foo'});");
+
+ assertEmpty(execute("SELECT * FROM %s WHERE account = 'xyz' AND categories CONTAINS KEY 'lmn';"));
+
+ assertRows(execute("SELECT * FROM %s WHERE account = 'test' AND categories CONTAINS KEY 'lmn';"), row("test", 5, ImmutableMap.of("lmn", "foo")));
+ assertRows(execute("SELECT * FROM %s WHERE categories CONTAINS KEY 'lmn';"), row("test", 5, ImmutableMap.of("lmn", "foo")));
+ }
+
+ @Test
+ public void testMapValueContains() throws Throwable
+ {
+ createTable("CREATE TABLE %s (account text, id int, categories map<text,text>, PRIMARY KEY (account, id));");
+ execute("CREATE INDEX cat_index_map_value ON %s(categories);");
+ execute("INSERT INTO %s (account, id , categories) VALUES ('test', 5, {'lmn':'foo'});");
+
+ assertEmpty(execute("SELECT * FROM %s WHERE account = 'xyz' AND categories CONTAINS 'foo';"));
+
+ assertRows(execute("SELECT * FROM %s WHERE account = 'test' AND categories CONTAINS 'foo';"), row("test", 5, ImmutableMap.of("lmn", "foo")));
+ assertRows(execute("SELECT * FROM %s WHERE categories CONTAINS 'foo';"), row("test", 5, ImmutableMap.of("lmn", "foo")));
+ }
+}