Return-Path: X-Original-To: apmail-cassandra-user-archive@www.apache.org Delivered-To: apmail-cassandra-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5BAD31021E for ; Wed, 26 Feb 2014 23:54:22 +0000 (UTC) Received: (qmail 60154 invoked by uid 500); 26 Feb 2014 23:54:19 -0000 Delivered-To: apmail-cassandra-user-archive@cassandra.apache.org Received: (qmail 60115 invoked by uid 500); 26 Feb 2014 23:54:18 -0000 Mailing-List: contact user-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cassandra.apache.org Delivered-To: mailing list user@cassandra.apache.org Received: (qmail 60107 invoked by uid 99); 26 Feb 2014 23:54:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Feb 2014 23:54:18 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of clint.kelly@gmail.com designates 209.85.160.175 as permitted sender) Received: from [209.85.160.175] (HELO mail-yk0-f175.google.com) (209.85.160.175) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Feb 2014 23:54:12 +0000 Received: by mail-yk0-f175.google.com with SMTP id 131so4620735ykp.6 for ; Wed, 26 Feb 2014 15:53:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=cRlarG0ezM5AyUpjGT0osLrNxEXcE0Fy+a3J+ivjug4=; b=aIkQqrF935JOihbjUqM/HpeVs16OstBkB3p8wJNTD34jBVjFSqE1ARQU9ORuN1kKj0 SHi+yCSjDG4RiAK3/bNw1qPa7vYH5Tyedhx9qL34xJd+X1u3eANjvAUCe09ozfC2jKyO iluUEfM3T+UTWfAUxEdb6CGp8EqRzror/Rdllq/lzrWM0wd7QAvZAR+/k3TC2bmgWSz7 xq/aLd8TbcBWiDdlix8rZ+/7iyhuH1jfE1VhtEpLfmaQq+yEK9KC7KGfL6+HqxLfJpdh MaTkkwuisNcNqLdQKEdhfW1X1LfOaM8OmbGfmVBzWO+jKGSNgBte0Nk35USafEQIda5O /nrg== MIME-Version: 1.0 X-Received: by 10.236.16.83 with SMTP id g59mr11657791yhg.14.1393458831521; Wed, 26 Feb 2014 15:53:51 -0800 (PST) Received: by 10.170.75.87 with HTTP; Wed, 26 Feb 2014 15:53:51 -0800 (PST) In-Reply-To: References: Date: Wed, 26 Feb 2014 15:53:51 -0800 Message-ID: Subject: Re: Update multiple rows in a CQL lightweight transaction From: Clint Kelly To: user@cassandra.apache.org Content-Type: multipart/alternative; boundary=089e01634eeea97db804f357eae5 X-Virus-Checked: Checked by ClamAV on apache.org --089e01634eeea97db804f357eae5 Content-Type: text/plain; charset=ISO-8859-1 Thanks for your help everyone. Sylvain, as I understand it, the scenario I described above is not resolved by CASSANDRA-6561, correct? (This scenario may not matter to most folks, which is totally fine, I just want to make sure that I understand.) Should I instead look into using the Thrift API to address this? Best regards, Clint On Tue, Feb 25, 2014 at 11:30 PM, Sylvain Lebresne wrote: > Sorry to interfere again here but CASSANDRA-5633 will not be picked up > because pretty much everything it was set to fix is fixed by > CASSANDRA-6561, this is *not* a syntax problem anymore. > > > On Wed, Feb 26, 2014 at 3:18 AM, Tupshin Harper wrote: > >> Unfortunately there is no option to vote for a "resolved" ticket, but if >> you can propose a better syntax that people agree on, you could probably >> get some fresh traction on it. >> >> -Tupshin >> On Feb 25, 2014 7:20 PM, "Clint Kelly" wrote: >> >>> Hi Tupshin, >>> >>> Thanks for your help! Unfortunately in my case, I will need to do a >>> compare and set in which the compare is against a value in a dynamic column. >>> >>> In general, I need to be able to do the following: >>> >>> - Check whether a given value exists in a dynamic column >>> - If so, perform some number of insertions / deletions for dynamic >>> columns in the same row (i.e., with the same partition key as the dynamic >>> column used for the compare) >>> >>> I think you are correct that I need >>> https://issues.apache.org/jira/browse/CASSANDRA-5633 to be >>> implemented. Is there any way to vote for that to get picked up again? :) >>> >>> Best regards, >>> Clint >>> >>> >>> >>> >>> >>> On Mon, Feb 24, 2014 at 2:32 PM, Tupshin Harper wrote: >>> >>>> Hi Clint, >>>> >>>> That does appear to be an omission in CQL3. It would be possible to >>>> simulate it by doing >>>> BEGIN BATCH >>>> UPDATE foo SET z = 10 WHERE x = 'a' AND y = 1 IF t= 2 AND z=10; >>>> UPDATE foo SET t = 5,z=6 where x = 'a' AND y = 4 >>>> APPLY BATCH; >>>> >>>> However, this does a redundant write to the first row if the condition >>>> holds, and I certainly wouldn't recommend doing that routinely. >>>> >>>> Alternatively, depending on your needs, you might be able to use a >>>> static column (coming with 2.0.6) as your conditional flag, as that column >>>> is shared by all rows in the partition. >>>> >>>> -Tupshin >>>> >>>> >>>> >>>> On Mon, Feb 24, 2014 at 3:57 PM, Clint Kelly wrote: >>>> >>>>> Hi Tupshin, >>>>> >>>>> Thanks for your help; I appreciate it. >>>>> >>>>> Could I do something like the following? >>>>> >>>>> Given the same table you started with: >>>>> >>>>> x | y | t | z >>>>> ---+---+---+---- >>>>> a | 1 | 2 | 10 >>>>> a | 2 | 2 | 20 >>>>> >>>>> I'd like to write a compare-and-set that does something like: >>>>> >>>>> "If there is a row with (x,y,t,z) = (a,1,2,10), then update/insert a >>>>> row with (x,y,t,z) = (a,3,4,5) and update/insert a row with (x,y,t,z) >>>>> = (a,4,5,6)." >>>>> >>>>> >>>>> I don't see how I could do this with what you outlined above---just >>>>> curious. It seems like what I describe above under the hood would be >>>>> a compare-and-(batch)-set on a single wide row, so it maybe is >>>>> possible with the Thrift API (I have to check). >>>>> >>>>> Thanks again! >>>>> >>>>> Best regards, >>>>> Clint >>>>> >>>>> On Sat, Feb 22, 2014 at 11:38 AM, Tupshin Harper >>>>> wrote: >>>>> > #5633 was actually closed because the static columns feature >>>>> > (https://issues.apache.org/jira/browse/CASSANDRA-6561) which has >>>>> been >>>>> > checked in to the 2.0 branch but is not yet part of a release (it >>>>> will be in >>>>> > 2.0.6). >>>>> > >>>>> > That feature will let you update multiple rows within a single >>>>> partition by >>>>> > doing a CAS write based on a static column shared by all rows within >>>>> the >>>>> > partition. >>>>> > >>>>> > Example extracted from the ticket: >>>>> > CREATE TABLE foo ( >>>>> > x text, >>>>> > y bigint, >>>>> > t bigint static, >>>>> > z bigint, >>>>> > PRIMARY KEY (x, y) ); >>>>> > >>>>> > insert into foo (x,y,t, z) values ('a', 1, 1, 10); >>>>> > insert into foo (x,y,t, z) values ('a', 2, 2, 20); >>>>> > >>>>> > select * from foo; >>>>> > >>>>> > x | y | t | z >>>>> > ---+---+---+---- >>>>> > a | 1 | 2 | 10 >>>>> > a | 2 | 2 | 20 >>>>> > (Note that both values of "t" are 2 because it is static) >>>>> > >>>>> > >>>>> > begin batch update foo set z = 1 where x = 'a' and y = 1; update >>>>> foo set z >>>>> > = 2 where x = 'a' and y = 2 if t = 4; apply batch; >>>>> > >>>>> > [applied] | x | y | t >>>>> > -----------+---+------+--- >>>>> > False | a | null | 2 >>>>> > >>>>> > (Both updates failed to apply because there was an unmet conditional >>>>> on one >>>>> > of them) >>>>> > >>>>> > select * from foo; >>>>> > >>>>> > x | y | t | z >>>>> > ---+---+---+---- >>>>> > a | 1 | 2 | 10 >>>>> > a | 2 | 2 | 20 >>>>> > >>>>> > >>>>> > begin batch update foo set z = 1 where x = 'a' and y = 1; update foo >>>>> set z = >>>>> > 2 where x = 'a' and y = 2 if t = 2; apply batch; >>>>> > >>>>> > [applied] >>>>> > ----------- >>>>> > True >>>>> > >>>>> > (both updates succeeded because the check on t succeeded) >>>>> > >>>>> > select * from foo; >>>>> > x | y | t | z >>>>> > ---+---+---+--- >>>>> > a | 1 | 2 | 1 >>>>> > a | 2 | 2 | 2 >>>>> > >>>>> > Hope this helps. >>>>> > >>>>> > -Tupshin >>>>> > >>>>> > >>>>> > >>>>> > On Fri, Feb 21, 2014 at 6:05 PM, DuyHai Doan >>>>> wrote: >>>>> >> >>>>> >> Hello Clint >>>>> >> >>>>> >> The Resolution status of the JIRA is set to "Later", probably the >>>>> >> implementation is not done yet. The JIRA was opened to discuss >>>>> about impl >>>>> >> strategy but nothing has been coded so far I guess. >>>>> >> >>>>> >> >>>>> >> >>>>> >> On Sat, Feb 22, 2014 at 12:02 AM, Clint Kelly < >>>>> clint.kelly@gmail.com> >>>>> >> wrote: >>>>> >>> >>>>> >>> Folks, >>>>> >>> >>>>> >>> Does anyone know how I can modify multiple rows at once in a >>>>> >>> lightweight transaction in CQL3? >>>>> >>> >>>>> >>> I saw the following ticket: >>>>> >>> >>>>> >>> https://issues.apache.org/jira/browse/CASSANDRA-5633 >>>>> >>> >>>>> >>> but it was not obvious to me from the comments how (or whether) >>>>> this >>>>> >>> got resolved. I also couldn't find anything in the DataStax >>>>> >>> documentation about how to perform these operations. >>>>> >>> >>>>> >>> I'm in particular interested in how to perform a compare-and-set >>>>> >>> operation that modifies multiple rows (with the same partition key) >>>>> >>> using the DataStax Java driver. >>>>> >>> >>>>> >>> Thanks! >>>>> >>> >>>>> >>> Best regards, >>>>> >>> Clint >>>>> >> >>>>> >> >>>>> > >>>>> >>>> >>>> >>> > --089e01634eeea97db804f357eae5 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thanks for your help everyone.

