cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [08/13] cassandra git commit: 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.
Date Fri, 06 May 2016 18:24:29 GMT
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/411c5601
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/411c5601
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/411c5601

Branch: refs/heads/cassandra-3.7
Commit: 411c56014d3eb8fdd001c2381c376c968cdef499
Parents: 08b1efe
Author: T Jake Luciani <jake@apache.org>
Authored: Fri May 6 11:36:04 2016 -0400
Committer: T Jake Luciani <jake@apache.org>
Committed: Fri May 6 14:19:57 2016 -0400

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


http://git-wip-us.apache.org/repos/asf/cassandra/blob/411c5601/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 2e2b6af..af8be97 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,7 +1,9 @@
 3.0.7
  * Refactor Materialized View code (CASSANDRA-11475)
  * Update Java Driver (CASSANDRA-11615)
- 
+Merged from 2.2:
+ * Prohibit Reversed Counter type as part of the PK (CASSANDRA-9395)
+
 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)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/411c5601/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 c19f970..04f76d3 100644
--- a/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/CreateTableStatement.java
@@ -241,7 +241,7 @@ public class CreateTableStatement extends SchemaAlteringStatement
             {
                 stmt.keyAliases.add(alias);
                 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));
@@ -255,7 +255,7 @@ public class CreateTableStatement extends SchemaAlteringStatement
                 stmt.columnAliases.add(t);
 
                 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/411c5601/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 89fd767..c9939c8 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/CountersTest.java
@@ -186,4 +186,14 @@ public class CountersTest extends CQLTester
                                  "SELECT * FROM %s WHERE b = null ALLOW FILTERING");
         }
     }
+
+    /**
+     * 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()));
+    }
 }


Mime
View raw message