Reject counter writes in CQLSSTableWriter

patch by Paulo Motta; reviewed by Aleksey Yeschenko for CASSANDRA-10258
This commit is contained in:
Paulo Motta 2015-10-22 11:38:31 -07:00 committed by Aleksey Yeschenko
parent 852a8babd4
commit 3674ad9dab
3 changed files with 25 additions and 0 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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
{