Cassandra中的单个分区批处理如何用于多列更新? [英] How single partition batch in Cassandra function for multiple column update?

查看:73
本文介绍了Cassandra中的单个分区批处理如何用于多列更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在单个列族的单个分区中有多个更新查询。如下所示

We have multiple update queries in a single partition of a single columnfamily. Like below

update t1 set username = 'abc', url = 'www.something.com', age = ? where userid = 100;
update t1 set username = 'abc', url = 'www.something.com', weight = ? where userid = 100;
update t1 set username = 'abc', url = 'www.something.com', height = ? where userid = 100;

用户名 url 将始终相同,并且是必填字段。

username, url will be always same and are mandatory fields. But depending on the information given there will be extra columns.

由于这是单个分区操作,因此我们需要原子+隔离。我们将分批执行该操作。

As this is a single partition operation and we need atomicity + isolation. We will execute this in a batch.

根据文档


一个批处理语句将多个数据修改语言(DML)语句(INSERT,UPDATE,DELETE)组合到单个逻辑操作中,并为该批处理中的语句所写的所有列设置客户端提供的时间戳。

A BATCH statement combines multiple data modification language (DML) statements (INSERT, UPDATE, DELETE) into a single logical operation, and sets a client-supplied timestamp for all columns written by the statements in the batch.

现在,当我们在多条语句中更新具有相同值的列(用户名,URL)时,C *会将其合并为一条语句在执行它之前

Now as we are updating columns(username, url) with same value in multiple statement, will C* combines it as a single statement before executing it like

update t1 set username = 'abc', url = 'www.something.com', age = ?, weight = ?, height = ? where userid = 100;

还是相同的值将是upsert?

or same value will be upsert?

另一个问题是,由于它们都具有相同的时间戳,因此C *如何解决该冲突。 C *将比较每个列(用户名,URL)的值。

Another question is that, as they all have the same timestamp how C* resolves that conflict. Will C* compare every column (username, url) value.


由于它们都具有相同的时间戳,C *通过选择单元的最大值。 卡桑德拉中的原子批处理

或者我们应该像下面这样批量添加查询。在这种情况下,我们必须检查用户名,URL已添加到语句中。

Or should we add queries in batch like below. In this case we have to check username, url has already been added in statement.

update t1 set username = 'abc', url = 'www.something.com', age = ? where userid = 100;
update t1 set weight = ? where userid = 100;
update t1 set height = ? where userid = 100;

总之,什么是最好的方法。

In short what will be the best way to do it.

推荐答案

对于您的第一个问题(C *是否将其组合为单个语句?)答案是肯定的。

For your first question(will C* combines it as a single statement?) answer is yes.

将单个分区批处理应用为单行突变。

A single partition batch is applied as a single row mutation.

查看此链接以获取详细信息:
https://issues.apache.org/jira/browse/CASSANDRA-6737

check this link for details: https://issues.apache.org/jira/browse/CASSANDRA-6737

对于第二个问题(C *是否会比较每列(用户名,URL)的值?)答案也是肯定的。

For your second question(Will C* compare every column (username, url) value?) answer is also yes.

提供了链接通过选择单元格的最大值来解决冲突

As given in the answer of your provided link "Conflict is resolved by choosing the largest value for the cells"

因此,您可以以任何一种方式(根据您的问题)批量编写查询。
,因为它将最终在内部转换为单个写入。

So, you can write queries in batch in either way(given in your question). As it will ultimately converted to a single write internally.

这篇关于Cassandra中的单个分区批处理如何用于多列更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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