gpt4 book ai didi

Cassandra宽行/动态列

转载 作者:行者123 更新时间:2023-12-04 13:36:51 25 4
gpt4 key购买 nike

我是NoSQL的新手。因此,我试图了解一些Cassandra概念,这些概念我从我研究的数十种资料中无法真正得到。

  • 我应该将宽行和动态列视为同义词吗?还是两个不同的概念?
  • 我认为集合类型的列为宽行是正确的吗?
  • 在我看来,宽行是Cassandra早期版本中的一个概念,只能通过Thrift API创建;而集合类型是宽行的现代版本。
  • 收集类型是否仍限于64k元素?还是在CQL 3之后,该限制已被删除?
  • 最佳答案

    A common misunderstanding is that CQL does not support dynamic columns or wide rows. On the contrary, CQL was designed to support everything you can do with the Thrift model, but make it easier and more accessible.



    让我们看一下下面的cql表。
    CREATE TABLE data (
    sensor_id int,
    collected_at timestamp,
    volts float,
    PRIMARY KEY (sensor_id, collected_at)
    );

    并插入一些数据
    sensor_id | collected_at             | volts
    ----------+--------------------------+-------
    1 | 2013-06-05 15:11:00-0500 | 3.1
    1 | 2013-06-05 15:11:10-0500 | 4.3
    1 | 2013-06-05 15:11:20-0500 | 5.7
    2 | 2013-06-05 15:11:00-0500 | 3.2
    3 | 2013-06-05 15:11:00-0500 | 3.3
    3 | 2013-06-05 15:11:10-0500 | 4.3

    这里的聚类列collected_at与Thrift动态列类似。(Q.1)

    如果我们看一下这个表的内部结构
    RowKey: 1
    => (cell=2013-06-05 15:11:00-0500, value=3.1, timestamp=1370463146717000)
    => (cell=2013-06-05 15:11:10-0500, value=4.3, timestamp=1370463282090000)
    => (cell=2013-06-05 15:11:20-0500, value=5.7, timestamp=1370463282093000)
    -------------------
    RowKey: 2
    => (cell=2013-06-05 15:11:00-0500, value=3.2, timestamp=1370463332361000)
    -------------------
    RowKey: 3
    => (cell=2013-06-05 15:11:00-0500, value=3.3, timestamp=1370463332365000)
    => (cell=2013-06-05 15:11:10-0500, value=4.3, timestamp=1370463332368000)

    您可以看到,群集列collected_at使此表成为表宽行(Q.1)

    因此,我们可以说,如果一个表具有一个或多个集群键,我们可以称该表为宽行。

    让我们再举一个例子:
    CREATE TABLE example (
    key1 text PRIMARY KEY,
    map1 map<text,text>,
    list1 list<text>,
    set1 set<text>
    );

    插入数据:
     key1 | list1             | map1                                         | set1
    ------+-------------------+----------------------------------------------+-----------------------
    john | ['doug', 'scott'] | {'doug': '555-1579', 'patricia': '555-4326'} | {'patricia', 'scott'}

    现在看一下内部结构:
    RowKey: john
    => (column=, value=, timestamp=1374683971220000)
    => (column=map1:doug, value='555-1579', timestamp=1374683971220000)
    => (column=map1:patricia, value='555-4326', timestamp=1374683971220000)
    => (column=list1:26017c10f48711e2801fdf9895e5d0f8, value='doug', timestamp=1374683971220000)
    => (column=list1:26017c12f48711e2801fdf9895e5d0f8, value='scott', timestamp=1374683971220000)
    => (column=set1:'patricia', value=, timestamp=1374683971220000)
    => (column=set1:'scott', value=, timestamp=1374683971220000)

    您可以看到映射键和设置值存储为动态列,映射值和列表值存储为该列的值。类似于宽行(Q.2)

    最后一个: 集合类型映射键和设置大小限制为64k。
  • 收集(列表):收集限制:〜20亿(2 ^ 31);值的大小:65535(216-1)
  • 集合(Set):集合限制:〜20亿(2 ^ 31);值的大小:65535(216-1)
  • 集合( map ):集合数量上限:约20亿(2 ^ 31);按键数:65535(216-1);值的大小:65535(216-1)

  • 来源 :
    https://www.datastax.com/blog/2013/06/does-cql-support-dynamic-columns-wide-rows
    https://teddyma.gitbooks.io/learncassandra/content/model/cql_and_data_structure.html
    http://docs.datastax.com/en/cql/3.3/cql/cql_reference/refLimits.html

    关于Cassandra宽行/动态列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44634953/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com