How to define dynamic column families in cassandra

Balo picture Balo · Jan 22, 2013 · Viewed 11.6k times · Source

Here it is said, that no special effort is need to get a dynamic column family. But I always get an exception, when I try to set a value for an undefined column.

I created a column family like this:

CREATE TABLE places (
   latitude double,
   longitude double,
   name text,
   tags text,
   PRIMARY KEY (latitude, longitude, name)
)

BTW: I had to define the tags column. Can somebody explain me why? Maybe because all other columns are part of the Index?

Now when inserting data like this:

INSERT INTO places ("latitude","longitude","name","tags") VALUES (49.797888,9.934771,'Test','foo,bar')

it works just fine! But when I try:

INSERT INTO places ("latitude","longitude","name","tags","website") VALUES (49.797888,9.934771,'Test','foo,bar','test.de')

I get following error:

Bad Request: Unknown identifier website
text could not be lexed at line 1, char 21

Which changes are needed so I can dynamically add columns?

I am using Cassandra 1.1.9 with CQL3 with the cqlsh directly on a server.

Answer

manuzhang picture manuzhang · Jan 23, 2013

CQL3 supports dynamic column family but you have to alter the table schema first

ALTER TABLE places ADD website varchar;

Check out the 1.2 documentation and CQL in depth slides