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

2

8

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.

Lamarckian answered 25/3, 2015 at 8:14 Comment(0)
K
5

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

Karlee answered 25/3, 2015 at 8:45 Comment(0)
H
3

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

Hedgerow answered 25/3, 2015 at 8:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.