Repository: cassandra
Updated Branches:
  refs/heads/cassandra-3.11 4f12c4092 -> 425880ffb
  refs/heads/trunk f40198fc6 -> adf025bd4


Revert CASSANDRA-10368 of support non-pk base column filtering on MV due to 
correctness

Patch by Zhao Yang; Reviewed by Paulo Motta for CASSANDRA-13798


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

Branch: refs/heads/cassandra-3.11
Commit: 425880ffb2e6bd5aeaa509fdbfa553db58b74c43
Parents: 4f12c40
Author: Zhao Yang <[email protected]>
Authored: Fri Aug 25 17:55:22 2017 +0800
Committer: Paulo Motta <[email protected]>
Committed: Thu Aug 31 05:14:05 2017 -0500

----------------------------------------------------------------------
 CHANGES.txt                                          |  1 +
 NEWS.txt                                             |  6 ++++++
 .../cql3/statements/CreateViewStatement.java         | 15 +++++++++++++++
 .../org/apache/cassandra/cql3/ViewFilteringTest.java |  9 +++++++++
 .../org/apache/cassandra/cql3/ViewSchemaTest.java    | 15 +++++++++++++++
 5 files changed, 46 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/425880ff/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index af185cf..e5ccf45 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.11.1
+ * Revert CASSANDRA-10368 of supporting non-pk column filtering due to 
correctness (CASSANDRA-13798)
  * Fix cassandra-stress hang issues when an error during cluster connection 
happens (CASSANDRA-12938)
  * Better bootstrap failure message when blocked by (potential) range movement 
(CASSANDRA-13744)
  * "ignore" option is ignored in sstableloader (CASSANDRA-13721)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/425880ff/NEWS.txt
----------------------------------------------------------------------
diff --git a/NEWS.txt b/NEWS.txt
index 10f631f..8e39667 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -26,6 +26,12 @@ Upgrading
 
 Upgrading
 ---------
+   - Creating Materialized View with filtering on non-primary-key base column
+     (added in CASSANDRA-10368) is disabled, because the liveness of view row
+     is depending on multiple filtered base non-key columns and base non-key
+     column used in view primary-key. This semantic cannot be supported without
+     storage format change, see CASSANDRA-13826. For append-only use case, you
+     may still use this feature with a startup flag: 
"-Dcassandra.mv.allow_filtering_nonkey_columns_unsafe=true"
    - ALTER TABLE (ADD/DROP COLUMN) operations concurrent with a read might
      result into data corruption (see CASSANDRA-13004 for more details).
      Fixing this bug required a messaging protocol version bump. By default,

http://git-wip-us.apache.org/repos/asf/cassandra/blob/425880ff/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 668f791..8a8fc17 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java
@@ -19,6 +19,7 @@
 package org.apache.cassandra.cql3.statements;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
@@ -210,6 +211,20 @@ public class CreateViewStatement extends 
SchemaAlteringStatement
         if (!prepared.boundNames.isEmpty())
             throw new InvalidRequestException("Cannot use query parameters in 
CREATE MATERIALIZED VIEW statements");
 
+        // SEE CASSANDRA-13798, use it if the use case is append-only.
+        final boolean allowFilteringNonKeyColumns = 
Boolean.parseBoolean(System.getProperty("cassandra.mv.allow_filtering_nonkey_columns_unsafe",
+                                                                               
             "false"));
+        if (!restrictions.nonPKRestrictedColumns(false).isEmpty() && 
!allowFilteringNonKeyColumns)
+        {
+            throw new InvalidRequestException(
+                                              String.format("Non-primary key 
columns cannot be restricted in the SELECT statement used"
+                                                      + " for materialized 
view creation (got restrictions on: %s)",
+                                                            
restrictions.nonPKRestrictedColumns(false)
+                                                                        
.stream()
+                                                                        
.map(def -> def.name.toString())
+                                                                        
.collect(Collectors.joining(", "))));
+        }
+
         String whereClauseText = 
View.relationsToWhereClause(whereClause.relations);
 
         Set<ColumnIdentifier> basePrimaryKeyCols = new HashSet<>();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/425880ff/test/unit/org/apache/cassandra/cql3/ViewFilteringTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/ViewFilteringTest.java 
b/test/unit/org/apache/cassandra/cql3/ViewFilteringTest.java
index cc8bfe9..87b19ad 100644
--- a/test/unit/org/apache/cassandra/cql3/ViewFilteringTest.java
+++ b/test/unit/org/apache/cassandra/cql3/ViewFilteringTest.java
@@ -21,6 +21,7 @@ package org.apache.cassandra.cql3;
 import java.util.*;
 
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -48,7 +49,15 @@ public class ViewFilteringTest extends CQLTester
     public static void startup()
     {
         requireNetwork();
+        
System.setProperty("cassandra.mv.allow_filtering_nonkey_columns_unsafe", 
"true");
     }
+
+    @AfterClass
+    public static void TearDown()
+    {
+        
System.setProperty("cassandra.mv.allow_filtering_nonkey_columns_unsafe", 
"false");
+    }
+
     @Before
     public void begin()
     {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/425880ff/test/unit/org/apache/cassandra/cql3/ViewSchemaTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/ViewSchemaTest.java 
b/test/unit/org/apache/cassandra/cql3/ViewSchemaTest.java
index 86e00dc..c83d96d 100644
--- a/test/unit/org/apache/cassandra/cql3/ViewSchemaTest.java
+++ b/test/unit/org/apache/cassandra/cql3/ViewSchemaTest.java
@@ -684,4 +684,19 @@ public class ViewSchemaTest extends CQLTester
             Assert.assertEquals("Cannot use DROP TABLE on Materialized View", 
e.getMessage());
         }
     }
+
+    @Test
+    public void testCreateMVWithFilteringOnNonPkColumn() throws Throwable
+    {
+        // SEE CASSANDRA-13798, we cannot properly support non-pk base column 
filtering for mv without huge storage
+        // format changes.
+        createTable("CREATE TABLE %s ( a int, b int, c int, d int, PRIMARY KEY 
(a, b, c))");
+
+        executeNet(protocolVersion, "USE " + keyspace());
+
+        assertInvalidMessage("Non-primary key columns cannot be restricted in 
the SELECT statement used for materialized view creation",
+                             "CREATE MATERIALIZED VIEW " + keyspace() + ".mv 
AS SELECT * FROM %s "
+                                     + "WHERE b IS NOT NULL AND c IS NOT NULL 
AND a IS NOT NULL "
+                                     + "AND d = 1 PRIMARY KEY (c, b, a)");
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to