2
votes

I am new to cassandra and I read some articles about static and dynamic column family. It is mentioned ,From Cassandra 3 table and column family are same.

I created key space, some tables and inserted data into that table.

CREATE TABLE subscribers(
 id uuid,
 email text,
 first_name text,
 last_name text,
 PRIMARY KEY(id,email)
);

INSERT INTO subscribers(id,email,first_name,last_name) 
    VALUES(now(),'[email protected]','Test1','User1');
INSERT INTO subscribers(id,email,first_name,last_name) 
    VALUES(now(),'[email protected]','Test2','User2');
INSERT INTO subscribers(id,email,first_name,last_name) 
    VALUES(now(),'[email protected]','Test3','User3');

It all seems to work fine.

But what I need is to create a dynamic column family with only data types and no predefined columns.

With insert query I can have different arguments and the table should be inserted.

In articles, it is mentioned ,for dynamic column family, there is no need to create a schema(predefined columns). I am not sure if this is possible in cassandra or my understanding is wrong.

Let me know if this is possible or not? if possible Kindly provide with some examples.

Thanks in advance.

1
Alex is correct. In its early days Cassandra used to be considered "schemaless," but that is no longer the case.Aaron

1 Answers

1
votes

I think that articles that you're referring where written in the first years of Cassandra, when it was based on the Thrift protocols. Cassandra Query Language was introduced many years ago, and now it's the way to work with Cassandra - Thrift is deprecated in Cassandra 3.x, and fully removed in the 4.0 (not released yet).

If you really need to have fully dynamic stuff, then you can try to emulate this by using table with columns as maps from text to specific type, like this:

create table abc (
  id int primary key,
  imap map<text,int>,
  tmap map<text,text>,
  ... more types
);

but you need to be careful - there are limitations and performance effects when using collections, especially if you want to store more then hundreds of elements.

another approach is to store data as individual rows:

create table xxxx (
  id int,
  col_name text,
  ival int,
  tval text,
  ... more types
  primary key(id, col_name));

then you can insert individual values as separate columns:

insert into xxxx(id, col_name, ival) values (1, 'col1', 1);
insert into xxxx(id, col_name, tval) values (1, 'col2', 'text');

and select all columns as:

select * from xxxx where id = 1;