我正在使用Cassandra的insert JSON功能将数据插入表中。在我创建的 JSON 中,我不包括null
值。这意味着,忽略包含null
值的字段。
卡桑德拉在这种情况下会创建墓碑吗,如果我第一次插入记录说?
我假设对于同一key
的后续更新插入将创建墓碑。是吗?
仍应为您尝试插入的 JSON 中未包含的值创建单元格逻辑删除。
考虑一个名为 cyclist 的表,该表具有 ID、名字和姓氏。我们将使用仅包含姓氏的 json 字符串插入一行。
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" }';
现在,如果我们查看 sstable 中的数据结构,它如下所示。
[
{
"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" }
]
}
]
}
]
观察为first_name创建的单元格墓碑。
这与我们使用选择性字段插入数据时的稳定结构不同。
INSERT INTO cycling.cyclist(id, first_name) VALUES ( 'c49d1614-e841-4bd4-993b-02d49ae7414c', 'MYFIRSTNAME');
现在看看稳定结构
[
{
"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" }
]
}
]
}
]