【问题标题】:Dynamic columns with CQL 3使用 CQL 3 的动态列
【发布时间】:2016-09-12 14:16:31
【问题描述】:

我阅读了关于存储时间序列数据的 Datastax 文章https://academy.datastax.com/resources/getting-started-time-series-data-modeling

根据文章,它应该创建宽行来存储一些时间序列。像这样(文章图片): 我创建了表:

CREATE TABLE test.times ( id text, time timestamp, temperature text, PRIMARY KEY (id, time));

并插入一些值:

cqlsh> insert into test.times (id, time , temperature ) VALUES ( '1', '2013-04-03 07:03:00', '72F');
cqlsh> insert into test.times (id, time , temperature ) VALUES ( '1', '2013-04-03 07:03:01', '73F');
cqlsh> insert into test.times (id, time , temperature ) VALUES ( '1', '2013-04-03 07:03:02', '74F');
cqlsh> insert into test.times (id, time , temperature ) VALUES ( '2', '2013-04-03 07:04:02', '74F');
cqlsh> insert into test.times (id, time , temperature ) VALUES ( '2', '2013-04-03 07:04:03', '72F');

我使用sstabledump 工具转储了我的时间表。我得到了下一个转储:

[
  {
    "partition" : {
      "key" : [ "2" ],
      "position" : 0
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 15,
        "clustering" : [ "2013-04-03 07:04+0200" ],
        "liveness_info" : { "tstamp" : 1463419324694096 },
        "cells" : [
          { "name" : "temperature", "value" : "74F" }
        ]
      },
      {
        "type" : "row",
        "position" : 36,
        "clustering" : [ "2013-04-03 07:04+0200" ],
        "liveness_info" : { "tstamp" : 1463419332655070 },
        "cells" : [
          { "name" : "temperature", "value" : "72F" }
        ]
      }
    ]
  },
  {
    "partition" : {
      "key" : [ "1" ],
      "position" : 58
    },
    "rows" : [
      {
        "type" : "row",
        "position" : 73,
        "clustering" : [ "2013-04-03 07:03+0200" ],
        "liveness_info" : { "tstamp" : 1463419298628467 },
        "cells" : [
          { "name" : "temperature", "value" : "72F" }
        ]
      },
      {
        "type" : "row",
        "position" : 91,
        "clustering" : [ "2013-04-03 07:03+0200" ],
        "liveness_info" : { "tstamp" : 1463419310835537 },
        "cells" : [
          { "name" : "temperature", "value" : "73F" }
        ]
      },
      {
        "type" : "row",
        "position" : 112,
        "clustering" : [ "2013-04-03 07:03+0200" ],
        "liveness_info" : { "tstamp" : 1463419317481809 },
        "cells" : [
          { "name" : "temperature", "value" : "74F" }
        ]
      }
    ]
  }
]

正如我所见,C* 为每个新条目创建了新行。我做错了什么?以及如何使用 CQL 创建宽行?

Cassandra v. 3.5

【问题讨论】:

    标签: cassandra cql


    【解决方案1】:

    你做得对。 宽行实际上意味着宽分区。您看到您有包含多个逻辑cql rows分区(由id 标识)。这些分区是你想要的宽度。

    C* 3.0 存储引擎的链接

    1. http://thelastpickle.com/blog/2016/03/04/introductiont-to-the-apache-cassandra-3-storage-engine.html

    2. http://www.datastax.com/2015/12/storage-engine-30

    【讨论】:

    • CQL 中的行是否与 Thrift 中的列相同?
    • 有点,这个问题在 C* 3.0 中并不真正相关,因为 C* 3.0 已经重写了存储系统。以前,您可以将cql row 想象为一组相邻的单元格,每个单元格都将聚类键值作为“标题”,并将不同的非主键列的值作为其值。请参阅stackoverflow.com/questions/20512710/… 使用新的存储格式,虽然实际上不再有 Thrift 等价物。
    • 非常感谢!您能否推荐一些有关 C* 3.x 中数据存储模型的文章?
    猜你喜欢
    • 2016-09-22
    • 1970-01-01
    • 2014-02-01
    • 2012-09-02
    • 2015-10-04
    • 2023-02-05
    • 2018-04-21
    • 2015-09-27
    • 2013-04-09
    相关资源
    最近更新 更多