问题
I am using Cassandra's insert JSON feature to insert data into the table. In the JSON that I create, I do not include the null
values. Meaning, ignore the fields that have null
values in it.
Does Cassandra create tombstones in such cases, if I am inserting the record say, for the first time?
I assume for subsequent upsert for the same key
will create tombstone. Is that right?
回答1:
Cell tombstone should still get created for the values which are not included in the json you are trying to insert.
Consider a table called cyclist having id, first name and last name. We will insert a row using a json string which contains only last name.
CREATE KEYSPACE IF NOT EXISTS cycling WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 3 };
CREATE TABLE cycling.cyclist ( id UUID PRIMARY KEY, first_name text, last_name text );
CREATE TABLE cycling.cyclist ( id UUID PRIMARY KEY, first_name text, last_name text );
INSERT INTO cycling.cyclist JSON '{"id" : "829aa84a-4bba-411f-a4fb-38167a987cda", "last_name" : "MYLASTNAME" }';
Now if we look at the data structure within sstable, it looks like below.
[
{
"partition" : {
"key" : [ "829aa84a-4bba-411f-a4fb-38167a987cda" ],
"position" : 0
},
"rows" : [
{
"type" : "row",
"position" : 30,
"liveness_info" : { "tstamp" : "2020-05-13T07:10:59.298374Z" },
"cells" : [
{ "name" : "first_name", "deletion_info" : { "local_delete_time" : "2020-05-13T07:10:59Z" }
},
{ "name" : "last_name", "value" : "MYLASTNAME" }
]
}
]
}
]
Observe the cell tombstone created for first_name.
This is different than the sstable structure when we insert the data using selective fields.
INSERT INTO cycling.cyclist(id, first_name) VALUES ( 'c49d1614-e841-4bd4-993b-02d49ae7414c', 'MYFIRSTNAME');
Now look at the sstable structure
[
{
"partition" : {
"key" : [ "829aa84a-4bba-411f-a4fb-38167a987cda" ],
"position" : 0
},
"rows" : [
{
"type" : "row",
"position" : 30,
"liveness_info" : { "tstamp" : "2020-05-13T07:10:59.298374Z" },
"cells" : [
{ "name" : "first_name", "deletion_info" : { "local_delete_time" : "2020-05-13T07:10:59Z" }
},
{ "name" : "last_name", "value" : "MYLASTNAME" }
]
}
]
},
{
"partition" : {
"key" : [ "c49d1614-e841-4bd4-993b-02d49ae7414c" ],
"position" : 47
},
"rows" : [
{
"type" : "row",
"position" : 77,
"liveness_info" : { "tstamp" : "2020-05-13T07:23:42.964609Z" },
"cells" : [
{ "name" : "first_name", "value" : "MYFIRSTNAME" }
]
}
]
}
]
来源:https://stackoverflow.com/questions/61768228/does-cassandra-insert-json-creates-tombstones