Reputation: 2920
I have a cassandra table with data in it.
I add three new columns country
as text
, lat
and long
as double
.
When these columns are added null values are inserted against the already present rows in the table. However, null is inserted as text
in country column and null
as value in lat and long columns.
Is this something that is the default behavior and can I add null as value under the newly created text columns?
Upvotes: 1
Views: 1409
Reputation: 87069
Cassandra uses null
to show that value is missing, not that this is explicitly inserted. In your case, when you add new columns - they are just added to table's specification stored in Cassandra itself - existing data (stored in SSTables) is not modified, so when Cassandra reads old data it doesn't find values for that columns in SSTable, and output null instead.
But you can have the same behavior without adding new columns - just don't insert value for specific regular column (you must have non-null values for columns of primary key!). For example:
cqlsh> create table test.abc (id int primary key, t1 text, t2 text);
cqlsh> insert into test.abc (id, t1, t2) values (1, 't1-1', 't2-1');
cqlsh> insert into test.abc (id, t1) values (2, 't1-2');
cqlsh> insert into test.abc (id, t2) values (3, 't3-3');
cqlsh> SELECT * from test.abc;
id | t1 | t2
----+------+------
1 | t1-1 | t2-1
2 | t1-2 | null
3 | null | t3-3
(3 rows)
Upvotes: 2