这种计数器表定义有效吗? [英] Is this type of counter table definition valid?

查看:111
本文介绍了这种计数器表定义有效吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个具有宽分区的表(或者换一种说法,就是没有值列(非主键列)的表),从而可以有效地获取其任何分区中的行数。这是此类表的简单定义

I want to create a table with wide partitions (or, put another way, a table which has no value columns (non primary key columns)) that enables the number of rows in any of its partitions to be efficiently procured. Here is a simple definition of such a table

CREATE TABLE IF NOT EXISTS test_table
(
    partitionKeyCol         timestamp
    clusteringCol           timeuuid
    partitionRowCountCol    counter    static
    PRIMARY KEY             (partitionKeyCol, clusteringCol)
)

此定义以及其他类似定义的问题是,不能从文档中包含的信息中明确推导出其有效性。

The problem with this definition, and others structured like it, is that their validity cannot be clearly deduced from the information contained in the docs.

文档说明的内容(关于计数器):


  • 计数器列既不能被指定为表的 PRIMARY KEY 的一部分,也不用于创建 INDEX

  • A counter column can neither be specified as part of a table's PRIMARY KEY, nor used to create an INDEX

计数器列只能在专用计数器表中定义(我认为这是一个仅将计数器列定义为其值列的表)

A counter column can only be defined in a dedicated counter table (which I take to be a table which solely has counter columns defined as its value columns)

什么他的文档未声明(针对计数器):


  • 表具有静态功能为其定义的计数器列(考虑到计数器的唯一写入路径,我认为这值得一提)

  • The ability of a table to have a static counter column defined for it (given the unique write path of counters, I feel that this is worth mentioning)

表的功能(值为零)为此定义的列(根据我对术语的理解,使其成为专用计数器表),也为其定义了静态计数器列

The ability of a table, which has zero value columns defined for it (making it a dedicated counter table, given my understanding of the term), to also have a static counter column defined for it

鉴于文档中存在(或不存在)的有关此主题的信息,这样的定义似乎是有效的。但是,由于对 partitionRowCountCol 进行的更新将需要使用与用于插入的写入路径不同的写入路径,因此我不确定如何实现。 (partitionKeyCol,clusteringCol)元组。

Given the information on this subject that is present in (and absent from) the docs, such a definition appears to be valid. However, I'm not sure how that is possible, given that the updates to partitionRowCountCol would require use of a write path different from that used to insert (partitionKeyCol, clusteringCol) tuples.

这种类型的计数器表定义有效吗?如果是这样,如何对表进行写操作?

Is this type of counter table definition valid? If so, how are writes to the table carried out?

推荐答案

看起来可以定义具有这种结构的表,但是我正在努力寻找一个好的用例。

It looks like a table with this structure can be defined, but I'm struggling to find a good use case for it. It seems there is no way to actually write to that clustering column.

CREATE TABLE test.test_table (
    a timestamp,
    b timeuuid,
    c counter static,
    PRIMARY KEY (a, b)
);

cassandra@cqlsh:test> insert into test_table (a,b,c) VALUES (unixtimestampof(now()), now(), 3);
InvalidRequest: code=2200 [Invalid query] message="INSERT statements are not allowed on counter tables, use UPDATE instead"
cassandra@cqlsh:test> update test_table set c = c + 1 where a=unixtimestampof(now());
cassandra@cqlsh:test> update test_table set c = c + 1 where a=unixtimestampof(now());
cassandra@cqlsh:test> select * from test_table;

 a                        | b    | c
--------------------------+------+---
 2016-03-24 15:04:31+0000 | null | 1
 2016-03-24 15:04:37+0000 | null | 1

(2 rows)
cassandra@cqlsh:test> update test_table set c = c + 1 where a=unixtimestampof(now()) and b=now();
InvalidRequest: code=2200 [Invalid query] message="Invalid restrictions on clustering columns since the UPDATE statement modifies only static columns"
cassandra@cqlsh:test> insert into test_table (a,b) VALUES (unixtimestampof(now()), now());
InvalidRequest: code=2200 [Invalid query] message="INSERT statements are not allowed on counter tables, use UPDATE instead"
cassandra@cqlsh:test> update test_table set b = now(), c = c + 1 where a=unixtimestampof(now());
InvalidRequest: code=2200 [Invalid query] message="PRIMARY KEY part b found in SET part"

您要建模的是什么?

这篇关于这种计数器表定义有效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