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 D379A10C03 for ; Mon, 2 Dec 2013 10:11:16 +0000 (UTC) Received: (qmail 61049 invoked by uid 500); 2 Dec 2013 10:11:12 -0000 Delivered-To: apmail-cassandra-user-archive@cassandra.apache.org Received: (qmail 60880 invoked by uid 500); 2 Dec 2013 10:11:11 -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 60870 invoked by uid 99); 2 Dec 2013 10:11:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Dec 2013 10:11:10 +0000 X-ASF-Spam-Status: No, hits=1.7 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of rameshj1977@gmail.com designates 209.85.219.53 as permitted sender) Received: from [209.85.219.53] (HELO mail-oa0-f53.google.com) (209.85.219.53) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Dec 2013 10:11:04 +0000 Received: by mail-oa0-f53.google.com with SMTP id m1so12669865oag.26 for ; Mon, 02 Dec 2013 02:10:43 -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=EEYBj9XjEL/rsIStx87m0gXhDRPRfDFOrirf9tHK3k8=; b=HyBC8d2AbfUal/PD92/mNGeRcx9L05TP0lpC1klX7yIXmh6n9AZOD+qTgjBc/Tk2lR tGjjE52APPKYGZRTq2CIVJy0BWURQtJq2r+Q+x+8SRz0KXSV88w13iH7chw8qsuEx/s5 wH7NjyoYZjmEo/UGCDgn2r2R0nKOi26IcaCj5bh01ZAPM6n0ihjbq2NgRwqvuo67zqIi M1vrJgLjDgKBx/ln4YaXBnFKQd8XSM6pO/9368naywkndyYYQarnRP8SJXbaRdhx7s37 B0tnfeYWUPJBI7rmVmaHb8bu1Sn3RjohNFFFmQy37oE7bl6TPqIPje5LDzf2enUMVFXz +lyA== MIME-Version: 1.0 X-Received: by 10.182.255.137 with SMTP id aq9mr61394obd.80.1385979043182; Mon, 02 Dec 2013 02:10:43 -0800 (PST) Received: by 10.182.146.45 with HTTP; Mon, 2 Dec 2013 02:10:43 -0800 (PST) In-Reply-To: References: Date: Mon, 2 Dec 2013 15:40:43 +0530 Message-ID: Subject: Re: Sample Trigger Code to get inserted value From: J Ramesh Kumar To: user@cassandra.apache.org Content-Type: multipart/alternative; boundary=001a1134a71a88fdbe04ec8a64a2 X-Virus-Checked: Checked by ClamAV on apache.org --001a1134a71a88fdbe04ec8a64a2 Content-Type: text/plain; charset=ISO-8859-1 Finally I got it working... Below are the code snippet which will be useful for trigger users, public Collection augment(ByteBuffer key, ColumnFamily cf) { try { ByteBuffer id_bb = CompositeType.extractComponent(key, 0); UUID id=TimeUUIDType.instance.compose(id_bb); ByteBuffer data_key_bb = CompositeType.extractComponent(key, 1); String data_key=UTF8Type.instance.compose(data_key_bb); Iterator col_itr=cf.iterator(); Column ts_col=(Column)col_itr.next(); ByteBuffer time_bb=CompositeType.extractComponent(ts_col.name(),0); long time=(TimestampType.instance.compose(time_bb)).getTime(); Column data_bb=(Column)col_itr.next(); String data=UTF8Type.instance.compose(data_bb.value()); log(" id --> "+id.toString()); log(" data_key-->"+data_key); log(" time == "+time); log(" data == "+data); } catch (Exception e) { logger.warn("Exception ", e); } return null; } PS: Since I know my table format, I hardcoded the column comparator type. If we want to write generic trigger code, we can use cf.getComponentComparator()/getKeyValidator(). - Ramesh On Wed, Nov 27, 2013 at 5:10 PM, J Ramesh Kumar wrote: > Hi, > > I need your help on extract column names and values in the trigger augment > method. > > *Table Def :* > > create table dy_data ( > id timeuuid, > data_key text, > time timestamp, > data text, > primary key((id,data_key),time)) with clustering order by (time desc); > > public class ArchiveTrigger implements ITrigger { > public Collection augment(ByteBuffer key, ColumnFamily cf) { > try { > *// Below loop only has 2 columns ( one is "data" and another > one may be "time" but i am not sure, because i cannot get value. * > > for (Column cell : cf) { > * //Got Exception if I try to get column name* > String name = ByteBufferUtil.string(cell.name()); > * //Got only "data" column value and empty value for > another column may be "time"*. *If I try > ByteBufferUtil.toLong(cell.value()) it throws exception* > String value = ByteBufferUtil.string(cell.value()); > log(" name = " + name); > log(" value = " + value); > } > } catch (Exception e) { > logger.warn("Exception ", e); > } > return null; > } > } > > > I tried my best to search sample code in google. But failed. Please help > me with sample code. > > Thanks in advance. > > Regards, > Ramesh > --001a1134a71a88fdbe04ec8a64a2 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Finally I got it working...

Below are the code sn= ippet which will be useful for trigger users,

public Collection<RowMutation> augment(ByteBuffer key, Col=
umnFamily cf) {
        try {
            ByteBuffer id_bb =3D CompositeType.extractComponent(key, 0);
            UUID id=3DTimeUUIDType.instance.compose(id_bb);

            ByteBuffer data_key_bb =3D CompositeType.extractComponent(key, =
1);
            String data_key=3DUTF8Type.instance.compose(data_key_bb);


            Iterator col_itr=3Dcf.iterator();

            Column ts_col=3D(Column)col_itr.next();
            ByteBuffer time_bb=3DCompositeType.extractComponent(ts_col.name(),0);
            long time=3D(TimestampType.instance.compose(time_bb)).getTime()=
;


            Column data_bb=3D(Column)col_itr.next();
            String data=3DUTF8Type.instance.compose(data_bb.value());

            log(" id --> "+id.toString());
            log(" data_key-->"+data_key);
            log(" time =3D=3D "+time);
            log(" data =3D=3D "+data);
        } catch (Exception e) {
            logger.warn("Exception ", e);
        }
        return null;
    }

PS: Since I know my table format, I hardcoded the column comparator=20 type. If we want to write generic trigger code, we can use=20 cf.getComponentComparator()/getKeyValidator().


- Ramesh



On Wed, N= ov 27, 2013 at 5:10 PM, J Ramesh Kumar <rameshj1977@gmail.com><= /span> wrote:
Hi,

I need your help= on extract column names and values in the trigger augment method.
<= br> Table Def :

create table dy_data (
id timeuuid,
data_key text,
time= timestamp,
data=20 text,
primary key((id,data_key),time)) with clustering order by (time=20 desc);

public class ArchiveTrigger i= mplements ITrigger {
=A0 public Collection<RowMutation> augment(By= teBuffer key, ColumnFamily cf) {
=A0=A0=A0=A0=A0=A0=A0 try {
=A0 =A0 =A0 =A0 =A0 =A0 // Below loop onl= y has 2 columns ( one is "data" and another one may be "time= " but i am not sure, because i cannot get value. =A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 for (Column cell : cf= ) {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 //Got Exception if I try t= o get column name
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Stri= ng name =3D ByteBufferUtil.string(cell.name());
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= //Got only "data" column value and empty value for another colum= n may be "time". If I try ByteBufferUtil.toLong(cell.value= ()) it throws exception
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 String value =3D ByteBufferUt= il.string(cell.value());
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 l= og(" name =3D " + name);
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 log(" value =3D " + value);
=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0 }
=A0=A0=A0=A0=A0=A0=A0 } catch (Exception e) {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 logger.warn("Exception ", e);=A0=A0=A0=A0=A0=A0=A0 }
=A0=A0=A0=A0=A0=A0=A0 return null;
=A0=A0= =A0 }
}

I tried my best to search sample code = in google. But failed. Please help me with sample code.

Thanks in advance.

Regards,
Ramesh

--001a1134a71a88fdbe04ec8a64a2--