Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra CQL: counter column creation and modification

Tags:

cassandra

cql

I am trying to create a counter column through Java but I am getting an error when running it. I am using CQL 3.0.0 and Cassandra 1.1.2

Statement st = con.createStatement();
String data = "CREATE COLUMNFAMILY user_count(priKey text PRIMARY KEY, countME counter)";
st.execute(data);

This is the error that I am getting:

Exception in thread "main" java.sql.SQLSyntaxErrorException:        
org.apache.cassandra.config.ConfigurationException: Cannot add a counter column   
(countme) in a non counter column family

'CREATE COLUMNFAMILY user_count(priKey text PRIMARY KEY, countME counter)'
at org.apache.cassandra.cql.jdbc.CassandraStatement.doExecute(CassandraStatement.java:179)
at org.apache.cassandra.cql.jdbc.CassandraStatement.execute(CassandraStatement.java:203)
at cassandratest.EdgeCreator.aaListData(EdgeCreator.java:1323)
at cassandratest.Main.main(Main.java:214)

I have tried the answer to Cassandra cql comparator type counter but I understand that default_validation for CQL 3.0.0 is no longer useable. I have searched the documentation but have found nothing. I am looking how to create a counter column family and increment it, using Java. Thanks for the help in advance!

This is also my first post on here, so please let me know if there is anything wrong with it so I can correct it in the future.

Update When using the CREATE statement in cqlsh, I get a ConfigurationException. The cqlsh session follows:

Connected to Test Cluster at localhost:9160.
[cqlsh 3.0.0 | Cassandra 1.1.0 | CQL spec 3.0.0 | Thrift protocol 19.30.0]
Use HELP for help.
cqlsh> use "Keyspace2";
cqlsh:Keyspace2> CREATE COLUMNFAMILY user_count(priKey text PRIMARY KEY, countME
counter);
Bad Request: org.apache.cassandra.config.ConfigurationException: Cannot add a 
counter column (countme) in a non counter column family
cqlsh:Keyspace2>
like image 627
D. Gibbs Avatar asked Nov 03 '22 20:11

D. Gibbs


1 Answers

Are you sure you're using cql 3? It looks from your traceback like you're not, and that's the error I would expect if you were accidentally using cql 2.

That create statement should work in cql 3.

Edit: You were using cql 3, but you weren't using Cassandra 1.1.2. That was a known bug with 1.1.0; it should be fixed if you upgrade to 1.1.2.

like image 180
the paul Avatar answered Nov 13 '22 02:11

the paul