Prohibit reversed counter type as part of the primary key. Check the actual 
CQL3Type to get the base type from the abstract type when comparing against 
CounterColumnType.

Patch by Brett Snyder; reviewed by tjake for CASSANDRA-9395


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

Branch: refs/heads/trunk
Commit: 483c745334619ff19df8469f565b5346e7b2a5d0
Parents: 5a923f6
Author: Brett Snyder <bsny...@iland.com>
Authored: Fri Oct 2 11:41:04 2015 -0500
Committer: T Jake Luciani <j...@apache.org>
Committed: Fri May 6 14:11:16 2016 -0400

----------------------------------------------------------------------
 CHANGES.txt                                              |  1 +
 .../cassandra/cql3/statements/CreateTableStatement.java  |  6 +++---
 .../cassandra/cql3/validation/entities/CountersTest.java | 11 +++++++++++
 3 files changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/483c7453/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index a46aa56..18cd90b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.2.7
+ * Prohibit Reverse Counter type as part of the PK (CASSANDRA-9395)
  * cqlsh: correctly handle non-ascii chars in error messages (CASSANDRA-11626)
  * Exit JVM if JMX server fails to startup (CASSANDRA-11540)
  * Produce a heap dump when exiting on OOM (CASSANDRA-9861)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/483c7453/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
index 1b3665c..e761674 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
@@ -268,7 +268,7 @@ public class CreateTableStatement extends 
SchemaAlteringStatement
             {
                 stmt.keyAliases.add(alias.bytes);
                 AbstractType<?> t = getTypeAndRemove(stmt.columns, alias);
-                if (t instanceof CounterColumnType)
+                if (t.asCQL3Type().getType() instanceof CounterColumnType)
                     throw new InvalidRequestException(String.format("counter 
type is not supported for PRIMARY KEY part %s", alias));
                 if (staticColumns.contains(alias))
                     throw new InvalidRequestException(String.format("Static 
column %s cannot be part of the PRIMARY KEY", alias));
@@ -316,7 +316,7 @@ public class CreateTableStatement extends 
SchemaAlteringStatement
 
                     stmt.columnAliases.add(alias.bytes);
                     AbstractType<?> at = getTypeAndRemove(stmt.columns, alias);
-                    if (at instanceof CounterColumnType)
+                    if (at.asCQL3Type().getType() instanceof CounterColumnType)
                         throw new 
InvalidRequestException(String.format("counter type is not supported for 
PRIMARY KEY part %s", stmt.columnAliases.get(0)));
                     stmt.comparator = new SimpleDenseCellNameType(at);
                 }
@@ -328,7 +328,7 @@ public class CreateTableStatement extends 
SchemaAlteringStatement
                         stmt.columnAliases.add(t.bytes);
 
                         AbstractType<?> type = getTypeAndRemove(stmt.columns, 
t);
-                        if (type instanceof CounterColumnType)
+                        if (type.asCQL3Type().getType() instanceof 
CounterColumnType)
                             throw new 
InvalidRequestException(String.format("counter type is not supported for 
PRIMARY KEY part %s", t));
                         if (staticColumns.contains(t))
                             throw new 
InvalidRequestException(String.format("Static column %s cannot be part of the 
PRIMARY KEY", t));

http://git-wip-us.apache.org/repos/asf/cassandra/blob/483c7453/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java
----------------------------------------------------------------------
diff --git 
a/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java 
b/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java
index e5ff251..41b73bc 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java
@@ -112,4 +112,15 @@ public class CountersTest extends CQLTester
                    row(1L) // no change to the counter value
         );
     }
+
+    /**
+     * Test for the validation bug of #9395.
+     */
+    @Test
+    public void testProhibitReversedCounterAsPartOfPrimaryKey() throws 
Throwable
+    {
+        assertInvalidThrowMessage("counter type is not supported for PRIMARY 
KEY part a",
+                                  InvalidRequestException.class, 
String.format("CREATE TABLE %s.%s (a counter, b int, PRIMARY KEY (b, a)) WITH 
CLUSTERING ORDER BY (a desc);", KEYSPACE, createTableName()));
+    }
+
 }

Reply via email to