Cassandra是否插入json创建墓碑?

mcdcgff0  于 2021-06-13  发布在  Cassandra
关注(0)|答案(1)|浏览(367)

我使用cassandra的insert json特性将数据插入表中。在我创建的json中,我没有包含 null 价值观。也就是说,忽略 null 价值观。
如果我是第一次插入记录,Cassandra会在这种情况下创建墓碑吗?
我假设以后的升级也是一样的 key 将创建墓碑。是这样吗?

bvhaajcl

bvhaajcl1#

仍然应该为您尝试插入的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" }
        ]
      }
    ]
  }
]

观察为名字创建的单元格墓碑。
这与使用选择性字段插入数据时的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" }
        ]
      }
    ]
  }
]

相关问题