Search code examples
cassandracql

Can Cassandra hold an empty list?


I want to create a Cassandra collection with some list<int> field and insert an empty list;

CREATE TABLE test (
    name text PRIMARY KEY,
    scores list<int>,
);

INSERT INTO test (name, scores)  VALUES ('John', []);

However, this returns null

SELECT * FROM test;


 name |scores
------+------------
 John | null

Does Cassandra not differentiate between null and empty list?


Solution

  • As always the recommendation goes with Cassandra don't insert NULL or try to insert EMPTY values. Its just saving yourselves from Tombstones, storage, I/O bandwidth.

    The reason why Cassandra doesn't differentiate NULL Vs empty is because the way deletes are handled. There is no read before deleting any record in Cassandra. So it just marks as a tombstone and moves ahead.

    So actually you get penalized to initialize the list as empty (essentially creating tombstone).