You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ja...@apache.org on 2015/09/03 22:39:37 UTC
cassandra git commit: Allow "IS NOT NULL" to be excluded for
non-composite partition keys
Repository: cassandra
Updated Branches:
refs/heads/cassandra-3.0 eb01654b9 -> dc5b268d0
Allow "IS NOT NULL" to be excluded for non-composite partition keys
Patch by carlyeks; reviewed by tjake for (CASSANDRA-10147)
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/dc5b268d
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/dc5b268d
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/dc5b268d
Branch: refs/heads/cassandra-3.0
Commit: dc5b268d084b0ecc21a0a0a5e028cdadb05c7386
Parents: eb01654
Author: Carl Yeksigian <ca...@apache.org>
Authored: Tue Sep 1 12:31:56 2015 -0400
Committer: T Jake Luciani <ja...@apache.org>
Committed: Thu Sep 3 16:31:55 2015 -0400
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../CreateMaterializedViewStatement.java | 7 ++-
.../cassandra/cql3/MaterializedViewTest.java | 49 ++++++++++++++++++++
3 files changed, 56 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/dc5b268d/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index fccaf11..fb33de0 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
3.0.0-beta2
+ * Base table PRIMARY KEY can be assumed to be NOT NULL in MV creation (CASSANDRA-10147)
* Improve batchlog write patch (CASSANDRA-9673)
* Re-apply MaterializedView updates on commitlog replay (CASSANDRA-10164)
* Require AbstractType.isByteOrderComparable declaration in constructor (CASSANDRA-9901)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/dc5b268d/src/java/org/apache/cassandra/cql3/statements/CreateMaterializedViewStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/CreateMaterializedViewStatement.java b/src/java/org/apache/cassandra/cql3/statements/CreateMaterializedViewStatement.java
index 3e1a0bf..dee0577 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateMaterializedViewStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateMaterializedViewStatement.java
@@ -265,7 +265,12 @@ public class CreateMaterializedViewStatement extends SchemaAlteringStatement
{
throw new InvalidRequestException(String.format("Cannot include more than one non-primary key column '%s' in materialized view partition key", identifier));
}
- if (!allowedPKColumns.contains(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
+ boolean isSinglePartitionKey = cfm.getColumnDefinition(identifier).isPartitionKey()
+ && cfm.partitionKeyColumns().size() == 1;
+ if (!allowedPKColumns.remove(identifier) && !isSinglePartitionKey)
{
throw new InvalidRequestException(String.format("Primary key column '%s' is required to be filtered by 'IS NOT NULL'", identifier));
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/dc5b268d/test/unit/org/apache/cassandra/cql3/MaterializedViewTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/MaterializedViewTest.java b/test/unit/org/apache/cassandra/cql3/MaterializedViewTest.java
index 7d08a8b..6442a11 100644
--- a/test/unit/org/apache/cassandra/cql3/MaterializedViewTest.java
+++ b/test/unit/org/apache/cassandra/cql3/MaterializedViewTest.java
@@ -136,6 +136,55 @@ public class MaterializedViewTest extends CQLTester
}
@Test
+ public void testPrimaryKeyIsNotNull() throws Throwable
+ {
+ createTable("CREATE TABLE %s (" +
+ "k int, " +
+ "asciival ascii, " +
+ "bigintval bigint, " +
+ "PRIMARY KEY((k, asciival)))");
+
+ // Must include "IS NOT NULL" for primary keys
+ try
+ {
+ createView("mv_test", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s");
+ Assert.fail("Should fail if no primary key is filtered as NOT NULL");
+ }
+ catch (Exception e)
+ {
+ }
+
+ // Must include both when the partition key is composite
+ try
+ {
+ createView("mv_test", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE bigintval IS NOT NULL AND asciival IS NOT NULL PRIMARY KEY (bigintval, k, asciival)");
+ Assert.fail("Should fail if compound primary is not completely filtered as NOT NULL");
+ }
+ catch (Exception e)
+ {
+ }
+
+ dropTable("DROP TABLE %s");
+
+ createTable("CREATE TABLE %s (" +
+ "k int, " +
+ "asciival ascii, " +
+ "bigintval bigint, " +
+ "PRIMARY KEY(k, asciival))");
+ try
+ {
+ createView("mv_test", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s");
+ Assert.fail("Should fail if no primary key is filtered as NOT NULL");
+ }
+ catch (Exception e)
+ {
+ }
+
+ // Can omit "k IS NOT NULL" because we have a sinlge partition key
+ createView("mv_test", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE bigintval IS NOT NULL AND asciival IS NOT NULL PRIMARY KEY (bigintval, k, asciival)");
+ }
+
+ @Test
public void testAccessAndSchema() throws Throwable
{
createTable("CREATE TABLE %s (" +