=
Sylvain, as I understand it, the scenario I described above is not re= solved by CASSANDRA-6561, correct?

(This scenario may not matt= er to most folks, which is totally fine, I just want to make sure that I un= derstand.)

Should I instead look into using the Thrift API to address this?<= br>
Best regards,
Clint



On Tue, Feb 25, 2014 at 11:30 PM, Sylva= in Lebresne <sylvain@datastax.com> wrote:
Sorry to interfere again he= re but CASSANDRA-5633 will not be picked up because pretty much everything = it was set to fix is fixed by CASSANDRA-6561, this is *not* a syntax proble= m anymore.


On Wed, Feb 26, 2014 at 3:18 AM, Tupshin= Harper <tupshin@tupshin.com> wrote:

Unfortunately there is no option to vote fo= r a "resolved" ticket, but if you can propose a better syntax tha= t people agree on, you could probably get some fresh traction on it.

-Tupshin

On Feb 25, 2014 7:20 PM, "Clint Kelly"= <clint.kelly= @gmail.com> wrote:
Hi Tupshin,

Thanks for your help!=A0 Unfortunately = in my case, I will need to do a compare and set in which the compare is aga= inst a value in a dynamic column.

In general, I need to be able to d= o the following:
  • Check whether a given value exists in a dynamic column
  • = If so, perform some number of insertions / deletions for dynamic columns in= the same row (i.e., with the same partition key as the dynamic column used= for the compare)

