Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define dynamic column families in cassandra

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.

like image 885
Balo Avatar asked Jan 22 '13 10:01

Balo


1 Answers

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

like image 194
manuzhang Avatar answered Sep 29 '22 21:09

manuzhang