Fix 2ndary indexes on primary key columns to don't create expiring entries (CASSANDRA-13412)
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/263740da Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/263740da Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/263740da Branch: refs/heads/trunk Commit: 263740daa4c8162a157aa6fbb97793f158d142d1 Parents: 415d06b Author: adelapena <a.penya.gar...@gmail.com> Authored: Fri Apr 21 09:33:16 2017 +0100 Committer: adelapena <a.penya.gar...@gmail.com> Committed: Wed May 10 11:55:45 2017 +0100 ---------------------------------------------------------------------- .../validation/entities/SecondaryIndexTest.java | 42 ++++++++++++++++++++ 1 file changed, 42 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/263740da/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 8376652..1a1b881 100644 --- a/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java +++ b/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java @@ -1231,4 +1231,46 @@ public class SecondaryIndexTest extends CQLTester return super.getInvalidateTask(); } } + + @Test + public void testIndexOnPartitionKeyInsertExpiringColumn() throws Throwable + { + createTable("CREATE TABLE %s (k1 int, k2 int, a int, b int, PRIMARY KEY ((k1, k2)))"); + createIndex("CREATE INDEX on %s(k1)"); + execute("INSERT INTO %s (k1, k2, a, b) VALUES (1, 2, 3, 4)"); + assertRows(execute("SELECT * FROM %s WHERE k1 = 1"), row(1, 2, 3, 4)); + execute("UPDATE %s USING TTL 1 SET b = 10 WHERE k1 = 1 AND k2 = 2"); + Thread.sleep(1000); + assertRows(execute("SELECT * FROM %s WHERE k1 = 1"), row(1, 2, 3, null)); + } + + @Test + public void testIndexOnClusteringKeyInsertExpiringColumn() throws Throwable + { + createTable("CREATE TABLE %s (pk int, ck int, a int, b int, PRIMARY KEY (pk, ck))"); + createIndex("CREATE INDEX on %s(ck)"); + execute("INSERT INTO %s (pk, ck, a, b) VALUES (1, 2, 3, 4)"); + assertRows(execute("SELECT * FROM %s WHERE ck = 2"), row(1, 2, 3, 4)); + execute("UPDATE %s USING TTL 1 SET b = 10 WHERE pk = 1 AND ck = 2"); + Thread.sleep(1000); + assertRows(execute("SELECT * FROM %s WHERE ck = 2"), row(1, 2, 3, null)); + } + + @Test + public void testIndexOnRegularColumnInsertExpiringColumn() throws Throwable + { + createTable("CREATE TABLE %s (pk int, ck int, a int, b int, PRIMARY KEY (pk, ck))"); + createIndex("CREATE INDEX on %s(a)"); + execute("INSERT INTO %s (pk, ck, a, b) VALUES (1, 2, 3, 4)"); + assertRows(execute("SELECT * FROM %s WHERE a = 3"), row(1, 2, 3, 4)); + + execute("UPDATE %s USING TTL 1 SET b = 10 WHERE pk = 1 AND ck = 2"); + Thread.sleep(1000); + assertRows(execute("SELECT * FROM %s WHERE a = 3"), row(1, 2, 3, null)); + + execute("UPDATE %s USING TTL 1 SET a = 5 WHERE pk = 1 AND ck = 2"); + Thread.sleep(1000); + assertEmpty(execute("SELECT * FROM %s WHERE a = 3")); + assertEmpty(execute("SELECT * FROM %s WHERE a = 5")); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org