mithrix
mithrix

Reputation: 542

How do you create a counter columnfamily with CQL3 in cassandra

How do you create a counter columnfamily with CQL3 in cassandra?

I used to use: CREATE COLUMNFAMILY userstats (username varchar PRIMARY KEY, images counter) WITH default_validation=counter AND comment='User Stats';

Now when i run that in CQL3 i get: Bad Request: default_validation is not a valid keyword argument for CREATE COLUMNFAMILY

Upvotes: 5

Views: 4844

Answers (1)

the paul
the paul

Reputation: 9161

CQL3 no longer sticks with the "dynamic column names" model. It can still make arbitrarily wide cassandra rows, but they look like "normal" narrow tables in CQL, with all columns named and defined. This is why CQL3 no longer supports setting a default_validation or comparator, etc.

You should read and understand http://www.datastax.com/dev/blog/schema-in-cassandra-1-1 before doing anything nontrivial in CQL3.

The answer to your question, though, is that it's as simple as leaving off the default_validation:

CREATE TABLE userstats (
    username varchar PRIMARY KEY,
    images counter
) WITH comment='User Stats';

Although it's not clear whether you intended to use multiple counters per row there, since you wanted a default_validation. If you did, and your comparator would have been varchar, you could do:

CREATE TABLE userstats (
    username varchar,
    countername varchar,
    value counter,
    PRIMARY KEY (username, countername)
) WITH comment='User Stats';

..and let images just be one of the counternames.

Upvotes: 3

Related Questions