cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ble...@apache.org
Subject [2/6] cassandra git commit: Fix secondary index queries on COMPACT tables
Date Mon, 26 Jun 2017 11:32:45 GMT
Fix secondary index queries on COMPACT tables

patch by Benjamin Lerer; reviewed by Andrés de la Peña for CASSANDRA-13627


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

Branch: refs/heads/cassandra-3.11
Commit: 57c590f6f71907dda6f3d88a16883b5dbcf259ee
Parents: 96bd3d5
Author: Benjamin Lerer <b.lerer@gmail.com>
Authored: Mon Jun 26 13:14:46 2017 +0200
Committer: Benjamin Lerer <b.lerer@gmail.com>
Committed: Mon Jun 26 13:14:46 2017 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/cql3/selection/Selection.java     |  2 +-
 .../validation/entities/SecondaryIndexTest.java | 43 ++++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/57c590f6/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 00e87bf..d90d220 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.15
+ * Fix secondary index queries on COMPACT tables (CASSANDRA-13627)
  * Nodetool listsnapshots output is missing a newline, if there are no snapshots (CASSANDRA-13568)
 
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/57c590f6/src/java/org/apache/cassandra/cql3/selection/Selection.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/selection/Selection.java b/src/java/org/apache/cassandra/cql3/selection/Selection.java
index 8a27314..0ecf063 100644
--- a/src/java/org/apache/cassandra/cql3/selection/Selection.java
+++ b/src/java/org/apache/cassandra/cql3/selection/Selection.java
@@ -81,7 +81,7 @@ public abstract class Selection
      */
     public boolean containsStaticColumns()
     {
-        if (!cfm.hasStaticColumns())
+        if (cfm.isStaticCompactTable() || !cfm.hasStaticColumns())
             return false;
 
         if (isWildcard())

http://git-wip-us.apache.org/repos/asf/cassandra/blob/57c590f6/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
b/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
index 1a1b881..0f6cba7 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
@@ -1273,4 +1273,47 @@ public class SecondaryIndexTest extends CQLTester
         assertEmpty(execute("SELECT * FROM %s WHERE a = 3"));
         assertEmpty(execute("SELECT * FROM %s WHERE a = 5"));
     }
+
+    @Test
+    public void testIndicesOnCompactTable() throws Throwable
+    {
+        assertInvalidMessage("COMPACT STORAGE with composite PRIMARY KEY allows no more than
one column not part of the PRIMARY KEY (got: v1, v2)",
+                             "CREATE TABLE test (pk int, c int, v1 int, v2 int, PRIMARY KEY(pk,
c)) WITH COMPACT STORAGE");
+
+        createTable("CREATE TABLE %s (pk int, c int, v int, PRIMARY KEY(pk, c)) WITH COMPACT
STORAGE");
+        assertInvalidMessage("Secondary indexes are not supported on COMPACT STORAGE tables
that have clustering columns",
+                             "CREATE INDEX ON %s(v)");
+
+        createTable("CREATE TABLE %s (pk int PRIMARY KEY, v int) WITH COMPACT STORAGE");
+        createIndex("CREATE INDEX ON %s(v)");
+
+        execute("INSERT INTO %s (pk, v) VALUES (?, ?)", 1, 1);
+        execute("INSERT INTO %s (pk, v) VALUES (?, ?)", 2, 1);
+        execute("INSERT INTO %s (pk, v) VALUES (?, ?)", 3, 3);
+
+        assertRows(execute("SELECT pk, v FROM %s WHERE v = 1"),
+                   row(1, 1),
+                   row(2, 1));
+
+        assertRows(execute("SELECT pk, v FROM %s WHERE v = 3"),
+                   row(3, 3));
+
+        assertEmpty(execute("SELECT pk, v FROM %s WHERE v = 5"));
+
+        createTable("CREATE TABLE %s (pk int PRIMARY KEY, v1 int, v2 int) WITH COMPACT STORAGE");
+        createIndex("CREATE INDEX ON %s(v1)");
+
+        execute("INSERT INTO %s (pk, v1, v2) VALUES (?, ?, ?)", 1, 1, 1);
+        execute("INSERT INTO %s (pk, v1, v2) VALUES (?, ?, ?)", 2, 1, 2);
+        execute("INSERT INTO %s (pk, v1, v2) VALUES (?, ?, ?)", 3, 3, 3);
+
+        assertRows(execute("SELECT pk, v2 FROM %s WHERE v1 = 1"),
+                   row(1, 1),
+                   row(2, 2));
+
+        assertRows(execute("SELECT pk, v2 FROM %s WHERE v1 = 3"),
+                   row(3, 3));
+
+        assertEmpty(execute("SELECT pk, v2 FROM %s WHERE v1 = 5"));
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Mime
View raw message