I think you are correct that I need https://issues.apache.o= rg/jira/browse/CASSANDRA-5633 to be implemented.=A0 Is there any way to= vote for that to get picked up again?=A0 :)

Best regards,
Clint






On Mon, Feb 24, 2014 at 2:32 PM, Tups= hin Harper <tupshin@tupshin.com> wrote:
Hi Clin= t,

That does appear to be an omission in CQL3. It would be pos= sible to simulate it by doing
BEGIN BATCH
=A0=A0=A0 UPDATE foo SET z =3D 10 WHERE x =3D 'a' A= ND y =3D 1 IF t=3D 2 AND z=3D10;
=A0=A0=A0 UPDATE foo SET t =3D 5,z=3D6 where x =3D 'a' AND y =3D 4 =
APPLY BATCH;

However, this does a redundant write to the first r= ow if the condition holds, and I certainly wouldn't recommend doing tha= t routinely.

Alternatively, depending on your needs, you might be able t= o use a static column (coming with 2.0.6) as your conditional flag, as that= column is shared by all rows in the partition.

-Tupshin



On Mon, Feb 24, 2014 at 3:57 PM, Clint Kelly <<= a href=3D"mailto:clint.kelly@gmail.com" target=3D"_blank">clint.kelly@gmail= .com> wrote:
Hi Tupshin,

