Add test for multiple non primary-keys in MV Patch by Carl Yeksigian; reviewed by Sylvain Lebresne for CASSANDRA-12044
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/a9a6e5fb Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/a9a6e5fb Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/a9a6e5fb Branch: refs/heads/trunk Commit: a9a6e5fb1656fa5918b6af644ab840c42fd60558 Parents: d95d8a9 Author: Carl Yeksigian <c...@apache.org> Authored: Tue Jul 5 11:44:18 2016 -0400 Committer: Carl Yeksigian <c...@apache.org> Committed: Tue Jul 5 11:44:18 2016 -0400 ---------------------------------------------------------------------- .../cql3/statements/CreateViewStatement.java | 2 +- .../org/apache/cassandra/cql3/ViewTest.java | 31 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/a9a6e5fb/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java b/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java index 6446602..13e528c 100644 --- a/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java @@ -316,7 +316,7 @@ public class CreateViewStatement extends SchemaAlteringStatement boolean isPk = basePK.contains(identifier); if (!isPk && hasNonPKColumn) - throw new InvalidRequestException(String.format("Cannot include more than one non-primary key column '%s' in materialized view partition key", identifier)); + throw new InvalidRequestException(String.format("Cannot include more than one non-primary key column '%s' in materialized view primary key", identifier)); // We don't need to include the "IS NOT NULL" filter on a non-composite partition key // because we will never allow a single partition key to be NULL http://git-wip-us.apache.org/repos/asf/cassandra/blob/a9a6e5fb/test/unit/org/apache/cassandra/cql3/ViewTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/ViewTest.java b/test/unit/org/apache/cassandra/cql3/ViewTest.java index 4a1dc07..85f01a6 100644 --- a/test/unit/org/apache/cassandra/cql3/ViewTest.java +++ b/test/unit/org/apache/cassandra/cql3/ViewTest.java @@ -1077,4 +1077,35 @@ public class ViewTest extends CQLTester mvRows = executeNet(protocolVersion, "SELECT a, b FROM mvmap WHERE b = ?", 0); assertRowsNet(protocolVersion, mvRows, row(0, 0)); } + + @Test + public void testMultipleNonPrimaryKeysInView() throws Throwable + { + createTable("CREATE TABLE %s (" + + "a int," + + "b int," + + "c int," + + "d int," + + "e int," + + "PRIMARY KEY ((a, b), c))"); + + try + { + createView("mv_de", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE a IS NOT NULL AND b IS NOT NULL AND c IS NOT NULL AND d IS NOT NULL AND e IS NOT NULL PRIMARY KEY ((d, a), b, e, c)"); + Assert.fail("Should have rejected a query including multiple non-primary key base columns"); + } + catch (Exception e) + { + } + + try + { + createView("mv_de", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE a IS NOT NULL AND b IS NOT NULL AND c IS NOT NULL AND d IS NOT NULL AND e IS NOT NULL PRIMARY KEY ((a, b), c, d, e)"); + Assert.fail("Should have rejected a query including multiple non-primary key base columns"); + } + catch (Exception e) + { + } + + } }