Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to insert/write data without defining columns in Cassandra?

I am trying to understand the fundamentals of Cassandra data model. I am using CQL. As per I know the schema must be defined before anyone can insert into new columns. If someone needs to add any column can use ALTER TABLE and can INSERT value to that new column.

But in cassandra definitive guide there is written that Cassandra is schema less.

In Cassandra, you don’t define the columns up front; you just define the column
families you want in the keyspace, and then you can start writing data without defining
the columns anywhere. That’s because in Cassandra, all of a column’s names are
supplied by the client.

I am getting confused and not finding any expected answer. Can someone please explain it to me or tell me if I am missing somthing?

Thanks in advance.

like image 543
Chaity Avatar asked Mar 25 '15 08:03

Chaity


People also ask

What are the ways to insert data into Cassandra?

You can insert data into the columns of a row in a table using the command INSERT.

Which values are compulsory to insert while inserting a row in Cassandra table?

All PRIMARY KEY fields are required. Nulls are inserted into any static columns that are excluded.

Which command would you use to add new columns to a table schema in Cassandra?

The ALTER TABLE command can be used to add new columns to a table and to alter the column type of an existing column.

Can we create table without primary key in Cassandra?

Therefore,defining a primary key is mandatory while creating a table. A primary key is made of one or more columns of a table. You can define a primary key of a table as shown below. CREATE TABLE tablename( column1 name datatype PRIMARYKEY, column2 name data type, column3 name data type. )


2 Answers

Theres two different APIs to interact with Cassandra for writing data. First there's the thrift API which always allowed to create columns dynamically, but also supports adding meta data for your columns. Next theres the newer CQL based API. CQL was created to provide another abstraction layer that would make it more user friendly to work with Cassandra. With CQL you're required to define a schema upfront for your column names and datatypes. However, that doesn't mean its not possible to use dynamic columns using CQL.

See here for differences: http://www.datastax.com/dev/blog/thrift-to-cql3

like image 81
Stefan Podkowinski Avatar answered Sep 23 '22 04:09

Stefan Podkowinski


You are reading "Cassandra, the definitive guide": a 3/4 years old book that is telling you something that has changed long time ago. Now you have to define the tables structure before being able to write data.

Here you can find some reasons behind CQL introduction and the schema-less abandonment.

The official Datastax documentation should be your definitive guide.

HTH,
Carlo

like image 36
Carlo Bertuccini Avatar answered Sep 22 '22 04:09

Carlo Bertuccini