Thanks for your help; I appreciate it.

Could I do something like the following?

Given the same table you started with:

x | y | t | z
---+---+---+----
=A0a | 1 | 2 | 10
=A0a | 2 | 2 | 20

I'd like to write a compare-and-set that does something like:

"If there is a row with (x,y,t,z) =3D (a,1,2,10), then update/insert a=
row with (x,y,t,z) =3D (a,3,4,5) and update/insert a row with (x,y,t,z)
=3D (a,4,5,6)."


I don't see how I could do this with what you outlined above---just
curious. =A0It seems like what I describe above under the hood would be
a compare-and-(batch)-set on a single wide row, so it maybe is
possible with the Thrift API (I have to check).

Thanks again!

Best regards,
Clint

On Sat, Feb 22, 2014 at 11:38 AM, Tupshin Harper <tupshin@tupshin.com> wrote:
> #5633 was actually closed =A0because the static columns feature
> (https://issues.apache.org/jira/browse/CASSANDRA-6561) whi= ch has been
> checked in to the 2.0 branch but is not yet part of a release (it will= be in
> 2.0.6).
>
> That feature will let you update multiple rows within a single partiti= on by
> doing a CAS write based on a static column shared by all rows within t= he
> partition.
>
> Example extracted from the ticket:
> CREATE TABLE foo (
> =A0 =A0 x text,
> =A0 =A0 y bigint,
> =A0 =A0 t bigint static,
> =A0 =A0 z bigint,
> PRIMARY KEY (x, y) );
>
> insert into foo (x,y,t, z) values ('a', 1, 1, 10);
> insert into foo (x,y,t, z) values ('a', 2, 2, 20);
>
> select * from foo;
>
> x | y | t | z
> ---+---+---+----
> =A0a | 1 | 2 | 10
> =A0a | 2 | 2 | 20
> (Note that both values of "t" are 2 because it is static) >
>
> =A0begin batch update foo set z =3D 1 where x =3D 'a' and y = =3D 1; update foo set z
> =3D 2 where x =3D 'a' and y =3D 2 if t =3D 4; apply batch;
>
> =A0[applied] | x | y =A0 =A0| t
> -----------+---+------+---
> =A0 =A0 =A0False | a | null | 2
>
> (Both updates failed to apply because there was an unmet conditional o= n one
> of them)
>
> select * from foo;
>
> =A0x | y | t | z
> ---+---+---+----
> =A0a | 1 | 2 | 10
> =A0a | 2 | 2 | 20
>
>
> begin batch update foo set z =3D 1 where x =3D 'a' and y =3D 1= ; update foo set z =3D
> 2 where x =3D 'a' and y =3D 2 if t =3D 2; apply batch;
>
> =A0[applied]
> -----------
> =A0 =A0 =A0 True
>
> (both updates succeeded because the check on t succeeded)
>
> select * from foo;
> x | y | t | z
> ---+---+---+---
> =A0a | 1 | 2 | 1
> =A0a | 2 | 2 | 2
>
> Hope this helps.
>
> -Tupshin
>
>
>
> On Fri, Feb 21, 2014 at 6:05 PM, DuyHai Doan <doanduyhai@gmail.com> wrote: >>
>> Hello Clint
>>
>> =A0The Resolution status of the JIRA is set to "Later", = probably the
>> implementation is not done yet. The JIRA was opened to discuss abo= ut impl
>> strategy but nothing has been coded so far I guess.
>>
>>
>>
>> On Sat, Feb 22, 2014 at 12:02 AM, Clint Kelly <clint.kelly@gmail.com> >> wrote:
>>>
>>> Folks,
>>>
>>> Does anyone know how I can modify multiple rows at once in a >>> lightweight transaction in CQL3?
>>>
>>> I saw the following ticket:
>>>
>>> =A0 =A0 https://issues.apache.org/jira/browse/CASSANDR= A-5633
>>>
>>> but it was not obvious to me from the comments how (or whether= ) this
>>> got resolved. =A0I also couldn't find anything in the Data= Stax
>>> documentation about how to perform these operations.
>>>
>>> I'm in particular interested in how to perform a compare-a= nd-set
>>> operation that modifies multiple rows (with the same partition= key)
>>> using the DataStax Java driver.
>>>
>>> Thanks!
>>>
>>> Best regards,
>>> Clint
>>
>>
>




--089e01634eeea97db804f357eae5--