cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alek...@apache.org
Subject [3/7] cassandra git commit: Reject counter writes in CQLSSTableWriter
Date Tue, 10 Nov 2015 13:47:48 GMT
Reject counter writes in CQLSSTableWriter

patch by Paulo Motta; reviewed by Aleksey Yeschenko for CASSANDRA-10258


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

Branch: refs/heads/trunk
Commit: 3674ad9dab8f29173d7d4ee82488a8e9ea586240
Parents: 852a8ba
Author: Paulo Motta <pauloricardomg@gmail.com>
Authored: Thu Oct 22 11:38:31 2015 -0700
Committer: Aleksey Yeschenko <aleksey@apache.org>
Committed: Tue Nov 10 13:41:01 2015 +0000

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/io/sstable/CQLSSTableWriter.java  |  2 ++
 .../io/sstable/CQLSSTableWriterTest.java        | 22 ++++++++++++++++++++
 3 files changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/3674ad9d/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 123c1f3..fa2017a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.12
+ * Reject counter writes in CQLSSTableWriter (CASSANDRA-10258)
  * Remove superfluous COUNTER_MUTATION stage mapping (CASSANDRA-10605)
  * Improve json2sstable error reporting on nonexistent columns (CASSANDRA-10401)
  * (cqlsh) fix COPY using wrong variable name for time_format (CASSANDRA-10633)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/3674ad9d/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java b/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java
index c364171..ae8a392 100644
--- a/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java
+++ b/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java
@@ -453,6 +453,8 @@ public class CQLSSTableWriter implements Closeable
             this.boundNames = p.right;
             if (this.insert.hasConditions())
                 throw new IllegalArgumentException("Conditional statements are not supported");
+            if (this.insert.isCounter())
+                throw new IllegalArgumentException("Counter update statements are not supported");
             if (this.boundNames.isEmpty())
                 throw new IllegalArgumentException("Provided insert statement has no bind
variables");
             return this;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/3674ad9d/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java b/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java
index fa5cbb4..9c8a2c2 100644
--- a/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java
+++ b/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java
@@ -135,6 +135,28 @@ public class CQLSSTableWriterTest
         assertEquals(12, row.getInt("v2"));
     }
 
+    @Test(expected = IllegalArgumentException.class)
+    public void testForbidCounterUpdates() throws Exception
+    {
+        String KS = "cql_keyspace";
+        String TABLE = "counter1";
+
+        File tempdir = Files.createTempDir();
+        File dataDir = new File(tempdir.getAbsolutePath() + File.separator + KS + File.separator
+ TABLE);
+        assert dataDir.mkdirs();
+
+        String schema = "CREATE TABLE cql_keyspace.counter1 (" +
+                        "  my_id int, " +
+                        "  my_counter counter, " +
+                        "  PRIMARY KEY (my_id)" +
+                        ")";
+        String insert = String.format("UPDATE cql_keyspace.counter1 SET my_counter = my_counter
- ? WHERE my_id = ?");
+        CQLSSTableWriter.builder().inDirectory(dataDir)
+                        .forTable(schema)
+                        .withPartitioner(StorageService.instance.getPartitioner())
+                        .using(insert).build();
+    }
+
     @Test
     public void testSyncWithinPartition() throws Exception
     {


Mime
View raw message