Cassandra Insert JSON 会创建墓碑吗?
Does Cassandra Insert JSON creates Tombstones?
我正在使用 Cassandra's insert JSON feature 将数据插入 table。在我创建的 JSON 中,我不包含 null
值。意思是,忽略其中具有 null
值的字段。
如果我是第一次插入记录,Cassandra 会在这种情况下创建墓碑吗?
我假设相同 key
的后续更新插入将创建墓碑。是吗?
仍应为您尝试插入的 json 中未包含的值创建单元格墓碑。
考虑一个叫 table 的骑自行车的人,他有身份证、名字和姓氏。我们将使用仅包含姓氏的 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 创建的单元格墓碑。
当我们使用选择字段插入数据时,这与 sstable 结构不同。
INSERT INTO cycling.cyclist(id, first_name) VALUES ( 'c49d1614-e841-4bd4-993b-02d49ae7414c', 'MYFIRSTNAME');
现在看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" }
]
}
]
},
{
"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" }
]
}
]
}
]
我正在使用 Cassandra's insert JSON feature 将数据插入 table。在我创建的 JSON 中,我不包含 null
值。意思是,忽略其中具有 null
值的字段。
如果我是第一次插入记录,Cassandra 会在这种情况下创建墓碑吗?
我假设相同 key
的后续更新插入将创建墓碑。是吗?
仍应为您尝试插入的 json 中未包含的值创建单元格墓碑。
考虑一个叫 table 的骑自行车的人,他有身份证、名字和姓氏。我们将使用仅包含姓氏的 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 创建的单元格墓碑。
当我们使用选择字段插入数据时,这与 sstable 结构不同。
INSERT INTO cycling.cyclist(id, first_name) VALUES ( 'c49d1614-e841-4bd4-993b-02d49ae7414c', 'MYFIRSTNAME');
现在看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" }
]
}
]
},
{
"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" }
]
}
]
}
]