Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra: Can't use 'NOT NULL' constraint while creating table

Tags:

cassandra

I see many examples on here that create tables using the NOT NULL constraint. Ironically I can't seem to do the same.

This is the cql command I use :

CREATE TABLE activities_dev (activity_id  uuid ,actor_id bigint NOT NULL, actor_appid bigint NOT NULL, item_id text NOT NULL, verb text NOT NULL,viewer_id bigint NOT NULL,viewer_appid bigint NOT NULL, ts timestamp, PRIMARY KEY(activity_id,actor_id,actor_appid,item_id,verb));

but this is the error I get:

SyntaxException: line 1:62 mismatched input 'NOT' expecting ')' (...activities_dev(activity_id uuid, actor_id integer [NOT] NULL...)

What am I doing wrong ?

like image 404
arshellium Avatar asked Feb 05 '23 13:02

arshellium


2 Answers

In Cassandra NOT NULL keyword not supported.

For primary key columns cassandra automatically handle that. If you try to insert null to any primary key value cassandra will throw exception

Invalid null value in condition for column

like image 145
Ashraful Islam Avatar answered May 31 '23 13:05

Ashraful Islam


Null column in Cassandra does not mean empty column.

Cassandra uses nulls for marking deleted columns : you can delete one or several columns of a row in Cassandra.

This timestamped marker called tombstone is used for data reconciliation locally and between nodes (Commitlog, memtables, SStables) and in replicated keyspaces prevents resurrection of data (see this article for example about replicated deleted).

In this context, it makes sense not to allow a 'NOT NULL' clause in CREATE TABLE and ALTER TABLE CQL syntax.

Alain

like image 35
ARA Avatar answered May 31 '23 13:05

ARA