Repository: cassandra Updated Branches: refs/heads/cassandra-3.0 a1cc804f5 -> 6d725afae refs/heads/trunk e16d8a7a6 -> 7a7249ac4
Disallow creating view with a static column patch by Carl Yeksigian; reviewed by Sylvain Lebresne for CASSANDRA-11602 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/6d725afa Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/6d725afa Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/6d725afa Branch: refs/heads/cassandra-3.0 Commit: 6d725afaef5bc8604cf775ff2498f21530c0288c Parents: a1cc804 Author: Carl Yeksigian <[email protected]> Authored: Mon May 2 16:12:00 2016 -0400 Committer: Carl Yeksigian <[email protected]> Committed: Mon May 2 16:12:00 2016 -0400 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cql3/statements/CreateViewStatement.java | 15 ++++++------- .../org/apache/cassandra/cql3/ViewTest.java | 22 ++++++++++++++++++-- 3 files changed, 29 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/6d725afa/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 95db7bc..f947568 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.0.6 + * Disallow creating view with a static column (CASSANDRA-11602) * Reduce the amount of object allocations caused by the getFunctions methods (CASSANDRA-11593) * Potential error replaying commitlog with smallint/tinyint/date/time types (CASSANDRA-11618) * Fix queries with filtering on counter columns (CASSANDRA-11629) http://git-wip-us.apache.org/repos/asf/cassandra/blob/6d725afa/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 5af4887..45231b7 100644 --- a/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/CreateViewStatement.java @@ -168,10 +168,7 @@ public class CreateViewStatement extends SchemaAlteringStatement if (cdef == null) throw new InvalidRequestException("Unknown column name detected in CREATE MATERIALIZED VIEW statement : "+identifier); - if (cdef.isStatic()) - ClientWarn.instance.warn(String.format("Unable to include static column '%s' in Materialized View SELECT statement", identifier)); - else - included.add(identifier); + included.add(identifier); } Set<ColumnIdentifier.Raw> targetPrimaryKeys = new HashSet<>(); @@ -246,10 +243,14 @@ public class CreateViewStatement extends SchemaAlteringStatement for (ColumnDefinition def : cfm.allColumns()) { ColumnIdentifier identifier = def.name; + boolean includeDef = included.isEmpty() || included.contains(identifier); + + if (includeDef && def.isStatic()) + { + throw new InvalidRequestException(String.format("Unable to include static column '%s' which would be included by Materialized View SELECT * statement", identifier)); + } - if ((included.isEmpty() || included.contains(identifier)) - && !targetClusteringColumns.contains(identifier) && !targetPartitionKeys.contains(identifier) - && !def.isStatic()) + if (includeDef && !targetClusteringColumns.contains(identifier) && !targetPartitionKeys.contains(identifier)) { includedColumns.add(identifier); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/6d725afa/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 830f37f..ac4becb 100644 --- a/test/unit/org/apache/cassandra/cql3/ViewTest.java +++ b/test/unit/org/apache/cassandra/cql3/ViewTest.java @@ -207,13 +207,31 @@ public class ViewTest extends CQLTester try { createView("mv_static", "CREATE MATERIALIZED VIEW %%s AS SELECT * FROM %s WHERE sval IS NOT NULL AND k IS NOT NULL AND c IS NOT NULL PRIMARY KEY (sval,k,c)"); - Assert.fail("MV on static should fail"); + Assert.fail("Use of static column in a MV primary key should fail"); } catch (InvalidQueryException e) { } - createView("mv_static", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE val IS NOT NULL AND k IS NOT NULL AND c IS NOT NULL PRIMARY KEY (val,k,c)"); + try + { + createView("mv_static", "CREATE MATERIALIZED VIEW %%s AS SELECT val, sval FROM %s WHERE val IS NOT NULL AND k IS NOT NULL AND c IS NOT NULL PRIMARY KEY (val, k, c)"); + Assert.fail("Explicit select of static column in MV should fail"); + } + catch (InvalidQueryException e) + { + } + + try + { + createView("mv_static", "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE val IS NOT NULL AND k IS NOT NULL AND c IS NOT NULL PRIMARY KEY (val,k,c)"); + Assert.fail("Implicit select of static column in MV should fail"); + } + catch (InvalidQueryException e) + { + } + + createView("mv_static", "CREATE MATERIALIZED VIEW %s AS SELECT val,k,c FROM %%s WHERE val IS NOT NULL AND k IS NOT NULL AND c IS NOT NULL PRIMARY KEY (val,k,c)"); for (int i = 0; i < 100; i++) updateView("INSERT into %s (k,c,sval,val)VALUES(?,?,?,?)", 0, i % 2, "bar" + i, "baz");
